private SlaveConnectionManager() { if ( needToInitializeSSLContext() ) { try { SSLContext context = SSLContext.getInstance( SSL ); context.init( new KeyManager[ 0 ], new X509TrustManager[] { getDefaultTrustManager() }, new SecureRandom() ); SSLContext.setDefault( context ); } catch ( Exception e ) { //log.logError( "Default SSL context hasn't been initialized", e ); } } manager = new PoolingHttpClientConnectionManager(); manager.setDefaultMaxPerRoute( 100 ); manager.setMaxTotal( 200 ); }
public static void trustSelfSignedSSL() { try { 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); SSLContext.setDefault(ctx); } catch (Exception ex) { ex.printStackTrace(); } }
SSLContext.setDefault(ctx);
SSLContext.setDefault(sslContext);
SSLContext.setDefault(getTestSslContextFactory().create()); SSLContext.setDefault(dfltSslCtx);
public static void acceptUntrusted() { try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom()); SSLContext.setDefault(sslContext); } catch (Exception ex) { throw new RuntimeException("Could not change SSL TrustManager to accept arbitrary certificates", ex); } }
// load your key store as a stream and initialize a KeyStore InputStream trustStream = ... KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); // if your store is password protected then declare it (it can be null however) char[] trustPassword = ... // load the stream to your store trustStore.load(trustStream, trustPassword); // initialize a trust manager factory with the trusted store TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustFactory.init(trustStore); // get the trust managers from the factory TrustManager[] trustManagers = trustFactory.getTrustManagers(); // initialize an ssl context to use these managers and set as default SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustManagers, null); SSLContext.setDefault(sslContext);
import java.io.InputStream; import java.security.KeyStore; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; public class SSLClasspathTrustStoreLoader { public static void setTrustStore(String trustStore, String password) throws Exception { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream keystoreStream = SSLClasspathTrustStoreLoader.class.getResourceAsStream(trustStore); keystore.load(keystoreStream, password.toCharArray()); trustManagerFactory.init(keystore); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustManagers, null); SSLContext.setDefault(sc); } }
SSLContext.setDefault(sslContext);
SSLContext.setDefault(sslContext);
SSLContext.setDefault(context);
@Override public void stop(BundleContext bundleContext) throws Exception { if( original!=null ) { SSLContext.setDefault(original); original = null; } }
public static void addLetsEncrypt() { try { SSLContext.setDefault(getSSLContextWithLE()); } catch (Exception e) { LOGGER.warning("Failed adding cert: "+e); } }
public static void acceptUntrusted() { try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom()); SSLContext.setDefault(sslContext); } catch (Exception ex) { throw new RuntimeException("Could not change SSL TrustManager to accept arbitrary certificates", ex); } }
private void initSSLconfiguration() { log.info("SETUP: initialising SSL configuration ..."); /* Nervige SSL configuration */ SSLContext ctx; try { ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom()); SSLContext.setDefault(ctx); } catch (NoSuchAlgorithmException | KeyManagementException e) { e.printStackTrace(); } }
@BeforeClass public static void initHttps() throws NoSuchAlgorithmException, KeyManagementException { SSLContext ctx = SSLContext.getInstance("SSL"); TrustManager[] tm = new TrustManager[] {new TestTrustManager()}; ctx.init(new KeyManager[0], tm, new SecureRandom()); SSLContext.setDefault(ctx); HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new TestHostnameVerifier()); }
public TCServerSecurityManager(final SecurityConfig securityConfig, final KeyChain keyChain, final Realm realm) { super(securityConfig, keyChain); this.realm = realm; // Needed to open incoming connections with our setup (JMX) SSLContext.setDefault(getSSLBufferManagerFactory().getSslContext()); }
public TCServerSecurityManager(final SecurityConfig securityConfig, final KeyChain keyChain, final Realm realm) { super(securityConfig, keyChain); this.realm = realm; // Needed to open incoming connections with our setup (JMX) SSLContext.setDefault(getSSLBufferManagerFactory().getSslContext()); }
@Test public void testPropertiesSSLOptions() throws Exception { // don't use default for tests, issues with forcing algorithm exception in other tests break it SSLContext.setDefault(TestSSLUtils.createTestSSLContext()); Properties props = new Properties(); props.setProperty(Options.PROP_SECURE, "true"); Options o = new Options.Builder(props).build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertNotNull("property context", o.getSslContext()); }
@Test public void testChainedSecure() throws Exception { SSLContext ctx = TestSSLUtils.createTestSSLContext(); SSLContext.setDefault(ctx); Options o = new Options.Builder().secure().build(); assertEquals("chained context", ctx, o.getSslContext()); }