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
Ensure unique aliases in JKS files #129
Conversation
6c2d058
to
243e74f
Compare
// TODO: check that the cert content matches expectedCertPEMData exactly, not just | ||
// that the count is the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: implementing this would take a bit more work. It's doable but I didn't want this PR to balloon so I skipped it for this fix.
6db6da1
to
94b6e3a
Compare
pkg/bundle/sync.go
Outdated
// jksAlias creates a JKS-safe alias for the given certificate, such that | ||
// any two certificates will have a different aliases unless they're | ||
// identical in every way. | ||
// This unique alias fixes an issue where we used the Issuer field as an | ||
// alias, leading to different certs being treated as identical. | ||
func jksAlias(cert *x509.Certificate) string { | ||
certHashBytes := sha256.Sum256(cert.Raw) | ||
certHash := hex.EncodeToString(certHashBytes[:]) | ||
|
||
// Since certHash is the part which actually distinguishes between two | ||
// certificates, put it first so that it won't be truncated if a cert | ||
// with a really long subject is added. Not sure what the upper limit | ||
// for length actually is, but it shouldn't matter here. | ||
|
||
return certHash[:8] + "|" + cert.Subject.String() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: jksAlias
is the real core of the bug fix, and this is what fixes the reported issue.
For comparison, the Debian JKS file uses the filename that a trusted cert was taken from as the alias, which is unique in their case. We don't have filenames, but this approach of using a hash seems to work well.
To check the JKS truststore on a debian based machine with Java installed:
$ keytool -list -keystore /etc/ssl/certs/java/cacerts
<snip>
...
debian:verisign_universal_root_certification_authority.pem, 2 May 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): 23:99:56:11:27:A5:71:25:DE:8C:EF:EA:61:0D:DF:2F:A0:78:B5:C8:06:7F:4E:82:82:90:BF:B8:60:E8:4B:3C
debian:xramp_global_ca_root.pem, 2 May 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): CE:CD:DC:90:50:99:D8:DA:DF:C5:B1:D2:09:B7:37:CB:E2:C1:8C:FB:2C:10:C0:FF:0B:CF:0D:32:86:FC:1A:A2
Signed-off-by: Ashley Davis <ashley.davis@jetstack.io>
Signed-off-by: Ashley Davis <ashley.davis@jetstack.io>
Adds tests of the bug we're fixing[1] and an integration test for JKS functionality too. Also exports default password and changes function signatures to accept the password as a parameter. This should make it easier to add support for custom passwords in the future, if we decide to do so. [1] cert-manager#122 (comment) Signed-off-by: Ashley Davis <ashley.davis@jetstack.io>
Signed-off-by: Ashley Davis <ashley.davis@jetstack.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for resolving the remaining issues & feedback.
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: inteon, SgtCoDFish The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Just tried out v0.5.0-beta.1 and everything looks good to me. Thanks! |
Each commit should have a descriptive commit message.
This PR is intended to address the issue raised in this comment where two certs with the same Issuer field would be de-duped when added to the JKS file, despite them being different certificates.