AuthSSLX509TrustManager.java 2.91 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.replication.impl.transport;

import java.security.Principal;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Date;
import javax.net.ssl.X509TrustManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AuthSSLX509TrustManager
implements X509TrustManager {
    private X509TrustManager defaultTrustManager = null;
    private static final Logger LOG = LoggerFactory.getLogger(AuthSSLX509TrustManager.class);

    public AuthSSLX509TrustManager(X509TrustManager defaultTrustManager) {
        if (defaultTrustManager == null) {
            throw new IllegalArgumentException("Trust manager may not be null");
        }
        this.defaultTrustManager = defaultTrustManager;
    }

    @Override
    public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
        if (LOG.isDebugEnabled() && certificates != null) {
            for (int c = 0; c < certificates.length; ++c) {
                LOG.debug("------------------------------------------");
                X509Certificate cert = certificates[c];
                LOG.debug(" Client certificate " + (c + 1) + ":");
                LOG.debug("  Subject DN: " + cert.getSubjectDN());
                LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
                LOG.debug("  Valid from: " + cert.getNotBefore());
                LOG.debug("  Valid until: " + cert.getNotAfter());
                LOG.debug("  Issuer: " + cert.getIssuerDN());
                LOG.debug("------------------------------------------");
            }
        }
        this.defaultTrustManager.checkClientTrusted(certificates, authType);
    }

    @Override
    public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
        if (LOG.isDebugEnabled() && certificates != null) {
            for (int c = 0; c < certificates.length; ++c) {
                X509Certificate cert = certificates[c];
                LOG.debug("------------------------------------------");
                LOG.debug(" Server certificate " + (c + 1) + ":");
                LOG.debug("  Subject DN: " + cert.getSubjectDN());
                LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
                LOG.debug("  Valid from: " + cert.getNotBefore());
                LOG.debug("  Valid until: " + cert.getNotAfter());
                LOG.debug("  Issuer: " + cert.getIssuerDN());
                LOG.debug("------------------------------------------");
            }
        }
        this.defaultTrustManager.checkServerTrusted(certificates, authType);
    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        return this.defaultTrustManager.getAcceptedIssuers();
    }
}