Skip to content

Commit

Permalink
Merge pull request #2390 from telefonicaid/task/fix_trustore
Browse files Browse the repository at this point in the history
fix trustore
  • Loading branch information
fgalan authored Jun 27, 2024
2 parents f2f771d + 919869b commit 45972de
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,21 +613,15 @@ private MongoDatabase getDatabase(String dbName) {
if (sslEnabled) {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
KeyStore trustStore = 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 ((sslTruststorePathFile != null) && !sslTruststorePathFile.isEmpty()) {
try (InputStream trustStoreStream = new FileInputStream(sslTruststorePathFile)) {
trustStore.load(trustStoreStream, sslTruststorePassword.toCharArray());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate caCert = (X509Certificate) cf.generateCertificate(trustStoreStream);
keyStore.setCertificateEntry("caCert", caCert);
}
InputStream trustStoreStream = new FileInputStream(sslTruststorePathFile);
keyStore.load(trustStoreStream, sslTruststorePassword.toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
Expand Down

0 comments on commit 45972de

Please sign in to comment.