Skip to content

sources: add bottlerocket-crypto-provider crate#935

Open
sky1122 wants to merge 1 commit into
bottlerocket-os:developfrom
sky1122:br-crypto-provider
Open

sources: add bottlerocket-crypto-provider crate#935
sky1122 wants to merge 1 commit into
bottlerocket-os:developfrom
sky1122:br-crypto-provider

Conversation

@sky1122
Copy link
Copy Markdown
Contributor

@sky1122 sky1122 commented May 27, 2026

Description of changes:
Add a centralized CryptoProvider crate that provides runtime FIPS detection and TLS algorithm selection for Bottlerocket Rust binaries.

When the kernel FIPS flag is enabled (/proc/sys/crypto/fips_enabled = 1), the provider restricts TLS to FIPS-approved algorithms only (AES-GCM cipher suites, P-256/P-384 key exchange). On non-FIPS systems, the full algorithm set is available.

This crate exposes three public functions:

  • fips_enabled() - detect kernel FIPS mode
  • provider() - return the appropriate CryptoProvider based on runtime detection
  • install_provider() - install the provider as the rustls global default

Testing done:
Testing with this PR and these two code chunks running on both fips/non-fips fedora host and test pass on both

 cargo test --features http -p tough --test http test_fips_crypto_provider_e2e             
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running tests/http.rs (target/debug/deps/http-e659a739e99ce22d)

running 1 test
test http_custom_provider::test_fips_crypto_provider_e2e ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out; finished in 0.00s

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Add a centralized CryptoProvider crate that provides runtime FIPS
detection and TLS algorithm selection for Bottlerocket Rust binaries.

When the kernel FIPS flag is enabled (/proc/sys/crypto/fips_enabled = 1),
the provider restricts TLS to FIPS-approved algorithms only (AES-GCM
cipher suites, P-256/P-384 key exchange). On non-FIPS systems, the full
algorithm set is available.

This crate exposes three public functions:
* fips_enabled() - detect kernel FIPS mode
* provider() - return the appropriate CryptoProvider based on runtime
  detection
* install_provider() - install the provider as the rustls global default

Signed-off-by: Jingwei Wang <jweiw@amazon.com>
@sky1122 sky1122 force-pushed the br-crypto-provider branch from d825cab to e5af7ed Compare May 27, 2026 23:35
@sky1122 sky1122 marked this pull request as ready for review May 27, 2026 23:39
@sky1122
Copy link
Copy Markdown
Contributor Author

sky1122 commented May 28, 2026

forced pushed to rebase to the latest and regenerated the Cargo.lock file

@sky1122 sky1122 requested a review from ginglis13 May 28, 2026 20:02
Comment on lines +76 to +78
let mode = if fips_enabled() { "FIPS" } else { "default" };
info!("Installing {} CryptoProvider", mode);
let _ = provider().install_default();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: fips_enabled is called twice here - once just for the log message, then again inside the provider() method.

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.

2 participants