Skip to content
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

Merged
merged 4 commits into from May 9, 2023

Conversation

SgtCoDFish
Copy link
Member

@SgtCoDFish SgtCoDFish commented May 2, 2023

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.

@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 2, 2023
@SgtCoDFish SgtCoDFish force-pushed the uniquealias branch 2 times, most recently from 6c2d058 to 243e74f Compare May 3, 2023 13:05
Comment on lines +310 to +311
// TODO: check that the cert content matches expectedCertPEMData exactly, not just
// that the count is the same
Copy link
Member Author

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.

@SgtCoDFish SgtCoDFish force-pushed the uniquealias branch 2 times, most recently from 6db6da1 to 94b6e3a Compare May 4, 2023 12:32
Comment on lines 215 to 232
// 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()
}

Copy link
Member Author

@SgtCoDFish SgtCoDFish May 4, 2023

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

pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
test/env/data.go Show resolved Hide resolved
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>
Copy link
Member

@inteon inteon left a 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

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label May 9, 2023
@jetstack-bot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jetstack-bot jetstack-bot merged commit 5235aaf into cert-manager:main May 9, 2023
4 checks passed
@SgtCoDFish SgtCoDFish deleted the uniquealias branch May 9, 2023 16:14
@hazmat345
Copy link
Contributor

Just tried out v0.5.0-beta.1 and everything looks good to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants