Skip to content

Instantly share code, notes, and snippets.

@csabapalfi
Created August 17, 2010 15:28
Show Gist options
  • Save csabapalfi/530400 to your computer and use it in GitHub Desktop.
Save csabapalfi/530400 to your computer and use it in GitHub Desktop.
https Java hack
//Trusting all certificates
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) {
}
}};
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
//Disabling URL spoofing check
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String string, SSLSession ssls) {
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment