欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决jdk1.7不支持TSL1.2的问题(续)

程序员文章站 2022-06-25 11:36:14
...

解决jdk1.7 不支持TLS1.2的问题 

 

 

windows环境打开jdk安装目录:jdk1.7.0_80\jre\bin,找到javacpl.exe 

双击打开,高级选项卡,拉到最下方勾选TLS1.1 TLS1.2 ,如图

 

解决jdk1.7不支持TSL1.2的问题(续)
            
    
    博客分类: JAVALinuxwindows协议 javacplTLSv1.2HttpClientX509TrustManagerjdk1.7 

 

代码做微调: TLS 改为TLSv1.2 

 

  private static HttpClient httpClientEnableTLSTrust(final HttpClient base) {
        try {
            final SSLContext ctx = SSLContext.getInstance("TLSv1.2");
            final TrustManager tm = new X509TrustManager() {
                @Override
                public void checkClientTrusted(final X509Certificate[] xcs,
                        final String string) throws CertificateException {
                }

                @Override
                public void checkServerTrusted(final X509Certificate[] xcs,
                        final String string) throws CertificateException {
                }

                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            };
            ctx.init(null, new TrustManager[] { tm }, null);
            
            final SSLSocketFactory ssf = new SSLSocketFactory(ctx,
                    SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            final ClientConnectionManager ccm = base.getConnectionManager();
            final SchemeRegistry sr = ccm.getSchemeRegistry();
            sr.register(new Scheme("https", 443, ssf));
            return new DefaultHttpClient(ccm, base.getParams());
        } catch (final Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

 

 

 

linux 环境

测试了两个版本,直接上图 

 

解决jdk1.7不支持TSL1.2的问题(续)
            
    
    博客分类: JAVALinuxwindows协议 javacplTLSv1.2HttpClientX509TrustManagerjdk1.7 

解决jdk1.7不支持TSL1.2的问题(续)
            
    
    博客分类: JAVALinuxwindows协议 javacplTLSv1.2HttpClientX509TrustManagerjdk1.7 

 

 

其中checkTLS.jar  代码参考:查询JDK默认支持的SSL/TSL版本

 

 

就这