/** * Creates a new server using the default SSL context. * @param lc logger context for received events * @param port port on which the server is to listen * @throws NoSuchAlgorithmException if the default SSL context cannot be * created */ public SimpleSSLSocketServer(LoggerContext lc, int port) throws NoSuchAlgorithmException { this(lc, port, SSLContext.getDefault()); }
public void configure(HttpsParameters params) { try { SSLContext c = SSLContext.getDefault(); SSLEngine engine = c.createSSLEngine(); params.setNeedClientAuth(false); params.setCipherSuites(engine.getEnabledCipherSuites()); params.setProtocols(engine.getEnabledProtocols()); SSLParameters defaultSSLParameters = c.getDefaultSSLParameters(); params.setSSLParameters(defaultSSLParameters); } catch (Exception ex) { throw new IllegalStateException(ex); } } });
static void configureSsl(Binder binder) { final SSLContext context; try { context = SSLContext.getDefault(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } binder.bind(SSLContext.class).toProvider(Providers.of(context)).in(LazySingleton.class); }
@Override public SSLContext get() { try { return SSLContext.getDefault(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
private void addSSLConfiguration(ClientBuilder clientBuilder) { try { if (systemSSL) { clientBuilder.sslContext(SSLContext.getDefault()); } else if (trustStoreFileName != null) { KeyStore trustStore = KeyStore.getInstance(KEY_STORE_TYPE); FileInputStream fin = new FileInputStream(trustStoreFileName); trustStore.load(fin, trustStorePassword.toCharArray()); clientBuilder.trustStore(trustStore); } else if (sslContext != null) { clientBuilder.sslContext(sslContext); } } catch (Exception ex) { throw new IllegalArgumentException("Cannot setup SSL for Jersey2 client", ex); } }
public SslSocketFactory(final NiFiProperties nifiProperties) { final SSLContext sslCtx = SslContextFactory.createSslContext(nifiProperties); if (sslCtx == null) { try { sslSocketFactory = SSLContext.getDefault().getSocketFactory(); } catch (final NoSuchAlgorithmException nsae) { throw new SslSocketFactoryCreationException(nsae); } } else { sslSocketFactory = sslCtx.getSocketFactory(); } }
public SslServerSocketFactory(final NiFiProperties nifiProperties) { final SSLContext sslCtx = SslContextFactory.createSslContext(nifiProperties); if (sslCtx == null) { try { sslServerSocketFactory = SSLContext.getDefault().getServerSocketFactory(); } catch (final NoSuchAlgorithmException nsae) { throw new SslServerSocketFactoryCreationException(nsae); } } else { sslServerSocketFactory = sslCtx.getServerSocketFactory(); } }
private ProtocolSocketFactory getSocketFactory() throws Exception { final SSLSocketFactory delegate = SSLContext.getDefault().getSocketFactory(); return new ProtocolSocketFactory() { @Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException, UnknownHostException { return delegate.createSocket(host, port, localAddress, localPort); } @Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { return this.createSocket(host, port, localAddress, localPort); } @Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { return delegate.createSocket(host, port); } }; }
@Override public SSLContext create() { try { return SSLContext.getDefault(); } catch (NoSuchAlgorithmException e) { throw new IgniteException(e); } } };
private SSLContext getSslContext() { try { return (sslSettings.getContext() == null) ? SSLContext.getDefault() : sslSettings.getContext(); } catch (NoSuchAlgorithmException e) { throw new MongoClientException("Unable to create default SSLContext", e); } } }
private SSLContext getSslContext() { try { return (sslSettings.getContext() == null) ? SSLContext.getDefault() : sslSettings.getContext(); } catch (NoSuchAlgorithmException e) { throw new MongoClientException("Unable to create default SSLContext", e); } }
private SSLContext getSslContext() { try { return (sslSettings.getContext() == null) ? SSLContext.getDefault() : sslSettings.getContext(); } catch (NoSuchAlgorithmException e) { throw new MongoClientException("Unable to create default SSLContext", e); } }
/** * Creates & configures the SSLContext when SSL is enabled. * * @return new SSLContext configured using the given protocols & properties * * @throws GeneralSecurityException if security information can not be found * @throws IOException if information can not be loaded */ private SSLContext createAndConfigureSSLContext() throws GeneralSecurityException, IOException { if (sslConfig.useDefaultSSLContext()) { return SSLContext.getDefault(); } SSLContext newSSLContext = getSSLContextInstance(); KeyManager[] keyManagers = getKeyManagers(); TrustManager[] trustManagers = getTrustManagers(); newSSLContext.init(keyManagers, trustManagers, null /* use the default secure random */); return newSSLContext; }
ClientHolder(int maxClientConnections) { final Lifecycle druidLifecycle = new Lifecycle(); try { this.client = HttpClientInit.createClient( new HttpClientConfig(maxClientConnections, SSLContext.getDefault(), Duration.ZERO), LifecycleUtils.asMmxLifecycle(druidLifecycle) ); } catch (Exception e) { throw Throwables.propagate(e); } }
@Test public void testCreateSSLContext_validCustomSSLContextClass() throws Exception { ZKConfig zkConfig = new ZKConfig(); ClientX509Util clientX509Util = new ClientX509Util(); zkConfig.setProperty(clientX509Util.getSslContextSupplierClassProperty(), SslContextSupplier.class.getName()); final SSLContext sslContext = clientX509Util.createSSLContext(zkConfig); Assert.assertEquals(SSLContext.getDefault(), sslContext); }
@Test public void testHttpsSilentServer() throws Throwable { final Lifecycle lifecycle = new Lifecycle(); try { final HttpClientConfig config = HttpClientConfig.builder() .withSslContext(SSLContext.getDefault()) .withSslHandshakeTimeout(new Duration(100)) .build(); final HttpClient client = HttpClientInit.createClient(config, lifecycle); final ListenableFuture<StatusResponseHolder> response = client .go( new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", silentServerSocket.getLocalPort()))), new StatusResponseHandler(StandardCharsets.UTF_8) ); Throwable e = null; try { response.get(); } catch (ExecutionException e1) { e = e1.getCause(); } Assert.assertTrue("ChannelException thrown by 'get'", e instanceof ChannelException); } finally { lifecycle.stop(); } }
@Test public void testHttpsConnectionClosingServer() throws Throwable { final Lifecycle lifecycle = new Lifecycle(); try { final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build(); final HttpClient client = HttpClientInit.createClient(config, lifecycle); final ListenableFuture<StatusResponseHolder> response = client .go( new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", closingServerSocket.getLocalPort()))), new StatusResponseHandler(StandardCharsets.UTF_8) ); Throwable e = null; try { response.get(); } catch (ExecutionException e1) { e = e1.getCause(); e1.printStackTrace(); } Assert.assertTrue("ChannelException thrown by 'get'", isChannelClosedException(e)); } finally { lifecycle.stop(); } }
public static SSLContext getEffectiveSSLContext(HttpEmitterSSLClientConfig sslConfig, SSLContext sslContext) { SSLContext effectiveSSLContext; if (sslConfig.isUseDefaultJavaContext()) { try { effectiveSSLContext = SSLContext.getDefault(); } catch (NoSuchAlgorithmException nsae) { throw new RuntimeException(nsae); } } else if (sslConfig.getTrustStorePath() != null) { log.info("Creating SSLContext for HttpEmitter client using config [%s]", sslConfig); effectiveSSLContext = new TLSUtils.ClientSSLContextBuilder() .setProtocol(sslConfig.getProtocol()) .setTrustStoreType(sslConfig.getTrustStoreType()) .setTrustStorePath(sslConfig.getTrustStorePath()) .setTrustStoreAlgorithm(sslConfig.getTrustStoreAlgorithm()) .setTrustStorePasswordProvider(sslConfig.getTrustStorePasswordProvider()) .build(); } else { effectiveSSLContext = sslContext; } return effectiveSSLContext; } }
@Test public void testHttpsEchoServer() throws Throwable { final Lifecycle lifecycle = new Lifecycle(); try { final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build(); final HttpClient client = HttpClientInit.createClient(config, lifecycle); final ListenableFuture<StatusResponseHolder> response = client .go( new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", echoServerSocket.getLocalPort()))), new StatusResponseHandler(StandardCharsets.UTF_8) ); expectedException.expect(ExecutionException.class); expectedException.expectMessage("org.jboss.netty.channel.ChannelException: Faulty channel in resource pool"); response.get(); } finally { lifecycle.stop(); } } }
final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build(); final HttpClient client = HttpClientInit.createClient(config, lifecycle);