Skip to content

Commit

Permalink
wiremock#994 added security store types to command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sab-cd-user committed Sep 26, 2018
1 parent 9abe490 commit cf40a50
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs-v2/_docs/running-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ certificate.
`--keystore-password`: Password to the keystore, if something other than
"password".

`--keystore-type`: Optional type of the keystore. Defaults to "JKS"
if not specified.

`--https-truststore`: Path to a keystore file containing client
certificates. See https and proxy-client-certs for details.

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

`--truststore-type`: Optional type of the trust store. Defaults
to "JKS" if not specified.

`--https-require-client-cert`: Force clients to authenticate with a
client certificate. See https for details.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ 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_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 @@ -106,8 +108,10 @@ public CommandLineOptions(String... args) {
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_PASSWORD, "Password for the trust store").withRequiredArg();
optionParser.accepts(HTTPS_TRUSTSTORE_TYPE, "Type of the trust store").withRequiredArg().defaultsTo("JKS");
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_PASSWORD, "Password for the alternative keystore.").withRequiredArg().defaultsTo("password");
optionParser.accepts(HTTPS_KEYSTORE_TYPE, "Type of the alternative keystore.").withRequiredArg().defaultsTo("JKS");
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());
optionParser.accepts(PROXY_ALL, "Will create a proxy mapping for /* to the specified URL").withRequiredArg();
optionParser.accepts(PRESERVE_HOST_HEADER, "Will transfer the original host header from the client to the proxied service");
Expand Down Expand Up @@ -237,8 +241,10 @@ 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))
.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 Expand Up @@ -426,7 +432,8 @@ public String toString() {

if (httpsSettings().enabled()) {
builder.put(HTTPS_PORT, nullToString(httpsSettings().port()))
.put(HTTPS_KEYSTORE, nullToString(httpsSettings().keyStorePath()));
.put(HTTPS_KEYSTORE, nullToString(httpsSettings().keyStorePath()))
.put(HTTPS_KEYSTORE_TYPE, nullToString(httpsSettings().keyStoreType()));
}

if (!(proxyVia() == NO_PROXY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ public void setsKeyStorePathAndPassword() {
assertThat(options.httpsSettings().keyStorePassword(), is("someotherpwd"));
}

@Test
public void setsKeyStoreType() {
CommandLineOptions options = new CommandLineOptions("--keystore-type", "keystoretype");
assertThat(options.httpsSettings().keyStoreType(), is("keystoretype"));
}

@Test
public void defaultsKeyStoreTypeIfNotSpecified() {
CommandLineOptions options = new CommandLineOptions();
assertThat(options.httpsSettings().keyStoreType(), is("JKS"));
}

@Test
public void setsTrustStoreType() {
CommandLineOptions options = new CommandLineOptions("--truststore-type", "truststoretype");
assertThat(options.httpsSettings().trustStoreType(), is("truststoretype"));
}

@Test
public void defaultsTrustStoreTypeIfNotSpecified() {
CommandLineOptions options = new CommandLineOptions();
assertThat(options.httpsSettings().trustStoreType(), is("JKS"));
}

@Test(expected=IllegalArgumentException.class)
public void throwsExceptionIfKeyStoreSpecifiedWithoutHttpsPort() {
new CommandLineOptions("--https-keystore", "/my/keystore");
Expand Down

0 comments on commit cf40a50

Please sign in to comment.