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

Add support for AWS-LC to openssl and openssl-sys crates #1805

Merged
merged 12 commits into from
Mar 18, 2025

Conversation

skmcgrail
Copy link
Contributor

@skmcgrail skmcgrail commented Feb 1, 2023

This pull request adds support for AWS Libcrypto (AWS-LC). This is AWS's BoringSSL fork that has been developed with additional performance optimizations and cryptographic algorithm support. The work to integrate AWS-LC into these crates required minimal changes from the existing BoringSSL support.

There are two feature flags that are added depending on the use-case required by the end-consumer. The first feature is aws-lc which will depend on our standard AWS-LC sys crate bindings which is based off of tagged release's of AWS-LC's main branch. The other feature is aws-lc-fips which will utilize the FIPS version of our sys crate. This currently uses the fips-2022-11-02 branch of AWS-LC which corresponds to our AWS-LC-FIPS 2.0 module with this associated certificate and security policy.

@skmcgrail
Copy link
Contributor Author

Looks like I might have misjudged one of the BoringSSL function signatures, will fix that in a subsequent commit.

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch 2 times, most recently from 73e0334 to a775d10 Compare February 6, 2023 17:39
@skmcgrail
Copy link
Contributor Author

Hey @sfackler just curious if you've had a chance to consider this pull request? If there are concerns that you may have, or more detail on why we are looking to perform this level of integration please let me know and I would be more then willing to help address those. Thanks!

@Skepfyr
Copy link
Collaborator

Skepfyr commented Mar 12, 2023

How is AWS-LC versioned? How stable is it and how do the bindings line up? Please correct me if this instance is different but taking on a new flavour of OpenSSL makes every single PR harder to write and review because we have to consider this. BoringSSL is odd because it's entirely unstable, is that also true for AWS-LC?

@sfackler
Copy link
Owner

I had hoped that the OpenSSL-alike situation had stabilized a decade ago with the post-Heartbleed introduction of LibreSSL and BoringSSL. Unfortunately, in the last year or so it appears that both AWS and Alibaba have decided to create their own new forks (or forks of forks) in AWS-LC and BabaSSL and sought support for them in this library.

Frankly, this is a disappointing trend. The open source ecosystem exists in a robust form today because corporations find it more beneficial to contribute improvements back to upstream open source projects than to maintain their own independent forks. I certainly hope that AWS-LC exists purely as a staging ground for the floating set of patches that have not yet been upstreamed!

Whatever the shape of projects like AWS-LC and BabaSSL actually are, I see three general options for them with respect to rust-openssl:

  1. Those projects put in the effort to look enough like their upstream that openssl-sys is happy to link to them as-is.
  2. The teams maintaining the forks of OpenSSL maintain forks of this project.
  3. If the organizations managing the forks are not interested in dealing with this themselves, they can pay us to formally support their forks.

@theoparis
Copy link

theoparis commented Jun 13, 2024

How is AWS-LC versioned? How stable is it and how do the bindings line up? Please correct me if this instance is different but taking on a new flavour of OpenSSL makes every single PR harder to write and review because we have to consider this. BoringSSL is odd because it's entirely unstable, is that also true for AWS-LC?

Is this still being worked on? AWS-LC is supposed to be more stable than boringssl since it has release tags. I also find it helpful that the requirement for Go and Perl is optional in AWS-LC, as well as QUIC being supported.

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch from a775d10 to 3c18c05 Compare March 3, 2025 21:06
@alex
Copy link
Collaborator

alex commented Mar 3, 2025

I spoke with @skmcgrail the other day, and I think it makes sense for us to add support for aws-lc at this point. It's gained a fair bit of traction in other parts of the rust ecosystem (notably rustls), and so there's value in being able to use the same crypto library consistently.

Separately, I think if we raised our minimum OpenSSL/LibreSSL version, we'd be able to drop a ton of cfg() and reduce our overall maintenance burden.

I'm happy to review this, so let me know when its ready.

Copy link
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

A few comments, but mostly this looks ok.

In addition: Let's add this to CI so it doesn't regress

