(NTS) Java and SSL

Posted on 11 Sep 2013 | Back to Bitloom home

If you try to open SSL connections to a site that uses a untrusted certificate, like a self signed certificate used for development purposes or a certificate that is not in the “standard” certificate lists then you might incur in a javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException complaining that PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

You have two ways to work around this problem: one is by modifying your code if you can do so, the other is to add the certificate to your JRE keystore.

The second one is less invasive and it consists of the following steps:

Set a password for your keystore, answer yes to the question whether the certificate should be trusted and that’s it.

You can re-run your code and everything should work fine.