use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class AbstractTest method startServer.
protected void startServer(Handler handler) throws Exception {
sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
sslContextFactory.setTrustStorePassword("storepwd");
sslContextFactory.setUseCipherSuitesOrder(true);
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
connector = newServerConnector(server);
server.addConnector(connector);
server.setHandler(handler);
server.start();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class TryFilesFilterTest method prepare.
public void prepare(HttpServlet servlet) throws Exception {
server = new Server();
connector = new ServerConnector(server);
server.addConnector(connector);
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");
sslConnector = new ServerConnector(server, sslContextFactory);
server.addConnector(sslConnector);
ServletContextHandler context = new ServletContextHandler(server, "/");
FilterHolder filterHolder = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
forwardPath = "/index.php";
filterHolder.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path " + forwardPath + "?p=$path");
context.addServlet(new ServletHolder(servlet), "/*");
client = new HttpClient(sslContextFactory);
server.addBean(client);
server.start();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class WordPressHTTP2FastCGIProxyServer method main.
public static void main(String[] args) throws Exception {
int tlsPort = 8443;
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");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
Server server = new Server();
// HTTP(S) Configuration
HttpConfiguration config = new HttpConfiguration();
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(tlsPort);
http2Connector.setIdleTimeout(15000);
server.addConnector(http2Connector);
String root = "/home/simon/programs/wordpress-3.7.1";
ServletContextHandler context = new ServletContextHandler(server, "/wp");
context.setResourceBase(root);
context.setWelcomeFiles(new String[] { "index.php" });
// Serve static resources
ServletHolder defaultServlet = new ServletHolder("default", DefaultServlet.class);
context.addServlet(defaultServlet, "/");
FilterHolder tryFilesFilter = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
// tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path $path/index.php"); // Permalink /?p=123
// Permalink /%year%/%monthnum%/%postname%
tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path /index.php?p=$path");
// FastCGI
ServletHolder fcgiServlet = context.addServlet(FastCGIProxyServlet.class, "*.php");
fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
fcgiServlet.setInitParameter("prefix", "/");
fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
server.start();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class DrupalHTTP2FastCGIProxyServer method main.
public static void main(String[] args) throws Exception {
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");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
Server server = new Server();
// HTTP(S) Configuration
HttpConfiguration config = new HttpConfiguration();
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);
// Drupal seems to only work on the root context,
// at least out of the box without additional plugins
String root = "/home/simon/programs/drupal-7.23";
ServletContextHandler context = new ServletContextHandler(server, "/");
context.setResourceBase(root);
context.setWelcomeFiles(new String[] { "index.php" });
// Serve static resources
ServletHolder defaultServlet = new ServletHolder(DefaultServlet.class);
defaultServlet.setName("default");
context.addServlet(defaultServlet, "/");
// FastCGI
ServletHolder fcgiServlet = new ServletHolder(FastCGIProxyServlet.class);
fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
fcgiServlet.setInitParameter("prefix", "/");
fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+\\.php)");
context.addServlet(fcgiServlet, "*.php");
server.start();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class ALPNNegotiationTest method testClientNotSupportingALPNServerSpeaksDefaultProtocol.
@Test
public void testClientNotSupportingALPNServerSpeaksDefaultProtocol() throws Exception {
InetSocketAddress address = prepare();
SslContextFactory sslContextFactory = newSslContextFactory();
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket(address.getAddress(), address.getPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
ALPN.put(client, new ALPN.ClientProvider() {
@Override
public void unsupported() {
}
@Override
public List<String> protocols() {
return null;
}
@Override
public void selected(String s) {
}
});
client.startHandshake();
// Verify that the server really speaks http/1.1
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost:" + address.getPort() + "\r\n" + "\r\n" + "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
}
}
Aggregations