mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-09 15:33:12 -06:00
Merge pull request #201 from justinchuch/improve-ssl
Improve SSLKsFactory
This commit is contained in:
commit
33be2f2dd2
@ -87,16 +87,16 @@ public class SSLKsFactory {
|
|||||||
logger.warn("Please update your 'ssl=true' parameter to 'ssl=jdk'");
|
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")
|
keyPassword = def.getParams().getOptionalString("keyPassword")
|
||||||
.map(String::toCharArray)
|
.map(String::toCharArray)
|
||||||
.orElse(null);
|
.orElse(keyStorePassword);
|
||||||
|
|
||||||
keyStore = def.getParams().getOptionalString("keystore").map(ksPath -> {
|
keyStore = def.getParams().getOptionalString("keystore").map(ksPath -> {
|
||||||
try {
|
try {
|
||||||
return KeyStore.getInstance(new File(ksPath),
|
return KeyStore.getInstance(new File(ksPath), keyStorePassword);
|
||||||
def.getParams().getOptionalString("kspass")
|
|
||||||
.map(String::toCharArray)
|
|
||||||
.orElse(null));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unable to load the keystore. Please check.", e);
|
throw new RuntimeException("Unable to load the keystore. Please check.", e);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,21 @@ public class SSLKsFactoryTest {
|
|||||||
"truststore=src/test/resources/ssl/server_truststore.p12",
|
"truststore=src/test/resources/ssl/server_truststore.p12",
|
||||||
"tspass=nosqlbench_server",
|
"tspass=nosqlbench_server",
|
||||||
"keystore=src/test/resources/ssl/client.p12",
|
"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",
|
"kspass=nosqlbench_client",
|
||||||
"keyPassword=nosqlbench_client"
|
"keyPassword=nosqlbench"
|
||||||
};
|
};
|
||||||
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
|
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
|
||||||
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
|
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
|
||||||
@ -66,8 +79,19 @@ public class SSLKsFactoryTest {
|
|||||||
String[] params = {
|
String[] params = {
|
||||||
"ssl=jdk",
|
"ssl=jdk",
|
||||||
"keystore=src/test/resources/ssl/client.p12",
|
"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",
|
"kspass=nosqlbench_client",
|
||||||
"keyPassword=nosqlbench_client"
|
"keyPassword=nosqlbench"
|
||||||
};
|
};
|
||||||
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
|
ActivityDef activityDef = ActivityDef.parseActivityDef(String.join(";", params));
|
||||||
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
|
assertThat(SSLKsFactory.get().getContext(activityDef)).isNotNull();
|
||||||
|
BIN
engine-api/src/test/resources/ssl/client_diff_password.p12
Normal file
BIN
engine-api/src/test/resources/ssl/client_diff_password.p12
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user