Skip to content

Conversation

@maraino
Copy link
Contributor

@maraino maraino commented Feb 14, 2025

Description

This commit adds the fips util package, which reports whether the cryptography libraries are operating in FIPS 140-3 mode.

It also uses the 160 leftmost bits of SHA-256 to generate the Subject Key IDs.

Related:

This commit adds the fipsutil package that reports whether the
cryptography libraries are operating in FIPS 140-3 mode.

It also uses the 160 leftmost bits of SHA-256 to generate the Subject
Key Ids
@hslatman
Copy link
Member

Linter issues fixed in #704.

Comment on lines +185 to +188
func Test_generateSubjectKeyID_fips(t *testing.T) {
if !fipsutil.Enabled() {
t.Skip("FIPS 140-3 mode is not enabled")
}
Copy link
Member

Choose a reason for hiding this comment

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

Could t.Setenv help executing the tests at all times, but with the GODEBUG env var set for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I've tried but GODEBUG cannot be changed after initializing, it will panic if you do it. See https://github.com/golang/go/blob/279da965329a74cd75320f15cb9672a282690ab7/src/crypto/fips140/fips140.go#L26-L28

if currentlyEnabled != fips140.Enabled {
        panic("crypto/fips140: GODEBUG setting changed after program start")
}

@maraino maraino requested a review from hslatman February 18, 2025 19:40
jose/encrypt.go Outdated
return data, nil
}
return nil, errors.New("failed to decrypt JWE: invalid password")
return nil, errors.New("failed to decrypt JWE: invalid password" + err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Added a space, but other options might work too. No fmt.Errorf?

Suggested change
return nil, errors.New("failed to decrypt JWE: invalid password" + err.Error())
return nil, errors.New("failed to decrypt JWE: invalid password " + err.Error())

Comment on lines 13 to 15
"github.com/stretchr/testify/assert"
"go.step.sm/crypto/fipsutil"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"github.com/stretchr/testify/assert"
"go.step.sm/crypto/fipsutil"
"github.com/stretchr/testify/assert"
"go.step.sm/crypto/fipsutil"

@maraino maraino merged commit 43a6d36 into master Feb 18, 2025
10 checks passed
@maraino maraino deleted the mariano/fipsutil branch February 18, 2025 20:21
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.

3 participants