Example usage for javax.net.ssl SSLServerSocket getEnabledProtocols

List of usage examples for javax.net.ssl SSLServerSocket getEnabledProtocols

Introduction

In this page you can find the example usage for javax.net.ssl SSLServerSocket getEnabledProtocols.

Prototype

public abstract String[] getEnabledProtocols();

Source Link

Document

Returns the names of the protocols which are currently enabled for use by the newly accepted connections.

Usage

From source file:net.i2p.util.I2PSSLSocketFactory.java

/**
 * Select protocols and cipher suites to be used
 * based on configured inclusion and exclusion lists
 * as well as enabled and supported protocols and cipher suites.
 *
 * Adapted from Jetty SslContextFactory.java
 *
 * @since 0.9.16/*from w w  w .ja  va  2 s .c o m*/
 */
public static void setProtocolsAndCiphers(SSLServerSocket socket) {
    String[] p = selectProtocols(socket.getEnabledProtocols(), socket.getSupportedProtocols());
    for (int i = 0; i < p.length; i++) {
        // if we left SSLv3 in there, we don't support TLS,
        // so we should't remove the SSL ciphers
        if (p[i].equals("SSLv3"))
            return;
    }
    socket.setEnabledProtocols(p);
    socket.setEnabledCipherSuites(
            selectCipherSuites(socket.getEnabledCipherSuites(), socket.getSupportedCipherSuites()));
}

From source file:com.predic8.membrane.core.transport.ssl.SSLContext.java

public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddress) throws IOException {
    SSLServerSocketFactory sslssf = sslc.getServerSocketFactory();
    SSLServerSocket sslss = (SSLServerSocket) sslssf.createServerSocket(port, backlog, bindAddress);
    applyCiphers(sslss);//from w w  w. j a  va 2  s.c om
    if (protocols != null) {
        sslss.setEnabledProtocols(protocols);
    } else {
        String[] protocols = sslss.getEnabledProtocols();
        Set<String> set = new HashSet<String>();
        for (String protocol : protocols) {
            if (protocol.equals("SSLv3") || protocol.equals("SSLv2Hello")) {
                continue;
            }
            set.add(protocol);
        }
        sslss.setEnabledProtocols(set.toArray(new String[0]));
    }
    sslss.setWantClientAuth(wantClientAuth);
    sslss.setNeedClientAuth(needClientAuth);
    return sslss;
}

From source file:coyote.commons.network.http.SSLServerSocketFactoryTest.java

@Test
public void createPassesTheProtocolsToServerSocket() throws IOException {
    // first find the supported protocols
    SecureServerSocketFactory secureServerSocketFactory = new SecureServerSocketFactory(
            HTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), null);
    SSLServerSocket socket = (SSLServerSocket) secureServerSocketFactory.create();
    String[] protocols = socket.getSupportedProtocols();

    // remove one element from supported protocols
    if (protocols.length > 0) {
        protocols = Arrays.copyOfRange(protocols, 0, protocols.length - 1);
    }//from   w w w.  j a v a2s . co m

    // test
    secureServerSocketFactory = new SecureServerSocketFactory(
            HTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), protocols);
    socket = (SSLServerSocket) secureServerSocketFactory.create();
    Assert.assertArrayEquals("Enabled protocols specified in the factory were not set to the socket.",
            protocols, socket.getEnabledProtocols());
}

From source file:com.adito.server.jetty.CustomJsseListener.java

protected ServerSocket newServerSocket(InetAddrPort p_address, int p_acceptQueueSize) throws IOException {
    SSLServerSocket serverSocket = (SSLServerSocket) super.newServerSocket(p_address, p_acceptQueueSize);
    if (serverSocket.getNeedClientAuth()) {

        serverSocket.setNeedClientAuth(require);
        setNeedClientAuth(require);//from  w  ww  .  j  av a2 s .  c o m
        if (!require)
            serverSocket.setWantClientAuth(true);
    }

    String[] ciphers = serverSocket.getSupportedCipherSuites();
    String[] protocols = serverSocket.getSupportedProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are supported:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    if (createAvailableCipherSuitesList) {
        File f = new File(ContextHolder.getContext().getTempDirectory(), "availableCipherSuites.txt");
        BufferedWriter writer = null;

        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
            if (log.isInfoEnabled())
                log.info("The following cipher suites are supported:");
            for (int i = 0; i < ciphers.length; i++) {
                if (log.isInfoEnabled())
                    log.info("     " + ciphers[i]);
                writer.write(ciphers[i]);
                writer.newLine();
            }
        } catch (Throwable e) {
            log.error("Could not create cipher list!", e);
            configureContext = false;
        } finally {
            if (writer != null)
                writer.close();
        }
        createAvailableCipherSuitesList = false;
    }

    if (configureContext) {

        PropertyList list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedProtocols"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledProtocols(list.asArray());
        }

        list = ContextHolder.getContext().getConfig()
                .retrievePropertyList(new ContextKey("ssl.supportedCiphers"));

        if (!list.isEmpty()) {
            serverSocket.setEnabledCipherSuites(list.asArray());
        }
    }

    protocols = serverSocket.getEnabledProtocols();

    if (log.isInfoEnabled()) {
        log.info("The following protocols are enabled:");
        for (int i = 0; i < protocols.length; i++) {
            log.info("     " + protocols[i]);
        }
    }

    ciphers = serverSocket.getEnabledCipherSuites();
    if (log.isInfoEnabled()) {
        log.info("The following cipher suites are enabled:");
        for (int i = 0; i < ciphers.length; i++) {
            log.info("     " + ciphers[i]);
        }
    }

    return serverSocket;
}

From source file:org.lockss.protocol.BlockingStreamComm.java

private void disableSelectedProtocols(SSLServerSocket sock) {
    if (paramDisableSslServerProtocols == null)
        return;//w  ww.j  a  va 2 s .  c o  m
    Set<String> enaprotos = new HashSet<String>();
    for (String s : sock.getEnabledProtocols()) {
        if (paramDisableSslServerProtocols.contains(s)) {
            continue;
        }
        enaprotos.add(s);
    }
    sock.setEnabledProtocols(enaprotos.toArray(new String[0]));
}