tech.ydb.core.ssl.MultiX509TrustManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-sdk-core Show documentation
Show all versions of ydb-sdk-core Show documentation
Core module of Java SDK for YDB
package tech.ydb.core.ssl;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.X509TrustManager;
final class MultiX509TrustManager implements X509TrustManager {
final List trustManagers;
MultiX509TrustManager(final List trustManagers) {
this.trustManagers = trustManagers;
}
@Override
public void checkClientTrusted(final X509Certificate[] x509Certificates, final String authType)
throws CertificateException {
for (X509TrustManager trustManager : trustManagers) {
try {
trustManager.checkClientTrusted(x509Certificates, authType);
return;
} catch (CertificateException ignored) {
}
}
throw new CertificateException("No trust manager trusts this certificates");
}
@Override
public void checkServerTrusted(final X509Certificate[] x509Certificates, final String authType)
throws CertificateException {
for (X509TrustManager trustManager : trustManagers) {
try {
trustManager.checkServerTrusted(x509Certificates, authType);
return;
} catch (CertificateException ignored) {
}
}
throw new CertificateException("No trust manager trusts this certificates");
}
@Override
public X509Certificate[] getAcceptedIssuers() {
List acceptedIssuers = new ArrayList<>();
for (X509TrustManager trustManager : trustManagers) {
acceptedIssuers.addAll(Arrays.asList(trustManager.getAcceptedIssuers()));
}
return acceptedIssuers.toArray(new X509Certificate[0]);
}
}