Skip to content

Instantly share code, notes, and snippets.

@bobguo
Created April 26, 2013 07:28
Show Gist options
  • Save bobguo/5465537 to your computer and use it in GitHub Desktop.
Save bobguo/5465537 to your computer and use it in GitHub Desktop.
static {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
HostnameVerifier trustingHostnameVerifier = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(trustingHostnameVerifier);
} catch (GeneralSecurityException e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment