List of usage examples for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE
NoopHostnameVerifier INSTANCE
To view the source code for org.apache.http.conn.ssl NoopHostnameVerifier INSTANCE.
Click Source Link
From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpClientProvider.java
private static SSLConnectionSocketFactory buildSslSocketFactory() { return new SSLConnectionSocketFactory(buildSslContext(), NoopHostnameVerifier.INSTANCE); }
From source file:io.apicurio.hub.api.security.KeycloakLinkedAccountsProvider.java
@PostConstruct protected void postConstruct() { try {/* w w w . j a v a 2 s. c o m*/ if (config.isDisableKeycloakTrustManager()) { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()) .build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); } else { httpClient = HttpClients.createSystem(); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
public static SSLConnectionSocketFactory getSSLFactory() throws Exception { SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, NoopHostnameVerifier.INSTANCE); return sslsf; }
From source file:com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.java
/** * Factory method that builds a new SSLConnectionSocketFactory. * @param options the current WebClientOptions * @return the SSLConnectionSocketFactory *//* ww w. ja va 2s . co m*/ public static SSLConnectionSocketFactory buildSSLSocketFactory(final WebClientOptions options) { try { final String[] sslClientProtocols = options.getSSLClientProtocols(); final String[] sslClientCipherSuites = options.getSSLClientCipherSuites(); final boolean useInsecureSSL = options.isUseInsecureSSL(); if (!useInsecureSSL) { final KeyStore keyStore = options.getSSLClientCertificateStore(); final KeyStore trustStore = options.getSSLTrustStore(); return new HtmlUnitSSLConnectionSocketFactory(keyStore, keyStore == null ? null : options.getSSLClientCertificatePassword(), trustStore, useInsecureSSL, sslClientProtocols, sslClientCipherSuites); } // we need insecure SSL + SOCKS awareness String protocol = options.getSSLInsecureProtocol(); if (protocol == null) { protocol = "SSL"; } final SSLContext sslContext = SSLContext.getInstance(protocol); sslContext.init(getKeyManagers(options), new TrustManager[] { new InsecureTrustManager2() }, null); final SSLConnectionSocketFactory factory = new HtmlUnitSSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE, useInsecureSSL, sslClientProtocols, sslClientCipherSuites); return factory; } catch (final GeneralSecurityException e) { throw new RuntimeException(e); } }
From source file:org.elasticsearch.xpack.ssl.SSLClientAuthTests.java
public void testThatHttpWorksWithSslClientAuth() throws IOException { SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(getSSLContext(), NoopHostnameVerifier.INSTANCE); try (RestClient restClient = createRestClient( httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy), "https")) { Response response = restClient.performRequest("GET", "/", new BasicHeader("Authorization", basicAuthHeaderValue(transportClientUsername(), transportClientPassword()))); assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); assertThat(EntityUtils.toString(response.getEntity()), containsString("You Know, for Search")); }/*w ww. j av a 2 s . c o m*/ }
From source file:RGSOplataRu.ClientConfiguretor.java
public CloseableHttpClient ConfigureSocketLayer() throws Exception { KeyStore keyStore = null;/*from www . j a v a 2 s. c o m*/ KeyStore trustStore = null; if (keyStoreResouce != null && keyStorePassword != null) keyStore = TrustStoreLoader.loadKeyStorePFX(keyStoreResouce, keyStorePassword); if (trustStoreResouce != null && trustStorePassword != null) trustStore = TrustStoreLoader.loadTrustStore(trustStoreResouce, trustStorePassword); SSLContext context = TrustStoreLoader.getTLSContext(keyStore, keyStorePassword, trustStore); // SSLConnectionSocketFactory SSLsf = new SSLConnectionSocketFactory(context, new DefaultHostnameVerifier()); SSLConnectionSocketFactory SSLsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", SSLsf).register("http", new PlainConnectionSocketFactory()).build(); HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry); return HttpClientBuilder.create().setConnectionManager(ccm) // !!! FOR TEST ONLY //.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); }
From source file:io.fabric8.maven.docker.access.hc.http.HttpClientBuilder.java
private static Registry<ConnectionSocketFactory> getSslFactoryRegistry(String certPath) throws IOException { try {//ww w. j ava 2 s . c om KeyStore keyStore = KeyStoreUtil.createDockerKeyStore(certPath); SSLContext sslContext = SSLContexts.custom().useProtocol(SSLConnectionSocketFactory.TLS) .loadKeyMaterial(keyStore, "docker".toCharArray()).loadTrustMaterial(keyStore, null).build(); String tlsVerify = System.getenv("DOCKER_TLS_VERIFY"); SSLConnectionSocketFactory sslsf = tlsVerify != null && !tlsVerify.equals("0") && !tlsVerify.equals("false") ? new SSLConnectionSocketFactory(sslContext) : new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); return RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslsf).build(); } catch (GeneralSecurityException e) { // this isn't ideal but the net effect is the same throw new IOException(e); } }
From source file:com.sonatype.nexus.ssl.plugin.internal.CertificateRetriever.java
/** * Retrieves certificate chain of specified host:port using https protocol. * * @param host to get certificate chain from (cannot be null) * @param port of host to connect to/*from ww w . j a va 2 s . c o m*/ * @return certificate chain * @throws Exception Re-thrown from accessing the remote host */ public Certificate[] retrieveCertificatesFromHttpsServer(final String host, final int port) throws Exception { checkNotNull(host); log.info("Retrieving certificate from https://{}:{}", host, port); // setup custom connection manager so we can configure SSL to trust-all SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, new TrustManager[] { ACCEPT_ALL_TRUST_MANAGER }, null); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sc, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register(HttpSchemes.HTTP, PlainConnectionSocketFactory.getSocketFactory()) .register(HttpSchemes.HTTPS, sslSocketFactory).build(); final HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(registry); try { final AtomicReference<Certificate[]> certificates = new AtomicReference<>(); HttpClient httpClient = httpClientManager.create(new Customizer() { @Override public void customize(final HttpClientPlan plan) { // replace connection-manager with customized version needed to fetch SSL certificates plan.getClient().setConnectionManager(connectionManager); // add interceptor to grab peer-certificates plan.getClient().addInterceptorFirst(new HttpResponseInterceptor() { @Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { ManagedHttpClientConnection connection = HttpCoreContext.adapt(context) .getConnection(ManagedHttpClientConnection.class); // grab the peer-certificates from the session if (connection != null) { SSLSession session = connection.getSSLSession(); if (session != null) { certificates.set(session.getPeerCertificates()); } } } }); } }); httpClient.execute(new HttpGet("https://" + host + ":" + port)); return certificates.get(); } finally { // shutdown single-use connection manager connectionManager.shutdown(); } }
From source file:com.github.tmyroadctfig.icloud4j.ICloudService.java
/** * Creates a new iCloud service instance * * @param clientId the client ID.//w w w. j a v a2s . c o m */ @SuppressWarnings("deprecation") public ICloudService(ICloudSession session) { this.session = session; try { HttpClientBuilder clientBuilder = HttpClientBuilder.create().setDefaultCookieStore(getCookieStore()); if (!Strings.isNullOrEmpty(PROXY_HOST)) { clientBuilder.setProxy(new HttpHost(PROXY_HOST, PROXY_PORT)); } if (DISABLE_SSL_CHECKS) { clientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSslcontext( new SSLContextBuilder().loadTrustMaterial(null, (x509CertChain, authType) -> true).build()); } httpClient = clientBuilder.build(); } catch (Exception e) { throw Throwables.propagate(e); } idmsaService = new IdmsaService(this); }