Skip to content

Conversation

@tsaarni
Copy link
Contributor

@tsaarni tsaarni commented Nov 7, 2025

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

@tsaarni tsaarni force-pushed the fix-zookeeper-4992 branch from dbbad6f to 95bd22b Compare November 8, 2025 05:33
@tsaarni
Copy link
Contributor Author

tsaarni commented Nov 10, 2025

One of the CI tests failed, but I think it might just be a flake. @kezhuw, could you please re-run the test?

@tsaarni
Copy link
Contributor Author

tsaarni commented Dec 5, 2025

When you have a chance, could someone review this PR? Thanks!

Copy link
Contributor

@anmolnar anmolnar left a 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);
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants