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:iristk.speech.nuancecloud.JSpeexNuanceCloudRecognizerListener.java
@SuppressWarnings("deprecation") private HttpClient getHttpClient() throws NoSuchAlgorithmException, KeyManagementException { // Standard HTTP parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUseExpectContinue(params, false); // Initialize the HTTP client httpclient = new DefaultHttpClient(params); // Initialize/setup SSL TrustManager easyTrustManager = new X509TrustManager() { @Override//from ww w . j av a 2 s. co m public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException { // TODO Auto-generated method stub } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException { // TODO Auto-generated method stub } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { // TODO Auto-generated method stub return null; } }; SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", sf, 443); httpclient.getConnectionManager().getSchemeRegistry().register(sch); // Return the initialized instance of our httpclient return httpclient; }
From source file:org.wso2.bam.integration.tests.reciever.RESTAPITestCase.java
@BeforeClass(groups = { "wso2.bam" }) private static void init() { DATA_RECEIVER = "/datareceiver/1.0.0"; // host = FrameworkSettings.HOST_NAME; // httpsPort = Integer.parseInt(FrameworkSettings.HTTPS_PORT); restAppParentURL = "https://" + host + ":" + httpsPort + DATA_RECEIVER; streamsURL = restAppParentURL + "/streams"; streamURL = restAppParentURL + "/stream"; stockQuoteVersion1URL = streamURL + "/stockquote.stream/1.0.2/"; stockQuoteVersion2URL = streamURL + "/stockquote.stream.2/2.0.0"; stockQuoteVersion3URL = streamURL + "/labit.stream/0.0.3"; stockQuoteVersion4URL = streamURL + "/eu.ima.event.stream/1.2.0"; stockQuoteVersion5URL = streamURL + "/eu.ima.event.stream.2/1.3.0"; try {//from w w w. j av a2 s. co m events1 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events1.json")); events2 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events2.json")); events3 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events3.json")); events4 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events4.json")); events5 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events5.json")); streamdefn1 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn1.json")); streamdefn2 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn2.json")); streamdefn3 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn3.json")); streamdefn4 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn4.json")); streamdefn5 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn5.json")); TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslContext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme = new Scheme("https", sf, httpsPort); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); client = new DefaultHttpClient(params); client.getConnectionManager().getSchemeRegistry().register(httpsScheme); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:org.dataone.proto.trove.net.SocketFactoryManager.java
public SSLSocketFactory getSSLSocketFactory() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException, CertificateException, IOException { // our return object log.debug("Enter getSSLSocketFactory"); SSLSocketFactory socketFactory = null; KeyStore keyStore = null;//from w ww.j a v a 2 s . co m // get the keystore that will provide the material // Catch the exception here so that the TLS connection scheme // will still be setup if the client certificate is not found. try { keyStore = getKeyStore(); } catch (FileNotFoundException e) { // these are somewhat expected for anonymous d1 client use log.warn( "Could not set up client side authentication - likely because the certificate could not be located: " + e.getMessage()); } // create SSL context SSLContext ctx = SSLContext.getInstance("TLS"); // use a very liberal trust manager for trusting the server // TODO: check server trust policy X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { log.info("checkClientTrusted - " + string); } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { log.info("checkServerTrusted - " + string); } public X509Certificate[] getAcceptedIssuers() { log.info("getAcceptedIssuers"); return null; } }; // specify the client key manager KeyManager[] keyManagers = { new X509KeyManagerImpl(keyStore, keyStorePassword.toCharArray(), "cilogon") }; // KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); // keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); // keyManagers = keyManagerFactory.getKeyManagers(); // initialize the context ctx.init(keyManagers, new TrustManager[] { tm }, new SecureRandom()); socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return socketFactory; }
From source file:com.mindprotectionkit.freephone.signaling.SignalingSocket.java
private Socket constructSSLSocket(Context context, String host, int port) throws SignalingException { try {/*from w w w .j a va 2 s. com*/ AssetManager assetManager = context.getAssets(); InputStream keyStoreInputStream = assetManager.open("whisper.store"); KeyStore trustStore = KeyStore.getInstance("BKS"); trustStore.load(keyStoreInputStream, "whisper".toCharArray()); SSLSocketFactory sslSocketFactory = new SSLSocketFactory(trustStore); if (Release.SSL) { sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); } else { Log.w("SignalingSocket", "Disabling hostname verification..."); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } return timeoutHackConnect(sslSocketFactory, host, port); } catch (IOException ioe) { throw new SignalingException(ioe); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } catch (KeyStoreException e) { throw new IllegalArgumentException(e); } catch (CertificateException e) { throw new IllegalArgumentException(e); } catch (KeyManagementException e) { throw new IllegalArgumentException(e); } catch (UnrecoverableKeyException e) { throw new IllegalArgumentException(e); } }
From source file:net.dataninja.oracle.client.DataNinjaHttpClient.java
private HttpClient getHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { // Keep only one copy of the HttpClient if (httpClient != null) { return httpClient; }/* w w w . j a va2s .c om*/ // Create a new instance of HTTPClient TrustStrategy acceptingTrustStrategy = new TrustStrategy() { public boolean isTrusted(X509Certificate[] cert, String authType) throws CertificateException { return true; } }; SSLSocketFactory factory = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", 443, factory)); ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); return httpClient; }
From source file:com.fujitsu.dc.client.http.HttpClientFactory.java
/** * This method is used to generate SSLSocket. * @return SSLSocket that is generated/*from w w w. ja va2 s .c om*/ */ private static SSLSocketFactory createInsecureSSLSocketFactory() { SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("SSL"); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } try { sslContext.init(null, new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { // System.out.println("getAcceptedIssuers ============="); X509Certificate[] ret = new X509Certificate[0]; return ret; } public final void checkClientTrusted(final X509Certificate[] certs, final String authType) { // System.out.println("checkClientTrusted ============="); } public final void checkServerTrusted(final X509Certificate[] certs, final String authType) { // System.out.println("checkServerTrusted ============="); } } }, new SecureRandom()); } catch (KeyManagementException e1) { throw new RuntimeException(e1); } HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, (X509HostnameVerifier) hostnameVerifier); // socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); return socketFactory; }
From source file:io.personium.client.http.HttpClientFactory.java
/** * This method is used to generate SSLSocket. * @return SSLSocket that is generated/*from w w w . j av a 2 s .co m*/ */ private static SSLSocketFactory createInsecureSSLSocketFactory() { SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLSv1.2"); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } try { sslContext.init(null, new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { // System.out.println("getAcceptedIssuers ============="); X509Certificate[] ret = new X509Certificate[0]; return ret; } public final void checkClientTrusted(final X509Certificate[] certs, final String authType) { // System.out.println("checkClientTrusted ============="); } public final void checkServerTrusted(final X509Certificate[] certs, final String authType) { // System.out.println("checkServerTrusted ============="); } } }, new SecureRandom()); } catch (KeyManagementException e1) { throw new RuntimeException(e1); } HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, (X509HostnameVerifier) hostnameVerifier); // socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); return socketFactory; }
From source file:com.waltz3d.common.httpclient.AsyncHttpClient.java
/** * Creates a new AsyncHttpClient.//w ww . j av a 2s .c o m */ public AsyncHttpClient() { KeyStore trustStore = null; try { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } SSLSocketFactory sf = null; try { sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnrecoverableKeyException 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(); } BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setUseExpectContinue(httpParams, false); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, String.format("android-async-http/%s (http://loopj.com/android-async-http)", VERSION)); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", sf, 443)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } for (String header : clientHeaderMap.keySet()) { request.addHeader(header, clientHeaderMap.get(header)); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } 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; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES)); threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); // threadPool = new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); requestMap = new WeakHashMap<Context, List<WeakReference<Future<?>>>>(); clientHeaderMap = new HashMap<String, String>(); }
From source file:org.socialbiz.cog.util.SSLPatch.java
/** * Constructs a new openID4Java Consumer Manager object, properly initialized * so that it does not validate certificates. *///from ww w. jav a2 s . c om public static ConsumerManager newConsumerManager() throws Exception { // Install the all-trusting trust manager SSL Context SSLContext sc = disableSSLCertValidation(); HttpFetcherFactory hff = new HttpFetcherFactory(sc, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); YadisResolver yr = new YadisResolver(hff); RealmVerifierFactory rvf = new RealmVerifierFactory(yr); Discovery d = new Discovery(new HtmlResolver(hff), yr, Discovery.getXriResolver()); ConsumerManager manager = new ConsumerManager(rvf, d, hff); manager.setAssociations(new InMemoryConsumerAssociationStore()); manager.setNonceVerifier(new InMemoryNonceVerifier(5000)); return manager; }