Created
October 23, 2017 14:49
-
-
Save jorgevila/7e78636f57a01c161115fe6498ab8a2f to your computer and use it in GitHub Desktop.
Trust every one
This file contains 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
private void trustEveryone() { | |
try { | |
SSLContext context = SSLContext.getInstance("TLS"); | |
context.init(null, new X509TrustManager[]{new X509TrustManager() { | |
public void checkClientTrusted(X509Certificate[] chain, | |
String authType) throws CertificateException { | |
} | |
public void checkServerTrusted(X509Certificate[] chain, | |
String authType) throws CertificateException { | |
} | |
public X509Certificate[] getAcceptedIssuers() { | |
return new X509Certificate[0]; | |
} | |
}}, new SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory( | |
context.getSocketFactory()); | |
} catch (Exception e) { // should never happen | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment