Skip to content

Commit 94f27ad

Browse files
authored
Merge pull request #46310 from ppalaga/i46309
Text cannot be parsed to a Duration when assessing TlsConfigurationRegistry.get("javax.net.ssl")
2 parents 213f178 + 9c716a3 commit 94f27ad

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

extensions/tls-registry/deployment/src/test/java/io/quarkus/tls/JavaNetSslTlsBucketConfigTest.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
68
import java.security.KeyStore;
79
import java.security.KeyStoreException;
810
import java.security.NoSuchAlgorithmException;
911
import java.security.cert.CertificateException;
1012
import java.security.cert.X509Certificate;
1113
import java.util.Collections;
1214
import java.util.List;
15+
import java.util.Locale;
1316
import java.util.stream.Collectors;
1417
import java.util.stream.Stream;
1518

@@ -26,10 +29,52 @@
2629
import io.quarkus.test.QuarkusUnitTest;
2730

2831
public class JavaNetSslTlsBucketConfigTest {
29-
3032
@RegisterExtension
31-
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer(
32-
() -> ShrinkWrap.create(JavaArchive.class));
33+
static final QuarkusUnitTest config = createConfig();
34+
35+
static QuarkusUnitTest createConfig() {
36+
final Path tsPath = defaultTrustStorePath();
37+
String tsType = System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType())
38+
.toLowerCase(Locale.US);
39+
if (tsType.equals("pkcs12")) {
40+
tsType = "p12";
41+
}
42+
final String password = System.getProperty("javax.net.ssl.trustStorePassword", "changeit");
43+
44+
return new QuarkusUnitTest()
45+
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
46+
.overrideConfigKey("quarkus.tls.javaNetSslLike.trust-store." + tsType + ".path", tsPath.toString())
47+
.overrideConfigKey("quarkus.tls.javaNetSslLike.trust-store." + tsType + ".password", password);
48+
49+
}
50+
51+
static Path defaultTrustStorePath() {
52+
final String rawTsPath = System.getProperty("javax.net.ssl.trustStore");
53+
if (rawTsPath != null && !rawTsPath.isEmpty()) {
54+
return Path.of(rawTsPath);
55+
}
56+
final String javaHome = System.getProperty("java.home");
57+
if (javaHome == null || javaHome.isEmpty()) {
58+
throw new IllegalStateException(
59+
"Could not locate the default Java truststore because the 'java.home' property is not set");
60+
}
61+
final Path javaHomePath = Path.of(javaHome);
62+
if (!Files.isDirectory(javaHomePath)) {
63+
throw new IllegalStateException("Could not locate the default Java truststore because the 'java.home' path '"
64+
+ javaHome + "' is not a directory");
65+
}
66+
final Path jssecacerts = javaHomePath.resolve("lib/security/jssecacerts");
67+
if (Files.isRegularFile(jssecacerts)) {
68+
return jssecacerts;
69+
}
70+
final Path cacerts = javaHomePath.resolve("lib/security/cacerts");
71+
if (Files.isRegularFile(cacerts)) {
72+
return cacerts;
73+
}
74+
throw new IllegalStateException(
75+
"Could not locate the default Java truststore. Tried javax.net.ssl.trustStore system property, " + jssecacerts
76+
+ " and " + cacerts);
77+
}
3378

3479
@Inject
3580
TlsConfigurationRegistry certificates;
@@ -82,4 +127,17 @@ void test() throws KeyStoreException, IOException, NoSuchAlgorithmException, Cer
82127
}
83128
}
84129
}
130+
131+
@Test
132+
void checkDefaults() {
133+
/*
134+
* The javaNetSslLike named TLS bucket mimics what JavaNetSslTlsBucketConfig does programmatically.
135+
* By asserting that their SSLOptions are equal, we make sure that all defaults set programmatically
136+
* in JavaNetSslTlsBucketConfig are in sync with @WithDefault values defined in TlsBucketConfig
137+
*/
138+
final TlsConfiguration javaNetSsl = certificates.get("javax.net.ssl").orElseThrow();
139+
final TlsConfiguration javaNetSslLike = certificates.get("javaNetSslLike").orElseThrow();
140+
assertThat(javaNetSsl.getSSLOptions()).isEqualTo(javaNetSslLike.getSSLOptions());
141+
142+
}
85143
}

extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/JavaNetSslTlsBucketConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public Set<String> protocols() {
121121

122122
@Override
123123
public Duration handshakeTimeout() {
124-
return Duration.parse("10S");
124+
return Duration.ofSeconds(10L);
125125
}
126126

127127
@Override

extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/ExpiryTrustOptions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.security.cert.CertificateExpiredException;
88
import java.security.cert.CertificateNotYetValidException;
99
import java.security.cert.X509Certificate;
10+
import java.util.Objects;
1011
import java.util.function.Function;
1112

1213
import javax.net.ssl.ManagerFactoryParameters;
@@ -148,4 +149,16 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
148149
return tm.getAcceptedIssuers();
149150
}
150151
}
152+
153+
@Override
154+
public boolean equals(Object obj) {
155+
if (this == obj)
156+
return true;
157+
if (obj != null && obj.getClass() == getClass()) {
158+
ExpiryTrustOptions that = (ExpiryTrustOptions) obj;
159+
return Objects.equals(delegate, that.delegate) &&
160+
Objects.equals(policy, that.policy);
161+
}
162+
return false;
163+
}
151164
}

0 commit comments

Comments
 (0)