@@ -36,6 +36,10 @@ public class JmxConnectionTest {
3636 private static final int JMX_PORT = 9999 ;
3737 private static final String APP_HOST = "app" ;
3838
39+ // key/trust stores passwords
40+ private static final String CLIENT_PASSWORD = "client" ;
41+ private static final String SERVER_PASSWORD = "server" ;
42+
3943 private static final Logger jmxScraperLogger = LoggerFactory .getLogger ("JmxScraperContainer" );
4044 private static final Logger appLogger = LoggerFactory .getLogger ("TestAppContainer" );
4145
@@ -90,27 +94,67 @@ private static void testServerSsl(Path tempDir, boolean sslRmiRegistry) {
9094 // server keystore with public/private key pair
9195 // client trust store with certificate from server
9296
93- String clientPassword = "client" ;
94- String serverPassword = "server" ;
95-
9697 Path serverKeystore = tempDir .resolve ("server.jks" );
97- Path clientKeystore = tempDir .resolve ("client.jks" );
98+ Path clientTrustStore = tempDir .resolve ("client.jks" );
9899
99- X509Certificate serverCertificate = createKeyStore (serverKeystore , serverPassword );
100+ X509Certificate serverCertificate = createKeyStore (serverKeystore , SERVER_PASSWORD );
100101
101- createKeyStore (clientKeystore , clientPassword );
102- addTrustedCertificate (clientKeystore , clientPassword , serverCertificate );
102+ createKeyStore (clientTrustStore , CLIENT_PASSWORD );
103+ addTrustedCertificate (clientTrustStore , CLIENT_PASSWORD , serverCertificate );
103104
104105 connectionTest (
105106 app ->
106107 (sslRmiRegistry ? app .withSslRmiRegistry (4242 ) : app )
107108 .withJmxPort (JMX_PORT )
108109 .withJmxSsl ()
109- .withKeyStore (serverKeystore , serverPassword ),
110+ .withKeyStore (serverKeystore , SERVER_PASSWORD ),
110111 scraper ->
111112 (sslRmiRegistry ? scraper .withSslRmiRegistry () : scraper )
112113 .withRmiServiceUrl (APP_HOST , JMX_PORT )
113- .withTrustStore (clientKeystore , clientPassword ));
114+ .withTrustStore (clientTrustStore , CLIENT_PASSWORD ));
115+ }
116+
117+ @ Test
118+ void serverSslClientSsl (@ TempDir Path tempDir ) {
119+ // Note: this could have been made simpler by relying on the fact that keystore could be used
120+ // as a trust store, but having clear split provides also some extra clarity
121+ //
122+ // 4 keystores:
123+ // server keystore with public/private key pair
124+ // server truststore with client certificate
125+ // client key store with public/private key pair
126+ // client trust store with certificate from server
127+
128+ Path serverKeystore = tempDir .resolve ("server-keystore.jks" );
129+ Path serverTrustStore = tempDir .resolve ("server-truststore.jks" );
130+
131+ X509Certificate serverCertificate = createKeyStore (serverKeystore , SERVER_PASSWORD );
132+ createKeyStore (serverTrustStore , SERVER_PASSWORD );
133+
134+ Path clientKeystore = tempDir .resolve ("client-keystore.jks" );
135+ Path clientTrustStore = tempDir .resolve ("client-truststore.jks" );
136+
137+ X509Certificate clientCertificate = createKeyStore (clientKeystore , CLIENT_PASSWORD );
138+ createKeyStore (clientTrustStore , CLIENT_PASSWORD );
139+
140+ // adding certificates in trust stores
141+ addTrustedCertificate (serverTrustStore , SERVER_PASSWORD , clientCertificate );
142+ addTrustedCertificate (clientTrustStore , CLIENT_PASSWORD , serverCertificate );
143+
144+ connectionTest (
145+ app ->
146+ app
147+ .withJmxPort (JMX_PORT )
148+ .withJmxSsl ()
149+ .withClientSslCertificate ()
150+ .withKeyStore (serverKeystore , SERVER_PASSWORD )
151+ .withTrustStore (serverTrustStore , SERVER_PASSWORD ),
152+ scraper ->
153+ scraper
154+ .withRmiServiceUrl (APP_HOST , JMX_PORT )
155+ .withKeyStore (clientKeystore , CLIENT_PASSWORD )
156+ .withTrustStore (clientTrustStore , CLIENT_PASSWORD )
157+ );
114158 }
115159
116160 private static void connectionTest (
0 commit comments