Skip to content

Commit 84c818d

Browse files
syedmqasim029MarkEWaiteolamy
authored
feat: add --httpsKeyStoreType option to support custom keystore types (#465)
* feat: add --httpsKeyStoreType option to support custom keystore types - Added HTTPS_KEY_STORE_TYPE option definition - Modified AbstractSecuredConnectorFactory to use custom keystore type - Updated README with documentation Fixes #450 * remove .DS_Store files * test: add unit test for HTTPS_KEY_STORE_TYPE option * remove .DS_Store file from tracking --------- Co-authored-by: Mark Waite <mark.earl.waite@gmail.com> Co-authored-by: Olivier Lamy <olamy@apache.org>
1 parent 31def01 commit 84c818d

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ To run locally exploded web archive:
6666
--httpsKeepAliveTimeout = how long idle HTTPS keep-alive connections are kept around (in ms; default 30000)?
6767
--httpsKeyStore = the location of the SSL KeyStore file. Default is ./winstone.ks
6868
--httpsKeyStorePassword = the password for the SSL KeyStore file. Default is null
69+
--httpsKeyStoreType = set the HTTPS keystore type (JKS, PKCS12, BCFKS, etc.).
70+
Default is the Java default keystore type.
6971
--httpsKeyManagerType = the SSL KeyManagerFactory type (eg SunX509, IbmX509). Default is SunX509
7072
--httpsRedirectHttp = redirect http requests to https (requires both --httpPort and --httpsPort)
7173
--http2Port = set the http2 listening port. -1 to disable, Default is disabled

src/main/java/winstone/AbstractSecuredConnectorFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected void configureSsl(Map<String, String> args, Server server) throws IOEx
4747

4848
this.keystorePassword = pwd;
4949

50-
keystore = KeyStore.getInstance(KeyStore.getDefaultType());
50+
String keyStoreType = Option.HTTPS_KEY_STORE_TYPE.get(args, KeyStore.getDefaultType());
51+
keystore = KeyStore.getInstance(keyStoreType);
5152
try (InputStream inputStream = new FileInputStream(keyStore)) {
5253
keystore.load(inputStream, this.keystorePassword.toCharArray());
5354
}
@@ -83,7 +84,8 @@ protected SslContextFactory.Server getSSLContext(Map<String, String> args) {
8384
KeyManagerFactory kmf = KeyManagerFactory.getInstance(Option.HTTPS_KEY_MANAGER_TYPE.get(args));
8485

8586
// In case the KeyStore password and the KeyPassword are not the same,
86-
// the KeyManagerFactory needs the KeyPassword because it will access the individual key(s)
87+
// the KeyManagerFactory needs the KeyPassword because it will access the
88+
// individual key(s)
8789
kmf.init(keystore, keystorePassword.toCharArray());
8890
Logger.log(Level.FINEST, SSL_RESOURCES, "HttpsListener.KeyCount", keystore.size() + "");
8991
for (Enumeration<String> e = keystore.aliases(); e.hasMoreElements(); ) {

src/main/java/winstone/cmdline/Option.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static List<Option<?>> all(Class<?> clazz) {
6666
integer("https" + _KEEP_ALIVE_TIMEOUT, _KEEP_ALIVE_TIMEOUT.defaultValue);
6767
public static final OFile HTTPS_KEY_STORE = file("httpsKeyStore");
6868
public static final OString HTTPS_KEY_STORE_PASSWORD = string("httpsKeyStorePassword");
69+
public static final OString HTTPS_KEY_STORE_TYPE = string("httpsKeyStoreType");
6970
public static final OString HTTPS_PRIVATE_KEY_PASSWORD = string("httpsPrivateKeyPassword");
7071
public static final OString HTTPS_KEY_MANAGER_TYPE = string("httpsKeyManagerType", "SunX509");
7172
public static final OString HTTPS_VERIFY_CLIENT = string("httpsVerifyClient", "false");

src/test/java/winstone/LauncherTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import java.net.http.HttpRequest;
1313
import java.net.http.HttpResponse;
1414
import java.nio.charset.StandardCharsets;
15+
import java.security.KeyStore;
1516
import java.util.HashMap;
1617
import java.util.Map;
1718
import java.util.zip.GZIPInputStream;
1819
import org.eclipse.jetty.server.ServerConnector;
1920
import org.junit.jupiter.api.Test;
2021
import org.jvnet.hudson.test.Issue;
22+
import winstone.cmdline.Option;
2123

2224
/**
2325
* @author Kohsuke Kawaguchi
@@ -121,4 +123,16 @@ void doubleGzip() throws Exception {
121123
assertFalse(response.headers().firstValue("Content-Encoding").isPresent());
122124
assertEquals(1345, response.body().length);
123125
}
126+
127+
@Test
128+
void testHttpsKeyStoreTypeOption() {
129+
Map<String, String> args = new HashMap<>();
130+
131+
String defaultType = Option.HTTPS_KEY_STORE_TYPE.get(args, KeyStore.getDefaultType());
132+
assertEquals(KeyStore.getDefaultType(), defaultType);
133+
134+
args.put("httpsKeyStoreType", "PKCS12");
135+
String customType = Option.HTTPS_KEY_STORE_TYPE.get(args, KeyStore.getDefaultType());
136+
assertEquals("PKCS12", customType);
137+
}
124138
}

0 commit comments

Comments
 (0)