Skip to content

sources: add bottlerocket-crypto-provider crate#935

Open
sky1122 wants to merge 2 commits into
bottlerocket-os:developfrom
sky1122:br-crypto-provider
Open

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

Conversation

@sky1122

@sky1122 sky1122 commented May 27, 2026

Copy link
Copy Markdown
Contributor

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.

@sky1122 sky1122 marked this pull request as draft May 27, 2026 19:02
@sky1122 sky1122 force-pushed the br-crypto-provider branch 2 times, most recently 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

sky1122 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

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 thread sources/bottlerocket-crypto-provider/src/lib.rs Outdated
@sky1122 sky1122 force-pushed the br-crypto-provider branch from e5af7ed to bae9a1b Compare June 2, 2026 23:20
@sky1122

sky1122 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

force pushed to address feedback

@sky1122 sky1122 requested a review from ginglis13 June 16, 2026 16:31
@sky1122 sky1122 force-pushed the br-crypto-provider branch 2 times, most recently from 37c75e8 to a2e3990 Compare June 17, 2026 17:56
@sky1122

sky1122 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

forced pushed to turn on fips build and correct branch.

Comment thread sources/bottlerocket-crypto-provider/src/lib.rs Outdated
Comment thread sources/bottlerocket-crypto-provider/src/lib.rs Outdated
@sky1122 sky1122 force-pushed the br-crypto-provider branch from a2e3990 to 7469bb4 Compare June 17, 2026 18:38
sky1122 added 2 commits June 17, 2026 18:57
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.

Signed-off-by: Jingwei Wang <jweiw@amazon.com>
Signed-off-by: Jingwei Wang <jweiw@amazon.com>
@sky1122 sky1122 force-pushed the br-crypto-provider branch from 7469bb4 to de5e662 Compare June 17, 2026 19:02
@sky1122

sky1122 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

forced pushed to address feedback change fips_enabled . For pub fn provider() -> CryptoProvider, I decide to keep return with no result and default handle the edge case to return true because I think if something unexpected happens, use the more restrictive mode. Breaking the caller (panicking or returning error) would prevent the binary from starting, which is worse than falling back to FIPS ciphers.

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