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

Merged
merged 5 commits into from
Jan 23, 2025

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does Openssl-3-fips support the use of md5? Just want to make sure we won't need to add any of these logic back when we add support for openssl-3-fips

Copy link
Contributor Author

Choose a reason for hiding this comment

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

openssl-3.0-fips doesn't support the use of md5, or a couple other options. But openssl-3.0 also doesn't support enabling MD5 this way. There's no overlap between how openssl-3.0 does fips and how openssl-1.0.2 did fips. We can't reuse the openssl-1.0.2-fips logic, so it's cleaner to just tear it out where we find it. And this particular logic is way more complicated / deceptive than it needs to be anyway.

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

Copy link
Contributor

@jouho jouho Jan 22, 2025

Choose a reason for hiding this comment

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

Since we are here, can we also update this comment to reflect the current behavior?
The handshake MD5 hash state will fail the s2n_hash_is_available() check since MD5 is not permitted in FIPS mode is no longer correct

/* The handshake MD5 hash state will fail the s2n_hash_is_available() check
* since MD5 is not permitted in FIPS mode. This check will not be used as
* the handshake MD5 hash state is specifically used by the TLS 1.0 and TLS 1.1
* PRF, which is required to comply with the TLS 1.0 and 1.1 RFCs and is approved
* as per NIST Special Publication 800-52 Revision 1.
*/

tests/unit/s2n_ecdsa_test.c Outdated Show resolved Hide resolved
@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
crypto/s2n_hash.c Show resolved Hide resolved
tests/unit/s2n_ecdsa_test.c Outdated Show resolved Hide resolved
Comment on lines +200 to +202
/* Re-initialize hashes for remaining tests */
EXPECT_SUCCESS(s2n_hash_init(&hash_one, S2N_HASH_SHA512));
EXPECT_SUCCESS(s2n_hash_init(&hash_two, S2N_HASH_SHA512));
Copy link
Contributor Author

@lrstewart lrstewart Jan 22, 2025

Choose a reason for hiding this comment

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

This test just kept using the hashes initialized to whatever hash algorithm was set last in the loop above, which just happens to be sha512 (the md5+sha1 was previously skipped). I kept the sha512 "choice", but made it explicit.

Comment on lines +186 to +187
EXPECT_FAILURE_WITH_ERRNO(sign_result, S2N_ERR_HASH_INVALID_ALGORITHM);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of just skipping the md5 algorithms, I checked that they really aren't supported so that we can't lose valid coverage.

@lrstewart lrstewart requested a review from goatgoose January 22, 2025 21:14
@lrstewart lrstewart added this pull request to the merge queue Jan 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 22, 2025
@lrstewart lrstewart added this pull request to the merge queue Jan 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 22, 2025
@lrstewart lrstewart added this pull request to the merge queue Jan 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 22, 2025
@lrstewart lrstewart enabled auto-merge January 22, 2025 22:53
@lrstewart lrstewart added this pull request to the merge queue Jan 23, 2025
Merged via the queue into aws:main with commit 8d521fc Jan 23, 2025
44 checks passed
@lrstewart lrstewart deleted the openssl3fips_hash_1 branch January 23, 2025 03:36
lrstewart added a commit to lrstewart/s2n that referenced this pull request Jan 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 24, 2025
CarolYeh910 pushed a commit to CarolYeh910/s2n-tls that referenced this pull request Jan 24, 2025
CarolYeh910 pushed a commit to CarolYeh910/s2n-tls that referenced this pull request Jan 24, 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.

3 participants