Created
March 25, 2013 10:31
-
-
Save azusa/5236248 to your computer and use it in GitHub Desktop.
オレオレ証明書によるhttps通信を認める
This file contains 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 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