Skip to content

Commit

Permalink
Handling issue where keystore file is empty for MongoDB SSL (#27250)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloem authored Jun 26, 2023
1 parent a845d97 commit 975bef7
Showing 1 changed file with 12 additions and 5 deletions.
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

0 comments on commit 975bef7

Please sign in to comment.