Search code examples
javaunixhttpscertificatekeystore

How to find the missing certificate and add it?


I have a simple JAVA application which connects to HTTPS website and downloads a file from there. This JAVA application has been deployed to a Unix server in the form of a JAR file. When I run the JAR, I get following exception :

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

When I searched this exceotion on Google, I came to know that the solution is to add the missing certificate to the keystore. But the thing is, I do not know how to find that which certificate is missing. And after finding it , how to add it? Where to add it?

There are many posts on multiple websites for above exception, but I get stuck on how to know the missing certificate, the server-alias of the https server and many more questions. Can someone help me with the exact steps?

Thanks in advance...


Solution

  • Could you please open https site and in the left side of address bar you can see the lock sign (in Firefox). Click on it, then go to view certificate and then export it to some file. Now you have the certificate. The next step would be to add this certificate into your certificate store. To import the certificate you can use java keytool command, please refer to this post http://www.planetlarg.net/support-cookbook/ssl-secure-sockets-layer/add-x509-certificate-java-keystore-using-keytool