1414 */
1515package org .htmlunit .util ;
1616
17+ import static org .eclipse .jetty .http .HttpVersion .HTTP_1_1 ;
18+
1719import java .io .IOException ;
1820import java .net .BindException ;
21+ import java .net .URL ;
1922import java .nio .charset .Charset ;
2023import java .util .EnumSet ;
2124import java .util .Map ;
4548import org .eclipse .jetty .servlet .ServletHolder ;
4649import org .eclipse .jetty .util .security .Constraint ;
4750import org .eclipse .jetty .util .thread .QueuedThreadPool ;
51+ import org .htmlunit .HttpWebConnectionInsecureSSLWithClientCertificateTest ;
4852import org .htmlunit .WebServerTestCase ;
53+ import org .htmlunit .WebServerTestCase .SSLVariant ;
4954import org .htmlunit .WebTestCase ;
5055
5156/**
@@ -59,7 +64,7 @@ public static Server startWebServer(final int port, final String resourceBase,
5964 final Map <String , Class <? extends Servlet >> servlets ,
6065 final Charset serverCharset ,
6166 final boolean isBasicAuthentication ,
62- final SslConnectionFactory sslConnectionFactory ) throws Exception {
67+ final WebServerTestCase . SSLVariant sslVariant ) throws Exception {
6368 final Server server = buildServer (port );
6469
6570 final ServletContextHandler context = new ServletContextHandler (ServletContextHandler .SESSIONS );
@@ -113,7 +118,31 @@ public static Server startWebServer(final int port, final String resourceBase,
113118
114119 server .setHandler (context );
115120
116- if (sslConnectionFactory != null ) {
121+ if (sslVariant != SSLVariant .NONE ) {
122+ org .eclipse .jetty .util .ssl .SslContextFactory .Server contextFactory = null ;
123+
124+ switch (sslVariant ) {
125+ case INSECURE : {
126+ final URL url = HttpWebConnectionInsecureSSLWithClientCertificateTest .class
127+ .getClassLoader ().getResource ("insecureSSL.pfx" );
128+
129+ contextFactory = new org .eclipse .jetty .util .ssl .SslContextFactory .Server ();
130+ contextFactory .setKeyStorePath (url .toExternalForm ());
131+ contextFactory .setKeyStorePassword ("nopassword" );
132+ contextFactory .setEndpointIdentificationAlgorithm (null );
133+ }
134+ case SELF_SIGNED : {
135+ final URL url = HttpWebConnectionInsecureSSLWithClientCertificateTest .class
136+ .getClassLoader ().getResource ("self-signed-cert.keystore" );
137+
138+ contextFactory = new org .eclipse .jetty .util .ssl .SslContextFactory .Server ();
139+ contextFactory .setKeyStoreType ("jks" );
140+ contextFactory .setKeyStorePath (url .toExternalForm ());
141+ contextFactory .setKeyStorePassword ("nopassword" );
142+ contextFactory .setEndpointIdentificationAlgorithm (null );
143+ }
144+ }
145+
117146 final HttpConfiguration sslConfiguration = new HttpConfiguration ();
118147 final SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer ();
119148
@@ -125,6 +154,7 @@ public static Server startWebServer(final int port, final String resourceBase,
125154
126155 final HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory (sslConfiguration );
127156
157+ final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory (contextFactory , HTTP_1_1 .toString ());
128158 final ServerConnector connector = new ServerConnector (server , sslConnectionFactory , httpConnectionFactory );
129159 connector .setPort (WebTestCase .PORT2 );
130160 server .addConnector (connector );
0 commit comments