Example usage for javax.net.ssl SSLParameters setProtocols

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

Introduction

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

Prototype

public void setProtocols(String[] protocols) 

Source Link

Document

Sets the array of protocols.

Usage

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

/**
 * factory method for custom usage.//from  ww  w. j a v a  2 s  .  c o m
 *
 * @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);
}