Skip to content

Instantly share code, notes, and snippets.

@azusa
Created March 25, 2013 10:31
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 azusa/5236248 to your computer and use it in GitHub Desktop.
Save azusa/5236248 to your computer and use it in GitHub Desktop.
オレオレ証明書によるhttps通信を認める
public static void initHttpsURLConnection() throws Exception {
HostnameVerifier hv = new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
KeyManager[] km = null;
TrustManager[] tm = { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {}
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(km, tm, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment