Skip to content

Switch macOS native certs to retrieve from JDK #6

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

Closed

Conversation

timja
Copy link
Contributor

@timja timja commented Jan 7, 2025

I tried to implement #3 in #5 but I couldn't make the JNA bindings work, I'm not sure if its JNA limitations to do with constants required or if I was doing something wrong but I was hitting a solid brick wall which gave me no clues on what was wrong.

Instead I've ported this to use the Apple truststores provided by the JVM which was trivial to do.

Closes #5

This won't fix #3 as its now dependent on the JVM.
But it will be fixed by openjdk/jdk#22911 which looks like it should get merged soon-ish and then hopefully it can be backported.


System.out.println(trustedRoots.size());
for (X509Certificate root : trustedRoots) {
System.out.println(root.getSubjectDN().toString());
}

Assert.assertTrue("Expected >100 system roots", trustedRoots.size() > 100);
// TODO remove when minimum Java version is 23 or higher
if (Runtime.version().feature() >= 23) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified this passes on Java 23

.collect(Collectors.toList());
} catch (KeyStoreException e) {
// only available from Java 23
if (e.getMessage().equals("KeychainStore-ROOT not found")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://bugs.openjdk.org/browse/JDK-8320362 was added in Java 23.

The Javadoc documented that this was only supported on Linux, although the unit tests did test for this:

* On some systems (currently, Linux) may return an entire set of trusted certificates.

If its needed to maintain this, we could restore the old code and use that to retrieve the roots on Java <23 WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR that does this here: #7

}
}

static boolean isSelfSignedCertificate(X509Certificate certificate) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved code only

@timja
Copy link
Contributor Author

timja commented Jan 7, 2025

cc @shalupov

@timja timja changed the title Switch apple native certs to retrieve from JDK Switch macOS native certs to retrieve from JDK Jan 7, 2025
@shalupov
Copy link
Collaborator

Sorry for a long wait, I'm back to do a little maintenance. It's a good idea to contribute it to JDK anyway, but I don't see anything wrong with fixing this code as is. I'll try

@timja
Copy link
Contributor Author

timja commented Feb 14, 2025

Sorry for a long wait, I'm back to do a little maintenance. It's a good idea to contribute it to JDK anyway, but I don't see anything wrong with fixing this code as is. I'll try

Thanks that’ll be great. I tried but found docs lacking a lot and limited examples.

@timja
Copy link
Contributor Author

timja commented Feb 15, 2025

A simple test environment can be found in:
https://github.com/timja/openjdk-intermediate-ca-reproducer

@timja timja closed this Feb 22, 2025
@timja timja deleted the use-apple-keychainstore-from-jdk branch February 22, 2025 16:51
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