AuthSSLProtocolSocketFactory.java 2.05 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.commons.httpclient.HttpClientError
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.replication.impl.transport;

import com.day.cq.replication.impl.transport.EasySSLProtocolSocketFactory;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.HttpClientError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AuthSSLProtocolSocketFactory
extends EasySSLProtocolSocketFactory {
    private static final Logger LOG = LoggerFactory.getLogger(AuthSSLProtocolSocketFactory.class);
    private SSLContext sslcontext;
    private KeyManager keyManager;
    private TrustManager trustManager;

    public AuthSSLProtocolSocketFactory(KeyManager keyManager, TrustManager trustManager, String[] disabledSuites, String[] enabledSuites) {
        super(disabledSuites, enabledSuites);
        this.keyManager = keyManager;
        this.trustManager = trustManager;
    }

    private SSLContext createSSLContext() {
        try {
            SSLContext sslcontext = SSLContext.getInstance("SSL");
            sslcontext.init(new KeyManager[]{this.keyManager}, new TrustManager[]{this.trustManager}, new SecureRandom());
            return sslcontext;
        }
        catch (NoSuchAlgorithmException e) {
            LOG.error(e.getMessage(), (Throwable)e);
            throw new HttpClientError("Unsupported algorithm exception: " + e.getMessage());
        }
        catch (GeneralSecurityException e) {
            LOG.error(e.getMessage(), (Throwable)e);
            throw new HttpClientError("Key management exception: " + e.getMessage());
        }
    }

    @Override
    protected SSLContext getSSLContext() {
        if (this.sslcontext == null) {
            this.sslcontext = this.createSSLContext();
        }
        return this.sslcontext;
    }
}