Skip to content
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

Enforce FIPS callback is only enabled for static builds #2241

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,18 @@ if(FIPS)
endif()

if(NOT BUILD_SHARED_LIBS AND NOT (NOT WIN32 AND NOT APPLE))
message(FATAL_ERROR "Static FIPS build of AWS-LC is suported only on Linux")
message(FATAL_ERROR "Static FIPS build of AWS-LC is supported only on Linux")
endif()

if(WIN32 AND CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
message(FATAL_ERROR "Windows Debug build is not supported with FIPS, use Release or RelWithDebInfo")
endif()

string(REGEX MATCH "(^| )-DAWSLC_FIPS_FAILURE_CALLBACK($| )" FIPS_CALLBACK_ENABLED "${CMAKE_C_FLAGS}")
if(FIPS_CALLBACK_ENABLED AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "AWSLC_FIPS_FAILURE_CALLBACK only supported with the static library build of AWS-LC")
endif ()

add_definitions(-DBORINGSSL_FIPS)
if(FIPS_BREAK_TEST)
add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
Expand Down
6 changes: 1 addition & 5 deletions crypto/fips_callback_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

#if defined(__ELF__) && defined(__GNUC__)

#include <gtest/gtest.h>
#include <openssl/crypto.h>
#include <openssl/curve25519.h>
Expand All @@ -15,7 +13,7 @@
#include "internal.h"

extern "C" {
OPENSSL_EXPORT void AWS_LC_fips_failure_callback(const char* message);
void AWS_LC_fips_failure_callback(const char* message);
}

int callback_call_count = 0;
Expand Down Expand Up @@ -164,5 +162,3 @@ TEST(FIPSCallback, PWCT) {
}
EVP_PKEY_free(dsa_raw);
}

#endif
2 changes: 1 addition & 1 deletion crypto/fipsmodule/ec/ec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ TEST(ECTest, SmallGroupOrder) {
#else
// AWSLCAndroidTestRunner does not take tests that do |ASSERT_DEATH| very well.
// GTEST issue: https://github.com/google/googletest/issues/1496.
#if !defined(OPENSSL_ANDROID)
#if !defined(OPENSSL_ANDROID) && !defined(AWSLC_FIPS_FAILURE_CALLBACK)

TEST(ECDeathTest, SmallGroupOrderAndDie) {
// Make a P-224 key and corrupt the group order to be small in order to fail
Expand Down
5 changes: 4 additions & 1 deletion tests/ci/run_fips_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ if static_linux_supported || static_openbsd_supported; then
fips_build_and_test -DCMAKE_BUILD_TYPE=Release

echo "Testing AWS-LC static breakable build with custom callback enabled"
run_build -DFIPS=1 -DCMAKE_C_FLAGS="-DBORINGSSL_FIPS_BREAK_TESTS -DAWSLC_FIPS_FAILURE_CALLBACK"
run_build -DFIPS=1 \
-DCMAKE_C_FLAGS="-DBORINGSSL_FIPS_BREAK_TESTS -DAWSLC_FIPS_FAILURE_CALLBACK" \
-DCMAKE_CXX_FLAGS="-DAWSLC_FIPS_FAILURE_CALLBACK"
./test_build_dir/crypto/crypto_test
./tests/ci/run_fips_callback_tests.sh

echo "Testing AWS-LC static breakable release build"
Expand Down
10 changes: 10 additions & 0 deletions tool/tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@

#include "internal.h"

#if defined(AWSLC_FIPS_FAILURE_CALLBACK)
extern "C" {
void AWS_LC_fips_failure_callback(const char* message);
}

void AWS_LC_fips_failure_callback(const char* message) {
fprintf(stderr, "FIPS failure:\n%s", message);
}
#endif

static bool version(const std::vector<std::string> &args) {
printf("%s\n", AWSLC_VERSION_NUMBER_STRING);
return true;
Expand Down
Loading