-
Notifications
You must be signed in to change notification settings - Fork 125
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
Make AWS_LC_fips_failure_callback optional in builds with AWSLC_FIPS_FAILURE_CALLBACK #2266
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear to me which path in the test is for the case when the build flag AWSLC_FIPS_FAILURE_CALLBACK is set but the callback is undefined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The callback is only defined in crypto_test, so ssl_test, test_fips, and bssl don't have the callback defined. This is why I was only running crypto_test before: the other tests/executables didn't have the callback defined and if you tried to call them they would abort because the callback was previosuly required. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,86 @@ set -ex | |
# SPDX-License-Identifier: Apache-2.0 OR ISC | ||
source tests/ci/common_posix_setup.sh | ||
|
||
original_test="${BUILD_ROOT}/crypto/crypto_test" | ||
broken_test="${BUILD_ROOT}/crypto/crypto_test_broken" | ||
|
||
# By default the test should pass | ||
$original_test --gtest_filter=FIPSCallback.PowerOnSelfTests | ||
$original_test --gtest_filter=FIPSCallback.PWCT | ||
|
||
# Break the tests | ||
KATS=$(go run "${SRC_ROOT}/util/fipstools/break-kat.go" --list-tests) | ||
for kat in $KATS; do | ||
go run "${SRC_ROOT}/util/fipstools/break-kat.go" "$original_test" "$kat" > "$broken_test" | ||
chmod +x "$broken_test" | ||
export FIPS_CALLBACK_TEST_EXPECTED_FAILURE="$kat" | ||
# When a callback is defined AWS-LC will not abort and the test should exit successfully | ||
$broken_test --gtest_filter=FIPSCallback.PowerOnSelfTests | ||
unset FIPS_CALLBACK_TEST_EXPECTED_FAILURE | ||
done | ||
|
||
for TEST in RSA_PWCT ECDSA_PWCT EDDSA_PWCT MLKEM_PWCT MLDSA_PWCT; do | ||
export FIPS_CALLBACK_TEST_EXPECTED_FAILURE="${TEST}" | ||
export BORINGSSL_FIPS_BREAK_TEST="${TEST}" | ||
$original_test --gtest_filter=FIPSCallback.PWCT | ||
done | ||
# This test file is designed to replicate the internal FIPS callback build defined in the build-glue package | ||
|
||
# This should follow AWS-LC-Build-GLue/bin/fips_tests.sh maybe_run_fips_tests | ||
function maybe_run_fips_tests() { | ||
expect_fips_mode=1 | ||
module_status=$("${BUILD_ROOT}/tool/bssl" isfips) | ||
[[ "${expect_fips_mode}" == "${module_status}" ]] || { | ||
echo >&2 "FIPS Mode validation failed." | ||
exit 1 | ||
} | ||
# Mainline AWS-LC does not have the CAVP tests anymore so only run the test_fips branch | ||
"${BUILD_ROOT}/util/fipstools/test_fips" | ||
} | ||
|
||
# This should follow AWS-LC-Build-GLue/bin/fips_tests.sh maybe_run_fips_break_tests | ||
function maybe_run_fips_break_tests() { | ||
break_kat_executable="${BUILD_ROOT}/break-kat" | ||
pushd "${SRC_ROOT}" | ||
go build -o "$break_kat_executable" "./util/fipstools/break-kat.go" | ||
"$break_kat_executable" -list-tests | ||
|
||
working_bssl="${BUILD_ROOT}/tool/bssl" | ||
broken_bssl="${BUILD_ROOT}/tool/brokenbssl" | ||
"$working_bssl" isfips | ||
|
||
# This breaks a local copy of bssl that will not be included in the build artifacts | ||
"$break_kat_executable" "$working_bssl" DRBG >"$broken_bssl" | ||
chmod +x "$broken_bssl" | ||
if ! ("$broken_bssl" isfips 2>&1 >/dev/null || true) | | ||
grep -q "DRBG"; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should you do a |
||
echo "Broken bssl did not mention DRBG failure in startup" | ||
exit 1 | ||
fi | ||
popd | ||
} | ||
|
||
function run_all_break_tests() { | ||
original_test="${BUILD_ROOT}/crypto/crypto_test" | ||
broken_test="${BUILD_ROOT}/crypto/crypto_test_broken" | ||
|
||
# By default the test should pass | ||
$original_test --gtest_filter=FIPSCallback.PowerOnSelfTests | ||
$original_test --gtest_filter=FIPSCallback.PWCT | ||
|
||
# Break the tests | ||
KATS=$(go run "${SRC_ROOT}/util/fipstools/break-kat.go" --list-tests) | ||
for kat in $KATS; do | ||
go run "${SRC_ROOT}/util/fipstools/break-kat.go" "$original_test" "$kat" > "$broken_test" | ||
chmod +x "$broken_test" | ||
export FIPS_CALLBACK_TEST_EXPECTED_FAILURE="$kat" | ||
# When a callback is defined AWS-LC will not abort and the test should exit successfully | ||
$broken_test --gtest_filter=FIPSCallback.PowerOnSelfTests | ||
unset FIPS_CALLBACK_TEST_EXPECTED_FAILURE | ||
done | ||
|
||
for TEST in RSA_PWCT ECDSA_PWCT EDDSA_PWCT MLKEM_PWCT MLDSA_PWCT; do | ||
export FIPS_CALLBACK_TEST_EXPECTED_FAILURE="${TEST}" | ||
export BORINGSSL_FIPS_BREAK_TEST="${TEST}" | ||
$original_test --gtest_filter=FIPSCallback.PWCT | ||
unset FIPS_CALLBACK_TEST_EXPECTED_FAILURE | ||
unset BORINGSSL_FIPS_BREAK_TEST | ||
done | ||
|
||
} | ||
|
||
echo "Testing AWS-LC static breakable build with custom callback and Jitter enabled" | ||
build_and_test -DFIPS=1 \ | ||
-DCMAKE_C_FLAGS="-DBORINGSSL_FIPS_BREAK_TESTS -DAWSLC_FIPS_FAILURE_CALLBACK" \ | ||
-DCMAKE_CXX_FLAGS="-DAWSLC_FIPS_FAILURE_CALLBACK" \ | ||
-DENABLE_FIPS_ENTROPY_CPU_JITTER=1 | ||
|
||
maybe_run_fips_tests | ||
maybe_run_fips_break_tests | ||
run_all_break_tests | ||
|
||
echo "Testing AWS-LC static build with custom callback and Jitter enabled" | ||
build_and_test -DFIPS=1 \ | ||
-DCMAKE_C_FLAGS="-DAWSLC_FIPS_FAILURE_CALLBACK" \ | ||
-DCMAKE_CXX_FLAGS="-DAWSLC_FIPS_FAILURE_CALLBACK" \ | ||
-DENABLE_FIPS_ENTROPY_CPU_JITTER=1 | ||
|
||
maybe_run_fips_tests | ||
# Can't run maybe_run_fips_break_tests or run_all_break_tests since they require BORINGSSL_FIPS_BREAK_TESTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the documentation here to indicate that a failure (even in FIPS mode) might be ignored by the callback. I.e., the failure doesn't necessarily "prevent any further cryptographic operations by the current process".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it, I was leaving it implied because to build AWS-LC in FIPS mode you can't specify the flag to turn the callback on. But I can add something explaining this behavior.