-
Notifications
You must be signed in to change notification settings - Fork 62
Add build option for exposing self-test failure messages #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
WillChilds-Klein
merged 48 commits into
corretto:main
from
WillChilds-Klein:self-test-failure
Mar 7, 2025
Merged
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
71882bc
Break self tests by modifying AWS-LC
amirhosv d1a075a
Provide isFipsStatusOk to check if FIPS tests have passed or not
amirhosv d16e616
Updating fips-experimentation branch with main (#294)
amirhosv f274433
Revert "Only register LibCryptoRng by default in non-FIPS mode"
WillChilds-Klein e006dee
Use FIPS approved APIs to generate RSA key pairs (#301)
amirhosv 355b0dd
Merge branch 'main' into fips-experimentation
WillChilds-Klein 893b388
Fix spotless
WillChilds-Klein 6c7d677
Remove obsolete MacOS CI jobs
WillChilds-Klein 7c3672a
Merge branch 'fips-experimentation'
WillChilds-Klein 9bb0c6d
Clean up merge
WillChilds-Klein 9a05c8e
Merge remote-tracking branch 'aws/main' into self-test-failure
WillChilds-Klein 9be07aa
Add getFipsStatusError method + JNI helpers
WillChilds-Klein 72a0568
Cross-thread access caused JVM heap issues, use native error queue
WillChilds-Klein 427ee31
Duct tape for the temp AWS-LC dep hack
WillChilds-Klein 0323a8d
Execute FipsStatusTest on main test thread
WillChilds-Klein 0c5e4b5
Add explanatory note for ibid.
WillChilds-Klein 0cdac70
Update AWS-LC version
WillChilds-Klein 50c61fe
Merge remote-tracking branch 'aws/main' into self-test-failure
WillChilds-Klein d536459
Temporarily skip ML-DSA tests
WillChilds-Klein 599d1ae
Appease spotless
WillChilds-Klein 10187b1
Remove break-tests example
WillChilds-Klein 5183a70
Update README and CHANGELOG
WillChilds-Klein f1e2e62
Put callback stuff behind ACCP build flag
WillChilds-Klein 2a40997
Appease spotless, check isFipsSelfTestFailureNoAbort in getInstance
WillChilds-Klein d2b5953
Update relevant test scripts tests/ci/run_accp_* t handle new flag
WillChilds-Klein ea7c873
Specify ALLOW_FIPS_TEST_BREAK in CI test scripts
WillChilds-Klein 62ef27f
Fix AWS-LC callback build flag plumbing, test PWCT breakage
WillChilds-Klein b5b19a8
Rename NoAbort to SkipAbort
WillChilds-Klein 78a3b44
Small TODO cleanups
WillChilds-Klein ce894e3
Merge remote-tracking branch 'aws/main' into self-test-failure
WillChilds-Klein 13c9f3c
Rewrite string vec with pthread rwlock
WillChilds-Klein 946b4e2
Call abort() in default AWS_LC_fips_failure_callback
WillChilds-Klein 923ae48
Guard ML-DSA PWCT test with exp fips
WillChilds-Klein b7801e7
Appease spotless
WillChilds-Klein 1971c8b
Iterate the old fashioned way, GCC 4.1 doesnt like range
WillChilds-Klein 9a85112
Comment and documentation fix-ups
WillChilds-Klein 10503bd
PR feedback
WillChilds-Klein 1129dc3
Include vector header in fips_status.cpp
WillChilds-Klein 4caf24b
Fix vector ctor call
WillChilds-Klein f3c1fd5
Disable EdDSA PWCT, block until self-tests finish
WillChilds-Klein b34faca
Remove self test status check from isFipsStatusOk()
WillChilds-Klein 25eac43
Fix non-FIPS
WillChilds-Klein ef0ed12
Appease spotless
WillChilds-Klein 6d9a71a
Busy poll self test status in isFipsStatusOk
WillChilds-Klein aedf5be
Fix conflict
WillChilds-Klein ad531ff
Appease spotless
WillChilds-Klein ffd6bc7
Add back Ed25519 PWCT tests with temporary guards
WillChilds-Klein 4ce2164
Throw RuntimeCryptoException on self-test timeout
WillChilds-Klein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#include <cstdio> | ||
#include <functional> | ||
#include <jni.h> | ||
#include <vector> | ||
|
||
#include "string_vector.h" | ||
|
||
static AmazonCorrettoCryptoProvider::ConcurrentStringVector fipsStatusErrors(1024); | ||
|
||
// To have this symbol exported, one needs to modify the final-link.version and the CMakeLists.txt | ||
extern "C" void AWS_LC_fips_failure_callback(char const* message); | ||
|
||
#if defined(FIPS_SELF_TEST_SKIP_ABORT) | ||
void AWS_LC_fips_failure_callback(char const* message) | ||
{ | ||
WillChilds-Klein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const size_t char_limit = 128; | ||
if (strnlen(message, char_limit + 1) > char_limit) { | ||
fprintf(stderr, "AWS_LC_fips_failure_callback invoked with message message exceeding %lu chars\n", char_limit); | ||
return; | ||
} | ||
fprintf(stderr, "AWS_LC_fips_failure_callback invoked with message: '%s'\n", message); | ||
fipsStatusErrors.push_back(message); | ||
} | ||
#else | ||
void AWS_LC_fips_failure_callback(char const* message) | ||
{ | ||
fprintf(stderr, "AWS_LC_fips_failure_callback invoked with message: '%s'\n", message); | ||
abort(); | ||
} | ||
#endif | ||
|
||
extern "C" JNIEXPORT jobject JNICALL | ||
Java_com_amazon_corretto_crypto_provider_AmazonCorrettoCryptoProvider_getFipsSelfTestFailuresInternal( | ||
JNIEnv* env, jobject thisObj) | ||
{ | ||
std::vector<std::string> errors = fipsStatusErrors.to_std(); | ||
|
||
// Construct a Java ArrayList, get a handle for the |add| method | ||
jclass arrayListClass = env->FindClass("java/util/ArrayList"); | ||
if (arrayListClass == NULL) { | ||
abort(); | ||
} | ||
jmethodID constructor = env->GetMethodID(arrayListClass, "<init>", "()V"); | ||
if (constructor == NULL) { | ||
abort(); | ||
} | ||
jobject arrayList = env->NewObject(arrayListClass, constructor); | ||
if (arrayList == NULL) { | ||
abort(); | ||
} | ||
jmethodID addMethod = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); | ||
if (addMethod == NULL) { | ||
abort(); | ||
} | ||
|
||
// Copy the errors over to |arrayList| and clean up temporary local reference | ||
for (size_t i = 0; i < errors.size(); i++) { | ||
jstring javaString = env->NewStringUTF(errors[i].c_str()); | ||
env->CallVoidMethod(arrayList, addMethod, javaString); | ||
env->DeleteLocalRef(javaString); | ||
} | ||
|
||
return arrayList; | ||
} | ||
|
||
extern "C" JNIEXPORT int JNICALL | ||
Java_com_amazon_corretto_crypto_provider_AmazonCorrettoCryptoProvider_fipsStatusErrorCount(JNIEnv* env, jobject thisObj) | ||
{ | ||
return fipsStatusErrors.size(); | ||
} | ||
|
||
// TEST methods below | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_com_amazon_corretto_crypto_provider_test_NativeTestHooks_resetFipsStatus( | ||
JNIEnv*, jclass) | ||
{ | ||
fipsStatusErrors.clear(); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_amazon_corretto_crypto_provider_test_NativeTestHooks_callAwsLcFipsFailureCallback(JNIEnv*, jclass) | ||
{ | ||
AWS_LC_fips_failure_callback("called by a test"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#ifndef STRING_VECTOR_H | ||
#define STRING_VECTOR_H | ||
|
||
#include "compiler.h" | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <deque> | ||
#include <pthread.h> | ||
#include <string> | ||
|
||
namespace AmazonCorrettoCryptoProvider { | ||
|
||
class ConcurrentStringVector { | ||
private: | ||
std::deque<std::string> vec; | ||
const size_t limit; | ||
mutable pthread_rwlock_t lock; | ||
WillChilds-Klein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public: | ||
ConcurrentStringVector(size_t limit) | ||
: limit(limit) | ||
{ | ||
pthread_rwlock_init(&lock, nullptr); | ||
} | ||
|
||
~ConcurrentStringVector() { pthread_rwlock_destroy(&lock); } | ||
|
||
// Disable copy constructors | ||
ConcurrentStringVector(const ConcurrentStringVector&); | ||
ConcurrentStringVector& operator=(const ConcurrentStringVector&); | ||
|
||
void push_back(const std::string& value) | ||
{ | ||
pthread_rwlock_wrlock(&lock); | ||
if (vec.size() >= limit) { // If we're at the limit, pop FIFO | ||
vec.pop_front(); | ||
} | ||
vec.push_back(std::string(value)); | ||
pthread_rwlock_unlock(&lock); | ||
} | ||
|
||
void clear() | ||
{ | ||
pthread_rwlock_wrlock(&lock); | ||
vec.clear(); | ||
pthread_rwlock_unlock(&lock); | ||
} | ||
|
||
size_t size() const | ||
{ | ||
pthread_rwlock_rdlock(&lock); | ||
size_t vec_size = vec.size(); | ||
pthread_rwlock_unlock(&lock); | ||
return vec_size; | ||
} | ||
|
||
std::vector<std::string> to_std() const | ||
{ | ||
pthread_rwlock_rdlock(&lock); | ||
std::vector<std::string> out(vec.begin(), vec.end()); // Use copy constructor, no references | ||
pthread_rwlock_unlock(&lock); | ||
return out; | ||
} | ||
}; | ||
|
||
} // namespace AmazonCorrettoCryptoProvider | ||
|
||
#endif // STRING_VECTOR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
global: | ||
Java_*; | ||
AWS_LC_fips_failure_callback; | ||
JNI_*; | ||
hook_*; | ||
local: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.