org.apache.http.conn.ssl.SSLSocketFactory Java Examples
The following examples show how to use
org.apache.http.conn.ssl.SSLSocketFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpService.java From oxAuth with MIT License | 7 votes |
public HttpClient getHttpsClientTrustAll() { try { SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){ @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, new AllowAllHostnameVerifier()); PlainSocketFactory psf = PlainSocketFactory.getSocketFactory(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, psf)); registry.register(new Scheme("https", 443, sf)); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); return new DefaultHttpClient(ccm); } catch (Exception ex) { log.error("Failed to create TrustAll https client", ex); return new DefaultHttpClient(); } }
Example #2
Source File: TestSSLWrong.java From hk with GNU General Public License v3.0 | 6 votes |
public HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #3
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #4
Source File: RetrofitClientBuilder.java From hello-pinnedcerts with MIT License | 6 votes |
public RetrofitClientBuilder pinCertificates(InputStream resourceStream, char[] password) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException { KeyStore keyStore = KeyStore.getInstance(HttpClientBuilder.BOUNCY_CASTLE); keyStore.load(resourceStream, password); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); TrustManager[] trustManagers = {new CustomTrustManager(keyStore)}; kmf.init(keyStore, password); SSLContext sslContext = SSLContext.getInstance(SSLSocketFactory.TLS); sslContext.init(kmf.getKeyManagers(), trustManagers, null); okHttpClient.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); okHttpClient.setSslSocketFactory(sslContext.getSocketFactory()); return this; }
Example #5
Source File: IgnorantHttpClient.java From hello-pinnedcerts with MIT License | 6 votes |
private MySSLSocketFactory newSslSocketFactory() { try { KeyStore trusted = KeyStore.getInstance(HttpClientBuilder.BOUNCY_CASTLE); try { trusted.load(null, null); } finally { } MySSLSocketFactory sslfactory = new MySSLSocketFactory(trusted); sslfactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return sslfactory; } catch (Exception e) { throw new AssertionError(e); } }
Example #6
Source File: BrooklynWebServerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
private void verifyHttpsFromConfig(BrooklynProperties brooklynProperties) throws Exception { webServer = new BrooklynWebServer(MutableMap.of(), newManagementContext(brooklynProperties)); webServer.skipSecurity(); webServer.start(); try { KeyStore keyStore = load("client.ks", "password"); KeyStore trustStore = load("client.ts", "password"); SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, "password", trustStore, (SecureRandom)null, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpToolResponse response = HttpTool.execAndConsume( HttpTool.httpClientBuilder() .port(webServer.getActualPort()) .https(true) .socketFactory(socketFactory) .build(), new HttpGet(webServer.getRootUrl())); assertEquals(response.getResponseCode(), 200); } finally { webServer.stop(); } }
Example #7
Source File: MySSLSocketFactory.java From Mobike with Apache License 2.0 | 6 votes |
/** * Gets getUrl DefaultHttpClient which trusts getUrl set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #8
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #9
Source File: Util.java From AppServiceRestFul with GNU General Public License v3.0 | 6 votes |
private static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #10
Source File: Util.java From AppServiceRestFul with GNU General Public License v3.0 | 6 votes |
private static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #11
Source File: WebServiceUtil.java From appinventor-extensions with Apache License 2.0 | 6 votes |
/** * Returns the one <code>WebServiceUtil</code> instance * @return the one <code>WebServiceUtil</code> instance */ public static WebServiceUtil getInstance() { // This needs to be here instead of in the constructor because // it uses classes that are in the AndroidSDK and thus would // cause Stub! errors when running the component descriptor. synchronized(httpClientSynchronizer) { if (httpClient == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicHttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); ConnManagerParams.setMaxTotalConnections(params, 20); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); WebServiceUtil.httpClient = new DefaultHttpClient(manager, params); } } return INSTANCE; }
Example #12
Source File: MetricsClientFactory.java From galaxy-sdk-java with Apache License 2.0 | 6 votes |
public static HttpClient generateHttpClient(final int maxTotalConnections, final int maxTotalConnectionsPerRoute, int connTimeout) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() { @Override public int getMaxForRoute(HttpRoute route) { return maxTotalConnectionsPerRoute; } }); HttpConnectionParams .setConnectionTimeout(params, connTimeout); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(conMgr, params); }
Example #13
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #14
Source File: NetUtils.java From Conquer with Apache License 2.0 | 6 votes |
private static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #15
Source File: BaseNet.java From AFBaseLibrary with Apache License 2.0 | 6 votes |
@SuppressWarnings("ConstantConditions") protected OkHttpClient getHttpClient() { if (httpClient == null) { OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().addInterceptor(getDefaultInterceptor()); if (isHttpsRequest()) { try { clientBuilder.sslSocketFactory(AFCertificateUtil.setCertificates(getApplicationContext(), getCertificateNames())) .hostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception e) { e.printStackTrace(); } } httpClient = clientBuilder.proxy(Proxy.NO_PROXY).build(); makeGlideSupportHttps(); } return httpClient; }
Example #16
Source File: WeixinUtil.java From android-common-utils with Apache License 2.0 | 6 votes |
private static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #17
Source File: MySSLSocketFactory.java From android-project-wo2b with Apache License 2.0 | 6 votes |
/** * Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore * * @param keyStore custom provided KeyStore instance * @return DefaultHttpClient */ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { try { SSLSocketFactory sf = new MySSLSocketFactory(keyStore); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
Example #18
Source File: EsendexService.java From JVoiceXML with GNU Lesser General Public License v2.1 | 6 votes |
public EsendexService(String user, String password, String account) { this.user = user; this.password = password; this.account = account; localContext = new BasicHttpContext(); httpClient = new DefaultHttpClient(); TrustStrategy easyStrategy = new TrustStrategy() { @Override public boolean isTrusted( java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }; SSLSocketFactory socketFactory = null; try { // socketFactory = new SSLSocketFactory(easyStrategy); } catch (Exception exception){ logger.error(exception); } // Scheme sch = new Scheme("https", 443, socketFactory); // httpClient.getConnectionManager().getSchemeRegistry().register(sch); }
Example #19
Source File: HttpAndroidClientFactory.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public HttpClient createHttpClient(ClientConfiguration clientconfiguration) { BasicHttpParams basichttpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(basichttpparams, clientconfiguration.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(basichttpparams, clientconfiguration.getSocketTimeout()); HttpConnectionParams.setStaleCheckingEnabled(basichttpparams, true); HttpConnectionParams.setTcpNoDelay(basichttpparams, true); int i = clientconfiguration.getSocketBufferSizeHints()[0]; int j = clientconfiguration.getSocketBufferSizeHints()[1]; if (i > 0 || j > 0) { HttpConnectionParams.setSocketBufferSize(basichttpparams, Math.max(i, j)); } SchemeRegistry schemeregistry = new SchemeRegistry(); schemeregistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (clientconfiguration.getProtocol() == Protocol.HTTPS) { schemeregistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } return new DefaultHttpClient(new SingleClientConnManager(basichttpparams, schemeregistry), basichttpparams); }
Example #20
Source File: AbstractGoogleClientFactory.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 6 votes |
/** * Replicates {@link ApacheHttpTransport#newDefaultHttpClient()} with one exception: * * 1 retry is allowed. * * @see DefaultHttpRequestRetryHandler */ DefaultHttpClient newDefaultHttpClient( SSLSocketFactory socketFactory, HttpParams params, ProxySelector proxySelector) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", socketFactory, 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, params); // retry only once defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true)); if (proxySelector != null) { defaultHttpClient.setRoutePlanner(new ProxySelectorRoutePlanner(registry, proxySelector)); } defaultHttpClient.setKeepAliveStrategy((response, context) -> KEEP_ALIVE_DURATION); return defaultHttpClient; }
Example #21
Source File: ApacheHttpClient.java From jus with Apache License 2.0 | 5 votes |
@Override public void prepare(States.GenericState state) { super.prepare(state); ClientConnectionManager connectionManager = new PoolingClientConnectionManager(); if (state.tls) { SslClient sslClient = SslClient.localhost(); connectionManager.getSchemeRegistry().register( new Scheme("https", 443, new SSLSocketFactory(sslClient.sslContext))); } client = new DefaultHttpClient(connectionManager); }
Example #22
Source File: MySSLSocketFactory.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public static SSLSocketFactory getFixedSocketFactory() { MySSLSocketFactory mysslsocketfactory; try { mysslsocketfactory = new MySSLSocketFactory(getKeystore()); mysslsocketfactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Throwable throwable) { throwable.printStackTrace(); return SSLSocketFactory.getSocketFactory(); } return mysslsocketfactory; }
Example #23
Source File: HttpClientStack.java From simple_net_framework with MIT License | 5 votes |
/** * 如果是https请求,则使用用户配置的SSLSocketFactory进行配置. * * @param request */ private void configHttps(Request<?> request) { SSLSocketFactory sslSocketFactory = mConfig.getSocketFactory(); if (request.isHttps() && sslSocketFactory != null) { Scheme sch = new Scheme("https", sslSocketFactory, 443); mHttpClient.getConnectionManager().getSchemeRegistry().register(sch); } }
Example #24
Source File: NoCertSSLSocketFactory.java From ForgePE with GNU Affero General Public License v3.0 | 5 votes |
public static NoCertSSLSocketFactory createDefault() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException, UnrecoverableKeyException { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); NoCertSSLSocketFactory factory = new NoCertSSLSocketFactory(keyStore); factory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return factory; }
Example #25
Source File: Utils.java From dummydroid with Apache License 2.0 | 5 votes |
public static Scheme getMockedScheme() throws NoSuchAlgorithmException, KeyManagementException { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { new DummyX509TrustManager() }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); Scheme https = new Scheme("https", 443, sf); return https; }
Example #26
Source File: ApacheHttpTransport.java From google-http-java-client with Apache License 2.0 | 5 votes |
/** * Creates a new instance of the Apache HTTP client that is used by the {@link * #ApacheHttpTransport()} constructor. * * @param socketFactory SSL socket factory * @param params HTTP parameters * @param proxySelector HTTP proxy selector to use {@link ProxySelectorRoutePlanner} or {@code * null} for {@link DefaultHttpRoutePlanner} * @return new instance of the Apache HTTP client */ static DefaultHttpClient newDefaultHttpClient( SSLSocketFactory socketFactory, HttpParams params, ProxySelector proxySelector) { // See http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", socketFactory, 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, params); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); if (proxySelector != null) { defaultHttpClient.setRoutePlanner(new ProxySelectorRoutePlanner(registry, proxySelector)); } return defaultHttpClient; }
Example #27
Source File: MySSLSocketFactory.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
/** * Returns a SSlSocketFactory which trusts all certificates * * @return SSLSocketFactory */ public static SSLSocketFactory getFixedSocketFactory() { SSLSocketFactory socketFactory; try { socketFactory = new MySSLSocketFactory(getKeystore()); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Throwable t) { t.printStackTrace(); socketFactory = SSLSocketFactory.getSocketFactory(); } return socketFactory; }
Example #28
Source File: HttpClientUtil.java From AndroidRobot with Apache License 2.0 | 5 votes |
/** * 访问https的网站 * @param httpclient */ private static void enableSSL(DefaultHttpClient httpclient){ //调用ssl try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { truseAllManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); httpclient.getConnectionManager().getSchemeRegistry() .register(https); } catch (Exception e) { e.printStackTrace(); } }
Example #29
Source File: LibSSLSocketFactory.java From YiBo with Apache License 2.0 | 5 votes |
private static SSLContext createLibSSLContext() throws IOException { try { SSLContext context = SSLContext.getInstance(SSLSocketFactory.TLS); context.init(null, new TrustManager[] {trustAllCerts}, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
Example #30
Source File: BrooklynWebServerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(dataProvider="keystorePaths") public void verifyHttps(String keystoreUrl) throws Exception { Map<String,?> flags = ImmutableMap.<String,Object>builder() .put("httpsEnabled", true) .put("keystoreUrl", keystoreUrl) .put("keystorePassword", "password") .build(); webServer = new BrooklynWebServer(flags, newManagementContext(brooklynProperties)); webServer.skipSecurity().start(); try { KeyStore keyStore = load("client.ks", "password"); KeyStore trustStore = load("client.ts", "password"); SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, "password", trustStore, (SecureRandom)null, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpToolResponse response = HttpTool.execAndConsume( HttpTool.httpClientBuilder() .port(webServer.getActualPort()) .https(true) .socketFactory(socketFactory) .build(), new HttpGet(webServer.getRootUrl())); assertEquals(response.getResponseCode(), 200); } finally { webServer.stop(); } }