Skip to content

Commit bd14613

Browse files
committed
SEC-1473 Allow no Truststore password
1 parent 933410e commit bd14613

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
@@ -545,7 +545,9 @@ public void join() throws InterruptedException {
545545
* @throws Exception If the application fails to stop
546546
*/
547547
public void stop() throws Exception {
548-
server.stop();
548+
if (server != null) {
549+
server.stop();
550+
}
549551
}
550552

551553
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
@@ -243,7 +243,9 @@ private Path getWatchLocation(RestConfig config) {
243243
return keystorePath;
244244
}
245245

246+
// CHECKSTYLE_RULES.OFF: CyclomaticComplexity|NPathComplexity
246247
private SslContextFactory createSslContextFactory(RestConfig config) {
248+
// CHECKSTYLE_RULES.ON: CyclomaticComplexity|NPathComplexity
247249
SslContextFactory sslContextFactory = new SslContextFactory.Server();
248250
if (!config.getString(RestConfig.SSL_KEYSTORE_LOCATION_CONFIG).isEmpty()) {
249251
sslContextFactory.setKeyStorePath(
@@ -301,9 +303,11 @@ private SslContextFactory createSslContextFactory(RestConfig config) {
301303
sslContextFactory.setTrustStorePath(
302304
config.getString(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG)
303305
);
304-
sslContextFactory.setTrustStorePassword(
305-
config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG).value()
306-
);
306+
if (config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG) != null) {
307+
sslContextFactory.setTrustStorePassword(
308+
config.getPassword(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG).value()
309+
);
310+
}
307311
sslContextFactory.setTrustStoreType(
308312
config.getString(RestConfig.SSL_TRUSTSTORE_TYPE_CONFIG)
309313
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public class RestConfig extends AbstractConfig {
161161
public static final String SSL_TRUSTSTORE_PASSWORD_CONFIG = "ssl.truststore.password";
162162
protected static final String SSL_TRUSTSTORE_PASSWORD_DOC =
163163
"The store password for the trust store file.";
164-
protected static final String SSL_TRUSTSTORE_PASSWORD_DEFAULT = "";
164+
protected static final String SSL_TRUSTSTORE_PASSWORD_DEFAULT = null;
165165
public static final String SSL_TRUSTSTORE_TYPE_CONFIG = "ssl.truststore.type";
166166
protected static final String SSL_TRUSTSTORE_TYPE_DOC =
167167
"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)