Ant s
Ant s

Reputation: 31

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

Where I run the below code I get the error:

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

I have tried to add the Certificate to the CAcerts keystore for the JDK but with no change in the error. Is their anyway to figure out what keystore it is reading from? Or is this problem something else?

public static void main(String args[]) throws Exception {

        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();


        String url = "https://www.mywebservice.com/ws";


    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(),url);



        // print SOAP Response
        System.out.print("Response SOAP Message:");
        soapResponse.writeTo(System.out);

        soapConnection.close();


    }

Thank you and I will happily provide any other details required.

Upvotes: 1

Views: 30475

Answers (2)

Mesut
Mesut

Reputation: 56

If you are using Zscaler, download ZscalerRootCA.crt certificate from browser and apply it to cacerts file for your jdk. Open CMD with admin rights and run keytool command in your jdk folder as below.

C:\Program Files\Java\jdk-20\lib\security>keytool -import -trustcacerts -keystore cacerts -storepass changeit -noprompt -alias ZscalerRootCA -file ZscalerRootCA.crt

Upvotes: 2

pedrofb
pedrofb

Reputation: 39261

You have to add the server certificate, or the root CA to the truststore used by JDK. By default is used jre/lib/security/cacerts.

If you already imported the server certificate, then verify that you are actually using the correct JDK, or the certificate is successfully imported. You can use a GUI tool like http://www.keystore-explorer.org/ or use keytool

You can also use your own trustore (recommended) using a JKS file which includes the server certificate. Configure the usage in this way

System.setProperty ("javax.net.ssl.trustStore", path_to_your_trustore_jks_file);
System.setProperty ("javax.net.ssl.trustStorePassword", "password");

Upvotes: 5

Related Questions