001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.net.ssl;
015
016import javax.net.ssl.SSLParameters;
017import javax.net.ssl.SSLSocket;
018
019/**
020 * An {@link SSLConfigurable} wrapper for an {@link SSLSocket}.
021 *
022 * @author Carl Harris
023 * @author Bruno Harbulot
024 */
025public class SSLConfigurableSocket implements SSLConfigurable {
026
027    private final SSLSocket delegate;
028
029    public SSLConfigurableSocket(SSLSocket delegate) {
030        this.delegate = delegate;
031    }
032
033    public String[] getDefaultProtocols() {
034        return delegate.getEnabledProtocols();
035    }
036
037    public String[] getSupportedProtocols() {
038        return delegate.getSupportedProtocols();
039    }
040
041    public void setEnabledProtocols(String[] protocols) {
042        delegate.setEnabledProtocols(protocols);
043    }
044
045    public String[] getDefaultCipherSuites() {
046        return delegate.getEnabledCipherSuites();
047    }
048
049    public String[] getSupportedCipherSuites() {
050        return delegate.getSupportedCipherSuites();
051    }
052
053    public void setEnabledCipherSuites(String[] suites) {
054        delegate.setEnabledCipherSuites(suites);
055    }
056
057    public void setNeedClientAuth(boolean state) {
058        delegate.setNeedClientAuth(state);
059    }
060
061    public void setWantClientAuth(boolean state) {
062        delegate.setWantClientAuth(state);
063    }
064
065    @Override
066    public void setHostnameVerification(boolean hostnameVerification) {
067        if (!hostnameVerification) {
068            return;
069        }
070        SSLParameters sslParameters = delegate.getSSLParameters();
071        sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
072        delegate.setSSLParameters(sslParameters);
073    }
074
075}