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.liferay.portal.search.solr.http.SSLSocketFactoryBuilderImpl.java
@Override public SSLSocketFactory build() throws Exception { KeyStore keyStore = _keyStoreLoader.load(_keyStoreType, _keyStorePath, _keyStorePassword); if (keyStore == null) { if (_log.isDebugEnabled()) { _log.debug("Use system defaults because there is no custom key store"); }//w w w.j a va2 s .c o m return SSLSocketFactory.getSystemSocketFactory(); } KeyStore trustKeyStore = null; TrustStrategy trustStrategy = null; if (_verifyServerCertificate) { trustKeyStore = _keyStoreLoader.load(_trustStoreType, _trustStorePath, _trustStorePassword); if (trustKeyStore == null) { if (_log.isDebugEnabled()) { _log.debug("Use system defaults because there is no custom " + "trust store"); } return SSLSocketFactory.getSystemSocketFactory(); } } else { trustStrategy = new TrustSelfSignedStrategy(); } X509HostnameVerifier x509HostnameVerifier = SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; if (!_verifyServerHostname) { x509HostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; } try { return new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, String.valueOf(_keyStorePassword), trustKeyStore, null, trustStrategy, x509HostnameVerifier); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Use system defaults because the custom SSL socket " + "factory was not able to initialize", e); } return SSLSocketFactory.getSystemSocketFactory(); } }
From source file:com.seajas.search.codex.social.connection.TrustingClientHttpRequestFactory.java
public TrustingClientHttpRequestFactory() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { super();/*www .j a va2s.c o m*/ this.getHttpClient().getConnectionManager().getSchemeRegistry() .register(new Scheme("https", 443, new SSLSocketFactory(new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { if (logger.isTraceEnabled()) logger.trace(format("Trusting certificate chain with %d certificates and auth type %s", chain != null ? chain.length : 0, authType)); return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER))); }
From source file:com.cloudhopper.httpclient.util.HttpSender.java
static public Response postXml(String url, String username, String password, String requestXml) throws Exception { ////from ww w . j a v a2 s .c o m // trust any SSL connection // TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // allow all } public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // allow all } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); //SchemeRegistry sr = new SchemeRegistry(); //sr.register(http); //sr.register(https); // create and initialize scheme registry //SchemeRegistry schemeRegistry = new SchemeRegistry(); //schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. //ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry); //cm.setMaxTotalConnections(1); DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(https); HttpPost post = new HttpPost(url); StringEntity postEntity = new StringEntity(requestXml, "ISO-8859-1"); postEntity.setContentType("text/xml; charset=\"ISO-8859-1\""); post.addHeader("SOAPAction", "\"\""); post.setEntity(postEntity); long start = System.currentTimeMillis(); client.getCredentialsProvider().setCredentials(new AuthScope(null, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and stick it to the local // execution context BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); // Add as the first request interceptor client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpResponse httpResponse = client.execute(post, localcontext); HttpEntity responseEntity = httpResponse.getEntity(); Response rsp = new Response(); // set the status line and reason rsp.statusCode = httpResponse.getStatusLine().getStatusCode(); rsp.statusLine = httpResponse.getStatusLine().getReasonPhrase(); // get an input stream rsp.body = EntityUtils.toString(responseEntity); // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources client.getConnectionManager().shutdown(); return rsp; }
From source file:com.allstate.client.ssl.SSLUtils.java
public static SSLSocketFactory getMergedSocketFactory(Security securityOne, Security securityTwo) throws GeneralSecurityException { X509KeyManager keyManagerOne = getKeyManager(securityOne.getKeyStore(), securityOne.getKeyStorePassword()); X509KeyManager keyManagerTwo = getKeyManager(securityTwo.getKeyStore(), securityTwo.getKeyStorePassword()); X509TrustManager trustManager = getMultiTrustManager(getTrustManager(securityOne.getTrustStore()), getTrustManager(securityTwo.getTrustStore())); SSLContext context = SSLContext.getInstance(securityOne.getSslContextProtocol()); boolean strictHostVerification = securityOne.isStrictHostVerification() && securityTwo.isStrictHostVerification(); context.init(new KeyManager[] { keyManagerOne, keyManagerTwo }, new TrustManager[] { trustManager }, new SecureRandom()); X509HostnameVerifier verifier = strictHostVerification ? SSLSocketFactory.STRICT_HOSTNAME_VERIFIER : SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; return new SSLSocketFactory(context, verifier); }
From source file:org.owasp.goatdroid.herdfinancial.requestresponse.CustomSSLSocketFactory.java
public static HttpClient getNewHttpClient() { try {//from ww w . jav a 2 s . co m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); 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:es.uja.photofirma.android.DoConnection.java
/** * //from w ww . j ava 2 s. co m * @return DefaultHttpClient(ccm, params) */ 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); //aado timeout HttpConnectionParams.setConnectionTimeout(params, 6000); //timeout en establecer conexion HttpConnectionParams.setSoTimeout(params, 10000); //timeout en recibir respuesta 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:com.betfair.testing.utils.cougar.manager.HttpPageManager.java
public int getPage(HttpPageBean bean) { // Get bean properties String requestedProtocol = bean.getProtocol(); String requestedHost = bean.getHost(); int requestedPort = bean.getPort(); String requestedLink = bean.getLink(); String username = bean.getAuthusername(); String password = bean.getAuthpassword(); final SSLSocketFactory sf = new SSLSocketFactory(createEasySSLContext(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", 9999, sf); // Set up httpClient to use given auth details and protocol DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(https); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); int status = -1; InputStream inputStream = null; // Make the request try {/*from www . j a v a2s .c o m*/ final HttpGet httpget = new HttpGet( URIUtils.createURI(requestedProtocol, requestedHost, requestedPort, requestedLink, null, null)); final HttpResponse httpResponse = client.execute(httpget); inputStream = httpResponse.getEntity().getContent(); status = httpResponse.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK) { bean.setPageLoaded(true); byte[] buffer = new byte[(int) httpResponse.getEntity().getContentLength()]; int read; int count = 0; while ((read = inputStream.read()) != -1) { buffer[count] = (byte) read; count++; } bean.setPageText(new String(buffer, "UTF-8")); bean.setBuffer(buffer); } } catch (IOException e1) { return -1; } catch (URISyntaxException e) { return -1; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // ignore } } } return status; }
From source file:com.cttapp.bby.mytlc.layer8apps.ConnectionManager.java
/************ * PURPOSE: Creates a new instance of client * ARGUMENTS: null/*from w w w . j ava 2 s.c o m*/ * RETURNS: ConnectionManager * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ private ConnectionManager() { try { SSLSocketFactory factory = new SimpleSSLSocketFactory(null); factory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, "MyTLC-Sync"); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", factory, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Create a new connection for our client client = new DefaultHttpClient(ccm, params); } catch (Exception ex) { client = new DefaultHttpClient(); } }
From source file:com.appfirst.communication.AFHttpClient.java
public DefaultHttpClient getAFHttpClient() { try {//from w w w . j a va2 s . c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); try { trustStore.load(null, null); } catch (CertificateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } SSLSocketFactory sf = new AFSSLSocketFactory(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 (NoSuchAlgorithmException nsae) { Log.e(TAG, nsae.getMessage()); return new DefaultHttpClient(); } catch (KeyManagementException kme) { Log.e(TAG, kme.getMessage()); return new DefaultHttpClient(); } catch (KeyStoreException kse) { Log.e(TAG, kse.getMessage()); return new DefaultHttpClient(); } catch (UnrecoverableKeyException uke) { Log.e(TAG, uke.getMessage()); return new DefaultHttpClient(); } }
From source file:com.openmeap.util.SSLUtils.java
static public HttpClient getRelaxedSSLVerificationHttpClient() { try {/*from ww w . j a va2 s . c o 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(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, FormConstants.CHAR_ENC_DEFAULT); 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(); } }