Skip to content

Commit 00cf424

Browse files
committed
8287109: Distrust.java failed with CertificateExpiredException
Backport-of: 5b7d066ca5cb68e07a704d3ce13283761c1cf3ad
1 parent d87927d commit 00cf424

File tree

4 files changed

+24
-152
lines changed

4 files changed

+24
-152
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,6 @@ sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-
688688
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
689689
sun/security/ssl/SSLSessionImpl/NoInvalidateSocketException.java 8277970 linux-all,macosx-x64
690690

691-
sun/security/ssl/X509TrustManagerImpl/Symantec/Distrust.java 8287109 generic-all
692-
693691
############################################################################
694692

695693
# jdk_sound

test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/Distrust.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,15 +54,14 @@ public class Distrust {
5454
// Each of the roots have a test certificate chain stored in a file
5555
// named "<root>-chain.pem".
5656
private static String[] rootsToTest = new String[] {
57-
"geotrustglobalca", "geotrustprimarycag2", "geotrustprimarycag3",
57+
"geotrustprimarycag2", "geotrustprimarycag3",
5858
"geotrustuniversalca", "thawteprimaryrootca", "thawteprimaryrootcag2",
5959
"thawteprimaryrootcag3", "verisignclass3g3ca", "verisignclass3g4ca",
6060
"verisignclass3g5ca", "verisignuniversalrootca" };
6161

6262
// Each of the subCAs with a delayed distrust date have a test certificate
6363
// chain stored in a file named "<subCA>-chain.pem".
64-
private static String[] subCAsToTest = new String[] {
65-
"appleistca2g1", "appleistca8g1" };
64+
private static String[] subCAsToTest = new String[]{"appleistca8g1"};
6665

6766
// A date that is after the restrictions take affect
6867
private static final Date APRIL_17_2019 =
@@ -180,13 +179,19 @@ private static void testTM(X509TrustManager xtm, X509Certificate[] chain,
180179
throw new Exception("chain should be invalid");
181180
}
182181
} catch (CertificateException ce) {
182+
// expired TLS certificates should not be treated as failure
183+
if (expired(ce)) {
184+
System.err.println("Test is N/A, chain is expired");
185+
return;
186+
}
183187
if (valid) {
184188
throw new Exception("Unexpected exception, chain " +
185189
"should be valid", ce);
186190
}
187191
if (ce instanceof ValidatorException) {
188192
ValidatorException ve = (ValidatorException)ce;
189193
if (ve.getErrorType() != ValidatorException.T_UNTRUSTED_CERT) {
194+
ce.printStackTrace(System.err);
190195
throw new Exception("Unexpected exception: " + ce);
191196
}
192197
} else {
@@ -195,6 +200,21 @@ private static void testTM(X509TrustManager xtm, X509Certificate[] chain,
195200
}
196201
}
197202

203+
// check if a cause of exception is an expired cert
204+
private static boolean expired(CertificateException ce) {
205+
if (ce instanceof CertificateExpiredException) {
206+
return true;
207+
}
208+
Throwable t = ce.getCause();
209+
while (t != null) {
210+
if (t instanceof CertificateExpiredException) {
211+
return true;
212+
}
213+
t = t.getCause();
214+
}
215+
return false;
216+
}
217+
198218
private static X509Certificate[] loadCertificateChain(String name)
199219
throws Exception {
200220
try (InputStream in = new FileInputStream(TEST_SRC + File.separator +

test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/appleistca2g1-chain.pem

Lines changed: 0 additions & 80 deletions
This file was deleted.

test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustglobalca-chain.pem

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)