Skip to content

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Apr 22, 2025

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.

@github-actions github-actions bot added the s2n-core team label Apr 22, 2025
@lrstewart lrstewart force-pushed the mldsa_1b_3 branch 4 times, most recently from c7573f3 to e28e94d Compare April 22, 2025 06:06
Comment on lines +110 to +111
int type_hint = 0;
POSIX_GUARD(s2n_stuffer_private_key_from_pem(key_in_stuffer, key_out_stuffer, &type_hint));
Copy link
Contributor Author

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.

Comment on lines +20 to +21

bool s2n_pkey_mldsa_supported()
Copy link
Contributor Author

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.

Comment on lines +34 to +35
/* For now, ML-DSA does not have a public value */
S2N_SIGNATURE_MLDSA,
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Comment on lines 120 to 128
* 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);
Copy link
Contributor Author

@lrstewart lrstewart Apr 22, 2025

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

  1. Initially, follow Sam's suggestion and reset signature_digest_nid on failure, but otherwise ignore failures.
  2. Update AWSLC's API version: Bump AWSLC_API_VERSION to account for OBJ_find_sigid_algs bug aws-lc#2349
  3. Wait for the next AWSLC release (probably later this week)
  4. Rebuild our codebuild images
  5. Make ML-DSA support depend on the new API version and revert the changes to this logic.

@lrstewart lrstewart marked this pull request as ready for review April 22, 2025 07:22
Comment on lines 120 to 128
* 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);
Copy link
Contributor

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?

@lrstewart lrstewart requested a review from goatgoose April 22, 2025 19:01
@jakemas
Copy link
Contributor

jakemas commented Apr 22, 2025

Just watching! Feel free to ping me regarding any questions around ML-DSA.

@lrstewart lrstewart added this pull request to the merge queue Apr 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2025
@lrstewart lrstewart added this pull request to the merge queue Apr 23, 2025
Merged via the queue into aws:main with commit 9fd38bd Apr 23, 2025
46 checks passed
@lrstewart lrstewart deleted the mldsa_1b_3 branch April 23, 2025 21:58
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.

4 participants