Search code examples
javasslhttpskeystoresslhandshakeexception

SunCertPathBuilderException; JAVA_OPTS with keystore required?


When connecting via a java API service to a remote server by https I got the following exception

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

The server is a Windows Server 2012 which has the corresponding wildcard certificate installed as root certificate too. I've used keytool to import that exact same certificate to the keystore called cacerts, so the jvm is using it to prevent the exception above. As keytool shows, the certificate is installed correctly but the handshake exception still occurs when connecting to the server.

I've checked the windows environment variables on the server and found out that the JAVA_OPTS is missing. Even tried restarting the entire server but this did not help either.

In order to get it work, do I need to add the environment variable manually referencing the keystore as shown below?

-Djavax.net.ssl.trustStore=C:\path\to\cacerts

Solution

  • I was able to fix this issue by adding the certificate to the java applications keystore too.