Replace SHA-1 with SHA-256 for X.509 SubjectKeyIdentifier computation#41
Open
G-Gobi wants to merge 1 commit into
Open
Replace SHA-1 with SHA-256 for X.509 SubjectKeyIdentifier computation#41G-Gobi wants to merge 1 commit into
G-Gobi wants to merge 1 commit into
Conversation
SHA-1 is deprecated by NIST (SP 800-131A Rev 2) and disallowed under FIPS 140-2/3. This change replaces the SHA-1-based bigIntHash method with computeSubjectKeyId, which implements RFC 7093 Method 4: SHA-256 of the full DER-encoded SubjectPublicKeyInfo structure. The previous implementation also only hashed privateKey.N (the RSA modulus), missing the public exponent and algorithm identifier. The new implementation uses x509.MarshalPKIXPublicKey to hash the complete SubjectPublicKeyInfo, which is cryptographically correct. Fixes cloudfoundry#39
|
|
There was a problem hiding this comment.
Pull request overview
This PR updates X.509 certificate generation to compute SubjectKeyId using SHA-256 over the full DER-encoded SubjectPublicKeyInfo (via x509.MarshalPKIXPublicKey), replacing the previous SHA-1 hash over only the RSA modulus.
Changes:
- Replaced SHA-1–based
SubjectKeyIdgeneration with SHA-256 over DER-encodedSubjectPublicKeyInfo. - Removed the old modulus-only hashing helper and added a dedicated
computeSubjectKeyIdhelper with error handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #39
crypto/sha1import andbigIntHash(*big.Int)method, which hashed only the RSA key modulus (privateKey.N) using SHA-1.computeSubjectKeyId(*rsa.PublicKey)implementing RFC 7093 Method 4: SHA-256 of the full DER-encodedSubjectPublicKeyInfostructure viax509.MarshalPKIXPublicKey.Why this matters
SHA-1 is deprecated by NIST SP 800-131A Rev 2 and is explicitly disallowed under FIPS 140-2/3 compliance requirements. Any deployment of config-server in a FIPS-enforcing environment (e.g. US Government, regulated industries) will fail cert generation at runtime with the current implementation.
What changed and why
privateKey.N(modulus only)SubjectPublicKeyInfoDERThe previous implementation was doubly incorrect: beyond using SHA-1, it only hashed the RSA modulus
N, omitting the public exponentEand the algorithm identifier. Two keys with the same modulus but different exponents could produce the same SubjectKeyId. The new implementation hashes the completeSubjectPublicKeyInfoas defined in RFC 5280 / RFC 7093.Impact on existing deployments
SubjectKeyIdfield, so it correctly reflects the CA's original 20-byte value. RFC 5280 does not require AKI and SKI to be the same size.Test plan
go build ./types/...compiles cleanlygo test ./types/...52/52 specs passSubjectKeyIdis non-nil on generated certsSubjectKeyId == AuthorityKeyIdAuthorityKeyId == signingCA.SubjectKeyIdReferences