List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER
X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
To view the source code for org.apache.http.conn.ssl SSLConnectionSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER.
Click Source Link
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
private static HttpClient createHttpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { HttpClientBuilder b = HttpClientBuilder.create(); // setup a Trust Strategy that allows all certificates. ////from w w w . j av a2 s. c o m SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build(); b.setSSLContext(sslContext); //b.setSSLHostnameVerifier(new NoopHostnameVerifier()); // don't check Hostnames, either. // -- use SSLConnectionSocketFactory.getDefaultHostnameVerifier(), if you don't want to weaken HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; // here's the special part: // -- need to create an SSL Socket Factory, to use our weakened "trust strategy"; // -- and create a Registry, to register it. // SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); // now, we create connection-manager using our Registry. // -- allows multi-threaded use PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); b.setConnectionManager(connMgr); // finally, build the HttpClient; // -- done! CloseableHttpClient client = b.build(); return client; }
From source file:org.hawkular.component.pinger.Pinger.java
private CloseableHttpClient getHttpClient(final String url) { if (url != null && url.startsWith("https://") && sslContext != null) { return HttpClientBuilder.create() .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setSslcontext(sslContext).build(); } else {//from ww w.j av a 2 s . co m return HttpClientBuilder.create().build(); } }
From source file:org.ops4j.pax.url.mvn.internal.HttpClients.java
private static PoolingHttpClientConnectionManager createConnManager(PropertyResolver resolver, String pid) { boolean SSL_INSECURE = getBoolean(resolver, "maven.wagon.http.ssl.insecure", !getBoolean(resolver, pid + "certificateCheck", false)); boolean IGNORE_SSL_VALIDITY_DATES = getBoolean(resolver, "maven.wagon.http.ssl.ignore.validity.dates", false);/* ww w . j a va 2 s . co m*/ boolean SSL_ALLOW_ALL = getBoolean(resolver, "maven.wagon.http.ssl.allowall", !getBoolean(resolver, pid + "certificateCheck", false)); boolean PERSISTENT_POOL = getBoolean(resolver, "maven.wagon.http.pool", true); int MAX_CONN_PER_ROUTE = getInteger(resolver, "maven.wagon.httpconnectionManager.maxPerRoute", 20); int MAX_CONN_TOTAL = getInteger(resolver, "maven.wagon.httpconnectionManager.maxTotal", 40); String sslProtocolsStr = getProperty(resolver, "https.protocols", null); String cipherSuitesStr = getProperty(resolver, "https.cipherSuites", null); String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split(" *, *") : null; String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split(" *, *") : null; SSLConnectionSocketFactory sslConnectionSocketFactory; if (SSL_INSECURE) { try { SSLContext sslContext = new SSLContextBuilder().useSSL() .loadTrustMaterial(null, new RelaxedTrustStrategy(IGNORE_SSL_VALIDITY_DATES)).build(); sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, sslProtocols, cipherSuites, SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } catch (Exception ex) { throw new SSLInitializationException(ex.getMessage(), ex); } } else { sslConnectionSocketFactory = new SSLConnectionSocketFactory( HttpsURLConnection.getDefaultSSLSocketFactory(), sslProtocols, cipherSuites, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", sslConnectionSocketFactory).build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry); if (PERSISTENT_POOL) { connManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE); connManager.setMaxTotal(MAX_CONN_TOTAL); } else { connManager.setMaxTotal(1); } boolean soKeepAlive = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_KEEPALIVE, false); int soLinger = getInteger(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_LINGER, -1); boolean soReuseAddress = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_REUSEADDRESS, false); boolean soTcpNoDelay = getBoolean(resolver, pid + ServiceConstants.PROPERTY_SOCKET_TCP_NODELAY, true); // int soTimeout = getInteger( resolver, pid + ServiceConstants.PROPERTY_SOCKET_SO_TIMEOUT, 0 ); SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(soKeepAlive) // default false .setSoLinger(soLinger) // default -1 .setSoReuseAddress(soReuseAddress) // default false .setTcpNoDelay(soTcpNoDelay) // default true .setSoTimeout(0) // default 0, but set in org.apache.http.impl.conn.CPoolProxy.setSocketTimeout() // this value is not used .build(); connManager.setDefaultSocketConfig(socketConfig); int bufferSize = getInteger(resolver, pid + ServiceConstants.PROPERTY_CONNECTION_BUFFER_SIZE, 8192); ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(bufferSize) // default 8192 .setFragmentSizeHint(bufferSize) // default 'buffer size' .build(); connManager.setDefaultConnectionConfig(connectionConfig); return connManager; }
From source file:com.cloud.agent.direct.download.HttpsDirectTemplateDownloader.java
public HttpsDirectTemplateDownloader(String url, Long templateId, String destPoolPath, String checksum, Map<String, String> headers) { super(url, templateId, destPoolPath, checksum, headers); SSLContext sslcontext = null; try {//from www . ja v a 2 s . c om sslcontext = getSSLContext(); } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) { throw new CloudRuntimeException("Failure getting SSL context for HTTPS downloader: " + e.getMessage()); } SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000) .setSocketTimeout(5000).build(); httpsClient = HttpClients.custom().setSSLSocketFactory(factory).setDefaultRequestConfig(config).build(); createUriRequest(url, headers); }
From source file:org.obm.satellite.client.SatelliteClientModule.java
@Provides private HttpClient provideHttpClient() { try {// w ww . jav a2 s . com SSLContext sslContext = buildSSLContext(TRUST_ALL_KEY_MANAGERS); return HttpClientBuilder.create().setSslcontext(sslContext) .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .useSystemProperties().build(); } catch (KeyManagementException e) { throw new IllegalArgumentException("Could not initialize a ssl context", e); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("Could not initialize a ssl context", e); } }
From source file:org.jenkinsci.plugins.kubernetesworkflowsteps.KubeStepExecution.java
private static CloseableHttpClient getClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { if (client == null) { synchronized (client_lock) { if (client == null) { SSLContextBuilder builder = SSLContexts.custom(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Collection<BasicHeader> headers = new ArrayList<BasicHeader>(); headers.add(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); headers.add(new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + env.get("BEARER_TOKEN"))); client = HttpClients.custom().setDefaultHeaders(headers).setSSLSocketFactory(sslsf).build(); }/* ww w .ja va2 s .co m*/ } } return client; }
From source file:securitytools.common.http.HttpClientFactory.java
public static CloseableHttpAsyncClient buildAsync(ClientConfiguration clientConfiguration) throws NoSuchAlgorithmException { HttpAsyncClientBuilder builder = HttpAsyncClients.custom(); // Certificate Validation // TODO/*from w w w . j a va2 s . c o m*/ if (clientConfiguration.isCertificateValidationEnabled()) { builder.setSSLStrategy(new SSLIOSessionStrategy(SSLContext.getDefault(), SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER)); } else { // Disable SSLIOSessionStrategy sslStrategy = new SSLIOSessionStrategy(SSLContext.getDefault(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); builder.setSSLStrategy(sslStrategy); } // Timeouts RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); requestConfigBuilder.setConnectTimeout(clientConfiguration.getConnectionTimeout()); requestConfigBuilder.setConnectionRequestTimeout(clientConfiguration.getConnectionTimeout()); requestConfigBuilder.setSocketTimeout(clientConfiguration.getSocketTimeout()); builder.setDefaultRequestConfig(requestConfigBuilder.build()); // User Agent builder.setUserAgent(clientConfiguration.getUserAgent()); // Proxy if (clientConfiguration.getProxyHost() != null) { builder.setProxy(clientConfiguration.getProxyHost()); } return builder.build(); }
From source file:org.ow2.proactive.http.HttpClientBuilderTest.java
@Test public void testAllowAnyHostnameTrue() throws Exception { httpClientBuilder.allowAnyHostname(true); httpClientBuilder.build();/*from w w w . j a v a 2 s .c om*/ Mockito.verify(internalHttpClientBuilder).build(); Mockito.verify(internalHttpClientBuilder) .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:org.olat.core.commons.services.webdav.WebDAVConnection.java
public WebDAVConnection(String protocol, String host, int port) { this.protocol = protocol; this.host = host; this.port = port; SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(SSLContexts.createDefault(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpclient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore) .setDefaultCredentialsProvider(provider).setSSLSocketFactory(sslFactory).build(); }
From source file:org.edeoliveira.oauth2.dropwizard.oauth2.auth.RestClientBuilder.java
public RestClientBuilder setupSSL(ApiServerConfig cfg) { SSLContext sslContext;//from w w w . ja v a 2s .c om ConnectorFactory factory = cfg.getClientConfig(); if (factory == null || !(factory instanceof HttpsConnectorFactory)) return this; HttpsConnectorFactory hcf = (HttpsConnectorFactory) factory; if (hcf.getKeyStorePath() != null) { keyStore = hcf.getKeyStorePath(); keyStorePassword = hcf.getKeyStorePassword(); trustStore = hcf.getTrustStorePath(); trustStorePassword = hcf.getTrustStorePassword(); sslContext = getSSLContext(); } else { SslConfigurator sslConfig = SslConfigurator.newInstance(); sslContext = sslConfig.createSSLContext(); } SSLConnectionSocketFactory sslConnectionSocketFactory = hcf.isValidateCerts() ? new SSLConnectionSocketFactory(sslContext) : new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", sslConnectionSocketFactory).build(); using(registry); return this; }