use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class TestTransparentProxyServer method main.
public static void main(String[] args) throws Exception {
((StdErrLog) Log.getLog()).setSource(false);
String jetty_root = "../../..";
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
// Setup server
Server server = new Server(threadPool);
server.manage(threadPool);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
server.addBean(Log.getLog());
// Common HTTP configuration
HttpConfiguration config = new HttpConfiguration();
config.setSecurePort(8443);
config.addCustomizer(new ForwardedRequestCustomizer());
config.setSendDateHeader(true);
config.setSendServerVersion(true);
// Http Connector
HttpConnectionFactory http = new HttpConnectionFactory(config);
ServerConnector httpConnector = new ServerConnector(server, http);
httpConnector.setPort(8080);
httpConnector.setIdleTimeout(30000);
server.addConnector(httpConnector);
// SSL configurations
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
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");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration(config);
https_config.addCustomizer(new SecureRequestCustomizer());
// HTTP2 factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h2.getProtocol());
// SSL Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
// HTTP2 Connector
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
http2Connector.setPort(8443);
http2Connector.setIdleTimeout(15000);
server.addConnector(http2Connector);
// Handlers
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
server.setHandler(handlers);
// Setup proxy webapp
WebAppContext webapp = new WebAppContext();
webapp.setResourceBase("src/main/webapp");
contexts.addHandler(webapp);
// start server
server.setStopAtShutdown(true);
server.start();
server.join();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class HttpClientTest method testRequestSentOnlyAfterConnectionOpen.
@Test
public void testRequestSentOnlyAfterConnectionOpen() throws Exception {
startServer(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
}
});
final AtomicBoolean open = new AtomicBoolean();
client = new HttpClient(new HttpClientTransportOverHTTP() {
@Override
protected HttpConnectionOverHTTP newHttpConnection(EndPoint endPoint, HttpDestination destination, Promise<Connection> promise) {
return new HttpConnectionOverHTTP(endPoint, destination, promise) {
@Override
public void onOpen() {
open.set(true);
super.onOpen();
}
};
}
}, sslContextFactory);
client.start();
final CountDownLatch latch = new CountDownLatch(2);
client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).onRequestBegin(request -> {
Assert.assertTrue(open.get());
latch.countDown();
}).send(result -> {
if (result.isSucceeded())
latch.countDown();
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class HttpClientTLSTest method createSslContextFactory.
private SslContextFactory createSslContextFactory() {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setEndpointIdentificationAlgorithm("");
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
sslContextFactory.setTrustStorePassword("storepwd");
return sslContextFactory;
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class HttpClientTLSTest method testMismatchBetweenTLSProtocolAndTLSCiphersOnClient.
@Test
public void testMismatchBetweenTLSProtocolAndTLSCiphersOnClient() throws Exception {
SslContextFactory serverTLSFactory = createSslContextFactory();
startServer(serverTLSFactory, new EmptyServerHandler());
CountDownLatch serverLatch = new CountDownLatch(1);
connector.addBean(new SslHandshakeListener() {
@Override
public void handshakeFailed(Event event, Throwable failure) {
serverLatch.countDown();
}
});
SslContextFactory clientTLSFactory = createSslContextFactory();
// TLS 1.1 protocol, but only TLS 1.2 ciphers.
clientTLSFactory.setIncludeProtocols("TLSv1.1");
clientTLSFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
startClient(clientTLSFactory);
CountDownLatch clientLatch = new CountDownLatch(1);
client.addBean(new SslHandshakeListener() {
@Override
public void handshakeFailed(Event event, Throwable failure) {
clientLatch.countDown();
}
});
try {
client.newRequest("localhost", connector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).timeout(5, TimeUnit.SECONDS).send();
Assert.fail();
} catch (ExecutionException x) {
// Expected.
}
Assert.assertTrue(serverLatch.await(1, TimeUnit.SECONDS));
Assert.assertTrue(clientLatch.await(1, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class HttpClientTest method testClientCannotValidateServerCertificate.
@Test(expected = ExecutionException.class)
public void testClientCannotValidateServerCertificate() throws Exception {
// Only run this test for transports over TLS.
Assume.assumeTrue(EnumSet.of(Transport.HTTPS, Transport.H2).contains(transport));
startServer(new EmptyServerHandler());
// Use a default SslContextFactory, requests should fail because the server certificate is unknown.
client = newHttpClient(provideClientTransport(transport), new SslContextFactory());
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
client.setExecutor(clientThreads);
client.start();
client.newRequest(newURI()).timeout(5, TimeUnit.SECONDS).send();
}
Aggregations