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:com.marklogic.client.impl.JerseyServices.java
@Override public void connect(String host, int port, String database, String user, String password, Authentication authenType, SSLContext context, SSLHostnameVerifier verifier) { X509HostnameVerifier x509Verifier = null; if (verifier == null) { if (context != null) x509Verifier = SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; } else if (verifier == SSLHostnameVerifier.ANY) x509Verifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; else if (verifier == SSLHostnameVerifier.COMMON) x509Verifier = SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; else if (verifier == SSLHostnameVerifier.STRICT) x509Verifier = SSLSocketFactory.STRICT_HOSTNAME_VERIFIER; else if (context != null) x509Verifier = new HostnameVerifierAdapter(verifier); else/*from ww w . j a v a2 s .c om*/ throw new IllegalArgumentException("Null SSLContent but non-null SSLHostnameVerifier for client"); connect(host, port, database, user, password, authenType, context, x509Verifier); }
From source file:com.mobilyzer.Checkin.java
/** * Return an appropriately-configured HTTP client. *//* ww w .j a v a2 s .com*/ private HttpClient getNewHttpClient() { DefaultHttpClient client; 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); HttpConnectionParams.setConnectionTimeout(params, POST_TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(params, POST_TIMEOUT_MILLISEC); 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); client = new DefaultHttpClient(ccm, params); } catch (Exception e) { Logger.w("Unable to create SSL HTTP client", e); client = new DefaultHttpClient(); } // TODO(mdw): For some reason this is not sending the cookie to the // test server, probably because the cookie itself is not properly // initialized. Below I manually set the Cookie header instead. CookieStore store = new BasicCookieStore(); store.addCookie(authCookie); client.setCookieStore(store); return client; }
From source file:de.wikilab.android.friendica01.TwAjax.java
public DefaultHttpClient getNewHttpClient() { if (ignoreSSLCerts) { try {//from w w w . jav a 2 s . c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new IgnoreCertsSSLSocketFactory(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.corebase.android.framework.http.client.AsyncHttpClient.java
/** * ?SSLSocketFactory?https?/*from ww w. j av a 2 s . co m*/ * * @return * @throws KeyStoreException * @throws NoSuchAlgorithmException * @throws UnrecoverableKeyException * @throws KeyManagementException */ private CustomSSLSocketFactory initCustomSSLSocketFactory() throws KeyStoreException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException { KeyStore keyStore = null; try { InputStream ins = context.getAssets().open("app_pay.cer"); // ?assets if (ins != null) { CertificateFactory cerFactory = CertificateFactory.getInstance("X.509"); Certificate cer = cerFactory.generateCertificate(ins); keyStore = KeyStore.getInstance("PKCS12", "BC"); keyStore.load(null, null); keyStore.setCertificateEntry("trust", cer); } else { keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); } CustomSSLSocketFactory customSSLSocketFactory = new CustomSSLSocketFactory(keyStore); customSSLSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return customSSLSocketFactory; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:net.vivekiyer.GAL.ActiveSyncManager.java
/** * @return the HttpClient object/*from www.j av a 2 s. c om*/ * * Creates a HttpClient object that is used to POST messages to the Exchange server */ private HttpClient createHttpClient() { HttpParams httpParams = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(httpParams, false); // Default connection and socket timeout of 120 seconds. Tweak to taste. HttpConnectionParams.setConnectionTimeout(httpParams, 120 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 120 * 1000); HttpConnectionParams.setSocketBufferSize(httpParams, 131072); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", mAcceptAllCerts ? new FakeSocketFactory() : SSLSocketFactory.getSocketFactory(), 443)); HttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams); // Set the headers httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Android"); // Make sure we are not validating any hostnames SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return httpclient; }
From source file:com.haoqee.chat.net.Utility.java
public static HttpClient getNewHttpClient(long timeout) { try {//from ww w . ja v a 2s .co m 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(); // HttpConnectionParams.setConnectionTimeout(params, 10000); // HttpConnectionParams.setSoTimeout(params, 10000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // HttpProtocolParams.setContentCharset(params, HTTP.); 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); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Utility.SET_CONNECTION_TIMEOUT); long soc_time = Utility.SET_SOCKET_TIMEOUT + timeout; HttpConnectionParams.setSoTimeout(params, (int) soc_time); HttpClient client = new DefaultHttpClient(ccm, params); return client; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.aliyun.api.gateway.demo.util.HttpUtil.java
private static void sslClient(HttpClient httpClient) { try {/* www .ja va 2 s . c o m*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] xcs, String str) { } public void checkServerTrusted(X509Certificate[] xcs, String str) { } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry registry = ccm.getSchemeRegistry(); registry.register(new Scheme("https", 443, ssf)); } catch (KeyManagementException ex) { throw new RuntimeException(ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } }
From source file:cn.tc.ulife.platform.msg.http.util.HttpUtil.java
private static void sslClient(HttpClient httpClient) { try {//from w ww . j a v a2 s .c om SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] xcs, String str) { } public void checkServerTrusted(X509Certificate[] xcs, String str) { } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry registry = ccm.getSchemeRegistry(); registry.register(new Scheme("https", ssf, 443)); } catch (KeyManagementException ex) { throw new RuntimeException(ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } }
From source file:fr.eolya.utils.http.HttpLoader.java
/** * @param /* www. jav a2 s . c om*/ * @return */ private HttpClient getHttpClient(String url) { try { // ClientConnectionManager SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); registry.register(new Scheme("https", 443, sf)); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); // Params HttpParams httpParams = getHttpParams(); // DefaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(ccm, httpParams); // Proxy setProxy(httpClient, url, proxyHost, proxyPort, proxyExclude, proxyUserName, proxyPassword); // if (StringUtils.isNotEmpty(proxyHost)) { // if (StringUtils.isNotEmpty(proxyUserName) && StringUtils.isNotEmpty(proxyPassword)) { // httpClient.getCredentialsProvider().setCredentials( // new AuthScope(proxyHost,Integer.valueOf(proxyPort)), // new UsernamePasswordCredentials(proxyUserName, proxyPassword)); // } // HttpHost proxy = new HttpHost(proxyHost,Integer.valueOf(proxyPort)); // httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy); // } else { // httpClient.getParams().removeParameter(ConnRoutePNames.DEFAULT_PROXY); // } // Cookies if (cookies != null) { CookieStore cookieStore = new BasicCookieStore(); Iterator<Entry<String, String>> it = cookies.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next(); BasicClientCookie cookie = new BasicClientCookie(pairs.getKey(), pairs.getValue()); //cookie.setDomain("your domain"); cookie.setPath("/"); cookieStore.addCookie(cookie); } httpClient.setCookieStore(cookieStore); } return new DecompressingHttpClient(httpClient); } catch (Exception e) { return new DecompressingHttpClient(new DefaultHttpClient()); } }