Skip to content

Instantly share code, notes, and snippets.

@aigor
Created June 22, 2017 11:49
Show Gist options
  • Select an option

  • Save aigor/cc14e1880ac59b428b8e500d92ffa5d6 to your computer and use it in GitHub Desktop.

Select an option

Save aigor/cc14e1880ac59b428b8e500d92ffa5d6 to your computer and use it in GitHub Desktop.
SSL without certificate check
private SSLContext noCheckSslContext() throws GeneralSecurityException {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(
X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
SSLContext allowAllCertificates;
allowAllCertificates = SSLContext.getInstance("SSL");
allowAllCertificates.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(allowAllCertificates.getSocketFactory());
return allowAllCertificates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment