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

feat[bindings]: fips feature flag #4527

Merged
merged 10 commits into from
May 1, 2024
Merged

feat[bindings]: fips feature flag #4527

merged 10 commits into from
May 1, 2024

Conversation

toidiu
Copy link
Contributor

@toidiu toidiu commented Apr 26, 2024

Description of changes:

This PR adds a new fips feature flag which builds the bindings in FIPS mode. We also exposes the underlying C function to retrieve the fips_mode() so Applications can check their FIPS status at runtime.

aws-lc-rs exposes a fips feature flag, which can be set to use aws-lc in FIPS mode. The changes in this PR simply propagate the fips flag down to aws-lc-rs so that s2n-tls is built with a FIPS compliant libcrypto.

Testing:

Added testing to ensure s2n-tls correctly enters FIPS mode when built with aws-lc-rs with fips enabled

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 26, 2024
@toidiu toidiu changed the title feat[bindings]: fips feature feat[bindings]: fips feature flag Apr 26, 2024
@toidiu toidiu marked this pull request as ready for review April 26, 2024 23:38
if #[cfg(feature = "fips")] {
assert_eq!(init::fips_mode().unwrap(), FipsMode::Enabled);
} else {
assert_eq!(init::fips_mode().unwrap(), FipsMode::Disabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it safe to make this disabled assertion? Couldn't someone use the aws-lc-rs FIPS feature flag to enable FIPS mode, rather than the s2n-tls feature flag? In this case, we wouldn't expect the FIPS feature, but we would still be in FIPS mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If someone enables the fips feature flag in aws-lc-rs, but not in s2n-tls then I would consider that odd behavior. At that point this test might actually help them catch the discrepancy and either enable/disable fips for their application.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it, okay. I guess I was thinking that someone might have aws-lc-rs as a direct dependency in addition to s2n-tls, or have multiple dependencies with an aws-lc-rs dependency, in which case just setting the fips flag for aws-lc-rs might make sense. But if this would be a strange thing to do, and they definitely should instead be setting the s2n-tls feature flag, then the test makes sense.

.github/workflows/ci_rust.yml Show resolved Hide resolved
.github/workflows/ci_rust.yml Show resolved Hide resolved
@toidiu toidiu requested a review from goatgoose April 29, 2024 18:53
if #[cfg(feature = "fips")] {
assert_eq!(init::fips_mode().unwrap(), FipsMode::Enabled);
} else {
assert_eq!(init::fips_mode().unwrap(), FipsMode::Disabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it, okay. I guess I was thinking that someone might have aws-lc-rs as a direct dependency in addition to s2n-tls, or have multiple dependencies with an aws-lc-rs dependency, in which case just setting the fips flag for aws-lc-rs might make sense. But if this would be a strange thing to do, and they definitely should instead be setting the s2n-tls feature flag, then the test makes sense.

bindings/rust/s2n-tls/src/testing/s2n_tls.rs Outdated Show resolved Hide resolved
bindings/rust/s2n-tls/Cargo.toml Outdated Show resolved Hide resolved
.github/workflows/ci_rust.yml Show resolved Hide resolved
Comment on lines +34 to +39
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum FipsMode {
Disabled,
Enabled,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can someone confirm that this should be non-exhaustive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@goatgoose confirmed that we might add some other states to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah - this was discussed when adding the FIPS getter. We decided to use an enum in case we want to add a new value in the future, rather than returning only true/false. So making this non-exhaustive makes sense.

match input {
s2n_fips_mode::FIPS_MODE_DISABLED => FipsMode::Disabled,
s2n_fips_mode::FIPS_MODE_ENABLED => FipsMode::Enabled,
_ => unreachable!(),
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I was thinking that fn fips_mode() didn't need to return an error, since I wasn't sure why it would fail. But now I see that s2n_get_fips_mode fails if s2n is not initialized, so there is a failure mode. And I guess fn fips_mode() should fail too if s2n_get_fips_mode started returning some new enum variant we didn't account for in the bindings yet. Anyway, I think this should probably go back to what you have before with TryFrom

@toidiu toidiu force-pushed the ak-fipsBindings branch from 8b344d8 to 7f0986a Compare May 1, 2024 05:40
@toidiu toidiu merged commit 8604442 into aws:main May 1, 2024
33 checks passed
@toidiu toidiu deleted the ak-fipsBindings branch May 1, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants