zoukankan      html  css  js  c++  java
  • com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException,OkHttp时间戳校验问题

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

  • 相关阅读:
    EBS中的采购单据状态及其控制
    详解EBS接口开发之采购接收&退货处理之关键API--(补充)
    数据挖掘系列
    如果看了这篇文章你还不懂傅里叶变换,那就过来掐死我吧
    机器学习中的数学
    一个机器学习博客 ,包括 Standford公开课machine learning
    机器学习流行算法一览
    java se 另一博客
    java 正则
    java map
  • 原文地址:https://www.cnblogs.com/linwen5723/p/11371856.html
Copyright © 2011-2022 走看看