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的主要内容,如果未能解决你的问题,请参考以下文章

简约之美Jodd-http--深入源码理解http协议

HttpClient,okhttp,Jodd-http 使用上的差异

jodd http客户端如何设置忽略证书

在后面的代码中创建样式

代码中创建的 UITabBarItem 图像不出现

在代码中创建 ui 时对性能有影响吗? [关闭]