Example usage for javax.net.ssl SSLParameters setCipherSuites

List of usage examples for javax.net.ssl SSLParameters setCipherSuites

Introduction

In this page you can find the example usage for javax.net.ssl SSLParameters setCipherSuites.

Prototype

public void setCipherSuites(String[] cipherSuites) 

Source Link

Document

Sets the array of ciphersuites.

Usage

From source file:com.vmware.bdd.security.tls.SimpleSeverTrustTlsSocketFactory.java

/**
 * factory method for custom usage.//from   w w w .  j  a  va2s.  c  om
 *
 * @return a factory
 */
public static SSLSocketFactory makeSSLSocketFactory(TrustStoreConfig trustStoreCfg) {
    check(trustStoreCfg);

    SimpleServerTrustManager simpleServerTrustManager = new SimpleServerTrustManager();
    simpleServerTrustManager.setTrustStoreConfig(trustStoreCfg);
    /**
     *  Initialize our own trust manager
     */
    TrustManager[] trustManagers = new TrustManager[] { simpleServerTrustManager };

    SSLContext customSSLContext = null;
    try {
        /**
         * Instantiate a context that implements the family of TLS protocols
         */
        customSSLContext = SSLContext.getInstance("TLS");

        /**
         * Initialize SSL context. Default instances of KeyManager and
         * SecureRandom are used.
         */
        customSSLContext.init(null, trustManagers, null);
    } catch (NoSuchAlgorithmException e) {
        throw new TlsInitException("SSLContext_INIT_ERR", e);
    } catch (KeyManagementException e) {
        throw new TlsInitException("SSLContext_INIT_ERR", e);
    }

    TlsClientConfiguration tlsClientConfiguration = new TlsClientConfiguration();
    /**
     * Build connection configuration and pass to socket
     */
    SSLParameters params = new SSLParameters();
    params.setCipherSuites(tlsClientConfiguration.getCipherSuites());
    params.setProtocols(tlsClientConfiguration.getSslProtocols());
    //      params.setEndpointIdentificationAlgorithm(
    //            config.getEndpointIdentificationAlgorithm());
    /**
     * Use the SSLSocketFactory generated by the SSLContext and wrap it to
     * enable custom cipher suites and protocols
     */
    return new SimpleSeverTrustTlsSocketFactory(customSSLContext.getSocketFactory(), params);
}

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  ww  w.j  a  va  2  s .  c  o  m*/
}

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

public void applyCiphers(SSLServerSocket sslServerSocket) {
    if (ciphers != null) {
        if (getSSLParametersMethod == null || setSSLParametersMethod == null) {
            sslServerSocket.setEnabledCipherSuites(ciphers);
        } else {//from   w  ww  . ja  v a2  s . c om
            SSLParameters sslParameters;
            try {
                // "sslParameters = sslServerSocket.getSSLParameters();" works only on Java 7+
                sslParameters = (SSLParameters) getSSLParametersMethod.invoke(sslServerSocket, new Object[] {});
                applyCipherOrdering(sslParameters);
                sslParameters.setCipherSuites(ciphers);
                // "sslServerSocket.setSSLParameters(sslParameters);" works only on Java 7+
                setSSLParametersMethod.invoke(sslServerSocket, new Object[] { sslParameters });
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            }
        }
    }
}