当前位置 : 主页 > 手机开发 > android >

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

来源:互联网 收集:自由互联 发布时间:2021-06-11
这个问题不常见,但是我遇到了,网上不好搜,基本是onFailure:javax.net.ssl.SSLHandshakeException,所以我标题没有前面加上这个 原因: 你看下你设备上系统时间是不是不对←..← 解决: 1、时

这个问题不常见,但是我遇到了,网上不好搜,基本是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,你试试吧

上一篇:View类
下一篇:Android 知识树杂谈(20190819)
网友评论