Skip to content

Commit ef4e197

Browse files
author
Marcus Linke
committed
Fixed ssl configuration for java 1.6
1 parent d669f20 commit ef4e197

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.github.dockerjava.core;
22

33
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
46
import java.io.IOException;
5-
import java.nio.charset.Charset;
6-
import java.nio.file.Files;
7-
import java.nio.file.Path;
8-
import java.nio.file.Paths;
7+
98
import java.security.KeyFactory;
109
import java.security.KeyPair;
1110
import java.security.KeyStore;
@@ -30,8 +29,8 @@ public class CertificateUtils {
3029
public static boolean verifyCertificatesExist(String dockerCertPath) {
3130
String[] files = {"ca.pem", "cert.pem", "key.pem"};
3231
for (String file : files) {
33-
Path path = Paths.get(dockerCertPath, file);
34-
boolean exists = Files.exists(path);
32+
File path = new File(dockerCertPath, file);
33+
boolean exists = path.exists();
3534
if(!exists) {
3635
return false;
3736
}
@@ -52,8 +51,8 @@ public static KeyStore createKeyStore(final String dockerCertPath) throws NoSuch
5251
}
5352

5453
public static KeyStore createTrustStore(final String dockerCertPath) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
55-
Path caPath = Paths.get(dockerCertPath, "ca.pem");
56-
BufferedReader reader = Files.newBufferedReader(caPath, Charset.defaultCharset());
54+
File caPath = new File(dockerCertPath, "ca.pem");
55+
BufferedReader reader = new BufferedReader(new FileReader(caPath));
5756
PEMParser pemParser = null;
5857

5958
try {
@@ -80,8 +79,8 @@ public static KeyStore createTrustStore(final String dockerCertPath) throws IOEx
8079
}
8180

8281
private static Certificate loadCertificate(final String dockerCertPath) throws IOException, CertificateException {
83-
Path certificate = Paths.get(dockerCertPath, "cert.pem");
84-
BufferedReader reader = Files.newBufferedReader(certificate, Charset.defaultCharset());
82+
File certificate = new File(dockerCertPath, "cert.pem");
83+
BufferedReader reader = new BufferedReader(new FileReader(certificate));
8584
PEMParser pemParser = null;
8685

8786
try {
@@ -102,8 +101,8 @@ private static Certificate loadCertificate(final String dockerCertPath) throws I
102101
}
103102

104103
private static KeyPair loadPrivateKey(final String dockerCertPath) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
105-
Path certificate = Paths.get(dockerCertPath, "key.pem");
106-
BufferedReader reader = Files.newBufferedReader(certificate, Charset.defaultCharset());
104+
File certificate = new File(dockerCertPath, "key.pem");
105+
BufferedReader reader = new BufferedReader(new FileReader(certificate));
107106

108107
PEMParser pemParser = null;
109108

src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ public void init(DockerClientConfig dockerClientConfig) {
112112

113113
Security.addProvider(new BouncyCastleProvider());
114114

115-
SslConfigurator sslConfig = SslConfigurator.newInstance();
116-
117115
KeyStore keyStore = CertificateUtils.createKeyStore(dockerCertPath);
118116
KeyStore trustStore = CertificateUtils.createTrustStore(dockerCertPath);
119-
117+
118+
// properties acrobatics not needed for java > 1.6
119+
String httpProtocols = System.getProperty("https.protocols");
120+
System.setProperty("https.protocols", "TLSv1");
121+
SslConfigurator sslConfig = SslConfigurator.newInstance(true);
122+
if(httpProtocols != null ) System.setProperty("https.protocols", httpProtocols);
123+
120124
sslConfig.keyStore(keyStore);
121125
sslConfig.keyStorePassword("docker");
122-
123126
sslConfig.trustStore(trustStore);
124127

125128
SSLContext sslContext = sslConfig.createSSLContext();
129+
130+
126131
clientBuilder.sslContext(sslContext);
127132

128133
}

src/test/java/com/github/dockerjava/api/model/AccessModeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void fromString() {
2323
}
2424

2525
@Test(expectedExceptions = IllegalArgumentException.class,
26-
expectedExceptionsMessageRegExp = "No enum constant.*")
26+
expectedExceptionsMessageRegExp = "No enum const.*")
2727
public void fromIllegalString() {
2828
AccessMode.valueOf("xx");
2929
}

src/test/java/com/github/dockerjava/core/command/EventsCmdImplTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public void testEventStreamTimeBound() throws InterruptedException, IOException
6767
boolean zeroCount = countDownLatch.await(5, TimeUnit.SECONDS);
6868

6969
executorService.shutdown();
70+
71+
7072
assertTrue(zeroCount, "Expected 4 events, [create, start, die, stop]");
7173
}
7274

src/test/java/com/github/dockerjava/core/command/PullImageCmdImplTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.github.dockerjava.api.DockerException;
2020
import com.github.dockerjava.api.InternalServerErrorException;
21+
import com.github.dockerjava.api.NotFoundException;
2122
import com.github.dockerjava.api.command.InspectImageResponse;
2223
import com.github.dockerjava.api.model.Info;
2324
import com.github.dockerjava.client.AbstractDockerClientTest;
@@ -61,7 +62,13 @@ public void testPullImage() throws DockerException, IOException {
6162
String testImage = "hackmann/empty";
6263

6364
LOG.info("Removing image: {}", testImage);
64-
dockerClient.removeImageCmd(testImage).exec();
65+
66+
try {
67+
dockerClient.removeImageCmd(testImage).exec();
68+
} catch (NotFoundException e) {
69+
// just ignore if not exist
70+
}
71+
6572

6673
info = dockerClient.infoCmd().exec();
6774
LOG.info("Client info: {}", info.toString());

src/test/java/com/github/dockerjava/core/command/WaitContainerCmdImplTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.github.dockerjava.api.DockerException;
1919
import com.github.dockerjava.api.InternalServerErrorException;
20+
import com.github.dockerjava.api.NotFoundException;
2021
import com.github.dockerjava.api.command.CreateContainerResponse;
2122
import com.github.dockerjava.api.command.InspectContainerResponse;
2223
import com.github.dockerjava.client.AbstractDockerClientTest;
@@ -70,12 +71,10 @@ public void testWaitContainer() throws DockerException {
7071

7172
@Test
7273
public void testWaitNonExistingContainer() throws DockerException {
73-
// docker returns InternalServerError instead of NotFound
74-
// see https://github.com/docker/docker/issues/8107
7574
try {
7675
dockerClient.waitContainerCmd("non-existing").exec();
77-
fail("expected InternalServerErrorException");
78-
} catch (InternalServerErrorException e) {
76+
fail("expected NotFoundException");
77+
} catch (NotFoundException e) {
7978
}
8079
}
8180
}

0 commit comments

Comments
 (0)