Refine search
instream.close(); SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, passwd.toCharArray()).build();
} else { sslSocketFactory = new SSLConnectionSocketFactory( SSLContexts.createDefault(), hostnameVerifier);
private SSLConnectionSocketFactory createDefaultSSLConnectionSocketFactory() { SSLContext sslcontext = SSLContexts.createSystemDefault(); X509HostnameVerifier hostnameVerifier = new BrowserCompatHostnameVerifier(); return new SSLConnectionSocketFactory(sslcontext, hostnameVerifier); }
public SSLSocketFactory( final KeyStore keystore, final String keystorePassword, final KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadKeyMaterial(keystore, keystorePassword != null ? keystorePassword.toCharArray() : null) .loadTrustMaterial(truststore) .build(), BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }
/** * @since 4.1 */ public SSLSocketFactory( final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadTrustMaterial(null, trustStrategy) .build(), BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }
private SSLContext createSslContext( final String algorithm, final KeyStore keystore, final String keyPassword, final KeyStore truststore, final SecureRandom random) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { return SSLContexts.custom() .useProtocol(algorithm) .setSecureRandom(random) .loadKeyMaterial(keystore, keyPassword != null ? keyPassword.toCharArray() : null) .loadTrustMaterial(truststore) .build(); }
private SSLSocketFactory createSSLSocketFactory(boolean useKeyStoreToConnect, String keyStorePath, String keyStorePassword) throws Exception { //Only load KeyStore when it's needed to connect to IP, SSLContext is fine with KeyStore being null otherwise. KeyStore trustStore = null; if (useKeyStoreToConnect) { trustStore = KeyStoreLoader.loadKeyStore(keyStorePath, keyStorePassword); } SSLContext sslContext = SSLContexts.custom() .useSSL() .loadTrustMaterial(trustStore, new TrustStrategy() { //Always trust @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }) .loadKeyMaterial(trustStore, keyStorePassword.toCharArray()) .setSecureRandom(new java.security.SecureRandom()) .build(); return sslContext.getSocketFactory(); }
public static HttpClient newClient() { SSLContext sslContext = SSLContexts.createDefault(); try { sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); } catch (Exception e) { e.printStackTrace(); } return HttpClientBuilder .create() .setSslcontext(sslContext) .setMaxConnPerRoute(50) .setMaxConnTotal(200) .setUserAgent(Http.randomAgent()) .setDefaultRequestConfig( RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000) .setConnectionRequestTimeout(30000).build()).build(); }
/** * * @param maxTotal maxTotal * @param maxPerRoute maxPerRoute * @param timeout timeout * @param retryExecutionCount retryExecutionCount * @return CloseableHttpClient */ public static CloseableHttpClient createHttpClient(int maxTotal,int maxPerRoute,int timeout,int retryExecutionCount) { try { SSLContext sslContext = SSLContexts.custom().useSSL().build(); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); poolingHttpClientConnectionManager.setMaxTotal(maxTotal); poolingHttpClientConnectionManager.setDefaultMaxPerRoute(maxPerRoute); SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(timeout).build(); poolingHttpClientConnectionManager.setDefaultSocketConfig(socketConfig); return HttpClientBuilder.create() .setConnectionManager(poolingHttpClientConnectionManager) .setSSLSocketFactory(sf) .setRetryHandler(new HttpRequestRetryHandlerImpl(retryExecutionCount)) .build(); } catch (KeyManagementException e) { logger.error("", e); } catch (NoSuchAlgorithmException e) { logger.error("", e); } return null; }
SSLContext sslContext = SSLContexts.custom().useSSL().loadKeyMaterial(keystore, keyPassword.toCharArray()).build(); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext,supportedProtocols, null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
public SSLSocketFactory( final KeyStore keystore, final String keystorePassword, final KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadKeyMaterial(keystore, keystorePassword != null ? keystorePassword.toCharArray() : null) .loadTrustMaterial(truststore) .build(), BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }
/** * @since 4.1 */ public SSLSocketFactory( final TrustStrategy trustStrategy, final X509HostnameVerifier hostnameVerifier) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadTrustMaterial(null, trustStrategy) .build(), hostnameVerifier); }
public SSLSocketFactory( final String algorithm, final KeyStore keystore, final String keyPassword, final KeyStore truststore, final SecureRandom random, final HostNameResolver nameResolver) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .useProtocol(algorithm) .setSecureRandom(random) .loadKeyMaterial(keystore, keyPassword != null ? keyPassword.toCharArray() : null) .loadTrustMaterial(truststore) .build(), nameResolver); }
public static HttpClient newClient() { SSLContext sslContext = SSLContexts.createDefault(); try { sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); } catch (Exception e) { e.printStackTrace(); } return HttpClientBuilder .create() .setSslcontext(sslContext) .setMaxConnPerRoute(50) .setMaxConnTotal(200) .setUserAgent(AgentUtils.randomAgent()) .setDefaultRequestConfig( RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000) .setConnectionRequestTimeout(30000).build()).build(); } }
SSLContext sslContext = SSLContexts.custom().useSSL().loadKeyMaterial(keystore, keyPassword.toCharArray()).build(); SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext,supportedProtocols, null,SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
public SSLSocketFactory( final KeyStore keystore, final String keystorePassword, final KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadKeyMaterial(keystore, keystorePassword != null ? keystorePassword.toCharArray() : null) .loadTrustMaterial(truststore) .build(), BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }
/** * @since 4.1 */ public SSLSocketFactory( final TrustStrategy trustStrategy, final X509HostnameVerifier hostnameVerifier) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { this(SSLContexts.custom() .loadTrustMaterial(null, trustStrategy) .build(), hostnameVerifier); }