Skip to content

Commit

Permalink
ARTEMIS-4266 mitigate NPE with bad SSL config
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and brusdev committed May 3, 2023
1 parent 3109568 commit dc0b3ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ private void checkSSLConfiguration() throws IllegalArgumentException {
if (configuration.containsKey(TransportConstants.SSL_CONTEXT_PROP_NAME)) {
return;
}
if (keyStorePath == null && TransportConstants.DEFAULT_KEYSTORE_PROVIDER.equals(keyStoreProvider)) {
if (keyStorePath == null && keyStoreProvider == null) {
throw new IllegalArgumentException("If \"" + TransportConstants.SSL_ENABLED_PROP_NAME + "\" is true then \"" + TransportConstants.KEYSTORE_PATH_PROP_NAME + "\" must be non-null unless an alternative \"" + TransportConstants.KEYSTORE_PROVIDER_PROP_NAME + "\" has been specified.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,33 @@ public void testActualPort() throws Exception {
Wait.assertEquals(61616, () -> server.getRemotingService().getAcceptor(normal).getActualPort());
Wait.assertEquals(-1, () -> server.getRemotingService().getAcceptor(invm).getActualPort());
}

@Test
public void testInvalidSSLConfig() {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, "true");

try {
new NettyAcceptor("netty", null, params, null, null, null, null, Map.of());
fail("This should have failed with an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
}

@Test
public void testValidSSLConfig1() {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, "true");
params.put(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME, RandomUtil.randomString());
new NettyAcceptor("netty", null, params, null, null, null, null, Map.of());
}

@Test
public void testValidSSLConfig2() {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, "true");
params.put(TransportConstants.SSL_CONTEXT_PROP_NAME, RandomUtil.randomString());
new NettyAcceptor("netty", null, params, null, null, null, null, Map.of());
}
}

0 comments on commit dc0b3ac

Please sign in to comment.