From 919869b33bcc33d40865ce585e52bea1897cb598 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 27 Jun 2024 12:56:25 +0200 Subject: [PATCH] fix trustore --- .../iot/cygnus/backends/mongo/MongoBackendImpl.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java index 7f45db7c1..d324e6b7a 100644 --- a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java +++ b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java @@ -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);