List of usage examples for org.apache.http.conn.ssl TrustStrategy TrustStrategy
TrustStrategy
From source file:com.vmware.identity.rest.idm.client.test.integration.util.TestClientFactory.java
/** * Create an IdmClient with the given parameters. * * @param host address of the remote server * @param tenant name of the tenant/*from w w w . jav a 2 s. co m*/ * @param username username in UPN format * @param password password * @return IdmClient * @throws IOException * @throws ClientException * @throws ClientProtocolException * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static IdmClient createClient(String host, String tenant, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, ClientException, IOException { HostRetriever hostRetriever = new SimpleHostRetriever(host, true); IdmClient client = new IdmClient(hostRetriever, NoopHostnameVerifier.INSTANCE, new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build()); String token = TokenFactory.getAccessToken(host, tenant, username, password); client.setToken(new AccessToken(token, AccessToken.Type.JWT)); return client; }
From source file:com.vmware.directory.rest.client.test.integration.util.TestClientFactory.java
/** * Create an VmdirClient with the given parameters. * * @param host address of the remote server * @param tenant name of the tenant//from w w w .j av a 2 s . c o m * @param username username in UPN format * @param password password * @return IdmClient * @throws IOException * @throws ClientException * @throws ClientProtocolException * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public static VmdirClient createClient(String host, String tenant, String username, String password) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, ClientProtocolException, ClientException, IOException { HostRetriever hostRetriever = new SimpleHostRetriever(host, true); VmdirClient client = new VmdirClient(hostRetriever, NoopHostnameVerifier.INSTANCE, new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build()); String token = TokenFactory.getAccessToken(host, tenant, username, password); client.setToken(new AccessToken(token, AccessToken.Type.JWT)); return client; }
From source file:com.netflix.http4.ssl.AcceptAllSocketFactory.java
public AcceptAllSocketFactory() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { super(new TrustStrategy() { @Override//from www. java 2s . co m public boolean isTrusted(final X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:photosharing.api.ExecutorUtil.java
/** * helper method that returns an HTTPClient executor with credentials * available./*from w w w. j a v a 2 s. co m*/ * * Also enables the test case to connect to ANY SSL Certificate * valid/invalid * * @return {Executor} or Null if there is an issue */ public static Executor getExecutor() { Executor executor = null; /* * if using one of the environments without a trusted CA chain or * you are using Fiddler, you want to set TRUST=TRUE in appconfig.properties */ Configuration config = Configuration.getInstance(null); String sTrust = config.getValue(Configuration.TRUST); boolean trusted = Boolean.parseBoolean(sTrust); if (trusted) { try { HttpClientBuilder builder = HttpClients.custom(); // Setup the SSL Context to Trust Any SSL Certificate SSLContextBuilder sslBuilder = new SSLContextBuilder(); sslBuilder.loadTrustMaterial(null, new TrustStrategy() { /** * override for fiddler proxy */ public boolean isTrusted(X509Certificate[] certs, String host) throws CertificateException { return true; } }); SSLContext sslContext = sslBuilder.build(); builder.setHostnameVerifier(new AllowAllHostnameVerifier()); builder.setSslcontext(sslContext); CloseableHttpClient httpClient = builder.build(); executor = Executor.newInstance(httpClient); } catch (NoSuchAlgorithmException e) { logger.log(Level.SEVERE, "Issue with No Algorithm " + e.toString()); } catch (KeyStoreException e) { logger.log(Level.SEVERE, "Issue with KeyStore " + e.toString()); } catch (KeyManagementException e) { logger.log(Level.SEVERE, "Issue with KeyManagement " + e.toString()); } } return executor; }
From source file:cn.wanghaomiao.seimi.http.hc.HttpClientCMPBox.java
public HttpClientCMPBox() { SSLContextBuilder builder = new SSLContextBuilder(); try {//from w w w. j a va2 s . c om builder.loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); SSLContext sslContext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { @Override public void verify(String host, SSLSocket ssl) throws IOException { } @Override public void verify(String host, X509Certificate cert) throws SSLException { } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", new PlainConnectionSocketFactory()).register("https", sslsf).build(); poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registry); poolingHttpClientConnectionManager.setMaxTotal(500); poolingHttpClientConnectionManager.setDefaultMaxPerRoute(1000); } catch (Exception e) { Logger logger = LoggerFactory.getLogger(getClass()); logger.error("init fail,err={}", e.getMessage(), e); } }
From source file:com.seajas.search.codex.social.connection.TrustingClientHttpRequestFactory.java
public TrustingClientHttpRequestFactory() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { super();/*w ww . j av a 2 s. c o m*/ this.getHttpClient().getConnectionManager().getSchemeRegistry() .register(new Scheme("https", 443, new SSLSocketFactory(new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { if (logger.isTraceEnabled()) logger.trace(format("Trusting certificate chain with %d certificates and auth type %s", chain != null ? chain.length : 0, authType)); return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER))); }
From source file:com.jt.https.test.send.java
public static String PostTo(String content) { String responseMessage = null; String filePath = ""; if (!filePath.endsWith("/")) { filePath = filePath + "/"; }/*from w w w. j av a 2 s . c o m*/ HttpClient httpclient = new DefaultHttpClient(); try { KeyStore keystore = KeyStore.getInstance("jks"); KeyStore trustStore = KeyStore.getInstance("jks"); FileInputStream keystoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\bis-stg-sdb.jks")); FileInputStream trustStoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\EXV_GROUP_BIS_IFRONT_JTLZX_100.jks")); //FileInputStream keystoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test.jks")); //FileInputStream trustStoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test_trust.jks")); try { keystore.load(keystoreInstream, "123456".toCharArray()); trustStore.load(trustStoreInstream, "paic1234".toCharArray()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } finally { keystoreInstream.close(); trustStoreInstream.close(); } SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.SSL, keystore, "123456", trustStore, null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", 8107, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpPost post = new HttpPost("https://222.68.184.181:8107"); StringEntity entity = new StringEntity(content, "text/html", "UTF-8"); post.setEntity(entity); HttpResponse res = httpclient.execute(post); HttpEntity resEntity = res.getEntity(); if (resEntity != null) { responseMessage = convertStreamToString(resEntity.getContent()); System.out.println("???" + content); System.out.println("?" + responseMessage); } } catch (KeyStoreException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } return responseMessage; }
From source file:org.hawkular.component.pinger.Pinger.java
public Pinger() throws Exception { SSLContext tmpSslContext;/* w w w. ja v a 2 s.c o m*/ try { SSLContextBuilder builder = SSLContexts.custom(); builder.loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); tmpSslContext = builder.build(); } catch (Exception e) { tmpSslContext = null; } sslContext = tmpSslContext; }
From source file:org.skfiy.typhon.spi.auth.p.QihooAuthenticator.java
public QihooAuthenticator() { try {//from w w w . j av a 2 s. co m SSLContextBuilder sslBuilder = new SSLContextBuilder(); sslBuilder.loadTrustMaterial(null, new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslBuilder.build()); HC_BUILDER.setSSLSocketFactory(sslFactory); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:edu.emory.bmi.medicurator.tcia.TciaQuery.java
private HttpClient getInsecureClient() throws Exception { SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; }//w w w. ja v a 2s. c o m }).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setSSLSocketFactory(sslsf); if (Constants.PROXY_HOST != null && Constants.PROXY_PORT != null) { HttpHost proxy = new HttpHost(Constants.PROXY_HOST, Constants.PROXY_PORT, "http"); builder.setProxy(proxy); } if (Constants.PROXY_USERNAME != null && Constants.PROXY_PASSWORD != null) { Credentials credentials = new UsernamePasswordCredentials(Constants.PROXY_USERNAME, Constants.PROXY_PASSWORD); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, credentials); builder.setDefaultCredentialsProvider(credsProvider); } return builder.build(); }