Example usage for javax.net.ssl SSLServerSocket getSupportedCipherSuites

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

Introduction

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

Prototype

public abstract String[] getSupportedCipherSuites();

Source Link

Document

Returns the names of the cipher suites which could be enabled for use on an SSL connection.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(8080);
    String[] suites = serverSocket.getSupportedCipherSuites();
    for (int i = 0; i < suites.length; i++) {
        System.out.println(suites[i]);
    }//from  w  w  w  .  j  a  va2s. com
    serverSocket.setEnabledCipherSuites(suites);
    String[] protocols = serverSocket.getSupportedProtocols();
    for (int i = 0; i < protocols.length; i++) {
        System.out.println(protocols[i]);
    }
    SSLSocket socket = (SSLSocket) serverSocket.accept();
    socket.startHandshake();
    System.out.println(socket.getRemoteSocketAddress());
}

From source file:MainClass.java

public static void main(String[] args) {
    int port = Integer.parseInt(args[0]);

    try {/*  ww w .j  a v a2s  .  co  m*/
        System.out.println("Locating server socket factory for SSL...");
        SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

        System.out.println("Creating a server socket on port " + port);
        SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port);

        String[] suites = serverSocket.getSupportedCipherSuites();
        System.out.println("Support cipher suites are:");
        for (int i = 0; i < suites.length; i++) {
            System.out.println(suites[i]);
        }
        serverSocket.setEnabledCipherSuites(suites);

        System.out.println("Support protocols are:");
        String[] protocols = serverSocket.getSupportedProtocols();
        for (int i = 0; i < protocols.length; i++) {
            System.out.println(protocols[i]);
        }

        System.out.println("Waiting for client...");
        SSLSocket socket = (SSLSocket) serverSocket.accept();

        System.out.println("Starting handshake...");
        socket.startHandshake();

        System.out.println("Just connected to " + socket.getRemoteSocketAddress());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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/*w  ww. j  a  v  a  2s.  co 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.apporiented.hermesftp.server.impl.SecureFtpServer.java

private void enableCipherSuites(SSLServerSocket sslServerSocket) {
    String[] cipherSuites = getOptions().getStringArray(OPT_SSL_CIPHER_SUITES, null);
    if (cipherSuites != null) {
        if (cipherSuites.length == 1 && "*".equals(cipherSuites[0])) {
            sslServerSocket.setEnabledCipherSuites(sslServerSocket.getSupportedCipherSuites());
        } else {//from  w w w.j a v a2s  . c  om
            sslServerSocket.setEnabledCipherSuites(cipherSuites);
        }
    }
}

From source file:com.apporiented.hermesftp.cmd.PassiveModeSocketProvider.java

/**
 * Enables the configured cipher suites in the passed server socket.
 * // www. j ava  2s  . c o m
 * @param sslServerSocket The server socket.
 */
private void enableCipherSuites(SSLServerSocket sslServerSocket) {
    String[] cipherSuites = ctx.getOptions().getStringArray(FtpConstants.OPT_SSL_CIPHER_SUITES, null);
    if (cipherSuites != null) {
        if (cipherSuites.length == 1 && FtpConstants.WILDCARD.equals(cipherSuites[0])) {
            sslServerSocket.setEnabledCipherSuites(sslServerSocket.getSupportedCipherSuites());
        } else {
            sslServerSocket.setEnabledCipherSuites(cipherSuites);
        }
    }
}

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  .  ja v a2  s .  c om*/
        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.apache.cassandra.security.SSLFactory.java

public static SSLServerSocket getServerSocket(EncryptionOptions options, InetAddress address, int port)
        throws IOException {
    SSLContext ctx = createSSLContext(options, true);
    SSLServerSocket serverSocket = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket();
    serverSocket.setReuseAddress(true);/*from www  .j a v a  2  s . c  om*/
    String[] suits = filterCipherSuites(serverSocket.getSupportedCipherSuites(), options.cipher_suites);
    serverSocket.setEnabledCipherSuites(suits);
    serverSocket.setNeedClientAuth(options.require_client_auth);
    serverSocket.setEnabledProtocols(ACCEPTED_PROTOCOLS);
    serverSocket.bind(new InetSocketAddress(address, port), 500);
    return serverSocket;
}

From source file:org.apache.ftpserver.ssl.Ssl.java

/**
 * Create secure server socket.//www .j  av a2s  .co m
 */
public ServerSocket createServerSocket(String protocol, InetAddress addr, int port) throws Exception {

    // get server socket factory
    SSLContext ctx = getSSLContext(protocol);
    SSLServerSocketFactory ssocketFactory = ctx.getServerSocketFactory();

    // create server socket
    SSLServerSocket serverSocket = null;
    if (addr == null) {
        serverSocket = (SSLServerSocket) ssocketFactory.createServerSocket(port, 100);
    } else {
        serverSocket = (SSLServerSocket) ssocketFactory.createServerSocket(port, 100, addr);
    }

    // initialize server socket
    String cipherSuites[] = serverSocket.getSupportedCipherSuites();
    serverSocket.setEnabledCipherSuites(cipherSuites);
    serverSocket.setNeedClientAuth(m_clientAuthReqd);
    return serverSocket;
}

From source file:org.wso2.carbon.databridge.receiver.binary.BinaryDataReceiver.java

private void startSecureTransmission() throws IOException, DataBridgeException {
    ServerConfiguration serverConfig = ServerConfiguration.getInstance();
    String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
    if (keyStore == null) {
        keyStore = System.getProperty("Security.KeyStore.Location");
        if (keyStore == null) {
            throw new DataBridgeException(
                    "Cannot start agent server, not valid Security.KeyStore.Location is null");
        }/*  ww w. java  2  s  . c  om*/
    }
    String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
    if (keyStorePassword == null) {
        keyStorePassword = System.getProperty("Security.KeyStore.Password");
        if (keyStorePassword == null) {
            throw new DataBridgeException(
                    "Cannot start agent server, not valid Security.KeyStore.Password is null ");
        }
    }
    System.setProperty("javax.net.ssl.keyStore", keyStore);
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory
            .getDefault();
    SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory
            .createServerSocket(binaryDataReceiverConfiguration.getSSLPort());
    sslserversocket.setEnabledCipherSuites(sslserversocket.getSupportedCipherSuites());
    for (int i = 0; i < binaryDataReceiverConfiguration.getSizeOfSSLThreadPool(); i++) {
        sslReceiverExecutorService.execute(new BinaryTransportReceiver(sslserversocket));
    }
    log.info("Started Binary SSL Transport on port : " + binaryDataReceiverConfiguration.getSSLPort());
}

From source file:org.wso2.carbon.databridge.receiver.binary.internal.BinaryDataReceiver.java

private void startSecureTransmission() throws IOException, DataBridgeException {
    String keyStore = dataBridgeReceiverService.getInitialConfig().getKeyStoreLocation();
    if (keyStore == null) {
        ServerConfiguration serverConfig = ServerConfiguration.getInstance();
        keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
        if (keyStore == null) {
            keyStore = System.getProperty("Security.KeyStore.Location");
            if (keyStore == null) {
                throw new DataBridgeException(
                        "Cannot start binary agent server, not valid Security.KeyStore.Location is null");
            }/*ww w . j  a  va  2 s . c o  m*/
        }
    }
    String keyStorePassword = dataBridgeReceiverService.getInitialConfig().getKeyStorePassword();
    if (keyStorePassword == null) {
        ServerConfiguration serverConfig = ServerConfiguration.getInstance();
        keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
        if (keyStorePassword == null) {
            keyStorePassword = System.getProperty("Security.KeyStore.Password");
            if (keyStorePassword == null) {
                throw new DataBridgeException(
                        "Cannot start binary agent server, not valid Security.KeyStore.Password is null ");
            }
        }
    }
    System.setProperty("javax.net.ssl.keyStore", keyStore);
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory
            .getDefault();
    SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory
            .createServerSocket(binaryDataReceiverConfiguration.getSSLPort());

    String sslProtocols = binaryDataReceiverConfiguration.getSslProtocols();
    if (sslProtocols != null && sslProtocols.length() != 0) {
        String[] sslProtocolsArray = sslProtocols.split(",");
        sslserversocket.setEnabledProtocols(sslProtocolsArray);
    }

    String ciphers = binaryDataReceiverConfiguration.getCiphers();
    if (ciphers != null && ciphers.length() != 0) {
        String[] ciphersArray = ciphers.split(",");
        sslserversocket.setEnabledCipherSuites(ciphersArray);
    } else {
        sslserversocket.setEnabledCipherSuites(sslserversocket.getSupportedCipherSuites());
    }

    Thread thread = new Thread(new BinarySecureEventServerAcceptor(sslserversocket));
    thread.start();
    log.info("Started Binary SSL Transport on port : " + binaryDataReceiverConfiguration.getSSLPort());
}