summaryrefslogtreecommitdiffstats
path: root/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java')
-rw-r--r--jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java64
1 files changed, 21 insertions, 43 deletions
diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java
index 787c976f6a0..21272f202ea 100644
--- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java
+++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/ssl/pem/PemKeyStore.java
@@ -2,6 +2,7 @@
package com.yahoo.jdisc.http.ssl.pem;
import com.google.common.base.Preconditions;
+import com.yahoo.jdisc.http.ssl.ReaderForPath;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
@@ -15,13 +16,9 @@ import javax.annotation.concurrent.GuardedBy;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.Reader;
-import java.io.UncheckedIOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.security.Key;
-import java.security.KeyStore;
import java.security.KeyStore.LoadStoreParameter;
+import java.security.KeyStore.ProtectionParameter;
import java.security.KeyStoreException;
import java.security.KeyStoreSpi;
import java.security.NoSuchAlgorithmException;
@@ -46,7 +43,7 @@ import static com.yahoo.jdisc.http.server.jetty.Exceptions.throwUnchecked;
* @author Tony Vaagenes
* @author bjorncs
*/
-class PemKeyStore extends KeyStoreSpi {
+public class PemKeyStore extends KeyStoreSpi {
private static String KEY_ALIAS = "KEY";
@@ -61,7 +58,9 @@ class PemKeyStore extends KeyStoreSpi {
@GuardedBy("this")
private final Map<String, Certificate> aliasToCertificate = new LinkedHashMap<>();
- PemKeyStore() {}
+
+ public PemKeyStore() {}
+
/**
* The user is responsible for closing any readers given in the parameter.
@@ -288,51 +287,30 @@ class PemKeyStore extends KeyStoreSpi {
}
}
- // A reader along with the path used to construct it.
- private static class ReaderForPath {
- final Reader reader;
- final Path path;
-
- private ReaderForPath(Reader reader, Path path) {
- this.reader = reader;
- this.path = path;
- }
-
- static ReaderForPath of(Path path) {
- try {
- return new ReaderForPath(Files.newBufferedReader(path), path);
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
- }
-
- static class TrustStoreLoadParameter implements KeyStore.LoadStoreParameter {
- final ReaderForPath certificateReader;
-
- TrustStoreLoadParameter(Path certificateReader) {
- this.certificateReader = ReaderForPath.of(certificateReader);
- }
+ public static class PemLoadStoreParameter implements LoadStoreParameter {
+ private PemLoadStoreParameter() {}
@Override
- public KeyStore.ProtectionParameter getProtectionParameter() {
+ public ProtectionParameter getProtectionParameter() {
return null;
}
}
- static class KeyStoreLoadParameter implements KeyStore.LoadStoreParameter {
- final ReaderForPath certificateReader;
- final ReaderForPath keyReader;
+ public static final class KeyStoreLoadParameter extends PemLoadStoreParameter {
+ public final ReaderForPath certificateReader;
+ public final ReaderForPath keyReader;
- KeyStoreLoadParameter(Path certificateReader, Path keyReader) {
- this.certificateReader = ReaderForPath.of(certificateReader);
- this.keyReader = ReaderForPath.of(keyReader);
+ public KeyStoreLoadParameter(ReaderForPath certificateReader, ReaderForPath keyReader) {
+ this.certificateReader = certificateReader;
+ this.keyReader = keyReader;
}
+ }
- @Override
- public KeyStore.ProtectionParameter getProtectionParameter() {
- return null;
+ public static final class TrustStoreLoadParameter extends PemLoadStoreParameter {
+ public final ReaderForPath certificateReader;
+
+ public TrustStoreLoadParameter(ReaderForPath certificateReader) {
+ this.certificateReader = certificateReader;
}
}
-
}