List of usage examples for javax.net.ssl SSLContext getInstance
public static SSLContext getInstance(String protocol) throws NoSuchAlgorithmException
From source file:com.wrmsr.neurosis.aws.client.WebClientDevWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {//from www. j a va2 s. c om SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; X509HostnameVerifier verifier = new X509HostnameVerifier() { @Override public void verify(String string, SSLSocket ssls) throws IOException { } @Override public void verify(String string, X509Certificate xc) throws SSLException { } @Override public void verify(String string, String[] strings, String[] strings1) throws SSLException { } @Override public boolean verify(String string, SSLSession ssls) { return true; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:com.google.resting.rest.CustomSSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*from w w w . j a v a2 s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new CustomX509TrustManager() }, new java.security.SecureRandom()); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:info.ajaxplorer.client.http.AjxpSSLSocketFactory.java
private static SSLContext createEasySSLContext(String certKey) throws IOException { try {/*from ww w .jav a 2 s.c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new AjxpSSLTrustManager(certKey) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.senseidb.dataprovider.http.HttpsClientDecorator.java
public static DefaultHttpClient decorate(DefaultHttpClient base) { try {//ww w. jav a 2 s. c om SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); return null; } }
From source file:Main.java
private static SSLContext sslContextForTrustedCertificates(InputStream in) { try {//w w w.ja v a2 s.c o m CertificateFactory e = CertificateFactory.getInstance("X.509"); Collection certificates = e.generateCertificates(in); if (certificates.isEmpty()) { throw new IllegalArgumentException("expected non-empty set of trusted certificates"); } else { char[] password = "password".toCharArray(); KeyStore keyStore = newEmptyKeyStore(password); int index = 0; Iterator keyManagerFactory = certificates.iterator(); while (keyManagerFactory.hasNext()) { Certificate trustManagerFactory = (Certificate) keyManagerFactory.next(); String sslContext = Integer.toString(index++); keyStore.setCertificateEntry(sslContext, trustManagerFactory); } KeyManagerFactory var10 = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); var10.init(keyStore, password); TrustManagerFactory var11 = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); var11.init(keyStore); SSLContext var12 = SSLContext.getInstance("TLS"); var12.init(var10.getKeyManagers(), var11.getTrustManagers(), new SecureRandom()); return var12; } } catch (Exception var9) { var9.printStackTrace(); } return null; }
From source file:cloudfoundry.norouter.f5.client.NaiveTrustManager.java
public static LayeredConnectionSocketFactory getSocketFactory() { try {/*from ww w. ja v a2s .c om*/ final SSLContext context = SSLContext.getInstance("TLS"); context.init(null, TRUST_MANAGERS, null); return new SSLConnectionSocketFactory(context, new X509HostnameVerifier() { @Override public void verify(String host, SSLSocket ssl) throws IOException { } @Override public void verify(String host, X509Certificate cert) throws SSLException { } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new Error(e); } }
From source file:org.transdroid.daemon.util.FakeSocketFactory.java
private static SSLContext createEasySSLContext(String certKey) throws IOException { try {/*w ww .ja v a2s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new FakeTrustManager(certKey) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:de.koczewski.maxapi.WebClientDevWrapper.java
public static DefaultHttpClient wrapClient(HttpClient base) { try {/*from w ww .ja v a2 s.c o m*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; X509HostnameVerifier verifier = new X509HostnameVerifier() { @Override public void verify(String string, SSLSocket ssls) throws IOException { } @Override public void verify(String string, X509Certificate xc) throws SSLException { } @Override public void verify(String string, String[] strings, String[] strings1) throws SSLException { } @Override public boolean verify(String string, SSLSession ssls) { return true; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.farru.android.network.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {//from ww w .ja v a 2 s .c o m SSLContext context = SSLContext.getInstance("SSL"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.android.volley.toolbox.SslSocketFactory.java
private static SSLContext createSSLContext(InputStream keyStore, String keyStorePassword) throws GeneralSecurityException { SSLContext sslcontext = null; try {// ww w. j a v a2 s . co m sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { new SsX509TrustManager(keyStore, keyStorePassword) }, null); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } catch (KeyManagementException e) { throw new IllegalStateException("Failure initializing default SSL context", e); } return sslcontext; }