jodd源代码中创建SSLSocketFactory
Posted 超人吃鸡蛋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jodd源代码中创建SSLSocketFactory相关的知识,希望对你有一定的参考价值。
SocketHttpConnectionProvider:
protected SSLSocketFactory getDefaultSSLSocketFactory(boolean trustAllCertificates) throws IOException { if (trustAllCertificates) { try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, TrustManagers.TRUST_ALL_CERTS, new java.security.SecureRandom()); return sc.getSocketFactory(); } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new IOException(e); } } else { return (SSLSocketFactory) SSLSocketFactory.getDefault(); } }
TrustManagers:
public static TrustManager[] TRUST_ALL_CERTS = new TrustManager[]{ new X509ExtendedTrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { } } };
以上是关于jodd源代码中创建SSLSocketFactory的主要内容,如果未能解决你的问题,请参考以下文章