美文网首页待写
Https校验服务器证书

Https校验服务器证书

作者: 咚咚_Coding | 来源:发表于2021-06-29 10:35 被阅读0次

Https忽略服务器证书

       X509TrustManager trustAllCertManager = new 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 new X509Certificate[]{};
                }
            };
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[]{trustAllCertManager}, null);
            okHttpClient.sslSocketFactory(sslContext.getSocketFactory(), trustAllCertManager);
            okHttpClient.hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String s, SSLSession sslSession) {
                    return true;
                }
            });

        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }

Https校验服务器证书

         X509TrustManager trustAllCertManager = new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return ACCEPT_ALL;
                }
                public void checkClientTrusted(X509Certificate[] chain, String authType) {
                }
                public void checkServerTrusted(X509Certificate[] chain, String authType) {
                    if (chain != null) {
                        for (X509Certificate cert : chain) {
                            try {
                                cert.verify(cert.getPublicKey());
                            } catch (CertificateException | InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException ignored) {
                            }
                        }
                    }
                }
            };
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[]{trustAllCertManager}, null);
            okHttpClient.sslSocketFactory(sslContext.getSocketFactory(), trustAllCertManager);
    //Trust the cert.
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            if (hostname != null && hostname.endsWith("soyoung.com")) {
                return true;
            } else {
                HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
                return hv.verify(hostname, session);
            }
        }
    };
    okHttpClient.hostnameVerifier(hostnameVerifier);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }

抓包工具配置ca证书

https://blog.csdn.net/pingsha_luoyan/article/details/106096702

相关文章

  • Https校验服务器证书

    Https忽略服务器证书 Https校验服务器证书 抓包工具配置ca证书

  • webview漏洞

    1. webView绕过证书校验漏洞(客户端访问使用Https协议加密的url时,如果服务器证书校验错误,客户端应...

  • Let's Encrypt更新报错

    今天收到letsencrypt的邮件说证书到期,上服务器检查,发现使用cerbot更新证书时,报错HTTPS校验错...

  • 2019-12-31

    证书校验,包括签名校验(是否是CA机构签名的证书)和属性校验(域名校验、有效期校验) 证书的作用,对服务器实体的身...

  • Https证书校验

    客户端校验服务器的证书,一般有两种情况: 直接校验服务器下发的证书,并与本地的证书作对比 证书锁定法,直接利用本地...

  • HTTPS证书校验

    HTTPS (全称:Hyper Text Transfer Protocol over SecureSocket ...

  • OkHttp https证书校验

    https证书校验

  • 屏蔽HTTPS证书校验

    屏蔽HTTPS证书校验 ————————————————————————————————————————— 背景需...

  • JAVA 不校验HTTPS服务器证书

    本章是HTTPS那些事儿的第三篇文章,其他相关文章请参见:前言本篇主要描述JAVA经常遇到的场景:不校验服务器CA...

  • flutter加载https图片遇到证书验证失败问题

    参考文章:Flutter加载图片证书校验失败问题 Flutter https证书问题

网友评论

    本文标题:Https校验服务器证书

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