码迷,mamicode.com
首页 > 其他好文 > 详细

jodd源代码中创建SSLSocketFactory

时间:2017-12-04 17:39:41      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:tee   issue   extend   tpc   str   ati   security   null   div   

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

标签:tee   issue   extend   tpc   str   ati   security   null   div   

原文地址:http://www.cnblogs.com/gj1990/p/7977904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!