Quantcast
Channel: Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error? - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Answer by Sandip S. for Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

$
0
0

It is possible to disable SSL verification programmatically. Works in a pinch for dev, but not recommended for production since you'll want to either use "real" SSL verification there or install and use your own trusted keys and then still use "real" SSL verification.

Below code works for me:

import java.security.cert.CertificateException;import java.security.cert.X509Certificate;import javax.net.ssl.X509TrustManager;public class TrustAnyTrustManager implements X509TrustManager {  public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {  }  public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {  }  public X509Certificate[] getAcceptedIssuers() {    return null;  }}

             HttpsURLConnection conn = null;             URL url = new URL(serviceUrl);             conn = (HttpsURLConnection) url.openConnection();             SSLContext sc = SSLContext.getInstance("SSL");               sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom());                      // Create all-trusting host name verifier             HostnameVerifier allHostsValid = new HostnameVerifier() {               public boolean verify(String hostname, SSLSession session) {                return true;              }            };            conn.setHostnameVerifier(allHostsValid);

Or if you don't control the Connections underneath, you can also override SSL verification globally for all connections https://stackoverflow.com/a/19542614/32453

If you are using Apache HTTPClient you must disable it "differently" (sadly): https://stackoverflow.com/a/2703233/32453


Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>