Skip to content

Commit

Permalink
log x509 cert
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Jun 27, 2024
1 parent f6df99b commit 220bb52
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,23 +611,22 @@ private MongoDatabase getDatabase(String dbName) {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
if ((sslKeystorePathFile != null) && !sslKeystorePathFile.isEmpty()) {
try (InputStream keyStoreStream = new FileInputStream(sslKeystorePathFile)) {
InputStream keyStoreStream = new FileInputStream(sslKeystorePathFile);
keyStore.load(keyStoreStream, sslKeystorePassword.toCharArray());
}
} else {
keyStore.load(null);
}
if ((sslCAPathFile != null) && !sslCAPathFile.isEmpty()) {
try (InputStream trustStoreStream = new FileInputStream(sslCAPathFile)) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate caCert = (X509Certificate) cf.generateCertificate(trustStoreStream);
keyStore.setCertificateEntry("caCert", caCert);
}
InputStream caStream = new FileInputStream(sslCAPathFile);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate caCert = (X509Certificate) cf.generateCertificate(caStream);
LOGGER.debug("CA subjectDN: " + caCert.getSubjectDN());
keyStore.setCertificateEntry("caCert", caCert);
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
} catch (Exception e) {
LOGGER.warn("Error when init SSL Context: " + e.getMessage());
}
Expand Down

0 comments on commit 220bb52

Please sign in to comment.