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 +
0 commit comments