Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,32 +338,11 @@ private SSLEngine createEngine(boolean isClient, ByteBufAllocator allocator) {
return engine;
}

private static TrustManager[] credulousTrustStoreManagers() {
return new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {
}

@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
throws CertificateException {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}};
}

private static TrustManager[] trustStoreManagers(
File trustStore, String trustStorePassword,
boolean trustStoreReloadingEnabled, int trustStoreReloadIntervalMs)
throws IOException, GeneralSecurityException {
if (trustStore == null || !trustStore.exists()) {
return credulousTrustStoreManagers();
} else {
if (trustStore != null && trustStore.exists()) {
if (trustStoreReloadingEnabled) {
ReloadingX509TrustManager reloading = new ReloadingX509TrustManager(
KeyStore.getDefaultType(), trustStore, trustStorePassword, trustStoreReloadIntervalMs);
Expand All @@ -372,6 +351,12 @@ private static TrustManager[] trustStoreManagers(
} else {
return defaultTrustManagers(trustStore, trustStorePassword);
}
} else {
// Use the system default TrustManager instead of a "trust-all" implementation
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmf.init((KeyStore) null);
return tmf.getTrustManagers();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ public void testKeyAndKeystorePasswordsAreDistinct() throws Exception {
factory.createSSLEngine(true, ByteBufAllocator.DEFAULT);
});
}

@Test
public void testBuildWithoutTrustStoreUsesSystemDefault() throws Exception {
// Should not throw exception and should not use credulous managers
SSLFactory factory = new SSLFactory.Builder()
.requestedProtocol("TLSv1.3")
.keyStore(new File(SslSampleConfigs.keyStorePath), "password")
.build();
assertNotNull(factory.createSSLEngine(true, ByteBufAllocator.DEFAULT));
}
}