Skip to content

Commit 63f276a

Browse files
author
Marcus Linke
committed
Fix load certs from file system
1 parent 4f11537 commit 63f276a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/main/java/com/github/dockerjava/core/LocalDirectorySSLConfig.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import static com.google.common.base.Preconditions.checkNotNull;
44

5+
import java.io.File;
56
import java.io.Serializable;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
69
import java.security.Security;
710

811
import javax.net.ssl.SSLContext;
@@ -50,9 +53,17 @@ public SSLContext getSSLContext() {
5053
System.setProperty("https.protocols", httpProtocols);
5154
}
5255

53-
sslConfig.keyStore(CertificateUtils.createKeyStore(dockerCertPath));
56+
String caPemPath = dockerCertPath + File.separator + "ca.pem";
57+
String keyPemPath = dockerCertPath + File.separator + "key.pem";
58+
String certPemPath = dockerCertPath + File.separator + "cert.pem";
59+
60+
String keypem = new String(Files.readAllBytes(Paths.get(keyPemPath)));
61+
String certpem = new String(Files.readAllBytes(Paths.get(certPemPath)));
62+
String capem = new String(Files.readAllBytes(Paths.get(caPemPath)));
63+
64+
sslConfig.keyStore(CertificateUtils.createKeyStore(keypem, certpem));
5465
sslConfig.keyStorePassword("docker");
55-
sslConfig.trustStore(CertificateUtils.createTrustStore(dockerCertPath));
66+
sslConfig.trustStore(CertificateUtils.createTrustStore(capem));
5667

5768
return sslConfig.createSSLContext();
5869

src/main/java/com/github/dockerjava/core/util/CertificateUtils.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919

2020
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
21+
2122
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
2223
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
2324
import org.bouncycastle.cert.X509CertificateHolder;
@@ -49,15 +50,6 @@ public static boolean verifyCertificatesExist(String dockerCertPath) {
4950
return result;
5051
}
5152

52-
/**
53-
* @param dockerCertPath with standard named files.
54-
*/
55-
public static KeyStore createKeyStore(final String dockerCertPath) throws NoSuchAlgorithmException,
56-
InvalidKeySpecException, IOException, CertificateException, KeyStoreException {
57-
return createKeyStore("key.pem", "cert.pem");
58-
}
59-
60-
6153
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
6254
public static KeyStore createKeyStore(final String keypem, final String certpem) throws NoSuchAlgorithmException,
6355
InvalidKeySpecException, IOException, CertificateException, KeyStoreException {

0 commit comments

Comments
 (0)