Search in sources :

Example 76 with SSLConnectionSocketFactory

use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project intellij-community by JetBrains.

the class AuthenticationService method getClient.

@NotNull
private HttpClient getClient(@NotNull SVNURL repositoryUrl) {
    // TODO: Implement algorithm of resolving necessary enabled protocols (TLSv1 vs SSLv3) instead of just using values from Settings.
    SSLContext sslContext = createSslContext(repositoryUrl);
    List<String> supportedProtocols = getSupportedSslProtocols();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, ArrayUtil.toStringArray(supportedProtocols), null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    // TODO: Seems more suitable here to read timeout values directly from config file - without utilizing SvnAuthenticationManager.
    final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    if (haveDataForTmpConfig()) {
        IdeHttpClientHelpers.ApacheHttpClient4.setProxyIfEnabled(requestConfigBuilder);
        IdeHttpClientHelpers.ApacheHttpClient4.setProxyCredentialsIfEnabled(credentialsProvider);
    }
    return HttpClients.custom().setSSLSocketFactory(socketFactory).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(getAuthenticationManager().getReadTimeout(repositoryUrl)).build()).setDefaultRequestConfig(requestConfigBuilder.setConnectTimeout(getAuthenticationManager().getConnectTimeout(repositoryUrl)).build()).setDefaultCredentialsProvider(credentialsProvider).build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with SSLConnectionSocketFactory

use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project wildfly by wildfly.

the class WebSecurityCERTTestCase method getHttpsClient.

private static CloseableHttpClient getHttpsClient(String alias) {
    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        JBossJSSESecurityDomain jsseSecurityDomain = new JBossJSSESecurityDomain("client-cert");
        jsseSecurityDomain.setKeyStorePassword("changeit");
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        URL keystore = tccl.getResource("security/client.keystore");
        jsseSecurityDomain.setKeyStoreURL(keystore.getPath());
        jsseSecurityDomain.setClientAlias(alias);
        jsseSecurityDomain.reloadKeyAndTrustStore();
        KeyManager[] keyManagers = jsseSecurityDomain.getKeyManagers();
        TrustManager[] trustManagers = jsseSecurityDomain.getTrustManagers();
        ctx.init(keyManagers, trustManagers, null);
        HostnameVerifier verifier = (string, ssls) -> true;
        //SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(ctx, verifier);
        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
        HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
        return HttpClientBuilder.create().setSSLSocketFactory(ssf).setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm).build();
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) RegistryBuilder(org.apache.http.config.RegistryBuilder) Arquillian(org.jboss.arquillian.junit.Arquillian) URL(java.net.URL) ServerSetup(org.jboss.as.arquillian.api.ServerSetup) RunWith(org.junit.runner.RunWith) TrustManager(javax.net.ssl.TrustManager) JBossJSSESecurityDomain(org.jboss.security.JBossJSSESecurityDomain) WebCERTTestsSecurityDomainSetup(org.jboss.as.test.integration.web.security.WebCERTTestsSecurityDomainSetup) StatusLine(org.apache.http.StatusLine) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Registry(org.apache.http.config.Registry) ArquillianResource(org.jboss.arquillian.test.api.ArquillianResource) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) CommonCriteria(org.jboss.as.test.categories.CommonCriteria) Test(org.junit.Test) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) Category(org.junit.experimental.categories.Category) KeyManager(javax.net.ssl.KeyManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) HttpGet(org.apache.http.client.methods.HttpGet) Deployment(org.jboss.arquillian.container.test.api.Deployment) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) HttpResponse(org.apache.http.HttpResponse) SecuredServlet(org.jboss.as.test.integration.web.security.SecuredServlet) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) ManagementClient(org.jboss.as.arquillian.container.ManagementClient) Assert.assertEquals(org.junit.Assert.assertEquals) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) JBossJSSESecurityDomain(org.jboss.security.JBossJSSESecurityDomain) URL(java.net.URL) TrustManager(javax.net.ssl.TrustManager) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) KeyManager(javax.net.ssl.KeyManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager)

Example 78 with SSLConnectionSocketFactory

use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ats-framework by Axway.

the class HttpClient method setupSSL.

/**
     * Setup SSL. Pass the trusted certificates and client private key and certificate,
     * if applicable.
     *
     * @param httpClientBuilder The client builder
     * @throws HttpException
     */
private void setupSSL(HttpClientBuilder httpClientBuilder) throws HttpException {
    try {
        SSLContextBuilder sslContextBuilder = SSLContexts.custom();
        sslContextBuilder.loadTrustMaterial(convertToKeyStore(trustedServerCertificates), new TrustStrategy() {

            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return checkIsTrusted(chain);
            }
        });
        if (clientSSLKeyStore != null) {
            sslContextBuilder.loadKeyMaterial(clientSSLKeyStore, "".toCharArray());
        }
        SSLContext sslContext = sslContextBuilder.build();
        // Allow all supported protocols
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, new NoopHostnameVerifier());
        httpClientBuilder.setSSLSocketFactory(sslsf);
    } catch (Exception e) {
        throw new HttpException("Exception occurred when setting up SSL.", e);
    }
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) X509Certificate(java.security.cert.X509Certificate) URISyntaxException(java.net.URISyntaxException) GeneralSecurityException(java.security.GeneralSecurityException) ClientProtocolException(org.apache.http.client.ClientProtocolException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 79 with SSLConnectionSocketFactory

use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project ats-framework by Axway.

the class HttpsClient method connect.

/**
     * Connect to a remote host using basic authentication.
     *
     * @param hostname the host to connect to
     * @param userName the user name
     * @param password the password for the provided user name
     * @throws FileTransferException
     */
@Override
public void connect(String hostname, String userName, String password) throws FileTransferException {
    super.connect(hostname, userName, password);
    // trust everybody
    try {
        SSLContext sslContext = SslUtils.getTrustAllSSLContext();
        SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(sslContext, encryptionProtocols, cipherSuites, new NoopHostnameVerifier());
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", ssf).build();
        HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        this.httpBuilder.setConnectionManager(connectionManager).setSchemePortResolver(new DefaultSchemePortResolver());
        this.httpClient = this.httpBuilder.build();
    } catch (Exception e) {
        throw new FileTransferException("Error setting trust manager", e);
    }
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) DefaultSchemePortResolver(org.apache.http.impl.conn.DefaultSchemePortResolver) SSLContext(javax.net.ssl.SSLContext) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) CertificateException(java.security.cert.CertificateException) GeneralSecurityException(java.security.GeneralSecurityException) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 80 with SSLConnectionSocketFactory

use of org.apache.http.conn.ssl.SSLConnectionSocketFactory in project spark by perwendel.

the class SparkTestUtil method httpClientBuilder.

private HttpClientBuilder httpClientBuilder() {
    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(), (paramString, paramSSLSession) -> true);
    Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", sslConnectionSocketFactory).build();
    BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketRegistry);
    return HttpClientBuilder.create().setConnectionManager(connManager);
}
Also used : PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager)

Aggregations

SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)157 SSLContext (javax.net.ssl.SSLContext)99 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)63 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)54 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)52 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)49 IOException (java.io.IOException)42 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)42 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)42 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)31 KeyManagementException (java.security.KeyManagementException)30 RequestConfig (org.apache.http.client.config.RequestConfig)25 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)25 KeyStoreException (java.security.KeyStoreException)24 HttpClient (org.apache.http.client.HttpClient)24 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)24 KeyStore (java.security.KeyStore)22 CertificateException (java.security.cert.CertificateException)21 Test (org.junit.Test)21