码迷,mamicode.com
首页 > 编程语言 > 详细

javax.net.ssl.sslhandshakeexception: pkix path building failed

时间:2020-07-27 15:48:27      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:runtime   security   accept   解决   版本   common   tor   boolean   pre   

发送请求是跳过证书

package com.yurun.micro.common.third.ding;

import okhttp3.OkHttpClient;

import javax.net.ssl.*;

/**
 * okhttp ssl证书解决
 * @author dll
 * @create 2020-05-26
 */
public class OkHttpSSL {
    public static OkHttpClient getUnsafeOkHttpClient() {
        try {
            final TrustManager[] trustAllCerts = new TrustManager[]{
                    new X509TrustManager() {
                        @Override
                        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                        }

                        @Override
                        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                        }

                        @Override
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return new java.security.cert.X509Certificate[]{};
                        }
                    }
            };
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
            final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
            builder.sslSocketFactory(sslSocketFactory);

            builder.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
            return builder.build();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

之后使用第三方jar时候又出现了了这个ssl问题 。切换了好几个版本号机缘巧合解决了问题,并没有解决实质性问题

后来同事买了新电脑,发现没有这个问题。。。下定决心重装系统。。。完美解决了ssl证书问题和idea启动开2个小时左右,cpu飙升问题。。。。

 

javax.net.ssl.sslhandshakeexception: pkix path building failed

标签:runtime   security   accept   解决   版本   common   tor   boolean   pre   

原文地址:https://www.cnblogs.com/donglulu/p/13384735.html

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