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

Handling issue where keystore file is empty for MongoDB SSL #27250

Merged
merged 1 commit into from
Jun 26, 2023
Merged
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 @@ -25,9 +25,12 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.beam.sdk.util.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Utility class for registration of ssl context, and to allow all certificate requests. */
class SSLUtils {
private static final Logger LOG = LoggerFactory.getLogger(SSLUtils.class);

/** static class to allow all requests. */
private static final TrustManager[] trustAllCerts =
Expand Down Expand Up @@ -62,11 +65,15 @@ static SSLContext ignoreSSLCertificate() {
ClassLoader classLoader =
Preconditions.checkStateNotNull(
SSLUtils.class.getClassLoader(), "SSLUtil classloader is null - boot classloader?");
InputStream inputStream =
Preconditions.checkStateNotNull(
classLoader.getResourceAsStream("resources/.keystore"),
"resources/.keystore not found");
ks.load(inputStream, "changeit".toCharArray());
InputStream inputStream = classLoader.getResourceAsStream("resources/.keystore");
if (inputStream != null) {
LOG.info("Found keystore in classpath 'resources/.keystore'. Loading...");
ks.load(inputStream, "changeit".toCharArray());
} else {
LOG.info(
"Unable to find keystore under 'resources/.keystore' in the classpath. "
+ "Continuing with an empty keystore.");
}
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, "changeit".toCharArray());
Expand Down