Comment on lines 27 to 28
aws-lc-sys = { version = "0", features = ["ssl"], optional = true }
aws-lc-fips-sys = { version = "0", features = ["ssl", "bindgen"], optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This effectively uses any 0.x version, even if they're not semver compatible?

I guess that's considered ok here because we're just using the bindings which will be stable across them?

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch 6 times, most recently from 389c9e9 to f6a8368 Compare March 12, 2025 01:30
@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch 3 times, most recently from 94410e5 to 00884aa Compare March 12, 2025 18:19
@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch from 00884aa to fdafb31 Compare March 12, 2025 18:23
@skmcgrail
Copy link
Contributor Author

skmcgrail commented Mar 12, 2025

Rebased and appeared to have broken some things, need to get in a bit more. Will ping this when it's ready to look at.

Alright looks like we just need to resolve a minor issues when building libssl for x86/i686. I have a PR in AWS-LC to address this: aws/aws-lc#2267

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch from 6e14170 to 71a9ac9 Compare March 14, 2025 20:48
@skmcgrail
Copy link
Contributor Author

All the checks are passing with our latest sys crate release, should be good for eyes again.

@alex
Copy link
Collaborator

alex commented Mar 14, 2025

Will add to my TODO list once I'm not sick, thanks.

Copy link
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

Very very close, final mile!

Before this is mergable, I want to make sure @sfackler has no objections, but modulo this last comment, this LGTM.

const NO_CHECKS = ffi::OCSP_NOCHECKS as c_ulong;
const TRUST_OTHER = ffi::OCSP_TRUSTOTHER as c_ulong;
const RESPID_KEY = ffi::OCSP_RESPID_KEY as c_ulong;
const NO_TIME = ffi::OCSP_NOTIME as c_ulong;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So the implication here is that ffi:: types don't match between aws-lc and other OpenSSL-variants?

Is that an issue for anything else? I guess not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These aren't types though but preprocessor define values so they are untyped. When generating the Rust bindings with bindgen we have the option to tell it what type should be assigned to these numerical macros: signed or unsigned. With unsigned appearing to be the default that bindgen selects upon reviewing the documentation. AWS-LC and BoringSSL sys crates both default to using the signed types when generating types for numerical macro constants. This is more inline with the behavior defined in the C99 standard for integer constants see 6.4.4.1 where a signed integer would be used first.

As BoringSSL does not support this OCSP functionality this subtlety hadn't been seen yet to date in this project. Which is why it is popping up now. Bindgen supports changing the type for a specific set of macro constant defines, but this is only supported programmatically and not exposed via the bindgen-cli. Thus making that a no-go at the moment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha.

Copy link
Collaborator

@alex alex left a comment

Choose a reason for hiding this comment

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

This LGTM to me. Pinging @sfackler to make sure he's ok too.

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch from cb2a15c to f40a401 Compare March 18, 2025 20:04
@alex
Copy link
Collaborator

alex commented Mar 18, 2025

FWIW, at this juncture I think it'd be much easier to merge this PR as-is and expand the exposed functionality in follow-up PRs.

@skmcgrail
Copy link
Contributor Author

Pushed one more commit to enable a few additional capabilities that we can technically support from the AWS-LC side. Added a few tests as well on the cipher side for some of the AES modes.

@skmcgrail skmcgrail requested a review from alex March 18, 2025 20:05
@alex
Copy link
Collaborator

alex commented Mar 18, 2025

Looks like CI is failing.

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch 2 times, most recently from 8c80c70 to 759b9f8 Compare March 18, 2025 20:18
@skmcgrail
Copy link
Contributor Author

Sad, the remaining failures appear to be around the test cases for AES-128-XTS and AES-256-XTS that I added. I assume there might be some API behavioral differences in the older versions of OpenSSL and for LibreSSL that don't align with how the tests are structured. I can try to investigate why that is happening and what can be changed. I added in the tests since this was a gap in coverage at the moment.

@alex
Copy link
Collaborator

alex commented Mar 18, 2025 via email

@skmcgrail skmcgrail force-pushed the aws-lc-support-final branch from 759b9f8 to 71a9ac9 Compare March 18, 2025 21:04
@alex alex merged commit dde9ffb into sfackler:master Mar 18, 2025
158 checks passed
@botovq
Copy link
Contributor

botovq commented Mar 18, 2025

Not sure if my comment is visible anywhere, so I repeat it here. That test breakage in CCM mode on old OpenSSL and LibreSSL is an old trap:

        let mut buf = vec![];
        ctx.cipher_update(&aad, None).unwrap();
        ctx.cipher_update_vec(&ct, &mut buf).unwrap();
        ctx.cipher_final_vec(&mut buf).unwrap();

EVP_DecryptFinal_ex() must not be called when decrypting in CCM mode. This is pointed out in
"Authenticated Decryption using CCM mode" in the old OpenSSL wiki. Skipping that ctx_cipher_final_vec() on line 902 for (what will be) LibreSSL 4.1.0 makes tests pass, so that should be easily handled with a cfg_if! skipping this for the affected versions.

@skmcgrail
Copy link
Contributor Author

Not sure if my comment is visible anywhere, so I repeat it here. That test breakage in CCM mode on old OpenSSL and LibreSSL is an old trap:

        let mut buf = vec![];
        ctx.cipher_update(&aad, None).unwrap();
        ctx.cipher_update_vec(&ct, &mut buf).unwrap();
        ctx.cipher_final_vec(&mut buf).unwrap();

EVP_DecryptFinal_ex() must not be called when decrypting in CCM mode. This is pointed out in "Authenticated Decryption using CCM mode" in the old OpenSSL wiki. Skipping that ctx_cipher_final_vec() on line 902 for (what will be) LibreSSL 4.1.0 makes tests pass, so that should be easily handled with a cfg_if! skipping this for the affected versions.

Thanks for tracking this down, very much appreciated. Will have a subsequent PR with that commit here shortly including this suggested fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants