Java 8 SSLSocket - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SSLSocket class.

This code example shows how to use the following methods: setEnabledCipherSuites, setEnabledProtocols, setNeedClientAuth
        InetAddress address = InetAddress.getByName(host);
 
        SSLSocketFactory socketFactory = this.sslContext.getSocketFactory();
        SSLSocket socket = (SSLSocket) socketFactory.createSocket(address, port);
        if (this.jsseSecurityDomain.getProtocols() != null)
            socket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols());
        if (this.jsseSecurityDomain.getCipherSuites() != null)
            socket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites());
        socket.setNeedClientAuth(this.jsseSecurityDomain.isClientAuth());
        return socket;
    } 
 
    @Override 
    public Socket createSocket(String host, int port, int timeout) throws IOException, TIMEOUT {
        this.initSSLContext();
        InetAddress address = InetAddress.getByName(host);
 
        SSLSocketFactory socketFactory = this.sslContext.getSocketFactory();
        SSLSocket socket = (SSLSocket) socketFactory.createSocket();
        socket.connect(new InetSocketAddress(address, port), timeout);
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setEnableSessionCreation, setEnabledCipherSuites, setEnabledProtocols, setNeedClientAuth, setUseClientMode
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getSession, startHandshake
      */ 
    private void verifyHostname(Socket socket, String hostname) throws IOException {
        // The code at the start of OpenSSLSocketImpl.startHandshake() 
        // ensures that the call is idempotent, so we can safely call it. 
        SSLSocket ssl = (SSLSocket) socket;
        ssl.startHandshake();
 
        SSLSession session = ssl.getSession();
        if (session == null) {
            throw new SSLException("Cannot verify SSL socket without session");
        } 
        // TODO: Instead of reporting the name of the server we think we're connecting to, 
        // we should be reporting the bad name in the certificate.  Unfortunately this is buried 
        // in the verifier code and is not available in the verifier API, and extracting the 
        // CN & alts is beyond the scope of this patch. 
        if (!HOSTNAME_VERIFIER.verify(hostname, session)) {
            throw new SSLPeerUnverifiedException(
                    "Certificate hostname not useable for server: " + hostname);
        } 
    } 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getEnabledCipherSuites, getSession, setEnabledCipherSuites
        String hostname = (remoteAddress!=null) ? remoteAddress.getHostname() : null;
        int port = (remoteAddress!=null) ? remoteAddress.getPort() : 0;
        SSLSocket resultSocket = (SSLSocket)f.createSocket(lowerLayerSocket, hostname, port, autoClose);
         
        // set properties 
        log.finer("default enabledCipherSuites="+Arrays.toString(resultSocket.getEnabledCipherSuites()));
        if (enabledCipherSuites!=null) {
            resultSocket.setEnabledCipherSuites(enabledCipherSuites);
            log.fine("set enabledCipherSuites="+Arrays.toString(enabledCipherSuites));
        } 
         
        return new TLSNetSocket(new Socket2NetSocket(resultSocket), resultSocket.getSession(), ""+lowerLayerNetSocket);
    } 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getEnableSessionCreation, getEnabledCipherSuites, getEnabledProtocols, getNeedClientAuth, getWantClientAuth
            // to subclassing for the purpose of overriding this behavior (private methods, fields, etc.). 
            // As such, we create a socket (preconfigured by SSLContextParameters) from the context 
            // we gave to FTPSClient and then setup FTPSClient to reuse the already configured configuration 
            // from the socket for all future sockets it creates.  Not sexy and a little brittle, but it works. 
            SSLSocket socket = (SSLSocket)context.getSocketFactory().createSocket();
            client.setEnabledCipherSuites(socket.getEnabledCipherSuites());
            client.setEnabledProtocols(socket.getEnabledProtocols());
            client.setNeedClientAuth(socket.getNeedClientAuth());
            client.setWantClientAuth(socket.getWantClientAuth());
            client.setEnabledSessionCreation(socket.getEnableSessionCreation());
        } else { 
            client = new FTPSClient(getFtpsConfiguration().getSecurityProtocol(),
                                               getFtpsConfiguration().isImplicit()); 
             
            if (ftpClientKeyStoreParameters != null) {
                String type = (ftpClientKeyStoreParameters.containsKey("type"))
                        ? (String) ftpClientKeyStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientKeyStoreParameters.get("file");
                String password = (String) ftpClientKeyStoreParameters.get("password");
                String algorithm = (ftpClientKeyStoreParameters.containsKey("algorithm"))
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 SSLSocket Questions & Answers:

See Code Examples for Java 8 SSLSocket Methods: