List of usage examples for org.apache.http.ssl SSLContextBuilder SSLContextBuilder
public SSLContextBuilder()
From source file:org.mycontroller.restclient.core.RestHttpClient.java
private CloseableHttpClient getHttpClientTrustAll() { SSLContextBuilder builder = new SSLContextBuilder(); try {//from www.j a v a 2s. c om KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); builder.loadTrustMaterial(keyStore, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] trustedCert, String nameConstraints) throws CertificateException { return true; } }); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), new AnyHostnameVerifier()); return HttpClients.custom().setSSLSocketFactory(sslsf).setDefaultRequestConfig(customRequestConfig) .build(); } catch (Exception ex) { _logger.error("Exception, ", ex); throw new RuntimeException("Unable to create trust ANY http client. Error: " + ex.getMessage()); } }
From source file:io.openvidu.java.client.OpenVidu.java
/** * @param urlOpenViduServer Public accessible IP where your instance of OpenVidu * Server is up an running * @param secret Secret used on OpenVidu Server initialization *//*from w ww .j a va 2 s. c o m*/ public OpenVidu(String urlOpenViduServer, String secret) { OpenVidu.urlOpenViduServer = urlOpenViduServer; if (!OpenVidu.urlOpenViduServer.endsWith("/")) { OpenVidu.urlOpenViduServer += "/"; } this.secret = secret; TrustStrategy trustStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }; CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("OPENVIDUAPP", this.secret); provider.setCredentials(AuthScope.ANY, credentials); SSLContext sslContext; try { sslContext = new SSLContextBuilder().loadTrustMaterial(null, trustStrategy).build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { throw new RuntimeException(e); } RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(30000); requestBuilder = requestBuilder.setConnectionRequestTimeout(30000); OpenVidu.httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()) .setConnectionTimeToLive(30, TimeUnit.SECONDS).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .setSSLContext(sslContext).setDefaultCredentialsProvider(provider).build(); }
From source file:com.vmware.photon.controller.common.auth.AuthOIDCClient.java
private AfdClient setSSLTrustPolicy(String domainControllerFQDN, int domainControllerPort) throws AuthException { try {/*from w w w .j a v a2 s . c o m*/ return new AfdClient(domainControllerFQDN, domainControllerPort, new DefaultHostnameVerifier(), new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build()); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new AuthException("Failed to set SSL policy", e); } }
From source file:org.syslog_ng.elasticsearch_v2.client.http.ESHttpsClient.java
private SSLContextBuilder setupSSLContextBuilder(ElasticSearchOptions options) { SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); KeyStore trustStore = null;//from w w w . j ava2 s. c o m if (isSSLInsecure(options)) { logger.warn("Using insecure options for HTTPS client"); } else { trustStore = setupKeyStore(options.getJavaTrustStoreFilepath(), options.getJavaTrustStorePassword()); } loadTrustMaterial(sslContextBuilder, trustStore); if (options.getHttpAuthType().equals("clientcert")) { KeyStore keyStore = setupKeyStore(options.getJavaKeyStoreFilepath(), options.getJavaKeyStorePassword()); loadKeyMaterial(sslContextBuilder, keyStore, options.getJavaKeyStorePassword()); } return sslContextBuilder; }
From source file:com.github.horrorho.liquiddonkey.http.HttpClientFactory.java
SSLContext relaxedSSLContext() { try {//from ww w. j a va 2 s . c o m return new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true).build(); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { throw new IllegalStateException("Unable to create relaxed SSL context."); } }
From source file:com.code42.demo.RestInvoker.java
public RestInvoker(String host, int hostPort, String userName, String password, Boolean useSSL) { sHost = host;/*from ww w . ja v a 2 s. co m*/ sPort = hostPort; uName = userName; pWord = password; ssl = useSSL; if (!ssl) { ePoint = "http://" + sHost + ":" + sPort; } else { // use SSL ePoint = "https://" + sHost + ":" + sPort; sslBuilder = new SSLContextBuilder(); try { sslBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); } catch (NoSuchAlgorithmException | KeyStoreException e) { // TODO Auto-generated catch block m_log.error("Unable to build trusted self signed cert"); //m_log.debug(e.printStackTrace(), e); } try { /* the NoopHostnameVerifier turns OFF host verification * For Production environments you'll want to remove this. */ sslsf = new SSLConnectionSocketFactory(sslBuilder.build(), NoopHostnameVerifier.INSTANCE); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } } m_log.info("EndPoint set to: " + ePoint); credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(sHost, sPort), new UsernamePasswordCredentials(uName, pWord)); }
From source file:com.qwazr.utils.http.HttpUtils.java
/** * Create a new HttpClient which accept untrusted SSL certificates * * @return a new HttpClient/* w ww. j a v a2s.c o m*/ * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static CloseableHttpClient createHttpClient_AcceptsUntrustedCerts() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { final HttpClientBuilder unsecureHttpClientBuilder = HttpClientBuilder.create(); SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build(); unsecureHttpClientBuilder.setSSLContext(sslContext); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build(); PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); unsecureHttpClientBuilder.setConnectionManager(connMgr); return unsecureHttpClientBuilder.build(); }
From source file:org.hawkular.client.RestFactory.java
public HttpClient getHttpClient() { SSLContextBuilder builder = new SSLContextBuilder(); try {//w ww . j av a 2 s. c o m KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); builder.loadTrustMaterial(keyStore, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] trustedCert, String nameConstraints) throws CertificateException { return true; } }); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); return httpclient; } catch (Exception ex) { _logger.error("Exception, ", ex); return null; } }
From source file:com.spectralogic.ds3client.networking.NetworkClientImpl.java
private static CloseableHttpClient createInsecureSslHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException { final SSLContext sslContext = new SSLContextBuilder().useProtocol(INSECURE_SSL_PROTOCOL) .loadTrustMaterial(null, new TrustStrategy() { @Override/*from w ww .j ava2 s.c om*/ public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }).build(); final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslsf).build(); final HttpClientConnectionManager connectionManager = createConnectionManager(socketFactoryRegistry); return HttpClients.custom().setConnectionManager(connectionManager).setSSLSocketFactory(sslsf).build(); }