■79920 / inTopicNo.2) |
Re[1]: httpsURLConnectionを使用したCRLチェック |
□投稿者/ もりお (10回)-(2016/05/28(Sat) 20:19:56)
|
■No79894 (初心者 さん) に返信
X509TrustManagerを空で実装してSSLContextに設定して
SSLSocketFactoryを作ってhttpsURLConnectionに設定してって感じで行けるんじゃないかと思います。
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, KeyManagementException {
TrustManager trustManager = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
};
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(new KeyManager[0], new TrustManager[] { trustManager }, new SecureRandom());
URL url = new URL("https://www.google.co.jp/");
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
httpsURLConnection.getHeaderFields().forEach((key, value) -> {
System.out.printf("%s: %s\n", key, value);
});
}
|
|