Skip to content

Instantly share code, notes, and snippets.

@jbruchanov
Created March 24, 2015 14:34
Show Gist options
  • Save jbruchanov/20bafe030a512e1dc332 to your computer and use it in GitHub Desktop.
Save jbruchanov/20bafe030a512e1dc332 to your computer and use it in GitHub Desktop.
HttpURLConnection hc = (HttpURLConnection) connection;
HttpsURLConnection huc = (HttpsURLConnection) hc;
huc.setHostnameVerifier(mHostnameVerifier);
huc.setSSLSocketFactory(initSSLSocketFactory(new FakeTrustManager()));
private SSLSocketFactory initSSLSocketFactory(manager)
throws KeyManagementException, NoSuchAlgorithmException {
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[]{manager},
new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
return sslContext.getSocketFactory();
}
public class FakeTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment