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:brooklyn.launcher.BrooklynWebServerTest.java
@Test public void verifyHttpsFromConfig() throws Exception { brooklynProperties.put(BrooklynWebConfig.HTTPS_REQUIRED, true); brooklynProperties.put(BrooklynWebConfig.KEYSTORE_URL, getFile("server.ks")); brooklynProperties.put(BrooklynWebConfig.KEYSTORE_PASSWORD, "password"); webServer = new BrooklynWebServer(MutableMap.of(), newManagementContext(brooklynProperties)); webServer.start();/*from w w w. ja v a 2 s .co m*/ try { KeyStore keyStore = load("client.ks", "password"); KeyStore trustStore = load("client.ts", "password"); SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, keyStore, "password", trustStore, (SecureRandom) null, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpToolResponse response = HttpTool.execAndConsume(HttpTool.httpClientBuilder() .port(webServer.getActualPort()).https(true).socketFactory(socketFactory).build(), new HttpGet(webServer.getRootUrl())); assertEquals(response.getResponseCode(), 200); } finally { webServer.stop(); } }
From source file:com.rumblefish.friendlymusic.api.WebRequest.java
public static HttpClient getNewHttpClient(int timelimit) { try {//from w ww.ja v a 2 s .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); HttpConnectionParams.setConnectionTimeout(params, timelimit); HttpConnectionParams.setSoTimeout(params, timelimit); 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) { e.printStackTrace(); return new DefaultHttpClient(); } }
From source file:org.wso2.automation.platform.tests.apim.is.SingleSignOnTestCase.java
@BeforeClass(alwaysRun = true) public void init() throws APIManagerIntegrationTestException { super.init(TestUserMode.SUPER_TENANT_ADMIN); 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); httpClient = new DefaultHttpClient(mgr, client.getParams()); CookieStore cookieStore = new BasicCookieStore(); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); AutomationContext isContext;//from w ww . j a v a 2 s. c om httpsPublisherUrl = publisherUrls.getWebAppURLHttps() + "publisher"; httpsStoreUrl = storeUrls.getWebAppURLHttps() + "store"; try { providerName = publisherContext.getContextTenant().getContextUser().getUserName(); } catch (XPathExpressionException e) { log.error(e); throw new APIManagerIntegrationTestException("Error while getting server url", e); } try { isContext = new AutomationContext("IS", "SP", TestUserMode.SUPER_TENANT_ADMIN); commonAuthUrl = isContext.getContextUrls().getBackEndUrl().replaceAll("services/", "") + "commonauth"; samlSsoEndpointUrl = isContext.getContextUrls().getBackEndUrl().replaceAll("services/", "") + "samlsso"; } catch (XPathExpressionException e) { log.error("Error initializing IS server details", e); throw new APIManagerIntegrationTestException("Error initializing IS server details", e); } }
From source file:gov.nih.nci.nbia.StandaloneDMV1.java
private static List<String> connectAndReadFromURL(URL url, String fileName) { List<String> data = null; DefaultHttpClient httpClient = null; TrustStrategy easyStrategy = new TrustStrategy() { @Override/* w w w .ja v a2 s . c om*/ public boolean isTrusted(X509Certificate[] certificate, String authType) throws CertificateException { return true; } }; try { // SSLContext sslContext = SSLContext.getInstance("SSL"); // set up a TrustManager that trusts everything // sslContext.init(null, new TrustManager[] { new // EasyX509TrustManager(null)}, null); SSLSocketFactory sslsf = new SSLSocketFactory(easyStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme = new Scheme("https", 443, sslsf); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(httpsScheme); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); ClientConnectionManager ccm = new ThreadSafeClientConnManager(schemeRegistry); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 50000); HttpConnectionParams.setSoTimeout(httpParams, new Integer(12000)); httpClient = new DefaultHttpClient(ccm, httpParams); httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(schemeRegistry, ProxySelector.getDefault())); // // Additions by lrt for tcia - // // attempt to reduce errors going through a Coyote Point // Equalizer load balance switch httpClient.getParams().setParameter("http.socket.timeout", new Integer(12000)); httpClient.getParams().setParameter("http.socket.receivebuffer", new Integer(16384)); httpClient.getParams().setParameter("http.tcp.nodelay", true); httpClient.getParams().setParameter("http.connection.stalecheck", false); // // end lrt additions HttpPost httpPostMethod = new HttpPost(url.toString()); List<BasicNameValuePair> postParams = new ArrayList<BasicNameValuePair>(); postParams.add(new BasicNameValuePair("serverjnlpfileloc", fileName)); UrlEncodedFormEntity query = new UrlEncodedFormEntity(postParams); httpPostMethod.setEntity(query); HttpResponse response = httpClient.execute(httpPostMethod); // int responseCode = response.getStatusLine().getStatusCode(); // System.out.println("Response code for requesting datda file: " + // responseCode); InputStream inputStream = response.getEntity().getContent(); data = IOUtils.readLines(inputStream); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnrecoverableKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (httpClient != null) { httpClient.getConnectionManager().shutdown(); } } return data; }
From source file:wsattacker.plugin.intelligentdos.requestSender.Http4RequestSenderImpl.java
private SSLSocketFactory get() { // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new TrustAllManager() }; // Install the all-trusting trust manager try {//from ww w .j a va 2 s . c o m SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); return new SSLSocketFactory(sc, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (RuntimeException e) { ; } catch (Exception e) { ; } return null; }
From source file:org.andstatus.app.net.HttpApacheUtils.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); return new DefaultHttpClient(clientConnectionManager, params); }
From source file:com.pispower.video.sdk.net.SimpleSSLSocketFactory.java
/** * Returns a SSlSocketFactory which trusts all certificates * // w w w . j a v a2s. co m * @return SSLSocketFactory */ public static SSLSocketFactory getFixedSocketFactory() { SSLSocketFactory socketFactory; try { socketFactory = new SimpleSSLSocketFactory(getKeystore()); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Throwable t) { t.printStackTrace(); socketFactory = SSLSocketFactory.getSocketFactory(); } return socketFactory; }
From source file:com.betfair.cougar.client.HttpClientExecutable.java
public void init() throws Exception { super.init(); // create client if not been set externally (e.g for testing) if (client == null) { client = new DefaultHttpClient(clientConnectionManager); ((DefaultHttpClient) client).setUserTokenHandler(userTokenHandler); }/*from w w w .ja va2 s . com*/ // configure retryhandler if set if (retryHandler != null) { ((AbstractHttpClient) client).setHttpRequestRetryHandler(retryHandler); } // configure timeout if set if (connectTimeout != -1) { HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, connectTimeout); HttpConnectionParams.setSoTimeout(params, connectTimeout); } //Configure SSL - if relevant if (transportSSLEnabled) { KeyStoreManagement keyStore = KeyStoreManagement.getKeyStoreManagement(httpsKeystoreType, httpsKeystore, httpsKeyPassword); if (jmxControl != null && keyStore != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientKeyStore,beanName=" + beanName, keyStore); } KeyStoreManagement trustStore = KeyStoreManagement.getKeyStoreManagement(httpsTruststoreType, httpsTruststore, httpsTrustPassword); if (jmxControl != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientTrustStore,beanName=" + beanName, trustStore); } SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore != null ? keyStore.getKeyStore() : null, keyStore != null ? httpsKeyPassword : null, trustStore.getKeyStore()); if (hostnameVerificationDisabled) { socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); LOGGER.warn("CRITICAL SECURITY CHECKS ARE DISABLED: server SSL certificate hostname " + "verification is turned off."); } Scheme sch = new Scheme("https", extractPortFromAddress(), socketFactory); client.getConnectionManager().getSchemeRegistry().register(sch); } metrics = new HttpClientTransportMetrics(); if (jmxControl != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientExecutable,beanName=" + beanName, this); } }
From source file:oauth.commons.http.CommonsHttpOAuthProvider.java
public HttpClient getNewHttpClient() { try {/*from ww w . j a v a2s . co m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(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.dataconservancy.archive.impl.fcrepo.ri.MultiThreadedHttpClient.java
private static SSLSocketFactory createSSLSocketFactory(boolean skipSSLTrustCheck, boolean skipSSLHostnameVerification) { SSLContext sslContext = null; try {// ww w.j a v a 2 s . co m if (skipSSLTrustCheck) { sslContext = SSLContext.getInstance("TLS"); TrustManager easyTrustManager = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy! } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy! } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { easyTrustManager }, null); } else { sslContext = SSLContext.getDefault(); } } catch (KeyManagementException wontHappen) { throw new RuntimeException(wontHappen); } catch (NoSuchAlgorithmException wontHappen) { throw new RuntimeException(wontHappen); } SSLSocketFactory factory = new SSLSocketFactory(sslContext); if (skipSSLHostnameVerification) { factory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } return factory; }