Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly install default ssl socket factory when no key or trust store #13589

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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 @@ -29,6 +29,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -60,6 +61,7 @@ public final class TlsUtils {
private static final String TRUSTSTORE_PATH = "truststore.path";
private static final String TRUSTSTORE_PASSWORD = "truststore.password";
private static final String SSL_PROVIDER = "ssl.provider";
private static final String SSL_CONTEXT_PROTOCOL = "SSL";

private static final String FILE_SCHEME = "file";
private static final String FILE_SCHEME_PREFIX = FILE_SCHEME + "://";
Expand Down Expand Up @@ -227,19 +229,28 @@ public static void installDefaultSSLSocketFactory(String keyStoreType, String ke
String trustStoreType, String trustStorePath, String trustStorePassword) {
try {
SecureRandom secureRandom = new SecureRandom();
SSLFactory sslFactory = RenewableTlsUtils.createSSLFactory(keyStoreType, keyStorePath, keyStorePassword,
trustStoreType, trustStorePath, trustStorePassword,
"SSL", secureRandom, true, false);
if (isKeyOrTrustStorePathNullOrHasFileScheme(keyStorePath)
&& isKeyOrTrustStorePathNullOrHasFileScheme(trustStorePath)) {
RenewableTlsUtils.enableAutoRenewalFromFileStoreForSSLFactory(sslFactory, keyStoreType, keyStorePath,
keyStorePassword, trustStoreType, trustStorePath, trustStorePassword, "SSL", secureRandom,
PinotInsecureMode::isPinotInInsecureMode);
SSLContext sc;
if (keyStorePath == null && trustStorePath == null) {
// When neither keyStorePath nor trustStorePath is provided, a SSLFactory cannot be created. create SSLContext
// directly and use the default key manager and trust manager.
sc = SSLContext.getInstance(SSL_CONTEXT_PROTOCOL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed to be not null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the protocol SSL is valid, so SSLContext.getInstance(SSL_CONTEXT_PROTOCOL) is guaranteed to be not null

sc.init(null, null, secureRandom);
} else {
SSLFactory sslFactory =
RenewableTlsUtils.createSSLFactory(keyStoreType, keyStorePath, keyStorePassword, trustStoreType,
trustStorePath, trustStorePassword, SSL_CONTEXT_PROTOCOL, secureRandom, true, false);
if (isKeyOrTrustStorePathNullOrHasFileScheme(keyStorePath) && isKeyOrTrustStorePathNullOrHasFileScheme(
trustStorePath)) {
RenewableTlsUtils.enableAutoRenewalFromFileStoreForSSLFactory(sslFactory, keyStoreType, keyStorePath,
keyStorePassword, trustStoreType, trustStorePath, trustStorePassword, SSL_CONTEXT_PROTOCOL, secureRandom,
PinotInsecureMode::isPinotInInsecureMode);
}
sc = sslFactory.getSslContext();
}
// HttpsURLConnection
HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory.getSslSocketFactory());
setSslContext(sslFactory.getSslContext());
} catch (GenericSSLContextException e) {
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
setSslContext(sc);
} catch (GenericSSLContextException | GeneralSecurityException e) {
throw new IllegalStateException("Could not initialize SSL support", e);
}
}
Expand Down
Loading
Loading