Last active
August 29, 2015 13:58
-
-
Save dominicfarr/10136064 to your computer and use it in GitHub Desktop.
Resty.ignoreAllCerts() that also implements a HostnameVerifier that ignores hostname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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