Skip to content

Commit aa62109

Browse files
committed
Improved 2-way SSL test
Now using separate key and trust stores.
1 parent 5a7ebaa commit aa62109

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

marklogic-client-api/src/test/java/com/marklogic/client/test/ssl/TwoWaySSLTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class TwoWaySSLTest {
4848
private static DatabaseClient securityClient;
4949
private static ManageClient manageClient;
5050
private static File keyStoreFile;
51+
private static File trustStoreFile;
5152
private static File p12File;
5253

5354

@@ -73,9 +74,10 @@ public static void setup() throws Exception {
7374
writeClientCertificateFilesToTempDir(clientCertificate, tempDir);
7475
createPkcs12File(tempDir);
7576
createKeystoreFile(tempDir);
76-
keyStoreFile = new File(tempDir.toFile(), "client.jks");
77+
keyStoreFile = new File(tempDir.toFile(), "keyStore.jks");
78+
trustStoreFile = new File(tempDir.toFile(), "trustStore.jks");
7779
p12File = new File(tempDir.toFile(), "client.p12");
78-
addServerCertificateToKeyStore(tempDir);
80+
addServerCertificateToTrustStore(tempDir);
7981
}
8082

8183
@AfterAll
@@ -90,6 +92,12 @@ public static void teardown() {
9092
/**
9193
* After two-way SSL is configured on the java-unittest app server, verify that a DatabaseClient using a proper
9294
* SSLContext can connect to the app server.
95+
*
96+
* This test can be used for manual testing of two-way SSL - e.g. for ml-gradle - by doing the following:
97+
* - Add a breakpoint at the start of the test.
98+
* - Run the test in a debugger.
99+
* - When the breakpoint is hit, look for the location of the files in stdout.
100+
* - Copy those files to a more accessible location and use them for accessing the 8012 app server.
93101
*/
94102
@Test
95103
void digestAuthentication() {
@@ -106,7 +114,7 @@ void digestAuthentication() {
106114
.withSSLHostnameVerifier(DatabaseClientFactory.SSLHostnameVerifier.ANY)
107115

108116
// Starting in 6.5.0, we can use a real trust manager as the server certificate is in the keystore.
109-
.withTrustStorePath(keyStoreFile.getAbsolutePath())
117+
.withTrustStorePath(trustStoreFile.getAbsolutePath())
110118
.withTrustStorePassword(KEYSTORE_PASSWORD)
111119
.withTrustStoreType("JKS")
112120
.withTrustStoreAlgorithm("SunX509")
@@ -432,7 +440,7 @@ private static void createKeystoreFile(Path tempDir) throws Exception {
432440
builder.command("keytool", "-importkeystore",
433441
"-deststorepass", KEYSTORE_PASSWORD,
434442
"-destkeypass", KEYSTORE_PASSWORD,
435-
"-destkeystore", "client.jks",
443+
"-destkeystore", "keyStore.jks",
436444
"-srckeystore", "client.p12",
437445
"-srcstoretype", "PKCS12",
438446
"-srcstorepass", KEYSTORE_PASSWORD,
@@ -449,7 +457,7 @@ private static void createKeystoreFile(Path tempDir) throws Exception {
449457
* @param tempDir
450458
* @throws Exception
451459
*/
452-
private static void addServerCertificateToKeyStore(Path tempDir) throws Exception {
460+
private static void addServerCertificateToTrustStore(Path tempDir) throws Exception {
453461
Fragment xml = new CertificateTemplateManager(Common.newManageClient()).getCertificatesForTemplate("java-unittest-template");
454462
String serverCertificate = xml.getElementValue("/msec:certificate-list/msec:certificate/msec:pem");
455463

@@ -459,7 +467,7 @@ private static void addServerCertificateToKeyStore(Path tempDir) throws Exceptio
459467
ProcessBuilder builder = new ProcessBuilder();
460468
builder.directory(tempDir.toFile());
461469
builder.command("keytool", "-importcert",
462-
"-keystore", keyStoreFile.getAbsolutePath(),
470+
"-keystore", trustStoreFile.getAbsolutePath(),
463471
"-storepass", KEYSTORE_PASSWORD,
464472
"-file", certificateFile.getAbsolutePath(),
465473
"-noprompt",

0 commit comments

Comments
 (0)