I am trying to create some examples of Java projects that connect to a self-signed HTTPS server. I cannot get Java to stop trying to verify the certificate. I do not want to trust this certificate, I just want to completely ignore all certificate verification; this server is inside my network and I want to be able to run some test applications without worrying about whether the certificate is valid.
java -Dcom.sun.net.ssl.checkRevocation=false HelloWorld org.apache.axis2.AxisFault: Connection has been shutdown: 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
-Dcom.sun.net.ssl.checkRevocation = false did not help. I also tried adding the following code:
public static void DisableCertificateValidation() { TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { } }
But still the same problem. What's going on here?
source share