-
Notifications
You must be signed in to change notification settings - Fork 722
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
fix: Validate received signature algorithm in EVP verify #4574
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43d6d2b
to
a5fdff1
Compare
maddeleine
reviewed
May 30, 2024
maddeleine
approved these changes
May 31, 2024
lrstewart
reviewed
May 31, 2024
lrstewart
approved these changes
Jun 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
It was discovered in #4545 that it's possible for a signature algorithm type to be disallowed in a security policy, yet still be accepted when verifying the signature content of the CertificateVerify message when the EVP signing APIs are enabled (when s2n-tls is in FIPS mode and is linked with an EVP-compatible libcrypto). However, no security policies currently disallow all signature algorithms of one type (i.e. removing ALL RSA signature algorithms or ALL ECDSA signature algorithms), so this isn't currently an issue.
This PR adds a check to the EVP verify path to ensure that the certificate matches the received signature scheme, similar to how the non-EVP verify code currently works.
Further description:
The first two bytes of the CertificateVerify message contain the signature scheme used to sign the subsequent signature content in the CertificateVerify message. When s2n-tls receives a CertificateVerify message, the indicated signature scheme is validated against the set security policy:
s2n-tls/tls/s2n_tls13_certificate_verify.c
Line 148 in 6f7058f
Normally, s2n-tls then validates that the signature algorithm in the received signature scheme matches the certificate type. For example, if an RSA_PSS certificate is received, s2n-tls validates that the signature algorithm is RSA_PSS:
s2n-tls/crypto/s2n_rsa_pss.c
Lines 79 to 83 in 6f7058f
s2n-tls similarly validates an ECDSA signature algorithm against the certificate type:
s2n-tls/crypto/s2n_ecdsa.c
Lines 113 to 116 in 6f7058f
However, when s2n-tls is operating in FIPS mode with an EVP-compatible libcrypto, all pkey verify operations route to the same s2n_evp_verify() function, which currently doesn't validate the signature algorithm against the certificate type. Additionally,
s2n_evp_verify()
doesn't use the signature algorithm in the received signature scheme to actually perform the verify operation. Rather, the certificate public key type is used.This allows for a scenario in which the server signs the CertificateVerify signature content with one signature algorithm, and lies about the signature algorithm used in the first two bytes of the CertificateVerify message. s2n-tls would successfully validate the incorrect signature scheme against the security policy, and then proceed use another, potentially disallowed signature algorithm in the verify operation.
The following example demonstrates the issue:
Note that this issue doesn't impact the hash algorithm restrictions in security policies, since the indicated hash algorithm is used by s2n-tls to generate the content to sign. So, if the server lies about the hash algorithm, the received signature content won't match the content generated by s2n-tls. A test for this already exists.
Call-outs:
None
Testing:
A new unit test was added to test the new signature algorithm check, and ensure that the behavior is the same between the EVP and non-EVP code paths.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.