-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-4992: Avoid overriding same-subject certs in PEM trust store #2336
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
base: master
Are you sure you want to change the base?
Conversation
dbbad6f to
95bd22b
Compare
|
One of the CI tests failed, but I think it might just be a flake. @kezhuw, could you please re-run the test? |
|
When you have a chance, could someone review this PR? Thanks! |
anmolnar
left a comment
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.
I'm fine with the patch overall, but I have a small suggestion.
| for (X509Certificate certificate : certificateChain) { | ||
| X500Principal principal = certificate.getSubjectX500Principal(); | ||
| keyStore.setCertificateEntry(principal.getName("RFC2253"), certificate); | ||
| keyStore.setCertificateEntry(principal.getName("RFC2253") + "-" + i++, certificate); |
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.
Shall we check the name already exists first and add the suffix only when it's necessary?
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.
@anmolnar Yes, that's a good idea. I updated it and added a check to make sure the aliases have the right suffix. Now, the first suffix starts from 2 since the first one doesn't have one.
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.
The sequence numbers in the suffixes aren't working perfectly logically, for example, if adding four certificates with subjects cn=foo, cn=foo, cn=bar and cn=bar, the aliases become cn=foo, cn=foo-2, cn=bar, and cn=bar-3, but I hope it does not need to be perfect.
Signed-off-by: Tero Saarni <[email protected]>
95bd22b to
6b87ef5
Compare
When a PEM bundle is loaded as a trust store, each certificate is added to an in-memory
KeyStore.Previously, the certificate’s subject name was used as the alias, which caused entries to be overwritten when multiple certificates shared the same subject name.
This change assigns a unique alias to each certificate, ensuring that all certificates from the PEM bundle are preserved in the trust store.
Certificates valid at the same time can share the same subject name, for example CA certificate might be reissued with another key type.
https://issues.apache.org/jira/projects/ZOOKEEPER/issues/ZOOKEEPER-4992