Example usage for javax.net.ssl SSLSocket getSSLParameters

List of usage examples for javax.net.ssl SSLSocket getSSLParameters

Introduction

In this page you can find the example usage for javax.net.ssl SSLSocket getSSLParameters.

Prototype

public SSLParameters getSSLParameters() 

Source Link

Document

Returns the SSLParameters in effect for this SSLSocket.

Usage

From source file:Test.java

public static void main(String[] arstring) throws Exception {
        SSLServerSocketFactory sslServerSocketFactory = (SSLServerSocketFactory) SSLServerSocketFactory
                .getDefault();/*from   ww w  .java2s  . c om*/
        SSLServerSocket sslServerSocket = (SSLServerSocket) sslServerSocketFactory.createServerSocket(9999);
        System.out.println("Waiting for a client ...");
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();

        SSLParameters parameters = sslSocket.getSSLParameters();
        parameters.setAlgorithmConstraints(new SimpleConstraints());

        AlgorithmConstraints constraints = parameters.getAlgorithmConstraints();
        System.out.println("Constraint: " + constraints);

        String endPoint = parameters.getEndpointIdentificationAlgorithm();
        System.out.println("End Point: " + endPoint);

        System.out.println("Local Supported Signature Algorithms");
        if (sslSocket.getSession() instanceof ExtendedSSLSession) {
            ExtendedSSLSession extendedSSLSession = (ExtendedSSLSession) sslSocket.getSession();
            String alogrithms[] = extendedSSLSession.getLocalSupportedSignatureAlgorithms();
            for (String algorithm : alogrithms) {
                System.out.println("Algortihm: " + algorithm);
            }
        }

        System.out.println("Peer Supported Signature Algorithms");
        if (sslSocket.getSession() instanceof ExtendedSSLSession) {
            String alogrithms[] = ((ExtendedSSLSession) sslSocket.getSession())
                    .getPeerSupportedSignatureAlgorithms();
            for (String algorithm : alogrithms) {
                System.out.println("Algortihm: " + algorithm);
            }
        }

        InputStream inputstream = sslSocket.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

        SSLSession session = sslSocket.getHandshakeSession();
        if (session != null) {
            System.out.println("Last accessed: " + new Date(session.getLastAccessedTime()));
        }

        String string = null;
        while ((string = bufferedreader.readLine()) != null) {
            System.out.println(string);
            System.out.flush();
        }

    }

From source file:com.microsoft.tfs.core.config.httpclient.internal.DefaultSSLProtocolSocketFactory.java

private void configureSNI(final Socket socket, final String host) {

    if (System.getProperty("java.version").compareTo("1.8") < 0) { //$NON-NLS-1$ //$NON-NLS-2$
        return;//from   w  w  w.j  a  v a2  s.  c om
    }

    /*
     * Classes used to configure Server Name client-hello extension were
     * introduced in Java 8. So, we neither can use nor compile this code
     * using Java 6-7. Thus, let's use reflection.
     */

    try {
        final SSLSocket sslSocket = (SSLSocket) socket;
        final SSLParameters params = sslSocket.getSSLParameters();

        final Class<?> sniHostNameClass = Class.forName("javax.net.ssl.SNIHostName"); //$NON-NLS-1$
        final Constructor<?> sniHostNameClassConstructor = sniHostNameClass.getConstructor(String.class);

        final Object serverName = sniHostNameClassConstructor.newInstance(host);
        final List<Object> serverNames = new ArrayList<Object>(1);
        serverNames.add(serverName);

        final Class<?> paramsClass = params.getClass();
        final Method setServerNames = paramsClass.getMethod("setServerNames", List.class); //$NON-NLS-1$
        setServerNames.invoke(params, serverNames);

        sslSocket.setSSLParameters(params);
    } catch (final Exception e) {
        log.error("Eror configuring SSL socket with SNI cipher extension:", e); //$NON-NLS-1$
    }
}

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

public void applyCiphers(SSLSocket sslSocket) {
    if (ciphers != null) {
        SSLParameters sslParameters = sslSocket.getSSLParameters();
        applyCipherOrdering(sslParameters);
        sslParameters.setCipherSuites(ciphers);
        sslSocket.setSSLParameters(sslParameters);
    }//from   w w  w .  ja v a2  s  .  co m
}