Improve SSLKsFactory

Use kspass (keystore password) as the keyPassword if keyPassword is not specified
This commit is contained in:
Justin Chu 2020-09-08 17:00:49 -04:00
parent 563e792ffb
commit 8f2da8f448
3 changed files with 31 additions and 7 deletions

View File

@ -87,16 +87,16 @@ public class SSLKsFactory {
logger.warn("Please update your 'ssl=true' parameter to 'ssl=jdk'");
}
final char[] keyStorePassword = def.getParams().getOptionalString("kspass")
.map(String::toCharArray)
.orElse(null);
keyPassword = def.getParams().getOptionalString("keyPassword")
.map(String::toCharArray)
.orElse(null);
.orElse(keyStorePassword);
keyStore = def.getParams().getOptionalString("keystore").map(ksPath -> {
try {
return KeyStore.getInstance(new File(ksPath),
def.getParams().getOptionalString("kspass")
.map(String::toCharArray)
.orElse(null));
return KeyStore.getInstance(new File(ksPath), keyStorePassword);
} catch (Exception e) {
throw new RuntimeException("Unable to load the keystore. Please check.", e);
}

View File

@ -43,8 +43,21 @@ public class SSLKsFactoryTest {
"truststore=src/test/resources/ssl/server_truststore.p12",
"tspass=nosqlbench_server",
"keystore=src/test/resources/ssl/client.p12",
"kspass=nosqlbench_client"
};
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
}
@Test
public void testJdkGetContextWithTruststoreAndKeystoreAndDifferentKeyPassword() {
String[] params = {
"ssl=jdk",
"truststore=src/test/resources/ssl/server_truststore.p12",
"tspass=nosqlbench_server",
"keystore=src/test/resources/ssl/client_diff_password.p12",
"kspass=nosqlbench_client",
"keyPassword=nosqlbench_client"
"keyPassword=nosqlbench"
};
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
@ -66,8 +79,19 @@ public class SSLKsFactoryTest {
String[] params = {
"ssl=jdk",
"keystore=src/test/resources/ssl/client.p12",
"kspass=nosqlbench_client"
};
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
}
@Test
public void testJdkGetContextWithKeystoreAndDifferentKeyPassword() {
String[] params = {
"ssl=jdk",
"keystore=src/test/resources/ssl/client_diff_password.p12",
"kspass=nosqlbench_client",
"keyPassword=nosqlbench_client"
"keyPassword=nosqlbench"
};
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();