Skip to content

Commit

Permalink
Fixed #994 - added the ability to set the keystore type and trust sto…
Browse files Browse the repository at this point in the history
…re type from the CLI
  • Loading branch information
tomakehurst committed Jun 30, 2020
1 parent 6ded3d6 commit 129d00b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs-v2/_docs/running-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ certificate to use with HTTPS. The keystore must have a password of
If this option isn't used WireMock will default to its own self-signed
certificate.

`--keystore-type`: The HTTPS keystore type. Usually JKS or PKCS12.

`--keystore-password`: Password to the keystore, if something other than
"password".
Note: the behaviour of this changed in version 2.27.0. Previously this set Jetty's key manager password, whereas now it
Expand All @@ -56,6 +58,8 @@ authenticate with a proxy target that require client authentication. See
and [Running as a browser proxy](/docs/proxying#running-as-a-browser-proxy) for
details.

`--keystore-type`: The HTTPS trust store type. Usually JKS or PKCS12.

`--truststore-password`: Optional password to the trust store. Defaults
to "password" if not specified.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public class CommandLineOptions implements Options {
private static final String HTTPS_PORT = "https-port";
private static final String HTTPS_KEYSTORE = "https-keystore";
private static final String HTTPS_KEYSTORE_PASSWORD = "keystore-password";
private static final String HTTPS_KEYSTORE_TYPE = "keystore-type";
private static final String HTTPS_KEY_MANAGER_PASSWORD = "key-manager-password";
private static final String HTTPS_TRUSTSTORE = "https-truststore";
private static final String HTTPS_TRUSTSTORE_PASSWORD = "truststore-password";
private static final String HTTPS_TRUSTSTORE_TYPE = "truststore-type";
private static final String REQUIRE_CLIENT_CERT = "https-require-client-cert";
private static final String VERBOSE = "verbose";
private static final String ENABLE_BROWSER_PROXYING = "enable-browser-proxying";
Expand Down Expand Up @@ -125,8 +127,10 @@ public CommandLineOptions(String... args) {
optionParser.accepts(BIND_ADDRESS, "The IP to listen connections").withRequiredArg();
optionParser.accepts(CONTAINER_THREADS, "The number of container threads").withRequiredArg();
optionParser.accepts(REQUIRE_CLIENT_CERT, "Make the server require a trusted client certificate to enable a connection");
optionParser.accepts(HTTPS_TRUSTSTORE_TYPE, "The HTTPS trust store type").withRequiredArg().defaultsTo("JKS");
optionParser.accepts(HTTPS_TRUSTSTORE_PASSWORD, "Password for the trust store").withRequiredArg();
optionParser.accepts(HTTPS_TRUSTSTORE, "Path to an alternative truststore for HTTPS client certificates. Must have a password of \"password\".").requiredIf(REQUIRE_CLIENT_CERT).withRequiredArg();
optionParser.accepts(HTTPS_KEYSTORE_TYPE, "The HTTPS keystore type.").withRequiredArg().defaultsTo("JKS");
optionParser.accepts(HTTPS_KEYSTORE_PASSWORD, "Password for the alternative keystore.").withRequiredArg().defaultsTo("password");
optionParser.accepts(HTTPS_KEY_MANAGER_PASSWORD, "Key manager password for use with the alternative keystore.").withRequiredArg().defaultsTo("password");
optionParser.accepts(HTTPS_KEYSTORE, "Path to an alternative keystore for HTTPS. Password is assumed to be \"password\" if not specified.").requiredIf(HTTPS_TRUSTSTORE).requiredIf(HTTPS_KEYSTORE_PASSWORD).withRequiredArg().defaultsTo(Resources.getResource("keystore").toString());
Expand Down Expand Up @@ -281,9 +285,11 @@ public HttpsSettings httpsSettings() {
.port(httpsPortNumber())
.keyStorePath((String) optionSet.valueOf(HTTPS_KEYSTORE))
.keyStorePassword((String) optionSet.valueOf(HTTPS_KEYSTORE_PASSWORD))
.keyStoreType((String) optionSet.valueOf(HTTPS_KEYSTORE_TYPE))
.keyManagerPassword((String) optionSet.valueOf(HTTPS_KEY_MANAGER_PASSWORD))
.trustStorePath((String) optionSet.valueOf(HTTPS_TRUSTSTORE))
.trustStorePassword((String) optionSet.valueOf(HTTPS_TRUSTSTORE_PASSWORD))
.trustStoreType((String) optionSet.valueOf(HTTPS_TRUSTSTORE_TYPE))
.needClientAuth(optionSet.has(REQUIRE_CLIENT_CERT)).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,29 @@ public void setsRequireClientCert() {
}

@Test
public void setsTrustStorePathAndPassword() {
CommandLineOptions options = new CommandLineOptions("--https-port", "8443",
public void setsTrustStoreOptions() {
CommandLineOptions options = new CommandLineOptions(
"--https-port", "8443",
"--https-keystore", "/my/keystore",
"--https-truststore", "/my/truststore",
"--truststore-type", "PKCS12",
"--truststore-password", "sometrustpwd");
assertThat(options.httpsSettings().trustStorePath(), is("/my/truststore"));
assertThat(options.httpsSettings().trustStoreType(), is("PKCS12"));
assertThat(options.httpsSettings().trustStorePassword(), is("sometrustpwd"));
}

@Test
public void setsKeyStorePathPasswordAndKeyManagerPassword() {
CommandLineOptions options = new CommandLineOptions("--https-port", "8443", "--https-keystore", "/my/keystore", "--keystore-password", "someotherpwd", "--key-manager-password", "keymanpass");
public void setsHttpsKeyStorePathOptions() {
CommandLineOptions options = new CommandLineOptions(
"--https-port", "8443",
"--https-keystore", "/my/keystore",
"--keystore-type", "pkcs12",
"--keystore-password", "someotherpwd",
"--key-manager-password", "keymanpass"
);
assertThat(options.httpsSettings().keyStorePath(), is("/my/keystore"));
assertThat(options.httpsSettings().keyStoreType(), is("pkcs12"));
assertThat(options.httpsSettings().keyStorePassword(), is("someotherpwd"));
assertThat(options.httpsSettings().keyManagerPassword(), is("keymanpass"));
}
Expand Down

0 comments on commit 129d00b

Please sign in to comment.