aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_http_service/src/test/java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2017-11-14 10:44:23 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2017-11-14 10:44:23 +0100
commitc0b972c26f5e3b201c363928197ca81b694552b2 (patch)
treef0590ba9b9129a4c9898b8e164acb385409b4703 /jdisc_http_service/src/test/java
parentfea33aaa04ad925e2af4387ec63f59f6d9531c3d (diff)
Move JksKeyStore to test source directory
Diffstat (limited to 'jdisc_http_service/src/test/java')
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/JksKeyStore.java47
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java2
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java2
3 files changed, 48 insertions, 3 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/JksKeyStore.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/JksKeyStore.java
new file mode 100644
index 00000000000..7e29e26b045
--- /dev/null
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/JksKeyStore.java
@@ -0,0 +1,47 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.http;
+
+import com.yahoo.jdisc.http.ssl.SslKeyStore;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+
+/**
+ * @author Tony Vaagenes
+ * @author bjorncs
+ */
+public class JksKeyStore implements SslKeyStore {
+
+ private static final String KEY_STORE_TYPE = "JKS";
+ private final Path keyStoreFile;
+ private final String keyStorePassword;
+
+ public JksKeyStore(Path keyStoreFile) {
+ this(keyStoreFile, null);
+ }
+
+ public JksKeyStore(Path keyStoreFile, String keyStorePassword) {
+ this.keyStoreFile = keyStoreFile;
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+ @Override
+ public KeyStore loadJavaKeyStore() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
+ try(InputStream stream = Files.newInputStream(keyStoreFile)) {
+ KeyStore keystore = KeyStore.getInstance(KEY_STORE_TYPE);
+ keystore.load(stream, keyStorePassword != null ? keyStorePassword.toCharArray() : null);
+ return keystore;
+ }
+ }
+
+}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java
index 5dd5dca1667..d86516df453 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java
@@ -1,8 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http;
-import com.yahoo.jdisc.http.ssl.jks.JksKeyStore;
-
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
index 525cde9d8b3..bcc23facd95 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
@@ -7,7 +7,7 @@ import com.yahoo.jdisc.application.ContainerBuilder;
import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.http.ConnectorConfig;
import com.yahoo.jdisc.http.SslContextFactory;
-import com.yahoo.jdisc.http.ssl.jks.JksKeyStore;
+import com.yahoo.jdisc.http.JksKeyStore;
import javax.net.ssl.SSLContext;
import java.io.IOException;