Search in sources :

Example 11 with DefaultHostnameVerifier

use of org.apache.http.conn.ssl.DefaultHostnameVerifier in project scout.rt by eclipse.

the class ApacheHttpTransportFactory method getConfiguredConnectionManager.

/**
 * Return the {@link HttpClientConnectionManager}. Return <code>null</code> to create it using the
 * {@link HttpClientBuilder}. Caution: Returning a custom connection manager overrides several properties of the
 * {@link HttpClientBuilder}.
 */
protected HttpClientConnectionManager getConfiguredConnectionManager() {
    String[] sslProtocols = StringUtility.split(System.getProperty("https.protocols"), "\\s*,\\s*");
    String[] sslCipherSuites = StringUtility.split(System.getProperty("https.cipherSuites"), "\\s*,\\s*");
    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault(), sslProtocols != null && sslProtocols.length > 0 ? sslProtocols : null, sslCipherSuites != null && sslCipherSuites.length > 0 ? sslCipherSuites : null, new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault()));
    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslConnectionSocketFactory).build(), null, null, null, CONFIG.getPropertyValue(ApacheHttpTransportConnectionTimeToLiveProperty.class), TimeUnit.MILLISECONDS);
    connectionManager.setValidateAfterInactivity(1);
    Integer maxTotal = CONFIG.getPropertyValue(ApacheHttpTransportMaxConnectionsTotalProperty.class);
    if (maxTotal != null && maxTotal > 0) {
        connectionManager.setMaxTotal(maxTotal);
    }
    Integer defaultMaxPerRoute = CONFIG.getPropertyValue(ApacheHttpTransportMaxConnectionsPerRouteProperty.class);
    if (defaultMaxPerRoute > 0) {
        connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
    }
    return connectionManager;
}
Also used : PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) ApacheHttpTransportConnectionTimeToLiveProperty(org.eclipse.scout.rt.shared.http.HttpConfigurationProperties.ApacheHttpTransportConnectionTimeToLiveProperty) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 12 with DefaultHostnameVerifier

use of org.apache.http.conn.ssl.DefaultHostnameVerifier in project azure-tools-for-java by Microsoft.

the class SparkBatchSubmission method getSSLSocketFactory.

@Nullable
protected SSLConnectionSocketFactory getSSLSocketFactory() {
    TrustStrategy ts = ServiceManager.getServiceProvider(TrustStrategy.class);
    SSLConnectionSocketFactory sslSocketFactory = null;
    if (ts != null) {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(ts).build();
            sslSocketFactory = new SSLConnectionSocketFactory(sslContext, HttpObservable.isSSLCertificateValidationDisabled() ? NoopHostnameVerifier.INSTANCE : new DefaultHostnameVerifier());
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            log().error("Prepare SSL Context for HTTPS failure. " + ExceptionUtils.getStackTrace(e));
        }
    }
    return sslSocketFactory;
}
Also used : TrustStrategy(org.apache.http.ssl.TrustStrategy) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) KeyManagementException(java.security.KeyManagementException) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 13 with DefaultHostnameVerifier

use of org.apache.http.conn.ssl.DefaultHostnameVerifier in project azure-tools-for-java by Microsoft.

the class HttpObservable method createSSLSocketFactory.

private SSLConnectionSocketFactory createSSLSocketFactory() {
    TrustStrategy ts = ServiceManager.getServiceProvider(TrustStrategy.class);
    SSLConnectionSocketFactory sslSocketFactory = null;
    if (ts != null) {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(ts).build();
            sslSocketFactory = new SSLConnectionSocketFactory(sslContext, HttpObservable.isSSLCertificateValidationDisabled() ? NoopHostnameVerifier.INSTANCE : new DefaultHostnameVerifier());
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            log().error("Prepare SSL Context for HTTPS failure. " + ExceptionUtils.getStackTrace(e));
        }
    }
    return sslSocketFactory;
}
Also used : TrustStrategy(org.apache.http.ssl.TrustStrategy) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) KeyManagementException(java.security.KeyManagementException)

Aggregations

DefaultHostnameVerifier (org.apache.http.conn.ssl.DefaultHostnameVerifier)13 SSLContext (javax.net.ssl.SSLContext)9 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)9 KeyManagementException (java.security.KeyManagementException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)5 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)5 IOException (java.io.IOException)4 KeyStoreException (java.security.KeyStoreException)4 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)4 CertificateException (java.security.cert.CertificateException)3 HostnameVerifier (javax.net.ssl.HostnameVerifier)3 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)3 TrustStrategy (org.apache.http.ssl.TrustStrategy)3 URL (java.net.URL)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyStore (java.security.KeyStore)2 HttpResponse (org.apache.http.HttpResponse)2 CookieStore (org.apache.http.client.CookieStore)2 RequestConfig (org.apache.http.client.config.RequestConfig)2