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:org.ocsinventoryng.android.actions.CoolSSLSocketFactory.java
public CoolSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//from w ww .j av a 2 s.c o m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { for (X509Certificate aChain : chain) { Log.d("X509", aChain.getSubjectDN().toString()); } } public X509Certificate[] getAcceptedIssuers() { return null; } }; Log.d("X509", "CoolSSLSocketFactory"); sslContext.init(null, new TrustManager[] { tm }, null); setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:org.reficio.ws.client.ssl.SSLUtils.java
public static SSLSocketFactory getMergedSocketFactory(org.reficio.ws.client.core.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.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory.java
/** * Create an SSL factory which trusts all certificates and hosts. * {@link SSLSocketFactory#SSLSocketFactory(TrustStrategy, org.apache.http.conn.ssl.X509HostnameVerifier)} * @param factory javax.net.ssl.SSLSocketFactory * @throws GeneralSecurityException if there's a problem setting up the security *//*from w ww .java2 s.c o m*/ protected HC4TrustAllSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory) throws GeneralSecurityException { super(TRUSTALL, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); this.factory = factory; }
From source file:eu.prestoprime.p4gui.connection.P4HttpClient.java
public P4HttpClient(String userID) { HttpParams params = new BasicHttpParams(); // setup SSL/*from w ww .j a v a2 s . c o m*/ try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000L); SSLSocket socket = (SSLSocket) sf.createSocket(params); socket.setEnabledCipherSuites(new String[] { "SSL_RSA_WITH_RC4_128_MD5" }); Scheme sch = new Scheme("https", 443, sf); this.getConnectionManager().getSchemeRegistry().register(sch); } catch (IOException | KeyManagementException | NoSuchAlgorithmException e) { logger.error("Unable to create SSL handler for HttpClient..."); e.printStackTrace(); } // save userID this.userID = userID; }
From source file:com.odoo.core.rpc.http.OdooSafeClient.java
private static SSLSocketFactory getSecureConnectionSetting() { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override/*from ww w.ja va2 s.c o m*/ public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; } } }; SSLSocketFactory ssf = null; try { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, null); ssf = new OSSLSocketFactory(sc); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception ea) { ea.printStackTrace(); } return ssf; }
From source file:org.cloudifysource.restclient.RestSSLSocketFactory.java
/** * Ctor./*from www.ja v a 2 s . c o m*/ * * @param truststore * a {@link KeyStore} containing one or several trusted * certificates to enable server authentication. * @throws NoSuchAlgorithmException * Reporting failure to create SSLSocketFactory with the given * trust-store and algorithm TLS or initialize the SSLContext. * @throws KeyManagementException * Reporting failure to create SSLSocketFactory with the given * trust-store and algorithm TLS or initialize the SSLContext. * @throws KeyStoreException * Reporting failure to create SSLSocketFactory with the given * trust-store and algorithm TLS or initialize the SSLContext. * @throws UnrecoverableKeyException * Reporting failure to create SSLSocketFactory with the given * trust-store and algorithm TLS or initialize the SSLContext. */ public RestSSLSocketFactory(final KeyStore trustStore) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { this(trustStore, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:com.decody.android.core.json.JSONClient.java
public JSONClient(GsonFactory factory, boolean https) { this.factory = factory; if (https) {//from w w w. j a v a2s .c o m 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); this.client = new DefaultHttpClient(mgr, client.getParams()); } else { client = new DefaultHttpClient(); } }
From source file:net.peterkuterna.android.apps.devoxxsched.util.SyncUtils.java
/** * Generate and return a {@link HttpClient} configured for general use, * including setting an application-specific user-agent string. *//*from w ww . j av a 2 s. com*/ public static HttpClient getHttpClient(Context context) { final HttpParams params = new BasicHttpParams(); // Use generous timeouts for slow mobile networks HttpConnectionParams.setConnectionTimeout(params, 200 * SECOND_IN_MILLIS); HttpConnectionParams.setSoTimeout(params, 200 * SECOND_IN_MILLIS); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpProtocolParams.setUserAgent(params, buildUserAgent(context)); final HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); final SchemeRegistry schemeReg = new SchemeRegistry(); schemeReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeReg.register(new Scheme("https", sslSocketFactory, 443)); final ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeReg); final DefaultHttpClient client = new DefaultHttpClient(connectionManager, params); client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { // Add header to accept gzip content if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) { // Inflate any responses compressed with gzip final HttpEntity entity = response.getEntity(); final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); return client; }
From source file:eu.musesproject.client.connectionmanager.TLSManager.java
/** * Create SSLFactory object using certificate saved in the device * @return SSLSocketFactory/*from w w w. j a v a2 s . c o m*/ */ private SSLSocketFactory newSslSocketFactory() { try { InputStream in = new ByteArrayInputStream(MusesUtils.getCertificate().getBytes()); KeyStore trustedStore = null; if (in != null) { trustedStore = convertCerToBKS(in, "muses alias", "muses11".toCharArray()); } SSLSocketFactory sf = new SSLSocketFactory(trustedStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { throw new AssertionError(e); } }
From source file:com.allstate.client.ssl.SSLUtils.java
public static SSLSocketFactory getFactory(Security security) throws GeneralSecurityException { X509HostnameVerifier verifier = security.isStrictHostVerification() ? SSLSocketFactory.STRICT_HOSTNAME_VERIFIER : SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SSLSocketFactory socketFactory = new SSLSocketFactory(security.getSslContextProtocol(), security.getKeyStore(), security.getKeyStorePasswordAsString(), security.getTrustStore(), new SecureRandom(), null, verifier); return socketFactory; }