From 4b857cd33dc0fd7c2c9f5b22c8abddf32c2aa62d Mon Sep 17 00:00:00 2001 From: Mikko Kauhanen Date: Wed, 4 Dec 2024 13:40:14 +0200 Subject: [PATCH] Add temp jks file checker --- .../processor/producer/JksFileChecker.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 aoe-data-analytics/service-etl-processor/src/main/java/fi/csc/processor/producer/JksFileChecker.java diff --git a/aoe-data-analytics/service-etl-processor/src/main/java/fi/csc/processor/producer/JksFileChecker.java b/aoe-data-analytics/service-etl-processor/src/main/java/fi/csc/processor/producer/JksFileChecker.java new file mode 100644 index 00000000..a100502e --- /dev/null +++ b/aoe-data-analytics/service-etl-processor/src/main/java/fi/csc/processor/producer/JksFileChecker.java @@ -0,0 +1,44 @@ +package fi.csc.processor.producer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.io.FileInputStream; +import java.security.KeyStore; +import java.util.Enumeration; + +@Component +public class JksFileChecker implements CommandLineRunner { + + private static final Logger LOG = LoggerFactory.getLogger(JksFileChecker.class.getSimpleName()); + + + @Override + public void run(String... args) throws Exception { + String trustStorePath = System.getProperty("javax.net.ssl.trustStore"); + String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword"); + + if (trustStorePath == null || trustStorePassword == null) { + LOG.error("TrustStore properties are not set!"); + return; + } + + try (FileInputStream trustStoreStream = new FileInputStream(trustStorePath)) { + KeyStore trustStore = KeyStore.getInstance("JKS"); + trustStore.load(trustStoreStream, trustStorePassword.toCharArray()); + + LOG.info("JKS file loaded successfully!"); + LOG.info("Aliases in the JKS:"); + + Enumeration aliases = trustStore.aliases(); + while (aliases.hasMoreElements()) { + System.out.println(" - " + aliases.nextElement()); + } + } catch (Exception e) { + LOG.error("Failed to load JKS file: " + e.getMessage()); + e.printStackTrace(); + } + } +} \ No newline at end of file