Example usage for io.vertx.core.net TCPSSLOptions addEnabledSecureTransportProtocol

List of usage examples for io.vertx.core.net TCPSSLOptions addEnabledSecureTransportProtocol

Introduction

In this page you can find the example usage for io.vertx.core.net TCPSSLOptions addEnabledSecureTransportProtocol.

Prototype

public TCPSSLOptions addEnabledSecureTransportProtocol(String protocol) 

Source Link

Document

Add an enabled SSL/TLS protocols, appended to the ordered protocols.

Usage

From source file:io.servicecomb.foundation.vertx.VertxTLSBuilder.java

License:Apache License

private static TCPSSLOptions buildTCPSSLOptions(SSLOption sslOption, SSLCustom sslCustom,
        TCPSSLOptions httpClientOptions) {
    httpClientOptions.setSsl(true);//from   w w w  .  j  a  v a  2s .  co  m
    if (isFileExists(sslCustom.getFullPath(sslOption.getKeyStore()))) {
        if (STORE_PKCS12.equalsIgnoreCase(sslOption.getKeyStoreType())) {
            PfxOptions keyPfxOptions = new PfxOptions();
            keyPfxOptions.setPath(sslCustom.getFullPath(sslOption.getKeyStore()));
            keyPfxOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray())));
            httpClientOptions.setPfxKeyCertOptions(keyPfxOptions);
        } else if (STORE_JKS.equalsIgnoreCase(sslOption.getKeyStoreType())) {
            JksOptions keyJksOptions = new JksOptions();
            keyJksOptions.setPath(sslCustom.getFullPath(sslOption.getKeyStore()));
            keyJksOptions.setPassword(new String(sslCustom.decode(sslOption.getKeyStoreValue().toCharArray())));
            httpClientOptions.setKeyStoreOptions(keyJksOptions);
        } else {
            throw new IllegalArgumentException("invalid key store type.");
        }
    }

    if (isFileExists(sslCustom.getFullPath(sslOption.getTrustStore()))) {
        if (STORE_PKCS12.equalsIgnoreCase(sslOption.getTrustStoreType())) {
            PfxOptions trustPfxOptions = new PfxOptions();
            trustPfxOptions.setPath(sslCustom.getFullPath(sslOption.getTrustStore()));
            trustPfxOptions
                    .setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray())));
            httpClientOptions.setPfxTrustOptions(trustPfxOptions);
        } else if (STORE_JKS.equalsIgnoreCase(sslOption.getTrustStoreType())) {
            JksOptions trustJksOptions = new JksOptions();
            trustJksOptions.setPath(sslCustom.getFullPath(sslOption.getTrustStore()));
            trustJksOptions
                    .setPassword(new String(sslCustom.decode(sslOption.getTrustStoreValue().toCharArray())));
            httpClientOptions.setTrustStoreOptions(trustJksOptions);
        } else {
            throw new IllegalArgumentException("invalid trust store type.");
        }
    }

    for (String protocol : sslOption.getProtocols().split(",")) {
        httpClientOptions.addEnabledSecureTransportProtocol(protocol);
    }
    for (String cipher : SSLManager.getEnalbedCiphers(sslOption.getCiphers())) {
        httpClientOptions.addEnabledCipherSuite(cipher);
    }

    if (isFileExists(sslCustom.getFullPath(sslOption.getCrl()))) {
        httpClientOptions.addCrlPath(sslCustom.getFullPath(sslOption.getCrl()));
    }
    return httpClientOptions;
}