List of usage examples for org.apache.http.conn.ssl SSLSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER
X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
To view the source code for org.apache.http.conn.ssl SSLSocketFactory ALLOW_ALL_HOSTNAME_VERIFIER.
Click Source Link
From source file:org.changhong.sync.web.MySSLSocketFactory.java
public static DefaultHttpClient getNewHttpClient() { try {/*from w w w. j a v a 2s. c om*/ 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(); } }
From source file:piecework.client.LoadTester.java
public LoadTester(KeyStore keystore, SecuritySettings securitySettings) { ClientConnectionManager cm;/* ww w . j a v a 2 s.com*/ try { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(keystore, new String(securitySettings.getKeystorePassword())); X509HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; sslSocketFactory.setHostnameVerifier(hostnameVerifier); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", 8443, sslSocketFactory)); cm = new PoolingClientConnectionManager(schemeRegistry); } catch (Exception e) { cm = new BasicClientConnectionManager(); } this.client = new DefaultHttpClient(cm); }
From source file:com.netflix.http4.ssl.AcceptAllSocketFactory.java
public AcceptAllSocketFactory() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { super(new TrustStrategy() { @Override//from w w w . jav a 2 s .c om public boolean isTrusted(final X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:org.globus.crux.security.ClientTest.java
/** * Test client with invalid credentials. * //from w w w .ja v a 2s. c o m * @throws Exception * This should happen. */ @Test public void testInvalid() throws Exception { SSLConfigurator config = getConfig("classpath:/invalidkeystore.properties"); SSLSocketFactory fac = new SSLSocketFactory(config.getSSLContext()); fac.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); DefaultHttpClient httpclient = new DefaultHttpClient(); Scheme scheme = new Scheme("https", fac, getPort()); httpclient.getConnectionManager().getSchemeRegistry().register(scheme); HttpGet httpget = new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); try { httpclient.execute(httpget); fail(); } catch (SSLPeerUnverifiedException ex) { // this better happen } }
From source file:com.upyun.sdk.utils.HttpClientUtils.java
@SuppressWarnings("deprecation") public static HttpClient getInstance() { HttpClient client = new DefaultHttpClient(); SSLContext ctx = null;//from ww w. j a v a 2 s .c om try { ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); } catch (Exception e) { LogUtil.exception(logger, e); } SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); client = new DefaultHttpClient(ccm, client.getParams()); return client; }
From source file:org.jboss.as.test.http.util.HttpClientUtils.java
/** * Returns https ready client./*from ww w . ja va2s .c o m*/ * * @param base * @return */ public static HttpClient wrapHttpsClient(HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:com.navnorth.learningregistry.LRClient.java
public static HttpClient getHttpClient(String scheme) { // TODO: this allows for self-signed certificates, which should just be an option, not used by default. if (scheme.equals("https")) { try {/*from www .j a v a 2s .c om*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SelfSignSSLSocketFactory(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(); } } else { return new DefaultHttpClient(); } }
From source file:com.payu.sdk.helper.WebClientDevWrapper.java
/** * Wraps a default and secure httpClient * * @param base the original httpClient/*from w w w . j a v a2 s .com*/ * @return the hhtpClient wrapped * @throws ConnectionException */ public static HttpClient wrapClient(HttpClient base) throws ConnectionException { try { SSLContext ctx = SSLContext.getInstance(Constants.SSL_PROVIDER); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", Constants.HTTPS_PORT, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { throw new ConnectionException("Invalid SSL connection", ex); } }
From source file:com.googlecode.noweco.webmail.httpclient.UnsecureHttpClientFactory.java
public DefaultHttpClient createUnsecureHttpClient(final HttpHost proxy) { DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager()); SchemeRegistry schemeRegistry = httpclient.getConnectionManager().getSchemeRegistry(); schemeRegistry.unregister("https"); try {/*from w w w . j ava 2 s.c o m*/ SSLContext instance = SSLContext.getInstance("TLS"); TrustManager tm = UnsecureX509TrustManager.INSTANCE; instance.init(null, new TrustManager[] { tm }, null); schemeRegistry.register(new Scheme("https", 443, new SSLSocketFactory(instance, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER))); } catch (Exception e) { throw new RuntimeException("TLS issue", e); } httpclient.removeResponseInterceptorByClass(ResponseProcessCookies.class); httpclient.addResponseInterceptor(new UnsecureResponseProcessCookies()); HttpParams params = httpclient.getParams(); if (proxy != null) { ConnRouteParams.setDefaultProxy(params, proxy); } HttpConnectionParams.setSoTimeout(params, 7000); return httpclient; }
From source file:cn.keke.travelmix.EasySSLSocketFactory.java
public EasySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(TLS, null, null, truststore, null, null, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // skip }/*from www . ja v a2 s .co m*/ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // skip } public X509Certificate[] getAcceptedIssuers() { return null; } }; this.sslContext.init(null, new TrustManager[] { tm }, null); }