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

2020-12-18 19:34

阅读:407

标签: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


评论


亲,登录后才可以留言!