<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hello Graham,<div><br></div><div>This functionality is under review now at <a href="https://github.com/openjdk/jdk/pull/16722">https://github.com/openjdk/jdk/pull/16722</a></div><div>This patch proposes access to the MacOS trust store using new java KeychainStore-Root keystore.</div><div>Feel free to review and comment.</div><div><br></div><div>Regards</div><div>Aleksei<br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 14 Feb 2024, at 02:16, Graham Leggett <minfrin@sharp.fm> wrote:</div><br class="Apple-interchange-newline"><div><div>Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.<br><br><br>Hi all,<br><br>I am trying to make life easier for Apple and Windows users by providing functionality to use Window-MY and Windows-ROOT, however I got stuck with KeychainStore.<br><br>keyStore = KeyStore.getInstance("KeychainStore", "Apple");<br>keyStore.load(null, null);<br>keyManagerFactory = KeyManagerFactory<br>.getInstance("PKIX");<br>keyManagerFactory.init(keyStore, keyPassphrase);<br>trustStore = KeyStore.getInstance("KeychainStore", "Apple");<br>trustStore.load(null, null);<br>trustManagerFactory = TrustManagerFactory<br>.getInstance("PKIX");<br>trustManagerFactory.init(trustStore);<br>ctx = SSLContext.getInstance("TLS");<br>ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);<br>factory = ctx.getSocketFactory();<br><br>The problem is that when connecting to an TLS endpoint with a publicly issued certificate, Java cannot validate the server’s certificate as follows;<br><br>Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target<br><br>It looks like the functionality to access the MacOS trust store is missing, which is counterintuitive and makes it seem like I doing something wrong.<br><br>Digging into the JDK code it leads us here:<br><br>https://github.com/openjdk/jdk/blob/master/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m<br><br>Specifically, what I don’t see is a call to SecTrustCopyAnchorCertificates:<br><br>https://developer.apple.com/documentation/security/1401507-sectrustcopyanchorcertificates?language=objc<br><br>Am I right in understanding that java can access certificates in a keychain, but not certificates in the trust store?<br><br>Does it make sense to amend “KeychainStore” to allow access to the trust store, or does macos need a dedicated keystore like Windows-ROOT?<br><br>Regards,<br>Graham<br>—<br><br></div></div></blockquote></div><br></div></body></html>