Search in sources :

Example 36 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project qi4j-sdk by Qi4j.

the class SecureJettyMixin method buildConnector.

@Override
protected ServerConnector buildConnector(Server server, HttpConfiguration httpConfig) {
    SslConnectionFactory sslConnFactory = new SslConnectionFactory();
    configureSsl(sslConnFactory, configuration.get());
    return new ServerConnector(server, sslConnFactory, new HttpConnectionFactory(httpConfig));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 37 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project sonarqube by SonarSource.

the class SSLTest method startSSLTransparentReverseProxy.

public static void startSSLTransparentReverseProxy(boolean requireClientAuth) throws Exception {
    int httpPort = NetworkUtils.getNextAvailablePort();
    httpsPort = NetworkUtils.getNextAvailablePort();
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(500);
    server = new Server(threadPool);
    // HTTP Configuration
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme("https");
    httpConfig.setSecurePort(httpsPort);
    httpConfig.setSendServerVersion(true);
    httpConfig.setSendDateHeader(false);
    // Handler Structure
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { proxyHandler(), new DefaultHandler() });
    server.setHandler(handlers);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    http.setPort(httpPort);
    server.addConnector(http);
    Path serverKeyStore = Paths.get(SSLTest.class.getResource("/analysis/SSLTest/serverkeystore.jks").toURI()).toAbsolutePath();
    String keyStorePassword = "serverkeystorepwd";
    String serverKeyPassword = "serverp12pwd";
    Path serverTrustStore = Paths.get(SSLTest.class.getResource("/analysis/SSLTest/servertruststore.jks").toURI()).toAbsolutePath();
    String trustStorePassword = "servertruststorepwd";
    // SSL Context Factory
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(serverKeyStore.toString());
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setKeyManagerPassword(serverKeyPassword);
    sslContextFactory.setTrustStorePath(serverTrustStore.toString());
    sslContextFactory.setTrustStorePassword(trustStorePassword);
    sslContextFactory.setNeedClientAuth(requireClientAuth);
    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
    // SSL HTTP Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    // SSL Connector
    ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    sslConnector.setPort(httpsPort);
    server.addConnector(sslConnector);
    server.start();
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 38 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project spark by perwendel.

the class SocketConnectorFactoryTest method testCreateSecureSocketConnector.

@Test
@PrepareForTest({ ServerConnector.class })
public void testCreateSecureSocketConnector() throws Exception {
    final String host = "localhost";
    final int port = 8888;
    final String keystoreFile = "keystoreFile.jks";
    final String keystorePassword = "keystorePassword";
    final String truststoreFile = "truststoreFile.jks";
    final String trustStorePassword = "trustStorePassword";
    SslStores sslStores = SslStores.create(keystoreFile, keystorePassword, truststoreFile, trustStorePassword);
    Server server = new Server();
    ServerConnector serverConnector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
    String internalHost = Whitebox.getInternalState(serverConnector, "_host");
    int internalPort = Whitebox.getInternalState(serverConnector, "_port");
    assertEquals("Server Connector Host should be set to the specified server", host, internalHost);
    assertEquals("Server Connector Port should be set to the specified port", port, internalPort);
    Map<String, ConnectionFactory> factories = Whitebox.getInternalState(serverConnector, "_factories");
    assertTrue("Should return true because factory for SSL should have been set", factories.containsKey("ssl") && factories.get("ssl") != null);
    SslConnectionFactory sslConnectionFactory = (SslConnectionFactory) factories.get("ssl");
    SslContextFactory sslContextFactory = sslConnectionFactory.getSslContextFactory();
    assertEquals("Should return the Keystore file specified", keystoreFile, sslContextFactory.getKeyStoreResource().getFile().getName());
    assertEquals("Should return the Truststore file specified", truststoreFile, sslContextFactory.getTrustStoreResource().getFile().getName());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SslStores(spark.ssl.SslStores) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 39 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project neo4j by neo4j.

the class SslSocketConnectorFactory method createSslConnectionFactory.

private SslConnectionFactory createSslConnectionFactory(KeyStoreInformation ksInfo) {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStore(ksInfo.getKeyStore());
    sslContextFactory.setKeyStorePassword(String.valueOf(ksInfo.getKeyStorePassword()));
    sslContextFactory.setKeyManagerPassword(String.valueOf(ksInfo.getKeyPassword()));
    return new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 40 with SslConnectionFactory

use of org.eclipse.jetty.server.SslConnectionFactory in project spring-boot by spring-projects.

the class JettyServletWebServerFactoryTests method sslEnabledMultiProtocolsConfiguration.

@Test
public void sslEnabledMultiProtocolsConfiguration() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword("password");
    ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
    ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" });
    JettyServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    JettyWebServer jettyWebServer = (JettyWebServer) this.webServer;
    ServerConnector connector = (ServerConnector) jettyWebServer.getServer().getConnectors()[0];
    SslConnectionFactory connectionFactory = connector.getConnectionFactory(SslConnectionFactory.class);
    assertThat(connectionFactory.getSslContextFactory().getIncludeProtocols()).isEqualTo(new String[] { "TLSv1.1", "TLSv1.2" });
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) Ssl(org.springframework.boot.web.server.Ssl) Test(org.junit.Test)

Aggregations

SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)51 ServerConnector (org.eclipse.jetty.server.ServerConnector)48 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)41 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)40 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)37 Server (org.eclipse.jetty.server.Server)30 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)8 File (java.io.File)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)7 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)6 Test (org.junit.Test)6 ServletException (javax.servlet.ServletException)5 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)5 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)5 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)5 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 URI (java.net.URI)4