I'm trying to debug why an https connection fails. The error I get is
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target
The code is using Java 7's built-in truststore.
For this scenario, there is one client (written by me) run from two different machines (A and B) and one server. The connection works from A but fails with the above exception from B. I have run the following code to log the trust manager:
trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore)null);
for (TrustManager trustManager : trustManagerFactory.getTrustManagers()) {
System.out.println(trustManager);
if (trustManager instanceof X509TrustManager) {
X509TrustManager x509TrustManager = (X509TrustManager)trustManager;
for (X509Certificate c : x509TrustManager.getAcceptedIssuers())
{
System.out.println(c.get);
}
}
}
This code logs almost the same certificates on A and B, and most importantly the root cert required for the server is present on both.
So, I'm looking for a way to inspect the connection object at runtime to determine what certificates were actually used. Is there any way to do that?
Update: I cannot get ssl debugging to work, so I need a way to do this programmatically.