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.supremainc.biostar2.sdk.volley.toolbox.HttpClientStack.java
public HttpClient getNewHttpClient() { try {//from w ww .j ava 2s .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, 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.wso2.emm.agent.proxy.clients.MutualSSLClient.java
public HttpClient getHttpClient() throws IDPTokenManagerException { HttpClient client;// w ww . j a v a 2s. c om try { if (Constants.SERVER_PROTOCOL.equalsIgnoreCase("https://")) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Constants.HTTP)); SSLSocketFactory sslSocketFactory; AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory(); MutualSSLAuthenticator mutualSSLAuthenticator = (MutualSSLAuthenticator) authenticatorFactory .getClient(Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR, null, Constants.ADD_HEADER_CALLBACK); sslSocketFactory = new SSLSocketFactory(mutualSSLAuthenticator.getCredentialCertificate(), Constants.KEYSTORE_PASSWORD, localTrustStore); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, Constants.HTTPS)); HttpParams params = new BasicHttpParams(); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); client = new DefaultHttpClient(connectionManager, params); } else { client = new DefaultHttpClient(); } } catch (KeyStoreException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (NoSuchAlgorithmException e) { String errorMsg = "Error occurred while due to mismatch of defined algorithm."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (UnrecoverableKeyException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (KeyManagementException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } return client; }
From source file:com.base.net.volley.toolbox.HttpClientStack.java
/** * https?/* ww w. ja va2s .co m*/ * @param client */ private void setClientHttps(HttpClient client) { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // ?? ClientConnectionManager conManager = client.getConnectionManager(); SchemeRegistry schReg = conManager.getSchemeRegistry(); if (schReg == null) { schReg = new SchemeRegistry(); } schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", sf, 443)); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnrecoverableKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.incoherent.suseconferenceclient.app.HTTPWrapper.java
public static JSONObject get(String url) throws IllegalStateException, SocketException, UnsupportedEncodingException, IOException, JSONException { 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)); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); HttpGet get = new HttpGet(url); HttpResponse response = httpClient.execute(get); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode >= 200 && statusCode <= 299) { return HTTPWrapper.parseResponse(response); } else {/* www.jav a 2 s. c o m*/ throw new HttpResponseException(statusCode, statusLine.getReasonPhrase()); } }
From source file:pl.psnc.synat.wrdz.common.https.HttpsClientHelper.java
/** * Gets HTTPS client that can authenticate in WRDZ modules. * // www . j av a2 s . co m * @param module * module that wants to be authenticated * @return HTTPS client */ public synchronized HttpClient getHttpsClient(WrdzModule module) { DefaultHttpClient httpClient = httpsClients.get(module); if (httpClient == null) { logger.debug("HTTPS client for module " + module.name() + " is not yet initialized"); try { SSLSocketFactory socketFactory; if (config.getHttpsVerifyHostname()) { socketFactory = new SSLSocketFactory(new TrustAllStrategy()); } else { socketFactory = new SSLSocketFactory(new TrustAllStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } Scheme scheme = new Scheme("https", 443, socketFactory); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.getSchemeRegistry().register(scheme); String cipher = config.getModulesPassword(); byte[] key = SECRET.getBytes("utf-8"); Cipher c = Cipher.getInstance("AES"); SecretKeySpec k = new SecretKeySpec(key, "AES"); c.init(Cipher.DECRYPT_MODE, k); byte[] decrypted = c.doFinal(Base64.decodeBase64(cipher)); String password = new String(decrypted, "utf-8"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(module.name(), password); httpClient = new DefaultHttpClient(connectionManager); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpsClients.put(module, httpClient); } catch (Exception e) { throw new WrdzRuntimeException(e.getMessage(), e); } } return httpClient; }
From source file:org.apache.solr.client.solrj.impl.HttpClientConfigurer.java
public void configure(DefaultHttpClient httpClient, SolrParams config) { if (config.get(HttpClientUtil.PROP_MAX_CONNECTIONS) != null) { HttpClientUtil.setMaxConnections(httpClient, config.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS)); }/*ww w .ja va 2 s . c om*/ if (config.get(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST) != null) { HttpClientUtil.setMaxConnectionsPerHost(httpClient, config.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST)); } if (config.get(HttpClientUtil.PROP_CONNECTION_TIMEOUT) != null) { HttpClientUtil.setConnectionTimeout(httpClient, config.getInt(HttpClientUtil.PROP_CONNECTION_TIMEOUT)); } if (config.get(HttpClientUtil.PROP_SO_TIMEOUT) != null) { HttpClientUtil.setSoTimeout(httpClient, config.getInt(HttpClientUtil.PROP_SO_TIMEOUT)); } if (config.get(HttpClientUtil.PROP_FOLLOW_REDIRECTS) != null) { HttpClientUtil.setFollowRedirects(httpClient, config.getBool(HttpClientUtil.PROP_FOLLOW_REDIRECTS)); } // always call setUseRetry, whether it is in config or not HttpClientUtil.setUseRetry(httpClient, config.getBool(HttpClientUtil.PROP_USE_RETRY, true)); final String basicAuthUser = config.get(HttpClientUtil.PROP_BASIC_AUTH_USER); final String basicAuthPass = config.get(HttpClientUtil.PROP_BASIC_AUTH_PASS); HttpClientUtil.setBasicAuth(httpClient, basicAuthUser, basicAuthPass); if (config.get(HttpClientUtil.PROP_ALLOW_COMPRESSION) != null) { HttpClientUtil.setAllowCompression(httpClient, config.getBool(HttpClientUtil.PROP_ALLOW_COMPRESSION)); } boolean sslCheckPeerName = toBooleanDefaultIfNull( toBooleanObject(System.getProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME)), true); if (sslCheckPeerName == false) { HttpClientUtil.setHostNameVerifier(httpClient, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } }
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.eviware.soapui.impl.wsdl.support.http.SoapUISSLSocketFactory.java
@SuppressWarnings("deprecation") public SoapUISSLSocketFactory(KeyStore keyStore, String keystorePassword) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { super(keyStore); // trust everyone! X509TrustManager tm = new X509TrustManager() { @Override/*from ww w . j a va 2s .co m*/ public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(X509Certificate[] certs, String authType) { } }; if (keyStore != null) { KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keyStore, keystorePassword != null ? keystorePassword.toCharArray() : null); KeyManager[] keymanagers = kmfactory.getKeyManagers(); sslContext.init(keymanagers, new TrustManager[] { tm }, null); } else { sslContext.init(null, new TrustManager[] { tm }, null); } setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.thrift.ThriftAuthClient.java
public ThriftAuthClient(String serverIP, String remoteServerPort, String webContextRoot) throws AuthenticationException { try {/*from w ww .ja v a 2 s .c om*/ 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:com.msopentech.thali.utilities.universal.HttpKeySSLSocketFactory.java
public HttpKeySSLSocketFactory(final PublicKey serverPublicKey, final KeyStore clientKeyStore, final char[] clientPassPhrase) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { super((KeyStore) null); final ThaliPublicKeyComparer thaliPublicKeyComparer = serverPublicKey == null ? null : new ThaliPublicKeyComparer(serverPublicKey); TrustManager trustManager = new X509TrustManager() { @Override//ww w.j a va 2 s.co m public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException { throw new RuntimeException( "We should not have gotten a client trusted call, authType was:" + authType); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException { //TODO: We actually need to restrict authTypes to known secure ones if (serverPublicKey == null) { return; } PublicKey rootPublicKey = x509Certificates[x509Certificates.length - 1].getPublicKey(); if (thaliPublicKeyComparer.KeysEqual(rootPublicKey) == false) { throw new RuntimeException("Presented server root key does not match expected server root key"); } } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; KeyManagerFactory keyManagerFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(clientKeyStore, clientPassPhrase); sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyManagerFactory.getKeyManagers(), new TrustManager[] { trustManager }, new SecureRandom()); this.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }