Skip to content

Instantly share code, notes, and snippets.

@jorgevila
Created October 23, 2017 14:49
Show Gist options
  • Save jorgevila/7e78636f57a01c161115fe6498ab8a2f to your computer and use it in GitHub Desktop.
Save jorgevila/7e78636f57a01c161115fe6498ab8a2f to your computer and use it in GitHub Desktop.
Trust every one
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