Skip to content

Commit 379b4d1

Browse files
committed
SEC-1473 Allow no Truststore password
1 parent 1a1d53b commit 379b4d1

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

core/src/main/java/io/confluent/rest/Application.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,9 @@ public void join() throws InterruptedException {
602602
* @throws Exception If the application fails to stop
603603
*/
604604
public void stop() throws Exception {
605-
server.stop();
605+
if (server != null) {
606+
server.stop();
607+
}
606608
}
607609

608610
final void doShutdown() {

core/src/main/java/io/confluent/rest/ApplicationServer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ private Path getWatchLocation(RestConfig config) {
283283
return keystorePath;
284284
}
285285

286+
// CHECKSTYLE_RULES.OFF: CyclomaticComplexity|NPathComplexity
286287
private SslContextFactory createSslContextFactory(RestConfig config) {
288+
// CHECKSTYLE_RULES.ON: CyclomaticComplexity|NPathComplexity
287289
SslContextFactory sslContextFactory = new SslContextFactory.Server();
288290
if (!config.getString(RestConfig.SSL_KEYSTORE_LOCATION_CONFIG).isEmpty()) {
289291
sslContextFactory.setKeyStorePath(
@@ -341,9 +343,11 @@ private SslContextFactory createSslContextFactory(RestConfig config) {
341343
sslContextFactory.setTrustStorePath(
342344
config.getString(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG)
343345
);
344-
sslContextFactory.setTrustStorePassword(
345-
config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG).value()
346-
);
346+
if (config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG) != null) {
347+
sslContextFactory.setTrustStorePassword(
348+
config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG).value()
349+
);
350+
}
347351
sslContextFactory.setTrustStoreType(
348352
config.getString(RestConfig.SSL_TRUSTSTORE_TYPE_CONFIG)
349353
);

core/src/main/java/io/confluent/rest/RestConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public class RestConfig extends AbstractConfig {
168168
public static final String SSL_TRUSTSTORE_PASSWORD_CONFIG = "ssl.truststore.password";
169169
protected static final String SSL_TRUSTSTORE_PASSWORD_DOC =
170170
"The store password for the trust store file.";
171-
protected static final String SSL_TRUSTSTORE_PASSWORD_DEFAULT = "";
171+
protected static final String SSL_TRUSTSTORE_PASSWORD_DEFAULT = null;
172172
public static final String SSL_TRUSTSTORE_TYPE_CONFIG = "ssl.truststore.type";
173173
protected static final String SSL_TRUSTSTORE_TYPE_DOC =
174174
"The type of trust store file.";

core/src/test/java/io/confluent/rest/SslTest.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050
import javax.net.ssl.SSLContext;
5151
import javax.net.ssl.SSLException;
52-
import javax.net.ssl.SSLHandshakeException;
5352
import javax.ws.rs.GET;
5453
import javax.ws.rs.Path;
5554
import javax.ws.rs.Produces;
@@ -73,7 +72,7 @@ public class SslTest {
7372

7473
public static final String SSL_PASSWORD = "test1234";
7574
public static final String EXPECTED_200_MSG = "Response status must be 200.";
76-
public static final int CERT_RELOAD_WAIT_TIME = 20000;
75+
public static final int CERT_RELOAD_WAIT_TIME = 30000;
7776

7877
@Before
7978
public void setUp() throws Exception {
@@ -116,6 +115,15 @@ private void configServerTruststore(Properties props) {
116115
props.put(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG, SSL_PASSWORD);
117116
}
118117

118+
private void configServerTruststore(Properties props, String password) {
119+
props.put(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStore.getAbsolutePath());
120+
props.put(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG, password);
121+
}
122+
123+
private void configServerNoTruststorePassword(Properties props) {
124+
props.put(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStore.getAbsolutePath());
125+
}
126+
119127
private void enableSslClientAuth(Properties props) {
120128
props.put(RestConfig.SSL_CLIENT_AUTH_CONFIG, true);
121129
}
@@ -271,6 +279,45 @@ public void testHttpsWithNoClientCertAndNoServerTruststore() throws Exception {
271279
}
272280
}
273281

282+
@Test(expected = IOException.class)
283+
public void testHttpsWithEmptyStringTruststorePassword() throws Exception {
284+
Properties props = new Properties();
285+
String uri = "https://localhost:8080";
286+
props.put(RestConfig.LISTENERS_CONFIG, uri);
287+
configServerKeystore(props);
288+
configServerTruststore(props, "");
289+
TestRestConfig config = new TestRestConfig(props);
290+
SslTestApplication app = new SslTestApplication(config);
291+
try {
292+
// Empty string is a valid password, but it's not the password the truststore uses
293+
// The app should fail at startup with:
294+
// java.io.IOException: Keystore was tampered with, or password was incorrect
295+
app.start();
296+
} finally {
297+
app.stop();
298+
}
299+
}
300+
301+
@Test
302+
public void testHttpsWithNoTruststorePassword() throws Exception {
303+
Properties props = new Properties();
304+
String uri = "https://localhost:8080";
305+
props.put(RestConfig.LISTENERS_CONFIG, uri);
306+
configServerKeystore(props);
307+
configServerNoTruststorePassword(props);
308+
TestRestConfig config = new TestRestConfig(props);
309+
SslTestApplication app = new SslTestApplication(config);
310+
try {
311+
// With no password set (null), verification of the truststore is disabled
312+
app.start();
313+
314+
int statusCode = makeGetRequest(uri + "/test");
315+
assertEquals(EXPECTED_200_MSG, 200, statusCode);
316+
} finally {
317+
app.stop();
318+
}
319+
}
320+
274321
@Test(expected = SocketException.class)
275322
public void testHttpsWithAuthAndBadClientCert() throws Exception {
276323
Properties props = new Properties();

0 commit comments

Comments
 (0)