List of usage examples for org.apache.http.conn.scheme SchemeRegistry unregister
public final Scheme unregister(final String name)
From source file:org.eclipse.lyo.testsuite.server.util.OSLCUtils.java
static public void setupLazySSLSupport(HttpClient httpClient) { ClientConnectionManager connManager = httpClient.getConnectionManager(); SchemeRegistry schemeRegistry = connManager.getSchemeRegistry(); schemeRegistry.unregister("https"); /** Create a trust manager that does not validate certificate chains */ TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ }//from w w w.j ava2 s . c om public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; SSLContext sc = null; try { sc = SSLContext.getInstance("SSL"); //$NON-NLS-1$ sc.init(null, trustAllCerts, new java.security.SecureRandom()); } catch (NoSuchAlgorithmException e) { /* Fail Silently */ } catch (KeyManagementException e) { /* Fail Silently */ } SSLSocketFactory sf = new SSLSocketFactory(sc); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); schemeRegistry.register(https); }
From source file:com.googlecode.noweco.webmail.httpclient.UnsecureHttpClientFactory.java
public DefaultHttpClient createUnsecureHttpClient(final HttpHost proxy) { DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager()); SchemeRegistry schemeRegistry = httpclient.getConnectionManager().getSchemeRegistry(); schemeRegistry.unregister("https"); try {//from w w w .j av a 2 s . c om SSLContext instance = SSLContext.getInstance("TLS"); TrustManager tm = UnsecureX509TrustManager.INSTANCE; instance.init(null, new TrustManager[] { tm }, null); schemeRegistry.register(new Scheme("https", 443, new SSLSocketFactory(instance, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER))); } catch (Exception e) { throw new RuntimeException("TLS issue", e); } httpclient.removeResponseInterceptorByClass(ResponseProcessCookies.class); httpclient.addResponseInterceptor(new UnsecureResponseProcessCookies()); HttpParams params = httpclient.getParams(); if (proxy != null) { ConnRouteParams.setDefaultProxy(params, proxy); } HttpConnectionParams.setSoTimeout(params, 7000); return httpclient; }
From source file:io.undertow.testutils.TestHttpClient.java
public void setSSLContext(final SSLContext sslContext) { SchemeRegistry registry = getConnectionManager().getSchemeRegistry(); registry.unregister("https"); if (DefaultServer.getHostAddress(DefaultServer.DEFAULT).equals("localhost")) { registry.register(new Scheme("https", 443, new SSLSocketFactory(sslContext))); registry.register(//from w w w . j a v a 2s . co m new Scheme("https", DefaultServer.getHostSSLPort("default"), new SSLSocketFactory(sslContext))); } else { registry.register(new Scheme("https", 443, new SSLSocketFactory(sslContext, NO_OP_VERIFIER))); registry.register(new Scheme("https", DefaultServer.getHostSSLPort("default"), new SSLSocketFactory(sslContext, NO_OP_VERIFIER))); } }
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.j a v a2 s .co 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.android.volley.toolbox.http.HttpClientStack.java
public void setSSLSocketFactory(HttpClient mClient, SSLSocketFactory mSslSocketFactory) { if (mSslSocketFactory != null && mClient != null) { ClientConnectionManager manager = mClient.getConnectionManager(); SchemeRegistry schemeRegistry = manager.getSchemeRegistry(); schemeRegistry.unregister("https"); Scheme scheme = new Scheme("https", mSslSocketFactory, 443); schemeRegistry.register(scheme); }/*from www. ja v a2 s . c o m*/ }
From source file:com.android.emailcommon.utility.EmailClientConnectionManager.java
/** * Unregisters a custom connection type that uses a client certificate on the connection * manager./* ww w.j av a 2 s . c o m*/ * @see #registerClientCert(Context, String, boolean) */ public synchronized void unregisterClientCert(String clientCertAlias, boolean trustAllServerCerts) { SchemeRegistry registry = getSchemeRegistry(); String schemeName = makeSchemeForClientCert(clientCertAlias, trustAllServerCerts); Scheme existing = registry.get(schemeName); if (existing != null) { registry.unregister(schemeName); } }
From source file:org.spiffyui.server.AuthServlet.java
/** * If the authentication URL uses SSL then we need to use an SSLContext to connect to * it. The JDK provides on by default that will work fine for us, but it is possible * for some code running in some other place of the JVM to set a new default and that * new default might not be compatible with the type of connection we want to create. * /*from w ww. j ava 2s . c o m*/ * The solution is to always set our own SSLContext. In that case we will use a context * that allows any connection since we let administrators control this connection using * the whitelist so we know that we will only connect to trusted servers. * * @param httpclient the HTTPClient making the connection * @param port the port of the connection */ private void setupClientSSL(HttpClient httpclient, int port) { try { SSLSocketFactory sslSocketFactory = null; SSLContext sslContext = SSLContext.getInstance("TLS"); TrustManager relaxedTrustManager = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { /* We accept all certs so there is nothing to test here. */ } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { /* We accept all certs so there is nothing to test here. */ } @Override public X509Certificate[] getAcceptedIssuers() { /* This indicates that we accept all certificates */ return null; } }; sslContext.init(null, new TrustManager[] { relaxedTrustManager }, new SecureRandom()); sslSocketFactory = new SSLSocketFactory(sslContext); sslSocketFactory.setHostnameVerifier(new HostVerifier()); /* No that we've configured our SSLContext we'll make sure our request uses it. */ ClientConnectionManager connMgr = httpclient.getConnectionManager(); SchemeRegistry schemeReg = connMgr.getSchemeRegistry(); schemeReg.unregister("https"); if (port != -1) { schemeReg.register(new Scheme("https", sslSocketFactory, port)); } else { /* If the port is -1 it means they were access the server without a port. 443 is the default port for SSL so we fill that in when making the connection. */ schemeReg.register(new Scheme("https", sslSocketFactory, 443)); } } catch (NoSuchAlgorithmException nsae) { LOGGER.throwing(AuthServlet.class.getName(), "setupClientSSL", nsae); } catch (KeyManagementException mke) { LOGGER.throwing(AuthServlet.class.getName(), "setupClientSSL", mke); } }
From source file:org.eclipse.lyo.client.oslc.OslcClient.java
private void setupSSLSupport(TrustManager[] trustManagers, X509HostnameVerifier hostnameVerifier) { ClientConnectionManager connManager = httpClient.getConnectionManager(); SchemeRegistry schemeRegistry = connManager.getSchemeRegistry(); schemeRegistry.unregister("https"); /** Create a trust manager that does not validate certificate chains */ TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ }// w ww .j a v a2s . c o m public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; try { SSLContext sc = findInstalledSecurityContext(); if (trustManagers == null) { trustManagers = trustAllCerts; } if (hostnameVerifier == null) { hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; } sc.init(null, trustManagers, new java.security.SecureRandom()); SSLSocketFactory sf = new SSLSocketFactory(sc, hostnameVerifier); Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$ schemeRegistry.register(https); } catch (NoSuchAlgorithmException e) { /* Fail Silently */ } catch (KeyManagementException e) { /* Fail Silently */ } }
From source file:com.lp.alm.lyo.client.oslc.OslcClient.java
private void setupSSLSupport() { ClientConnectionManager connManager = httpClient.getConnectionManager(); SchemeRegistry schemeRegistry = connManager.getSchemeRegistry(); schemeRegistry.unregister("https"); /** Create a trust manager that does not validate certificate chains */ TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override/* ww w. jav a 2s .c om*/ public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; try { SSLContext sc = findInstalledSecurityContext(); if (trustManagers == null) { trustManagers = trustAllCerts; } if (hostnameVerifier == null) { hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; } sc.init(null, trustManagers, new java.security.SecureRandom()); SSLSocketFactory sf = new SSLSocketFactory(sc, hostnameVerifier); Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$ schemeRegistry.register(https); } catch (NoSuchAlgorithmException e) { /* Fail Silently */ } catch (KeyManagementException e) { /* Fail Silently */ } }