인디노트
How To Avoid javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Problem Using Apache HttpClient 본문
How To Avoid javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Problem Using Apache HttpClient
인디개발자 2018. 5. 31. 17:48
public static HttpClient wrapClient(HttpClient base) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { }
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { }
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = base.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
return new DefaultHttpClient(ccm, base.getParams());
} catch (Exception ex) {
return null;
}
}
'소스 팁 > Java, Android, Kotlin' 카테고리의 다른 글
JRE cacerts 에 들어있는 인증서 리스트 (0) | 2018.06.01 |
---|---|
Java code 에서 Java 버전 확인 (0) | 2018.06.01 |
How to read p12 file from system in Java? (0) | 2018.05.16 |
Java Code Examples for java.security.cert.X509Certificate (0) | 2018.05.16 |
[안드로이드] 외부 앱 실행 (0) | 2017.08.02 |