List of usage examples for org.apache.http.conn.ssl SSLSocketFactory setHostnameVerifier
public void setHostnameVerifier(final X509HostnameVerifier hostnameVerifier)
From source file:org.surveydroid.android.coms.SDHttpClient.java
private SSLSocketFactory newSslSocketFactory() { try {/*from w w w . ja v a 2 s .c om*/ KeyStore trusted = KeyStore.getInstance("BKS"); InputStream in = ctxt.getResources().openRawResource(R.raw.sd_keystore); try { trusted.load(in, PASSWORD.toCharArray()); } catch (CertificateException e) { Util.e(null, TAG, "Cert Exception: " + Util.fmt(e)); throw new AssertionError(e); } finally { in.close(); } SSLSocketFactory sf = new SSLSocketFactory(trusted); //TODO look into this sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { Util.e(ctxt, TAG, Util.fmt(e)); throw new AssertionError(e); } }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.thrift.ThriftAuthClient.java
public ThriftAuthClient(String serverIP, String remoteServerPort, String webContextRoot) throws AuthenticationException { try {// w w w.j a v a 2s .c o m TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) { } public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; //skip host name verification SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslContext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); //REGISTERS SCHEMES FOR BOTH HTTP AND HTTPS SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", sf, Integer.parseInt(remoteServerPort))); PoolingClientConnectionManager manager = new PoolingClientConnectionManager(registry); HttpClient httpClient = new DefaultHttpClient(manager); //If the webContextRoot is null or / if (webContextRoot == null || "/".equals(webContextRoot)) { //Assign it an empty value since it is part of the thriftServiceURL. webContextRoot = ""; } String thriftServiceURL = "https://" + serverIP + ':' + remoteServerPort + webContextRoot + '/' + "thriftAuthenticator"; client = new THttpClient(thriftServiceURL, httpClient); } catch (TTransportException e) { throw new AuthenticationException("Error in creating thrift authentication client..", e); } catch (Exception e) { throw new AuthenticationException("Error in creating thrift authentication client..", e); } }
From source file:es.uja.photofirma.android.DoConnection.java
/** * /*from w ww . j a v a 2s . 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:org.globus.crux.security.ClientTest.java
/** * Test client with invalid credentials. * /*from w w w . j a v a 2s. co 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:org.qi4j.library.http.AbstractSecureJettyTest.java
@Before public void beforeSecure() throws GeneralSecurityException, IOException { // Trust HTTP Client KeyStore truststore = KeyStore.getInstance("JCEKS"); truststore.load(new FileInputStream(TRUSTSTORE_FILE), KS_PASSWORD.toCharArray()); AllowAllHostnameVerifier verifier = new AllowAllHostnameVerifier(); DefaultHttpClient trustClient = new DefaultHttpClient(); SSLSocketFactory trustSslFactory = new SSLSocketFactory(truststore); trustSslFactory.setHostnameVerifier(verifier); SchemeRegistry trustSchemeRegistry = trustClient.getConnectionManager().getSchemeRegistry(); trustSchemeRegistry.unregister(HTTPS); trustSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, trustSslFactory)); trustHttpClient = trustClient;/*from w w w . jav a 2s . c o m*/ // Mutual HTTP Client KeyStore keystore = KeyStore.getInstance("JCEKS"); keystore.load(new FileInputStream(CLIENT_KEYSTORE_FILE), KS_PASSWORD.toCharArray()); DefaultHttpClient mutualClient = new DefaultHttpClient(); SSLSocketFactory mutualSslFactory = new SSLSocketFactory(keystore, KS_PASSWORD, truststore); mutualSslFactory.setHostnameVerifier(verifier); SchemeRegistry mutualSchemeRegistry = mutualClient.getConnectionManager().getSchemeRegistry(); mutualSchemeRegistry.unregister(HTTPS); mutualSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, mutualSslFactory)); mutualHttpClient = mutualClient; }
From source file:com.wso2telco.gsma.shorten.BitlyUrlShorten.java
/** * Gets the new http client./*from w w w.ja va 2 s . c o m*/ * * @return the new http client */ @SuppressWarnings("deprecation") public CloseableHttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); org.apache.http.conn.ssl.SSLSocketFactory sf = new SSLSocket(trustStore); sf.setHostnameVerifier(org.apache.http.conn.ssl.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:org.globus.crux.security.ClientTest.java
/** * Test a client using valid credentials * //from w ww . j av a 2 s. c o m * @throws Exception * if this happens, the test fails. */ @Test public void testValid() throws Exception { SSLConfigurator config = getConfig("classpath:/mykeystore.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()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } if (entity != null) { entity.consumeContent(); } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system stores httpclient.getConnectionManager().shutdown(); }
From source file:com.eTilbudsavis.etasdk.network.impl.DefaultHttpNetwork.java
private void setHostNameVerifierAndRoutePlanner(DefaultHttpClient httpClient) { // Use custom HostVerifier to accept our wildcard SSL Certificates: *.etilbudsavis.dk HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Change RoutePlanner to avoid SchemeRegistry causing IllegalStateException. // Some devices with faults in their default route planner httpClient.setRoutePlanner(new DefaultHttpRoutePlanner(registry)); HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); }
From source file:com.android.volley.toolbox.https.SslHttpClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); PlainSocketFactory pfs = PlainSocketFactory.getSocketFactory(); Scheme s = new Scheme(HTTP_SCHEME, pfs, HTTP_DEFAULT_PORT); registry.register(s);// w ww. java 2s .c o m ThreadSafeClientConnManager ret = null; try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); registry.register(new Scheme(HTTP_SSL_SCHEME, sf, mHttpsPort)); ret = new ThreadSafeClientConnManager(new BasicHttpParams(), registry); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (IOException e) { e.printStackTrace(); } return ret; }
From source file:org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule.java
@Singleton @Provides/*ww w . j a va 2s .c o m*/ final ClientConnectionManager newClientConnectionManager(HttpParams params, X509HostnameVerifier verifier, SSLContext context, Closer closer) throws NoSuchAlgorithmException, KeyManagementException { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sf = new SSLSocketFactory(context); sf.setHostnameVerifier(verifier); schemeRegistry.register(new Scheme("https", sf, 443)); final ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); closer.addToClose(new Closeable() { @Override public void close() throws IOException { cm.shutdown(); } }); return cm; }