Skip to content

Instantly share code, notes, and snippets.

@pmauduit
Created July 29, 2014 13:15
Show Gist options
  • Save pmauduit/f2901a87a3ea86f23360 to your computer and use it in GitHub Desktop.
Save pmauduit/f2901a87a3ea86f23360 to your computer and use it in GitHub Desktop.
Get rid of SSL checks in Java
// don't really care of SSL issues ...
public static void disableCertificates() {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
}
static { disableCertificates(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment