-
Notifications
You must be signed in to change notification settings - Fork 739
feature: add support for configuring (but not yet using) ml-dsa certs #5263
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
Conversation
c7573f3
to
e28e94d
Compare
int type_hint = 0; | ||
POSIX_GUARD(s2n_stuffer_private_key_from_pem(key_in_stuffer, key_out_stuffer, &type_hint)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing "type" to "type_hint" isn't strictly necessary, but I think it makes the code much clearer. We're really just guessing at the type.
|
||
bool s2n_pkey_mldsa_supported() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if I should name this "s2n_mldsa_supported" instead, despite the name of this module.
/* For now, ML-DSA does not have a public value */ | ||
S2N_SIGNATURE_MLDSA, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm avoiding adding any publicly visible values (the S2N_TLS_SIGNATURE_ values are all defined in s2n.h) until this feature is complete.
#define S2N_MAX_TEST_PEM_SIZE 8192 | ||
#define S2N_MAX_TEST_PEM_SIZE 12000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The largest test ML-DSA file was like 11k.
crypto/s2n_openssl_x509.c
Outdated
* Note: this method may fail for ML-DSA-44 and ML-DSA-87, depending on the | ||
* version of AWS-LC. See https://github.com/aws/aws-lc/issues/2347 | ||
* In order to handle this bug, we intentionally do not check the return | ||
* value of OBJ_find_sigid_algs. Since OBJ_find_sigid_algs should only fail | ||
* if signature_nid is unsupported by the libcrypto, and we retrieve signature_nid | ||
* from the libcrypto, OBJ_find_sigid_algs should only fail for library bugs | ||
* like the linked issue. | ||
*/ | ||
RESULT_GUARD_OSSL(OBJ_find_sigid_algs(info->signature_nid, &info->signature_digest_nid, NULL), | ||
S2N_ERR_CERT_TYPE_UNSUPPORTED); | ||
OBJ_find_sigid_algs(info->signature_nid, &info->signature_digest_nid, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a PR out to fix the awslc bug: aws/aws-lc#2348
But even if I fix it, we won't be able to assume that we're building against a fixed version of awslc :/ So I think we're stuck with handling this case. If just ignoring the error isn't acceptable, I could instead skip the method call for the MLDSA nids, since we don't actually need it. That's a pretty ugly check though: I'll need to specifically list the MLDSA nids to skip. And it'll need an if/def since the nids don't exist in awslc before MLDSA support was added.
We could also ask awslc to bump their API version, and then gate MLDSA support on the newer API version. I'm not sure that's any better than just ignoring the bug and failing to load the cert though: in both cases, a customer would build s2n-tls with a version of awslc that they would reasonably expect supports MLDSA, but be unable to load an MLDSA cert. The only difference would be the "S2N_AWSLC_MLDSA_SUPPORT" feature flag printed during the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my only problem with this is that it doesn't seem like we should trust any returned signature_digest_nid if the call to OBJ_find_sigid_algs
fails. If we don't actually need this value anyway for ML-DSA, could we just not update info->signature_digest_nid
unless the call succeeds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm so like check for failure, but if the failure occurs, just explicitly set signature_digest_nid to 0 in case OBJ_find_sigid_algs set it to something else? I don't think that's super useful, but I'm probably biased by having looked at the implementation of OBJ_find_sigid_algs :P I can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so the current plan:
- Initially, follow Sam's suggestion and reset signature_digest_nid on failure, but otherwise ignore failures.
- Update AWSLC's API version: Bump AWSLC_API_VERSION to account for OBJ_find_sigid_algs bug aws-lc#2349
- Wait for the next AWSLC release (probably later this week)
- Rebuild our codebuild images
- Make ML-DSA support depend on the new API version and revert the changes to this logic.
crypto/s2n_openssl_x509.c
Outdated
* Note: this method may fail for ML-DSA-44 and ML-DSA-87, depending on the | ||
* version of AWS-LC. See https://github.com/aws/aws-lc/issues/2347 | ||
* In order to handle this bug, we intentionally do not check the return | ||
* value of OBJ_find_sigid_algs. Since OBJ_find_sigid_algs should only fail | ||
* if signature_nid is unsupported by the libcrypto, and we retrieve signature_nid | ||
* from the libcrypto, OBJ_find_sigid_algs should only fail for library bugs | ||
* like the linked issue. | ||
*/ | ||
RESULT_GUARD_OSSL(OBJ_find_sigid_algs(info->signature_nid, &info->signature_digest_nid, NULL), | ||
S2N_ERR_CERT_TYPE_UNSUPPORTED); | ||
OBJ_find_sigid_algs(info->signature_nid, &info->signature_digest_nid, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my only problem with this is that it doesn't seem like we should trust any returned signature_digest_nid if the call to OBJ_find_sigid_algs
fails. If we don't actually need this value anyway for ML-DSA, could we just not update info->signature_digest_nid
unless the call succeeds?
Just watching! Feel free to ping me regarding any questions around ML-DSA. |
Release Summary:
Resolved issues:
related to #5257
Description of changes:
I update s2n-tls to successfully parse and load ML-DSA certificates. It's mostly minor changes to the certificate-loading logic, but it touches a lot of different files so I wanted to keep it separate from the actual signing logic PR. I left the signing methods, which are triggered by s2n_pkey_match, as no-ops for now.
Testing:
I added a unit test that successfully loads all combinations of ML-DSA private + public keys.
The version of awslc in our CI is recent enough to support ML-DSA. You can see the "-- feature S2N_AWSLC_SUPPORTS_MLDSA: TRUE" message in awslc builds like this AddressSanitizer one.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.