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

Only load OpenSSL when in FIPS mode. #207

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

dbenoit17
Copy link
Collaborator

We shouldn't depend on OpenSSL in non-FIPS mode, as it precludes binaries from running in any environment without OpenSSL. This commit moves the FIPS mode check to the beginning of init() and avoids initializing OpenSSL when we know Go standard crypto will be used.

We shouldn't depend on OpenSSL in non-FIPS mode, as it
precludes binaries from running in any environment without
OpenSSL.  This commit moves the FIPS mode check to the
beginning of init() and avoids initializing OpenSSL when
we know Go standard crypto will be used.
@dbenoit17 dbenoit17 requested a review from ueno June 26, 2024 23:19
+ fips = "1"
+ }
+
+ if fips == "" {
Copy link
Collaborator

@ueno ueno Jun 27, 2024

Choose a reason for hiding this comment

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

According to the comment above, should this check against any other value than "0" nor "1", not only ""?

I'm also not sure what to do with "GOLANG_FIPS=0"; should it just return or go through the openssl.SetFIPS path below?

Choose a reason for hiding this comment

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

We will want to keep functionality to explicitly disable fips mode via openssl, so I suggest keeping GOLANG_FIPS=0 to use openssl, but turn off FIPS mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ueno We were originally talking about including an option to use openssl as the crypto backend without using FIPS, so Derek may have been setting us up for that in the future with the fips == "0" path. However, currently that path will still use standard crypto, because other bits aren't implemented and boring.Enabled() will still return false. So my initial thought was to just remove the fips == "0" branch and nest all of the openssl initialization under fips == "1", since I think with the recent direction of the project it's questionable we will ever fully implement non-FIPS openssl as a backend. Then @rphillips suggested lifting the FIPS mode check and skipping the rest, which I like as a good middle ground to keep things the same until we can discuss with Derek whether we still intend to implement GOLANG_FIPS=0. But I'm also open to just removing the fips == "0" branch now and then add it back if things change later. Either way it won't matter what happens with GOLANG_FIPS=0, but you're right, other values will need to be handled too, good catch.

Copy link
Collaborator

@ueno ueno Jun 27, 2024

Choose a reason for hiding this comment

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

I agree that leaving the current logic would be safer, though on Fedora/CentOS Stream/RHEL, the current GOLANG_FIPS=0 behavior is mostly identical to GOLANG_FIPS=1 OPENSSL_FORCE_FIPS_MODE=0.

@rphillips
Copy link

lgtm

@xnox
Copy link

xnox commented Aug 14, 2024

I known certain customers that are using this, precisely to use openssl even in non-fips mode, because for them it is "faster". Although I personally am not convinced of such benefits.

Copy link
Collaborator

@ueno ueno left a comment

Choose a reason for hiding this comment

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

Still nice to handle other values than 0 and 1, but otherwise it looks good to me.

@archanaravindar archanaravindar merged commit 709044a into golang-fips:main Aug 29, 2024
5 of 6 checks passed
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.

5 participants