Skip to content

Replace SHA-1 with SHA-256 for X.509 SubjectKeyIdentifier computation - #21

Merged
aramprice merged 1 commit into
cloudfoundry:mainfrom
G-Gobi:fix/sha256-subjectkeyid
Aug 6, 2026
Merged

Replace SHA-1 with SHA-256 for X.509 SubjectKeyIdentifier computation#21
aramprice merged 1 commit into
cloudfoundry:mainfrom
G-Gobi:fix/sha256-subjectkeyid

Conversation

@G-Gobi

@G-Gobi G-Gobi commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the deprecated crypto/sha1 import and bigIntHash(*big.Int) method, which hashed only the RSA key modulus (privateKey.N) using SHA-1.
  • Introduces computeSubjectKeyId(*rsa.PublicKey) implementing RFC 7093 Method 4: SHA-256 of the full DER-encoded SubjectPublicKeyInfo structure via x509.MarshalPKIXPublicKey.
  • All 54 existing unit tests pass without modification.

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

Before After
Hash algorithm SHA-1 SHA-256
Hash input privateKey.N (modulus only) Full SubjectPublicKeyInfo DER
Output size 20 bytes 32 bytes
RFC alignment Non-standard (missing exponent + algorithm OID) RFC 7093 Method 4

The previous implementation was doubly incorrect: beyond using SHA-1, it only hashed the RSA modulus N, omitting the public exponent E and the algorithm identifier. Two keys with the same modulus but different exponents could produce the same SubjectKeyId. The new implementation hashes the complete SubjectPublicKeyInfo as defined in RFC 5280 / RFC 7093.

Impact on existing deployments

  • Existing certificates in the database are not affected — only newly generated certs are changed.
  • Chain validation is unaffected — TLS chain verification uses cryptographic signatures, not SKI/AKI values.
  • Mixed environments (new certs signed by old SHA-1-SKI CAs): the AKI on the new cert is copied directly from the signing CA's SubjectKeyId field, 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 cleanly
  • go test ./types/... 54/54 specs pass
  • Verified SubjectKeyId is non-nil on generated certs
  • Verified self-signed CA SubjectKeyId == AuthorityKeyId
  • Verified leaf cert AuthorityKeyId == signingCA.SubjectKeyId

References

Ports cloudfoundry/config-server#41 to this repo, since config-server
was archived and its code inlined here. Implements RFC 7093 Method 4:
hashes the full DER-encoded SubjectPublicKeyInfo instead of just the
RSA modulus, replacing the deprecated SHA-1-based bigIntHash.
@aramprice

Copy link
Copy Markdown
Member

GitHub workers are currently having issues, which is causing the PR checks to timeout:
=> https://www.githubstatus.com/

@github-project-automation github-project-automation Bot moved this from Pending Review | Discussion to Pending Merge | Prioritized in Foundational Infrastructure Working Group Aug 6, 2026
@aramprice
aramprice merged commit 132a0f6 into cloudfoundry:main Aug 6, 2026
2 of 4 checks passed
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants