Search in sources :

Example 1 with SSLContextBuilder

use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.

the class GeoSDIHttpClient5 method createClientConnectionManager.

/**
 * @return {@link HttpClientConnectionManager}
 */
HttpClientConnectionManager createClientConnectionManager() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, (chain, authType) -> true);
        SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
        cm.setMaxTotal(10);
        cm.setDefaultMaxPerRoute(3);
        return cm;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IllegalStateException(ex);
    }
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) URISyntaxException(java.net.URISyntaxException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IOException(java.io.IOException) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Example 2 with SSLContextBuilder

use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.

the class GPAbstractServerConnector method createDefaultSSLConnectionSocketFactory.

/**
 * @return {@link SSLConnectionSocketFactory}
 */
protected SSLConnectionSocketFactory createDefaultSSLConnectionSocketFactory() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, (chain, authType) -> true);
        return new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
    } catch (Exception ex) {
        logger.warn("#####################Error to createDefaultSSLConnectionSocketFactory cause : {}\n", ex.getMessage());
        ex.printStackTrace();
    }
    return SSLConnectionSocketFactory.getSocketFactory();
}
Also used : SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException)

Example 3 with SSLContextBuilder

use of org.apache.hc.core5.ssl.SSLContextBuilder in project commons-vfs by apache.

the class Http5FileProvider method createSSLContext.

/**
 * Create {@link SSLContext} for HttpClient. Invoked by {@link #createHttpClientBuilder(Http5FileSystemConfigBuilder, GenericFileName, FileSystemOptions)}.
 *
 * @param builder Configuration options builder for HTTP4 provider
 * @param fileSystemOptions The FileSystem options
 * @return a {@link SSLContext} for HttpClient
 * @throws FileSystemException if an error occurs
 */
protected SSLContext createSSLContext(final Http5FileSystemConfigBuilder builder, final FileSystemOptions fileSystemOptions) throws FileSystemException {
    try {
        final SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.setKeyStoreType(builder.getKeyStoreType(fileSystemOptions));
        File keystoreFileObject = null;
        final String keystoreFile = builder.getKeyStoreFile(fileSystemOptions);
        if (!StringUtils.isEmpty(keystoreFile)) {
            keystoreFileObject = new File(keystoreFile);
        }
        if (keystoreFileObject != null && keystoreFileObject.exists()) {
            final String keystorePass = builder.getKeyStorePass(fileSystemOptions);
            final char[] keystorePassChars = keystorePass != null ? keystorePass.toCharArray() : null;
            sslContextBuilder.loadTrustMaterial(keystoreFileObject, keystorePassChars, TrustAllStrategy.INSTANCE);
        } else {
            sslContextBuilder.loadTrustMaterial(TrustAllStrategy.INSTANCE);
        }
        return sslContextBuilder.build();
    } catch (final KeyStoreException e) {
        throw new FileSystemException("Keystore error. " + e.getMessage(), e);
    } catch (final KeyManagementException e) {
        throw new FileSystemException("Cannot retrieve keys. " + e.getMessage(), e);
    } catch (final NoSuchAlgorithmException e) {
        throw new FileSystemException("Algorithm error. " + e.getMessage(), e);
    } catch (final CertificateException e) {
        throw new FileSystemException("Certificate error. " + e.getMessage(), e);
    } catch (final IOException e) {
        throw new FileSystemException("Cannot open key file. " + e.getMessage(), e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) File(java.io.File) KeyManagementException(java.security.KeyManagementException)

Example 4 with SSLContextBuilder

use of org.apache.hc.core5.ssl.SSLContextBuilder in project selenide by selenide.

the class DownloadFileWithHttpRequest method createTrustingHttpClient.

/**
 * configure HttpClient to ignore self-signed certs
 * as described here: http://literatejava.com/networks/ignore-ssl-certificate-errors-apache-httpclient-4-4/
 */
@CheckReturnValue
@Nonnull
protected CloseableHttpClient createTrustingHttpClient() throws IOException {
    try {
        HttpClientBuilder builder = HttpClientBuilder.create();
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustAllStrategy()).build();
        HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        builder.setConnectionManager(connMgr);
        return builder.build();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TimeoutException(com.codeborne.selenide.ex.TimeoutException) HostnameVerifier(javax.net.ssl.HostnameVerifier) NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) CheckReturnValue(javax.annotation.CheckReturnValue) Nonnull(javax.annotation.Nonnull)

Example 5 with SSLContextBuilder

use of org.apache.hc.core5.ssl.SSLContextBuilder in project geo-platform by geosdi.

the class GPServerProxy method createClientConnectionManager.

/**
 * @return {@link HttpClientConnectionManager}
 */
HttpClientConnectionManager createClientConnectionManager() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, (chain, authType) -> true);
        SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
        cm.setMaxTotal(10);
        cm.setDefaultMaxPerRoute(3);
        return cm;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IllegalStateException(ex);
    }
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) ServletException(javax.servlet.ServletException) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Aggregations

SSLContextBuilder (org.apache.hc.core5.ssl.SSLContextBuilder)6 IOException (java.io.IOException)4 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)4 PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)3 ConnectionSocketFactory (org.apache.hc.client5.http.socket.ConnectionSocketFactory)3 PlainConnectionSocketFactory (org.apache.hc.client5.http.socket.PlainConnectionSocketFactory)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 SSLContext (javax.net.ssl.SSLContext)2 TimeoutException (com.codeborne.selenide.ex.TimeoutException)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 SocketAddress (java.net.SocketAddress)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ByteBuffer (java.nio.ByteBuffer)1 ByteChannel (java.nio.channels.ByteChannel)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1