Last active
December 11, 2020 07:56
-
-
Save michalbcz/f8e7fcdc2fe17605d3966f17956c40c0 to your computer and use it in GitHub Desktop.
turn off SSL verification #2
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
// methods | |
private static SSLSocketFactory createSslSocketFactory(X509TrustManager trustManager) { | |
try { | |
final SSLContext context = SSLContext.getInstance("TLS"); | |
context.init(null, new TrustManager[]{trustManager}, new SecureRandom()); | |
return context.getSocketFactory(); | |
} catch (NoSuchAlgorithmException | KeyManagementException e) { | |
return ExceptionUtils.rethrow(e); | |
} | |
} | |
private static X509TrustManager trustAllX509TrustManager() { | |
return new X509TrustManager() { | |
public void checkClientTrusted(X509Certificate[] chain, String authType) { } | |
public void checkServerTrusted(X509Certificate[] chain, String authType) { } | |
public X509Certificate[] getAcceptedIssuers() { | |
return new X509Certificate[0]; | |
} | |
}; | |
} | |
// then used in code somewhere | |
X509TrustManager trustManager = trustAllX509TrustManager(); | |
SSLSocketFactory socketFactoryWithoutVerification = createSslSocketFactory(trustManager); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment