Example usage for javax.net.ssl SSLServerSocket setUseClientMode

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

Introduction

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

Prototype

public abstract void setUseClientMode(boolean mode);

Source Link

Document

Controls whether accepted connections are in the (default) SSL server mode, or the SSL client mode.

Usage

From source file:com.myJava.file.driver.remote.ftp.SecuredSocketFactory.java

private void initServerSocket(SSLServerSocket socket) throws IOException {
    socket.setUseClientMode(true);
}

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

/**
 * Creates the server socket that accepts the data connection.
 * //w w  w. ja  v  a2s  . co m
 * @param localIp The local IP address.
 * @param port The port.
 * @return The server socket.
 * @throws IOException Error on creating server socket.
 */
private ServerSocket createServerSocket(InetAddress localIp, int port) throws IOException {
    ServerSocket sock;
    Boolean dataProtection = (Boolean) ctx.getAttribute(FtpConstants.ATTR_DATA_PROT);
    boolean ssl = dataProtection != null && dataProtection;
    if (ssl) {
        SSLServerSocketFactory factory = ctx.getOptions().getSslContext().getServerSocketFactory();
        SSLServerSocket sslServerSocket = (SSLServerSocket) factory.createServerSocket(port, 1, localIp);
        sslServerSocket.setUseClientMode(false);
        enableCipherSuites(sslServerSocket);
        sock = sslServerSocket;
    } else {
        sock = ServerSocketFactory.getDefault().createServerSocket(port, 1, localIp);
    }
    sock.setSoTimeout(DATA_CHANNEL_TIMEOUT);
    return sock;
}

From source file:org.nectarframework.base.service.nanohttp.NanoHttpService.java

/**
 * Creates an SSLSocketFactory for HTTPS. Pass a KeyStore resource with your
 * certificate and passphrase//w  ww .  j  av  a  2  s.  c  om
 */
public ServerSocket makeSSLServerSocket(String keyAndTrustStoreClasspathPath, char[] passphrase)
        throws IOException {
    try {
        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        InputStream keystoreStream = new FileInputStream(new File(keyAndTrustStoreClasspathPath));

        keystore.load(keystoreStream, passphrase);
        KeyManagerFactory keyManagerFactory = KeyManagerFactory
                .getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keystore, passphrase);

        SSLServerSocketFactory res = null;
        try {
            TrustManagerFactory trustManagerFactory = TrustManagerFactory
                    .getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(keystore);
            SSLContext ctx = SSLContext.getInstance("TLS");
            ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
            res = ctx.getServerSocketFactory();

        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }

        SSLServerSocket ss = null;
        ss = (SSLServerSocket) res.createServerSocket();
        ss.setEnabledProtocols(ss.getSupportedProtocols());
        ss.setUseClientMode(false);
        ss.setWantClientAuth(false);
        ss.setNeedClientAuth(false);

        return ss;

    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:org.apache.geode.internal.net.SocketCreator.java

/**
 * Configure the SSLServerSocket based on this SocketCreator's settings.
 *//*from  w  ww .  j a  v  a  2s .com*/
private void finishServerSocket(SSLServerSocket serverSocket) throws IOException {
    serverSocket.setUseClientMode(false);
    if (this.sslConfig.isRequireAuth()) {
        // serverSocket.setWantClientAuth( true );
        serverSocket.setNeedClientAuth(true);
    }
    serverSocket.setEnableSessionCreation(true);

    // restrict protocols
    String[] protocols = this.sslConfig.getProtocolsAsStringArray();
    if (!"any".equalsIgnoreCase(protocols[0])) {
        serverSocket.setEnabledProtocols(protocols);
    }
    // restrict ciphers
    String[] ciphers = this.sslConfig.getCiphersAsStringArray();
    if (!"any".equalsIgnoreCase(ciphers[0])) {
        serverSocket.setEnabledCipherSuites(ciphers);
    }
}