Skip to content

Use SHA-256 for subject key id on FIPS 140-3 mode#703

Merged
maraino merged 2 commits intomasterfrom
mariano/fipsutil
Feb 18, 2025
Merged

Use SHA-256 for subject key id on FIPS 140-3 mode#703
maraino merged 2 commits intomasterfrom
mariano/fipsutil

Conversation

@maraino
Copy link
Copy Markdown
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
Copy Markdown
Member

Linter issues fixed in #704.

Comment thread fipsutil/fipsutil_other.go Outdated
Comment thread fipsutil/fipsutil.go
Comment thread fipsutil/fipsutil_other.go
Comment thread x509util/utils.go
Comment thread x509util/utils.go Outdated
Comment thread x509util/utils.go Outdated
Comment thread x509util/utils_test.go Outdated
Comment thread x509util/utils_test.go
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
Copy Markdown
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
Copy Markdown
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
Comment thread 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
Copy Markdown
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 thread x509util/utils_test.go
Comment on lines +13 to +15
"github.com/stretchr/testify/assert"
"go.step.sm/crypto/fipsutil"
Copy link
Copy Markdown
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
@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.

2 participants