aboutsummaryrefslogtreecommitdiffstats
path: root/zookeeper-common/src
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-12-13 15:16:27 +0100
committerjonmv <venstad@gmail.com>2023-12-14 15:29:22 +0100
commitcee303d96079ec1ba05f421ff2791105a8fc0ce4 (patch)
treea68d1387233d7ba58b49201fbe694d0651878ca0 /zookeeper-common/src
parentc6e17fe52ba4ce72d3014b0c04fe9dee073d61d7 (diff)
Look up TLS context directly in X509ClientUtil, which simplifies a lot!
Diffstat (limited to 'zookeeper-common/src')
-rw-r--r--zookeeper-common/src/main/java/com/yahoo/vespa/zookeeper/VespaZookeeperTlsContextUtils.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/zookeeper-common/src/main/java/com/yahoo/vespa/zookeeper/VespaZookeeperTlsContextUtils.java b/zookeeper-common/src/main/java/com/yahoo/vespa/zookeeper/VespaZookeeperTlsContextUtils.java
new file mode 100644
index 00000000000..493f80d2b40
--- /dev/null
+++ b/zookeeper-common/src/main/java/com/yahoo/vespa/zookeeper/VespaZookeeperTlsContextUtils.java
@@ -0,0 +1,26 @@
+package com.yahoo.vespa.zookeeper;
+
+import com.yahoo.security.tls.ConfigFileBasedTlsContext;
+import com.yahoo.security.tls.TlsContext;
+import com.yahoo.security.tls.TransportSecurityUtils;
+import com.yahoo.vespa.defaults.Defaults;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+
+/**
+ * @author jonmv
+ */
+public class VespaZookeeperTlsContextUtils {
+
+ private static final Path ZOOKEEPER_TLS_CONFIG_FILE = Path.of(Defaults.getDefaults().underVespaHome("var/zookeeper/conf/tls.conf.json"));
+ private static final TlsContext tlsContext = Files.exists(ZOOKEEPER_TLS_CONFIG_FILE)
+ ? new ConfigFileBasedTlsContext(ZOOKEEPER_TLS_CONFIG_FILE, TransportSecurityUtils.getInsecureAuthorizationMode())
+ : TransportSecurityUtils.getSystemTlsContext().orElse(null);
+
+ public static Optional<TlsContext> tlsContext() {
+ return Optional.ofNullable(tlsContext);
+ }
+
+}