use of org.eclipse.jetty.util.ssl.SslContextFactory in project dropwizard by dropwizard.
the class HttpsConnectorFactoryTest method testSupportedProtocols.
@Test
public void testSupportedProtocols() {
List<String> supportedProtocols = ImmutableList.of("SSLv3", "TLS1");
HttpsConnectorFactory factory = new HttpsConnectorFactory();
// necessary to avoid a prompt for a password
factory.setKeyStorePassword("password");
factory.setSupportedProtocols(supportedProtocols);
SslContextFactory sslContextFactory = factory.configureSslContextFactory(new SslContextFactory());
assertThat(ImmutableList.copyOf(sslContextFactory.getIncludeProtocols())).isEqualTo(supportedProtocols);
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class JDK9HTTP2Client method main.
public static void main(String[] args) throws Exception {
HTTP2Client client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory(true);
client.addBean(sslContextFactory);
client.start();
String host = "localhost";
int port = 8443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(555, TimeUnit.SECONDS);
HttpFields requestFields = new HttpFields();
requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
MetaData.Request metaData = new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
HeadersFrame headersFrame = new HeadersFrame(metaData, null, true);
CountDownLatch latch = new CountDownLatch(1);
session.newStream(headersFrame, new Promise.Adapter<>(), new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
System.err.println(frame);
if (frame.isEndStream())
latch.countDown();
}
@Override
public void onData(Stream stream, DataFrame frame, Callback callback) {
System.err.println(frame);
callback.succeeded();
if (frame.isEndStream())
latch.countDown();
}
});
latch.await(5, TimeUnit.SECONDS);
client.stop();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class JDK9ALPNTest method testClientNotSupportingALPNServerSpeaksDefaultProtocol.
@Test
public void testClientNotSupportingALPNServerSpeaksDefaultProtocol() throws Exception {
startServer(new AbstractHandler.ErrorDispatchHandler() {
@Override
protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
}
});
SslContextFactory sslContextFactory = new SslContextFactory(true);
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
client.startHandshake();
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\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(" 200 "));
while (true) {
if (reader.readLine() == null)
break;
}
}
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class JDK9HTTP2Server method main.
public static void main(String... args) throws Exception {
Server server = new Server();
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(8443);
httpsConfig.setSendXPoweredBy(true);
httpsConfig.setSendServerVersion(true);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
HttpConnectionFactory http = new HttpConnectionFactory(httpsConfig);
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http.getProtocol());
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, http);
http2Connector.setPort(8443);
server.addConnector(http2Connector);
server.start();
}
use of org.eclipse.jetty.util.ssl.SslContextFactory in project jetty.project by eclipse.
the class HttpInputIntegrationTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
__config = new HttpConfiguration();
__server = new Server();
LocalConnector local = new LocalConnector(__server, new HttpConnectionFactory(__config));
local.setIdleTimeout(4000);
__server.addConnector(local);
ServerConnector http = new ServerConnector(__server, new HttpConnectionFactory(__config), new HTTP2CServerConnectionFactory(__config));
http.setIdleTimeout(4000);
__server.addConnector(http);
// SSL Context Factory for HTTPS and HTTP/2
String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
__sslContextFactory = new SslContextFactory();
__sslContextFactory.setKeyStorePath(jetty_distro + "/../../../jetty-server/src/test/config/etc/keystore");
__sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
__sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
// HTTPS Configuration
__sslConfig = new HttpConfiguration(__config);
__sslConfig.addCustomizer(new SecureRequestCustomizer());
// HTTP/1 Connection Factory
HttpConnectionFactory h1 = new HttpConnectionFactory(__sslConfig);
/* TODO
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(__sslConfig);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h1.getProtocol());
*/
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(__sslContextFactory, h1.getProtocol());
// HTTP/2 Connector
ServerConnector http2 = new ServerConnector(__server, ssl, /*TODO alpn,h2,*/
h1);
http2.setIdleTimeout(4000);
__server.addConnector(http2);
ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
ServletHolder holder = new ServletHolder(new TestServlet());
holder.setAsyncSupported(true);
context.addServlet(holder, "/*");
__server.start();
}
Aggregations