8373016: Passes instead of skips/ignoring the platform in sun/security/mscapi, jarsigner, keytool and pkcs12 tests

Reviewed-by: rhalade
This commit is contained in:
Mikhail Yankelevich 2026-04-30 09:34:33 +00:00
parent e6582b2e80
commit 100c500899
7 changed files with 86 additions and 50 deletions

View File

@ -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");
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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: ");

View File

@ -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");

View File

@ -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");

View File

@ -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