From 100c50089945f5dcbb3a0d7c2708e2ad896c2090 Mon Sep 17 00:00:00 2001 From: Mikhail Yankelevich Date: Thu, 30 Apr 2026 09:34:33 +0000 Subject: [PATCH] 8373016: Passes instead of skips/ignoring the platform in sun/security/mscapi, jarsigner, keytool and pkcs12 tests Reviewed-by: rhalade --- .../security/mscapi/IsSunMSCAPIAvailable.java | 14 +++++++-- .../security/mscapi/RSAEncryptDecrypt.java | 8 +++-- .../security/mscapi/SignUsingNONEwithRSA.java | 28 +++++++++++++----- .../security/mscapi/SignUsingSHA2withRSA.java | 24 ++++++++++----- .../security/pkcs12/StoreSecretKeyTest.java | 29 +++++++++---------- .../tools/jarsigner/CertChainUnclosed.java | 10 ++----- .../tools/keytool/StorePasswords.java | 23 ++++++++++----- 7 files changed, 86 insertions(+), 50 deletions(-) diff --git a/test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java b/test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java index 28a2242d72b..e9c6104e0a5 100644 --- a/test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java +++ b/test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,11 +26,19 @@ * @bug 6318171 6931562 * @requires os.family == "windows" * @modules jdk.crypto.mscapi/sun.security.mscapi + * @library /test/lib/ * @run main/othervm IsSunMSCAPIAvailable */ +import jtreg.SkippedException; + +import java.security.GeneralSecurityException; +import java.security.KeyPairGenerator; import java.security.Provider; -import java.security.*; +import java.security.SecureRandom; +import java.security.Security; +import java.security.Signature; +import java.security.KeyStore; import javax.crypto.Cipher; public class IsSunMSCAPIAvailable { @@ -105,7 +113,7 @@ public class IsSunMSCAPIAvailable { cipher.getClass().getName()); } catch (GeneralSecurityException e) { - System.out.println("Cipher not supported by provider, skipping..."); + throw new SkippedException("Cipher not supported by provider"); } } } diff --git a/test/jdk/sun/security/mscapi/RSAEncryptDecrypt.java b/test/jdk/sun/security/mscapi/RSAEncryptDecrypt.java index 18ad012ff9a..761d9b5a1e1 100644 --- a/test/jdk/sun/security/mscapi/RSAEncryptDecrypt.java +++ b/test/jdk/sun/security/mscapi/RSAEncryptDecrypt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,11 @@ * RSA cipher in the SunMSCAPI crypto provider. NOTE: The RSA cipher is * absent from the SunMSCAPI provider in OpenJDK builds. * @requires os.family == "windows" + * @library /test/lib/ */ +import jtreg.SkippedException; + import javax.crypto.Cipher; import java.security.GeneralSecurityException; import java.security.KeyPairGenerator; @@ -55,8 +58,7 @@ public class RSAEncryptDecrypt { cipher = Cipher.getInstance("RSA", "SunMSCAPI"); } catch (GeneralSecurityException e) { - System.out.println("Cipher not supported by provider, skipping..."); - return; + throw new SkippedException("Cipher not supported by provider"); } cipher.init(Cipher.ENCRYPT_MODE, publicKey); diff --git a/test/jdk/sun/security/mscapi/SignUsingNONEwithRSA.java b/test/jdk/sun/security/mscapi/SignUsingNONEwithRSA.java index e5d3d44aa53..556d358bb4a 100644 --- a/test/jdk/sun/security/mscapi/SignUsingNONEwithRSA.java +++ b/test/jdk/sun/security/mscapi/SignUsingNONEwithRSA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,12 +28,26 @@ * java.base/sun.security.tools.keytool * @requires os.family == "windows" * @summary Sign using the NONEwithRSA signature algorithm from SunMSCAPI + * @library /test/lib/ */ -import java.security.*; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.PublicKey; +import java.security.Security; +import java.security.Signature; +import java.security.KeyStore; +import java.security.SignatureException; import java.security.cert.X509Certificate; import java.security.interfaces.RSAPrivateCrtKey; -import java.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Arrays; + +import jtreg.SkippedException; import sun.security.tools.keytool.CertAndKeyGen; import sun.security.x509.X500Name; @@ -91,9 +105,8 @@ public class SignUsingNONEwithRSA { if (providers == null) { System.out.println("No JCE providers support the " + "'Signature.NONEwithRSA' algorithm"); - System.out.println("Skipping this test..."); - return; - + throw new SkippedException("No JCE providers support the " + + "'Signature.NONEwithRSA' algorithm"); } else { System.out.println("The following JCE providers support the " + "'Signature.NONEwithRSA' algorithm: "); @@ -109,7 +122,8 @@ public class SignUsingNONEwithRSA { ckg.generate(1024); RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey(); ks.setKeyEntry("6578658", k, null, new X509Certificate[]{ - ckg.getSelfCertificate(new X500Name("cn=6578658,c=US"), 1000) + ckg.getSelfCertificate( + new X500Name("cn=6578658,c=US"), 1000) }); ks.store(null, null); diff --git a/test/jdk/sun/security/mscapi/SignUsingSHA2withRSA.java b/test/jdk/sun/security/mscapi/SignUsingSHA2withRSA.java index 3a2c7472cb7..5dedd35f479 100644 --- a/test/jdk/sun/security/mscapi/SignUsingSHA2withRSA.java +++ b/test/jdk/sun/security/mscapi/SignUsingSHA2withRSA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,16 +26,26 @@ * @bug 6753664 8180570 * @summary Support SHA256 (and higher) in SunMSCAPI * @requires os.family == "windows" + * @library /test/lib/ * @modules java.base/sun.security.tools.keytool * java.base/sun.security.x509 */ +import jtreg.SkippedException; import sun.security.tools.keytool.CertAndKeyGen; import sun.security.x509.X500Name; -import java.security.*; +import java.security.PrivateKey; +import java.security.Provider; +import java.security.PublicKey; +import java.security.Security; +import java.security.Signature; +import java.security.KeyStore; +import java.security.SignatureException; import java.security.cert.Certificate; -import java.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; public class SignUsingSHA2withRSA { @@ -57,7 +67,8 @@ public class SignUsingSHA2withRSA { ks.setKeyEntry("6753664", gen.getPrivateKey(), null, new Certificate[] { - gen.getSelfCertificate(new X500Name("cn=localhost,c=US"), 100) + gen.getSelfCertificate( + new X500Name("cn=localhost,c=US"), 100) }); try { @@ -74,9 +85,8 @@ public class SignUsingSHA2withRSA { if (providers == null) { System.out.println("No JCE providers support the " + "'Signature.SHA256withRSA' algorithm"); - System.out.println("Skipping this test..."); - return; - + throw new SkippedException("No JCE providers support the " + + "'Signature.SHA256withRSA' algorithm"); } else { System.out.println("The following JCE providers support the " + "'Signature.SHA256withRSA' algorithm: "); diff --git a/test/jdk/sun/security/pkcs12/StoreSecretKeyTest.java b/test/jdk/sun/security/pkcs12/StoreSecretKeyTest.java index 9677b65aac8..579c54cfc30 100644 --- a/test/jdk/sun/security/pkcs12/StoreSecretKeyTest.java +++ b/test/jdk/sun/security/pkcs12/StoreSecretKeyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,16 +25,21 @@ * @test * @bug 8005408 8079129 8048830 * @summary KeyStore API enhancements - * @run main StoreSecretKeyTest */ -import java.io.*; -import java.security.*; -import java.security.cert.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; -import java.util.*; -import javax.crypto.*; -import javax.crypto.spec.*; +import java.security.cert.CertificateFactory; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import java.security.KeyStore; // Store a secret key in a keystore and retrieve it again. @@ -59,13 +64,6 @@ public class StoreSecretKeyTest { } public static void main(String[] args) throws Exception { boolean isSecretkeyAlgSupported = false; - // Skip test if AES is unavailable - try { - SecretKeyFactory.getInstance("AES"); - } catch (NoSuchAlgorithmException nsae) { - System.out.println("AES is unavailable. Skipping test..."); - return; - } for (ALGORITHM alg : ALGORITHM.values()) { isSecretkeyAlgSupported |= testSecretKeyAlgorithm(alg); @@ -137,7 +135,6 @@ public class StoreSecretKeyTest { private static Certificate loadCertificate(String certFile) throws Exception { - X509Certificate cert = null; try (FileInputStream certStream = new FileInputStream(certFile)) { CertificateFactory factory = CertificateFactory.getInstance("X.509"); diff --git a/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java b/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java index d658dd9504c..719e33555df 100644 --- a/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java +++ b/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,21 +27,17 @@ * @summary InputStream should be closed in sun.security.tools.jarsigner.Main * @modules java.base/sun.security.tools.keytool * jdk.jartool/sun.security.tools.jarsigner + * @requires os.family == "windows" + * @library /test/lib/ * @run main/othervm CertChainUnclosed */ import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Locale; public class CertChainUnclosed { public static void main(String[] args) throws Exception { - String os = System.getProperty("os.name"); - if (!os.toUpperCase(Locale.US).contains("WINDOWS")) { - System.out.println("Not Windows. Skip test."); - return; - } kt("-genkeypair -alias a -dname CN=A"); kt("-exportcert -file a.crt -alias a"); diff --git a/test/jdk/sun/security/tools/keytool/StorePasswords.java b/test/jdk/sun/security/tools/keytool/StorePasswords.java index b31fb92a7f9..8e0e01a33a7 100644 --- a/test/jdk/sun/security/tools/keytool/StorePasswords.java +++ b/test/jdk/sun/security/tools/keytool/StorePasswords.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,12 +30,21 @@ import jdk.test.lib.SecurityTools; import jdk.test.lib.process.OutputAnalyzer; +import jtreg.SkippedException; -import java.io.*; -import java.security.*; -import java.util.*; -import javax.crypto.*; -import javax.crypto.spec.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.KeyStoreException; +import java.security.UnrecoverableKeyException; +import javax.crypto.SecretKey; +import java.security.KeyStore; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.PBEParameterSpec; +import java.util.Arrays; /* * Store and retrieve passwords protected by a selection of PBE algorithms, @@ -148,7 +157,7 @@ public class StorePasswords { algorithm, specWithEightByteSalt)); count++; - } else if (inner2 instanceof InvalidKeyException) { + } else if (inner2 instanceof InvalidKeyException) { System.out.println("...skipping due to: " + inner2.getMessage()); // Unsupported crypto keysize