Skip to content

Commit

Permalink
add test for supported libcrypto
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Nov 26, 2024
1 parent 4a0f1a6 commit 6be1cfc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crypto/s2n_libcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ static S2N_RESULT s2n_libcrypto_validate_expected_version_number(void)
#endif

/* Attempt to detect if the libcrypto is OpenSSL.
*
* This check might need to be updated if s2n-tls adds support for a new
* libcrypto.
*
* Since several libcrypto implementations (such as BoringSSL and AWS-LC) are
* ABI compatible forks of OpenSSL, detecting OpenSSL is done by checking the
* absence of other known libcrypto variants.
*
* Note: This check needs to be updated if s2n-tls adds support for a new
* libcrypto.
*/
bool s2n_libcrypto_is_openssl()
{
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/s2n_build_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ S2N_RESULT s2n_test_lowercase_copy(const char *input, char *destination, size_t
return S2N_RESULT_OK;
}

S2N_RESULT s2n_check_supported_libcrypto(const char *s2n_libcrypto)
{
RESULT_ENSURE_REF(s2n_libcrypto);

/* List of supported libcrypto variants we test with */
const char *supported_libcrypto[] = {
"awslc",
"awslc-fips",
"awslc-fips-2022",
"boringssl",
"libressl",
"openssl-1.0.2",
"openssl-1.0.2-fips",
"openssl-1.1.1",
"openssl-3.0"
};

for (size_t i = 0; i < s2n_array_len(supported_libcrypto); i++) {
if (strcmp(s2n_libcrypto, supported_libcrypto[i]) == 0) {
return S2N_RESULT_OK;
}
}

/* Testing with an unexpected libcrypto. */
return S2N_RESULT_ERROR;
}

int main()
{
BEGIN_TEST();
Expand Down Expand Up @@ -131,6 +158,15 @@ int main()
}
};

/* Ensure we are testing with supported libcryto variants.
*
* We might need to update s2n_libcrypto_is_openssl() when adding support
* for a new libcrypto.
*/
{
EXPECT_OK(s2n_check_supported_libcrypto(s2n_libcrypto));
};

END_TEST();
return 0;
}

0 comments on commit 6be1cfc

Please sign in to comment.