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.jonbanjo.ssl.JfSSLScheme.java
public static Scheme getScheme() { FileInputStream fis = null;//from w ww . j a v a 2s .co m Scheme scheme; try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); try { fis = CupsPrintApp.getContext().openFileInput(trustfile); trustStore.load(fis, password.toCharArray()); } catch (Exception e) { trustStore.load(null, null); } SSLSocketFactory sf = new AdditionalKeyStoresSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); scheme = new Scheme("https", sf, 443); } catch (Exception e) { scheme = getDefaultScheme(); } finally { if (fis != null) { try { fis.close(); } catch (Exception e1) { } } } return scheme; }
From source file:com.emobc.android.utils.HttpUtils.java
/** * Take a client address is https by default if * @param https/* w ww. j a v a2 s . co m*/ * @return */ public static DefaultHttpClient getHttpClient(boolean https) { if (https) { HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; } return new DefaultHttpClient(); }
From source file:de.micromata.genome.gwiki.fssvn.SslUtils.java
public static SSLSocketFactory createEasySSLSocketFactory() { try {/*from w ww. j a va2 s . com*/ 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); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return ssf; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:vcclient.FakeSSLSocketFactory.java
public static SSLSocketFactory getInstance() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { return new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; }// w ww . ja va 2 s. c o m }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:com.subgraph.vega.internal.http.requests.AbstractHttpClientFactory.java
protected static SchemeRegistry createSchemeRegistry() { final SchemeRegistry sr = new SchemeRegistry(); sr.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); SSLContext ctx;// w w w . j a va 2 s . c o m try { 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 X509TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sr.register(new Scheme("https", 443, ssf)); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } return sr; }
From source file:com.lolay.android.security.OpenX509TrustManager.java
public static void openTrust() { LolayLog.w(TAG, "openTrust", "THIS IS AN OPEN TRUST MANAGER FOR DEBUGGING ONLY!"); try {//w w w . j a va 2 s .c o m SSLContext context = SSLContext.getInstance("SSL"); context.init(null, new TrustManager[] { new OpenX509TrustManager() }, null); HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception e) { LolayLog.e(TAG, "openTrust", "Could not open the trust", e); } }
From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java
static HttpClient getHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); // This is done to get rid of the "javax.net.ssl.SSLException: hostname in certificate didn't match" error // See e.g. http://stackoverflow.com/questions/8839541/hostname-in-certificate-didnt-match socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", socketFactory, 443)); HttpParams params = getHttpParams(); ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); HttpClient client = new DefaultHttpClient(clientConnectionManager, params); client.getParams()//from w ww . j a v a 2s .c o m .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, MyPreferences.getConnectionTimeoutMs()) .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, MyPreferences.getConnectionTimeoutMs()); return client; }
From source file:org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils.java
public static DefaultHttpClient getHttpsClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, DCRProxyUtils.getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }
From source file:org.apache.stratos.cli.WebClientWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {//from w w w . j av a 2s . co m 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); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { return null; } }
From source file:org.lorislab.armonitor.util.RestClient.java
/** * Gets the rest-service client./*from w w w. jav a2 s . com*/ * * @param <T> the rest-service client implementation. * @param clazz the rest-service class. * @param url the server URL. * @param username the username. * @param password the password. * @param auth the authentication flag. * @exception Exception if the method fails. * * @return the the rest-service client instance. */ public static <T> T getClient(final Class<T> clazz, String url, boolean auth, String username, char[] password) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); if (url.startsWith(HTTPS)) { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme(HTTPS, 443, sslSocketFactory)); } if (auth) { BasicCredentialsProvider provider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, new String(password)); provider.setCredentials(AuthScope.ANY, credentials); httpClient.setCredentialsProvider(provider); } return ProxyFactory.create(clazz, url, new ApacheHttpClient4Executor(httpClient)); }