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:li.klass.fhem.fhem.TrustAllSSLSocketFactory.java
public TrustAllSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); TrustManager trustManager = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }// w w w . j av a 2 s . c o m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { trustManager }, null); }
From source file:com.linkedin.pinot.monitor.util.HttpUtils.java
/** * {/* w w w . ja v a 2 s. com*/ text: "", attachments: [{ title: "", description: "??", url: "", color: "warning|info|primary|error|muted|success" }] displayUser: { name: "??", avatarUrl: "??" } } * @param text * @return */ public static void postMonitorData(String text) { SSLContext sslContext = null; HttpClient client = new DefaultHttpClient(); try { sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } } }, new SecureRandom()); } catch (Exception e) { e.printStackTrace(); } SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); HttpPost httpPost = new HttpPost("https://hooks.pubu.im/services/1d2d2rwn8wb6sx"); Map<String, Object> map = new HashMap<String, Object>(); Map<String, String> sender = new HashMap<String, String>(); sender.put("name", "Monitor"); map.put("displayUser", sender); List<String> list = new ArrayList<String>(); map.put("attachments", list); try { map.put("text", text); InputStreamEntity httpentity = new InputStreamEntity( new ByteArrayInputStream(mapper.writeValueAsBytes(map)), mapper.writeValueAsBytes(map).length); httpPost.setEntity(httpentity); httpPost.addHeader("Content-Type", "application/json"); HttpResponse response = client.execute(httpPost); String result = EntityUtils.toString(response.getEntity()); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } finally { // } }
From source file:org.lorislab.armonitor.jira.client.JIRAClient.java
/** * Creates the JIRA client./* w w w . j a va2 s . c o m*/ * * @param server the server URL. * @param username the username. * @param password the password. * @param auth the authentication flag. * @throws Exception if the method fails. */ public JIRAClient(String server, String username, char[] password, boolean auth) throws Exception { this.server = server; HttpClient httpClient = new DefaultHttpClient(); if (server.startsWith(HTTPS)) { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme(HTTPS, 443, sslSocketFactory)); } if (auth) { this.executor = new JiraApacheHttpClient4Executor(username, password, httpClient); } }
From source file:org.pixmob.appengine.client.SSLEnabledHttpClient.java
public static SSLEnabledHttpClient newInstance(String userAgent) { // the following code comes from AndroidHttpClient (API level 10) final HttpParams params = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); final int timeout = 60 * 1000; HttpConnectionParams.setConnectionTimeout(params, timeout); HttpConnectionParams.setSoTimeout(params, timeout); HttpConnectionParams.setSocketBufferSize(params, 8192); // Don't handle redirects -- return them to the caller. Our code // often wants to re-POST after a redirect, which we must do ourselves. HttpClientParams.setRedirecting(params, false); // Set the specified user agent and register standard protocols. HttpProtocolParams.setUserAgent(params, userAgent); // Prevent UnknownHostException error with 3G connections: // http://stackoverflow.com/questions/2052299/httpclient-on-android-nohttpresponseexception-through-umts-3g HttpProtocolParams.setUseExpectContinue(params, false); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); final ClientConnectionManager manager = new SingleClientConnManager(params, schemeRegistry); final SSLEnabledHttpClient client = new SSLEnabledHttpClient(manager, params); client.addRequestInterceptor(new GzipRequestInterceptor()); client.addResponseInterceptor(new GzipResponseInterceptor()); return client; }
From source file:com.googlecode.androidannotations.test15.SSLConnectionTest.java
@Test public void truststoreProvided() { assertNotNull(activity.mHttpsClientTest1); ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager(); assertNotNull(ccm);/*w w w . j a v a2 s . co m*/ Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https"); assertNotNull(httpsScheme); assertEquals(443, httpsScheme.getDefaultPort()); SocketFactory socketFactHttps = httpsScheme.getSocketFactory(); if (!(socketFactHttps instanceof SSLSocketFactory)) { Assert.fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps); } assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER, ((SSLSocketFactory) socketFactHttps).getHostnameVerifier()); }
From source file:org.jssec.android.https.vulnerables.VulnerableSamples.java
public void allowAllHostnameVerifier() { SSLSocketFactory sf = null; sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:com.jt.https.test.send.java
public static String PostTo(String content) { String responseMessage = null; String filePath = ""; if (!filePath.endsWith("/")) { filePath = filePath + "/"; }//from ww w . ja va2 s .c om HttpClient httpclient = new DefaultHttpClient(); try { KeyStore keystore = KeyStore.getInstance("jks"); KeyStore trustStore = KeyStore.getInstance("jks"); FileInputStream keystoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\bis-stg-sdb.jks")); FileInputStream trustStoreInstream = new FileInputStream( new File("F:\\temp\\?\\lz\\\\EXV_GROUP_BIS_IFRONT_JTLZX_100.jks")); //FileInputStream keystoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test.jks")); //FileInputStream trustStoreInstream = new FileInputStream(new File("F:\\temp\\?\\lz\\\\pingan2jiangtai_test_trust.jks")); try { keystore.load(keystoreInstream, "123456".toCharArray()); trustStore.load(trustStoreInstream, "paic1234".toCharArray()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } finally { keystoreInstream.close(); trustStoreInstream.close(); } SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.SSL, keystore, "123456", trustStore, null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", 8107, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpPost post = new HttpPost("https://222.68.184.181:8107"); StringEntity entity = new StringEntity(content, "text/html", "UTF-8"); post.setEntity(entity); HttpResponse res = httpclient.execute(post); HttpEntity resEntity = res.getEntity(); if (resEntity != null) { responseMessage = convertStreamToString(resEntity.getContent()); System.out.println("???" + content); System.out.println("?" + responseMessage); } } catch (KeyStoreException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } return responseMessage; }
From source file:com.gmail.nagamatu.radiko.installer.MySSLSocketFactory.java
public static HttpClient getNewHttpClient() { try {/*from w ww . j a v a 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:com.lugia.timetable.SSLHttpClient.java
public static SSLHttpClient getHttpClient() throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { HttpClient client = new DefaultHttpClient(); X509TrustManager tm = createX509TrustManager(); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new MySSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new SSLHttpClient(new ThreadSafeClientConnManager(client.getParams(), sr), client.getParams()); }
From source file:org.androidannotations.test.SSLConnectionTest.java
@Test public void truststoreProvided() { assertNotNull(activity.mHttpsClientTest1); ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager(); assertNotNull(ccm);/*from w ww. ja va 2 s . co m*/ Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https"); assertNotNull(httpsScheme); assertEquals(443, httpsScheme.getDefaultPort()); SocketFactory socketFactHttps = httpsScheme.getSocketFactory(); if (!(socketFactHttps instanceof SSLSocketFactory)) { fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps); } assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER, ((SSLSocketFactory) socketFactHttps).getHostnameVerifier()); }