List of usage examples for javax.net.ssl SSLContext init
public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws KeyManagementException
From source file:com.ksc.internal.SdkSSLContext.java
/** * @see SSLContexts#createDefault()// w w w . ja v a 2 s. co m */ public static final SSLContext getPreferredSSLContext(final SecureRandom secureRandom) { try { final SSLContext sslcontext = SSLContext.getInstance("TLS"); // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html sslcontext.init(null, null, secureRandom); return sslcontext; } catch (final NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } catch (final KeyManagementException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } }
From source file:edu.cmu.cylab.starslinger.exchange.CheckedSSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { KeyStore trusted = null;/* w w w. jav a2s . co m*/ try { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new CheckedX509TrustManager(trusted) }, null); return context; } catch (KeyManagementException e) { throw new IOException(e.getLocalizedMessage()); } catch (NoSuchAlgorithmException e) { throw new IOException(e.getLocalizedMessage()); } catch (KeyStoreException e) { throw new IOException(e.getLocalizedMessage()); } }
From source file:la.niub.network.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {/*from w w w. ja va 2 s . c o m*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } } }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:org.apache.camel.component.solr.JettySolrFactory.java
private static void installAllTrustingClientSsl() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); // // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override/* w ww.j a va 2 s .c o m*/ public void checkClientTrusted(final X509Certificate[] chain, final String authType) { } @Override public void checkServerTrusted(final X509Certificate[] chain, final String authType) { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } } }; final SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); SSLContext.setDefault(sslContext); // // Install the all-trusting trust manager // final SSLContext sslContext = SSLContext.getInstance( "SSL" ); // sslContext.init( null, trustAllCerts, new // java.security.SecureRandom() ); // // Create an ssl socket factory with our all-trusting manager // final SSLSocketFactory sslSocketFactory = // sslContext.getSocketFactory(); // HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory); }
From source file:com.dvdprime.android.app.http.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {// w ww . ja va 2 s . c o m SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; // return null; } public void checkClientTrusted(X509Certificate[] certificates, String authType) { } public void checkServerTrusted(X509Certificate[] certificates, String authType) { } } }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:com.dolphin.browser.Network.EasySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {//w w w . jav a2 s .c o m SSLContext context = HttpRequester.createSSLConext(); context.init(null, new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } } }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:gobblin.security.ssl.SSLContextFactory.java
/** * Create a {@link SSLContext} instance/*from w ww . ja va 2s .c o m*/ * * @param keyStoreFile a p12 or jks file depending on key store type * @param keyStorePassword password to access the key store * @param keyStoreType type of key store * @param trustStoreFile a jks file * @param trustStorePassword password to access the trust store */ public static SSLContext createInstance(File keyStoreFile, String keyStorePassword, String keyStoreType, File trustStoreFile, String trustStorePassword) { if (!keyStoreType.equalsIgnoreCase(P12_STORE_TYPE_NAME) && !keyStoreType.equalsIgnoreCase(JKS_STORE_TYPE_NAME)) { throw new IllegalArgumentException("Unsupported keyStoreType: " + keyStoreType); } try { // Load KeyStore KeyStore keyStore = KeyStore.getInstance(keyStoreType); keyStore.load(toInputStream(keyStoreFile), keyStorePassword.toCharArray()); // Load TrustStore KeyStore trustStore = KeyStore.getInstance(JKS_STORE_TYPE_NAME); trustStore.load(toInputStream(trustStoreFile), trustStorePassword.toCharArray()); // Set KeyManger from keyStore KeyManagerFactory kmf = KeyManagerFactory.getInstance(DEFAULT_ALGORITHM); kmf.init(keyStore, keyStorePassword.toCharArray()); // Set TrustManager from trustStore TrustManagerFactory trustFact = TrustManagerFactory.getInstance(DEFAULT_ALGORITHM); trustFact.init(trustStore); // Set Context to TLS and initialize it SSLContext sslContext = SSLContext.getInstance(DEFAULT_PROTOCOL); sslContext.init(kmf.getKeyManagers(), trustFact.getTrustManagers(), null); return sslContext; } catch (Exception e) { throw new RuntimeException(e); } }
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:com.amalto.workbench.utils.SSLContextProvider.java
public synchronized static void buildContext(String algorithm, String keypath, String keypass, String keytype, String trustpath, String trustpass, String trusttype) { try {/*from w ww . jav a 2s. c om*/ KeyManager[] kms = buildKeyManagers(keypath, keypass, keytype); TrustManager[] tms = buildTrustManagers(trustpath, trustpass, trusttype); SSLContext sslcontext = SSLContext.getInstance(algorithm); sslcontext.init(kms, tms, null); context = sslcontext; } catch (Exception e) { throw new SecurityException(e.getMessage(), e); } }
From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.AbstractSslContext.java
protected static SSLContext getAnonymousSSLContext() throws GeneralSecurityException { SSLContext sslContext = getSSLContext(); sslContext.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new SecureRandom()); return sslContext; }