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

com.yandex.ydb.core.ssl.MultiX509TrustManager Maven / Gradle / Ivy

The newest version!
package com.yandex.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;

    public 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 e) {
                continue;
            }
        }
        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 e) {
                continue;
            }
        }
        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[acceptedIssuers.size()]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy