
com.aliyun.credentials.http.X509TrustManagerImp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of credentials-java Show documentation
Show all versions of credentials-java Show documentation
Alibaba Cloud Credentials for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
https://www.aliyun.com
package com.aliyun.credentials.http;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class X509TrustManagerImp implements X509TrustManager {
private List trustManagers = new ArrayList();
private boolean ignoreSSLCert = false;
public boolean isIgnoreSSLCert() {
return ignoreSSLCert;
}
public X509TrustManagerImp(boolean ignoreSSLCert) {
this.ignoreSSLCert = ignoreSSLCert;
}
public X509TrustManagerImp(List trustManagers) {
this.trustManagers = trustManagers;
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
// do nothing
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
if (this.ignoreSSLCert) {
return;
}
for (X509TrustManager trustManager : this.trustManagers) {
try {
trustManager.checkServerTrusted(chain, authType);
return; // someone trusts them. success!
} catch (CertificateException e) {
// maybe someone else will trust them
}
}
throw new CertificateException("None of the TrustManagers trust this certificate chain");
}
@Override
public X509Certificate[] getAcceptedIssuers() {
List certificates = new ArrayList();
for (X509TrustManager trustManager : this.trustManagers) {
certificates.addAll(Arrays.asList(trustManager.getAcceptedIssuers()));
}
X509Certificate[] certificatesArray = new X509Certificate[certificates.size()];
return certificates.toArray(certificatesArray);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy