com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException, OkHttp time stamp verification issues

This problem is not common, but I met online search is not good, basic is onFailure: javax.net.ssl.SSLHandshakeException, so I was not preceded by the title

The reason: You look at your equipment on the system time is not right ← .. ←

solve:

1, the time change overnight ah

2, check local phone network time

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;
    }
}

Time to check OkHttpClient

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

 OK, you try it

Guess you like

Origin www.cnblogs.com/linwen5723/p/11371856.html