Search in sources :

Example 31 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project microservices by pwillhan.

the class BasicHttpsSecurityApplicationTests method socketFactory.

private SSLConnectionSocketFactory socketFactory() throws Exception {
    char[] password = "password".toCharArray();
    KeyStore truststore = KeyStore.getInstance("PKCS12");
    truststore.load(new ClassPathResource("rod.p12").getInputStream(), password);
    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadKeyMaterial(truststore, password);
    builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy());
    return new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
}
Also used : NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) KeyStore(java.security.KeyStore) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy)

Example 32 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project microservices by pwillhan.

the class X509ApplicationTests method socketFactory.

private SSLConnectionSocketFactory socketFactory() throws Exception {
    char[] password = "password".toCharArray();
    KeyStore truststore = KeyStore.getInstance("PKCS12");
    truststore.load(new ClassPathResource("rod.p12").getInputStream(), password);
    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadKeyMaterial(truststore, password);
    builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy());
    return new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
}
Also used : NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) KeyStore(java.security.KeyStore) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy)

Example 33 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project syncope by apache.

the class HttpUtils method createHttpsClient.

private static CloseableHttpClient createHttpsClient() {
    CloseableHttpClient chc = null;
    try {
        final SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        chc = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE)).build();
    } catch (Exception ex) {
    // ignore
    }
    return chc;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) IOException(java.io.IOException)

Example 34 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project ofbiz-framework by apache.

the class UtilHttp method getAllowAllHttpClient.

public static CloseableHttpClient getAllowAllHttpClient(String jksStoreFileName, String jksStorePassword) {
    try {
        // Trust own CA and all self-signed certs
        SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(FileUtil.getFile(jksStoreFileName), jksStorePassword.toCharArray(), new TrustSelfSignedStrategy()).build();
        // No host name verifier
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
        CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
        return httpClient;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        return HttpClients.createDefault();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) IOException(java.io.IOException)

Example 35 with TrustSelfSignedStrategy

use of org.apache.http.conn.ssl.TrustSelfSignedStrategy in project JFramework by gugumall.

the class JHttp method createSelfSigned.

/**
 * @param certFilePath
 * @param password
 * @param keyStoreType
 * @return
 * @throws Exception
 */
public static JHttp createSelfSigned(String certFilePath, String password, String[] protocols) throws Exception {
    JHttp jhttp = new JHttp();
    SSLContext ctx = SSLContexts.custom().loadTrustMaterial(new File(certFilePath), password.toCharArray(), new TrustSelfSignedStrategy()).build();
    ctx.init(null, new TrustManager[] { new MyTrustManager() }, null);
    SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(ctx, protocols, null, SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    jhttp.poolingmgr = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", factory).build(), null, null, null, 5000, TimeUnit.MILLISECONDS);
    jhttp.poolingmgr.setDefaultMaxPerRoute(100);
    jhttp.poolingmgr.setMaxTotal(1000);
    return jhttp;
}
Also used : SSLContext(javax.net.ssl.SSLContext) File(java.io.File) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)62 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)47 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)32 SSLContext (javax.net.ssl.SSLContext)23 IOException (java.io.IOException)18 HttpClient (org.apache.http.client.HttpClient)15 KeyStore (java.security.KeyStore)14 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)14 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 KeyManagementException (java.security.KeyManagementException)11 KeyStoreException (java.security.KeyStoreException)11 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)11 Test (org.junit.jupiter.api.Test)11 File (java.io.File)10 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SSLContextBuilder (org.apache.http.conn.ssl.SSLContextBuilder)9 RequestConfig (org.apache.http.client.config.RequestConfig)8 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7