All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.net.wanmo.common.http.jdk.ssl.MyTrustManager Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package cn.net.wanmo.common.http.jdk.ssl;

import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * 默认忽略 https 校验
 */
public class MyTrustManager implements X509TrustManager {
    @Override
    public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
        // 客户端校验不需要实现,留空即可
    }
    @Override
    public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
        // 服务器证书校验逻辑
        // 可以使用自定义的逻辑校验服务器证书,例如判断证书的颁发机构、有效期等
        // 如果校验失败,可以抛出CertificateException异常
    }
    @Override
    public X509Certificate[] getAcceptedIssuers() {
        // 返回信任的证书颁发机构列表,留空即可
        return new X509Certificate[0];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy