码迷,mamicode.com
首页 > 移动开发 > 详细

com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException,OkHttp时间戳校验问题

时间:2019-08-18 13:45:46      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:ring   nfa   and   hostname   key   rac   gets   throw   random   

这个问题不常见,但是我遇到了,网上不好搜,基本是onFailure:javax.net.ssl.SSLHandshakeException,所以我标题没有前面加上这个

原因:你看下你设备上系统时间是不是不对←..←

解决:

1、时间改过来啊

2、联网校验手机本地时间

public class SSLCertificate {

    public static SSLSocketFactory SSLSocketFactorygetSSLSocketFactory(){
        final TrustManager[] trustAllCerts =new TrustManager[]{
                new X509TrustManager() {

                    @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 new X509Certificate[0];
                    }
                }
        };

        SSLContext sslContext =null;
        try {
            sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }

        final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

        return sslSocketFactory;
    }
}

对 OkHttpClient 时间校验

OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .sslSocketFactory(SSLCertificate.SSLSocketFactorygetSSLSocketFactory())
                .hostnameVerifier(new HostnameVerifier() {
                    @Override
                    public boolean verify(String s, SSLSession sslSession) {
                        return true;
                    }
                });

 OK,你试试吧

com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException,OkHttp时间戳校验问题

标签:ring   nfa   and   hostname   key   rac   gets   throw   random   

原文地址:https://www.cnblogs.com/linwen5723/p/11371856.html

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