Skip to content

Instantly share code, notes, and snippets.

@dominicfarr
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominicfarr/10136064 to your computer and use it in GitHub Desktop.
Save dominicfarr/10136064 to your computer and use it in GitHub Desktop.
Resty.ignoreAllCerts() that also implements a HostnameVerifier that ignores hostname
public static void ignoreAllCerts() {
TrustManager trm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sc;
try {
sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{trm}, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
//SHOULD THIS METHOD ALSO IMPLEMENT HostnameVerifier??
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment