Created
January 13, 2017 14:25
-
-
Save michalbcz/3694f0cc27b71b6a817c5152e3193164 to your computer and use it in GitHub Desktop.
java turn off ssl client certification verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SSLContext sslContext = null; | |
try { | |
sslContext = SSLContext.getInstance("TLS"); | |
sslContext.init(null, new TrustManager[] { new SSLTrustManger() }, new java.security.SecureRandom()); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
SSLSocketFactory socketFactory = sslContext.getSocketFactory(); | |
private static class SSLTrustManger implements X509TrustManager { | |
@Override | |
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
} | |
@Override | |
public X509Certificate[] getAcceptedIssuers() { | |
return new X509Certificate[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment