private static class NoPreloadHolder { /** * The factory using the default JVM settings for secure connections. */ private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); }
/** * Since Jersey 1.19 depends on legacy apache http-client API, we have to as well. */ private ThreadSafeClientConnManager createConnectionManager() { try { ThreadSafeClientConnManager connectionManager; if (sslContext != null) { SchemeSocketFactory socketFactory = new SSLSocketFactory(sslContext, new AllowAllHostnameVerifier()); SchemeRegistry sslSchemeRegistry = new SchemeRegistry(); sslSchemeRegistry.register(new Scheme("https", 443, socketFactory)); connectionManager = new ThreadSafeClientConnManager(sslSchemeRegistry); } else { connectionManager = new ThreadSafeClientConnManager(); } return connectionManager; } catch (Exception e) { throw new IllegalStateException("Cannot initialize Apache connection manager", e); } }
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); Scheme sch = new Scheme("https", socketFactory, 443); httpclient.getConnectionManager().getSchemeRegistry().register(sch);
public KylinClient(KylinConnectionInfo connInfo) { this.connInfo = connInfo; this.connProps = connInfo.getConnectionProperties(); this.httpClient = new DefaultHttpClient(); this.jsonMapper = new ObjectMapper(); // trust all certificates if (isSSL()) { try { SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(final X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy... return true; } }); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sslsf)); } catch (Exception e) { throw new RuntimeException("Initialize HTTPS client failed", e); } } }
inputStream.close(); ret = new SSLSocketFactory(ks); } catch (UnrecoverableKeyException ex) { Log.d(TAG, ex.getMessage());
SSLSocketFactory sf = new SSLSocketFactory(sslContext, ALLOW_ALL_HOSTNAME_VERIFIER); return sslSocketFactory(sf);
final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext); final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);
in.close(); return new SSLSocketFactory(trusted); } catch (Exception e) { throw new AssertionError(e);
public static HttpClient getHttpClient() { HttpClient httpClient = null; TrustStrategy easyStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }; try { SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier()); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", DEFAULT_PORT, sf)); ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (KeyManagementException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (UnrecoverableKeyException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (NoSuchAlgorithmException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } catch (KeyStoreException e) { s_logger.error("failed to initialize http client " + e.getMessage()); } return httpClient; }
protected DefaultHttpClient getHttpsClient() { try { SSLContext sslContext = SSLUtils.getSSLContext(); X509TrustManager tm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] {tm}, new SecureRandom()); SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", nmsUrl.getPort(), socketFactory)); BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry); return new DefaultHttpClient(mgr); } catch (NoSuchAlgorithmException ex) { throw new CloudRuntimeException(ex.getMessage()); } catch (KeyManagementException ex) { throw new CloudRuntimeException(ex.getMessage()); } }
SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager();
final SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier()); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", DEFAULT_AGENT_PORT, sf));
SSLSocketFactory sf = new SSLSocketFactory(sslContext, ALLOW_ALL_HOSTNAME_VERIFIER); return sslSocketFactory(sf);
SSLSocketFactory sf = new SSLSocketFactory(easyStrategy, new AllowAllHostnameVerifier()); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", DEFAULT_PORT, sf));
/** * 默认httpclient * * @see <a * href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a> * @param clientConnectionManager */ public HttpComponent4_1Factory() { PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(); clientConnectionManager.setMaxTotal(30); clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager .getMaxTotal()); httpClient = new DefaultHttpClient(clientConnectionManager); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name()); httpClient.getParams().setParameter( CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET, Consts.UTF_8); SSLSocketFactory socketFactory = new SSLSocketFactory( HttpClientFactory.allowSSLContext()); socketFactory .setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme scheme = new Scheme("https", socketFactory, 443); httpClient.getConnectionManager().getSchemeRegistry().register(scheme); }
private void resolveHttpParams(HttpParams params) { if (params != null) { if (params.getProxy() != null) { InetSocketAddress socketAddress = (InetSocketAddress) params .getProxy().address(); HttpHost proxy = new HttpHost(socketAddress.getHostName(), socketAddress.getPort()); httpClient.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy); } httpClient.getParams().setIntParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, params.getConnectTimeout()); httpClient.getParams().setIntParameter( CoreConnectionPNames.SO_TIMEOUT, params.getReadTimeout()); if (params.getSSLContext() != null) { SSLSocketFactory socketFactory = new SSLSocketFactory( params.getSSLContext()); if (params.getHostnameVerifier() != null) { socketFactory .setHostnameVerifier(new CustomHostnameVerifier( params.getHostnameVerifier())); } Scheme scheme = new Scheme("https", socketFactory, 443); httpClient.getConnectionManager().getSchemeRegistry() .register(scheme); } } }
private SchemeRegistry createSchemeRegistry() { SchemeRegistry schemeRegistry = new SchemeRegistry(); try { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(createSocketFactory(), SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", getRemoteUrl().getPort(), sslSocketFactory)); return schemeRegistry; } catch (Exception e) { throw new IllegalStateException("Failure trying to create scheme registry", e); } }
private static class NoPreloadHolder { /** * The factory using the default JVM settings for secure connections. */ private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); }
private static class NoPreloadHolder { /** * The factory using the default JVM settings for secure connections. */ private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); }
public void setSSLContext(SSLContext sslContext) { SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext); SSLConfig sslConfig = new SSLConfig(); sslConfig = sslConfig.sslSocketFactory(socketFactory); RestAssuredConfig cfg = new RestAssuredConfig(); cfg = cfg.sslConfig(sslConfig); request = request.config(cfg); }