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

refactor: remove openssl-1.0.2-fips 'allow md5' logic #5048

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Jan 17, 2025

Release Summary:

Resolved issues:

related to #5045. We need to cleanup the old mess before we add a new mess.

Description of changes:

I remove the s2n_hash_allow_md5_for_fips, s2n_digest_is_md5_allowed_for_fips, and s2n_digest_allow_md5_for_fips methods because after the removal of openssl-1.0.2-fips support, they're not actually doing anything. I explain more in in-line comments, but:

  • s2n_hash_allow_md5_for_fips and s2n_digest_allow_md5_for_fips are a no-op for every libcrypto except openssl-1.0.2-fips
  • s2n_digest_is_md5_allowed_for_fips is mostly just used to gate calls to *_allow_md5_for_fips

Call-outs:

if you search for the removed methods, you'll still find references in the CBMC proofs. To keep this PR reviewable, I'm going to clean those up as a follow-up, since they don't affect testing.

Testing:

Existing tests continue to pass. I only needed to update one unit test, and I explain why in-line.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Jan 17, 2025
@lrstewart lrstewart force-pushed the openssl3fips_hash_1 branch 2 times, most recently from 61a6c2a to 2e4811b Compare January 18, 2025 00:20
@lrstewart lrstewart force-pushed the openssl3fips_hash_1 branch from 2e4811b to 9bfe1fa Compare January 18, 2025 00:53
@lrstewart lrstewart marked this pull request as ready for review January 18, 2025 01:23
Comment on lines -29 to -34
S2N_ERROR_IF(!s2n_is_in_fips_mode() || (evp_digest->ctx == NULL), S2N_ERR_ALLOW_MD5_FOR_FIPS_FAILED);

#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC)
EVP_MD_CTX_set_flags(evp_digest->ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
#endif
return S2N_SUCCESS;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This translates to "if openssl+fips, call an API to allow md5". With the removal of openssl-1.0.2-fips, we no longer support openssl+fips, and this is a no-op. I've removed it everywhere it appears.

Comment on lines -40 to -51
*out = false;
#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC)
if (s2n_is_in_fips_mode() && evp_digest && evp_digest->ctx && EVP_MD_CTX_test_flags(evp_digest->ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)) {
/* s2n is in FIPS mode and the EVP digest allows MD5. */
*out = true;
}
#else
if (s2n_is_in_fips_mode()) {
/* If s2n is in FIPS mode and built with AWS-LC or BoringSSL, there are no flags to check in the EVP digest to allow MD5. */
*out = true;
}
#endif
Copy link
Contributor Author

@lrstewart lrstewart Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's a bit trickier. It roughly translates to:

if not fips: false
If openssl+fips: maybe true
If awslc+fips: true

So with the removal of openssl+fips via openssl-1.0.2-fips, this method boils down to "is fips?".

We only use this method for two purposes (see search):

Comment on lines +18 to +20
/*
* TODO: update all CBMC proofs that depend on this file, then delete.
*/
Copy link
Contributor Author

@lrstewart lrstewart Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I delete this file, I have to update ALL of the s2n_hash CBMC proofs because they all declare it as a source file. It's unnecessary noise, so I'd prefer to do it in a follow-up PR: fe97ffa

Comment on lines -116 to -117
/* return false if in FIPS mode, as MD5 algs are not available in FIPS mode. */
return !s2n_is_in_fips_mode();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not really true even before this change. You could use md5 with fips in awslc, just not in openssl-1.0.2. So whenever we checked s2n_hash_is_available and got "false" because of fips, we'd then check s2n_digest_is_md5_allowed_for_fips and get "true", overriding the original "false". I'm just skipping straight to the final "true".

You can confirm the limited non-test usage of this method: https://github.com/search?q=repo%3Aaws%2Fs2n-tls+s2n_hash_is_available+-path%3A*tests%2Funit%2F*.c&type=code

Comment on lines +167 to +170
if (hash_alg == S2N_HASH_MD5 || hash_alg == S2N_HASH_MD5_SHA1) {
/* MD5 is only used for <TLS1.2, which does not support ECDSA */
continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only test I had to update. Before it was relying on s2n_hash_is_available being "false" for MD5 + fips when using fips, but the real limitation is from the EVP signing test after the hashes:

static S2N_RESULT s2n_evp_signing_validate_hash_alg(s2n_signature_algorithm sig_alg, s2n_hash_algorithm hash_alg)
{
switch (hash_alg) {
case S2N_HASH_NONE:
case S2N_HASH_MD5:
/* MD5 alone is never supported */
RESULT_BAIL(S2N_ERR_HASH_INVALID_ALGORITHM);
break;
case S2N_HASH_MD5_SHA1:
/* Only RSA supports MD5+SHA1.
* This should not be a problem, as we only allow MD5+SHA1 when
* falling back to TLS1.0 or 1.1, which only support RSA.
*/
RESULT_ENSURE(sig_alg == S2N_SIGNATURE_RSA, S2N_ERR_HASH_INVALID_ALGORITHM);
break;
default:
break;
}
/* Hash algorithm must be recognized and supported by EVP_MD */
RESULT_ENSURE(s2n_hash_alg_to_evp_md(hash_alg) != NULL, S2N_ERR_HASH_INVALID_ALGORITHM);
return S2N_RESULT_OK;
}

@lrstewart lrstewart requested review from goatgoose and jouho January 18, 2025 01:25
lrstewart added a commit to lrstewart/s2n that referenced this pull request Jan 18, 2025
lrstewart added a commit to lrstewart/s2n that referenced this pull request Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant