1
votes

I'm trying to use HttpsURLConnection in java 7 (on windows 7) to connect to a remote web server and send a post request. Everything seems to work except for the fact that it doesn't trust the certificate (it's self signed).

I've exported the certificate through chrome and then imported the certificate into the keystore with this:

keytool -import -file mysslcertificate.cer

The certificate is there if I run keytool -list.

When i try to run it (either using gradle or eclipse) after importing the certificate i get this 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

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

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Anyone have any tips?

1

1 Answers

2
votes

Most likely, Java is not using the keystore in which you imported the certificate. To tell Java where to find the keystore, use the following command line arguments:

java -Djavax.net.ssl.trustStore=<path to keystore file> -Djavax.net.ssl.trustStorePassword=<keystore password>

Eclipse and Gradle may have specific settings to forward the keystore location to Java.

See also: