美文网首页
Caused by: java.security.cert.Ce

Caused by: java.security.cert.Ce

作者: 最忆是深秋 | 来源:发表于2018-05-04 14:22 被阅读68次

    客户端在连接Server端https的时候出现了 以下错误,而且还和手机设置的当前时间有关系,把时间向将来设置超过一定范围就会出现上述错误。

    12-27 17:52:45.976: W/System.err(10361): Caused by: java.security.cert.CertPathValidatorException: timestamp check failed
    12-27 17:52:45.976: W/System.err(10361): at sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(PKIXMasterCertPathValidator.java:127)
    12-27 17:52:45.976: W/System.err(10361): at sun.security.provider.certpath.PKIXCertPathValidator.validate(PKIXCertPathValidator.java:215)
    12-27 17:52:45.976: W/System.err(10361): at sun.security.provider.certpath.PKIXCertPathValidator.validate(PKIXCertPathValidator.java:143)
    12-27 17:52:45.976: W/System.err(10361): at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(PKIXCertPathValidator.java:79)
    12-27 17:52:45.976: W/System.err(10361): at java.security.cert.CertPathValidator.validate(CertPathValidator.java:301)
    12-27 17:52:45.977: W/System.err(10361): at com.android.org.conscrypt.TrustManagerImpl.verifyChain(TrustManagerImpl.java:606)
    12-27 17:52:45.977: W/System.err(10361): ... 27 more
    12-27 17:52:45.977: W/System.err(10361): Caused by: java.security
    

    经查是证书除了问题~,使用下面的代码可以忽略证书:

    我是在Application的oncreate中调用此方法,验证OK.
    public static void disableChecks(Context context){  
        try {  
            SSLContext sslContext = SSLContext.getInstance("TLS");  
            sslContext.init(null, new TrustManager[]{new TrustAllTrustManager()}, null);  
            HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());  
            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {  
                @Override  
                public boolean verify(String hostname, SSLSession session) {  
                    return true;  
                }  
            });  
        }catch (Exception e){  
            e.printStackTrace();  
        }  
    }  
    
    import java.security.cert.CertificateException;  
    import java.security.cert.X509Certificate;  
    import javax.net.ssl.X509TrustManager;  
    
    public class TrustAllTrustManager implements X509TrustManager {  
        @Override public void checkClientTrusted(X509Certificate[] chain, String authType)  
                throws CertificateException {  
        }  
        @Override public void checkServerTrusted(X509Certificate[] chain, String authType)  
                throws CertificateException {  
        }  
        @Override public X509Certificate[] getAcceptedIssuers() {  
            return null;  
        }  
    }  
    

    相关文章

      网友评论

          本文标题:Caused by: java.security.cert.Ce

          本文链接:https://www.haomeiwen.com/subject/ihudrftx.html