Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Created January 13, 2017 14:25
Show Gist options
  • Save michalbcz/3694f0cc27b71b6a817c5152e3193164 to your computer and use it in GitHub Desktop.
Save michalbcz/3694f0cc27b71b6a817c5152e3193164 to your computer and use it in GitHub Desktop.
java turn off ssl client certification verification
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