Example usage for org.apache.http.nio.conn.ssl SSLIOSessionStrategy getDefaultHostnameVerifier

List of usage examples for org.apache.http.nio.conn.ssl SSLIOSessionStrategy getDefaultHostnameVerifier

Introduction

In this page you can find the example usage for org.apache.http.nio.conn.ssl SSLIOSessionStrategy getDefaultHostnameVerifier.

Prototype

public static HostnameVerifier getDefaultHostnameVerifier() 

Source Link

Usage

From source file:com.boonya.http.async.examples.nio.client.AsyncClientCustomSSL.java

public final static void main(String[] args) throws Exception {
    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    FileInputStream instream = new FileInputStream(new File("my.keystore"));
    try {/*w w  w.  ja v a2  s.  c  om*/
        trustStore.load(instream, "nopassword".toCharArray());
    } finally {
        instream.close();
    }
    // Trust own CA and all self-signed certs
    SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
            .build();
    // Allow TLSv1 protocol only
    SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" },
            null, SSLIOSessionStrategy.getDefaultHostnameVerifier());
    CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).build();
    try {
        httpclient.start();
        HttpGet request = new HttpGet("https://issues.apache.org/");
        Future<HttpResponse> future = httpclient.execute(request, null);
        HttpResponse response = future.get();
        System.out.println("Response: " + response.getStatusLine());
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:com.clxcommunications.xms.ApiHttpAsyncClient.java

/**
 * Creates a new HTTP asynchronous client suitable for communicating with
 * XMS.//from  w  ww.  j a v  a2 s  .co m
 * 
 * @param startedInternally
 *            whether this object was created inside this SDK
 */
ApiHttpAsyncClient(boolean startedInternally) {
    this.startedInternally = startedInternally;

    // Allow TLSv1.2 protocol only
    SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(SSLContexts.createSystemDefault(),
            new String[] { "TLSv1.2" }, null, SSLIOSessionStrategy.getDefaultHostnameVerifier());

    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout((int) DEFAULT_TIMEOUT.toMillis())
            .setSocketTimeout((int) DEFAULT_TIMEOUT.toMillis()).build();

    // TODO: Is this a good default setup?
    this.client = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).disableCookieManagement()
            .setMaxConnPerRoute(DEFAULT_MAX_CONN).setMaxConnTotal(DEFAULT_MAX_CONN)
            .setDefaultRequestConfig(requestConfig).build();
}

From source file:org.elasticsearch.xpack.core.ssl.SSLService.java

/**
 * Create a new {@link SSLIOSessionStrategy} based on the provided settings. The settings are used to identify the SSL configuration
 * that should be used to create the context.
 *
 * @param settings the settings used to identify the ssl configuration, typically under a *.ssl. prefix. An empty settings will return
 *                 a context created from the default configuration
 * @return Never {@code null}.//from www .j a  v a  2  s .c  o  m
 */
public SSLIOSessionStrategy sslIOSessionStrategy(Settings settings) {
    SSLConfiguration config = sslConfiguration(settings);
    SSLContext sslContext = sslContext(config);
    String[] ciphers = supportedCiphers(sslParameters(sslContext).getCipherSuites(), config.cipherSuites(),
            false);
    String[] supportedProtocols = config.supportedProtocols().toArray(Strings.EMPTY_ARRAY);
    HostnameVerifier verifier;

    if (config.verificationMode().isHostnameVerificationEnabled()) {
        verifier = SSLIOSessionStrategy.getDefaultHostnameVerifier();
    } else {
        verifier = NoopHostnameVerifier.INSTANCE;
    }

    return sslIOSessionStrategy(sslContext, supportedProtocols, ciphers, verifier);
}