From a2c0fa6f9ccefd3d1b088c51d0b8170cfb59a885 Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Mon, 20 Nov 2023 17:47:48 +0000 Subject: [PATCH] 8320372: test/jdk/sun/security/x509/DNSName/LeadingPeriod.java validity check failed Reviewed-by: alanb --- .../security/x509/DNSName/LeadingPeriod.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/jdk/sun/security/x509/DNSName/LeadingPeriod.java b/test/jdk/sun/security/x509/DNSName/LeadingPeriod.java index 50ce8e4b7ad..a293e5360a9 100644 --- a/test/jdk/sun/security/x509/DNSName/LeadingPeriod.java +++ b/test/jdk/sun/security/x509/DNSName/LeadingPeriod.java @@ -38,8 +38,8 @@ import java.security.cert.*; public class LeadingPeriod { - private static CertPath makeCertPath(String caStr, String targetCertStr) - throws CertificateException { + private static CertPath makeCertPath(String targetCertStr, + PKIXParameters params) throws CertificateException { // generate certificate from cert strings CertificateFactory cf = CertificateFactory.getInstance("X.509"); @@ -47,12 +47,11 @@ public class LeadingPeriod { is = new ByteArrayInputStream(targetCertStr.getBytes()); Certificate targetCert = cf.generateCertificate(is); - - is = new ByteArrayInputStream(caStr.getBytes()); - Certificate ca = cf.generateCertificate(is); + // set validity date so that validation won't fail when cert expires + params.setDate(((X509Certificate)targetCert).getNotBefore()); // generate certification path - List list = List.of(targetCert, ca); + List list = List.of(targetCert); return cf.generateCertPath(list); } @@ -91,8 +90,8 @@ public class LeadingPeriod { String caWithoutLeadingPeriod = Files.readString(caWithoutLeadingPeriodPath); PKIXParameters paramsForCAWithoutLeadingPeriod = genParams(caWithoutLeadingPeriod); - CertPath pathWithoutLeadingPeriod = makeCertPath(caWithoutLeadingPeriod, - targetFromCAWithoutPeriod); + CertPath pathWithoutLeadingPeriod = makeCertPath( + targetFromCAWithoutPeriod, paramsForCAWithoutLeadingPeriod); validator.validate(pathWithoutLeadingPeriod, paramsForCAWithoutLeadingPeriod); @@ -106,8 +105,8 @@ public class LeadingPeriod { String caWithLeadingPeriod = Files.readString(caWithLeadingPeriodPath); PKIXParameters paramsForCAWithLeadingPeriod = genParams(caWithLeadingPeriod); - CertPath pathWithLeadingPeriod = makeCertPath(caWithLeadingPeriod, targetFromCAWithPeriod); + CertPath pathWithLeadingPeriod = makeCertPath(targetFromCAWithPeriod, paramsForCAWithLeadingPeriod); validator.validate(pathWithLeadingPeriod, paramsForCAWithLeadingPeriod); } -} \ No newline at end of file +}