8372817: Remove test/jdk/sun/security/rsa silent skips

Reviewed-by: rhalade
This commit is contained in:
Mikhail Yankelevich 2026-05-01 08:26:06 +00:00
parent 59b437aaaf
commit 87fdbc5b4a
4 changed files with 105 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -21,20 +21,27 @@
* questions.
*/
/**
/*
* @test
* @bug 4853305
* @summary Test the new RSA provider can verify all the RSA certs in the cacerts file
* @author Andreas Sterbenz
* @library /test/lib/
*/
// this test serves as our known answer test
import java.io.*;
import java.util.*;
import jtreg.SkippedException;
import java.security.*;
import java.security.cert.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.PublicKey;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public class TestCACerts {
@ -51,6 +58,9 @@ public class TestCACerts {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(in, null);
in.close();
final List<String> skippedCases = new ArrayList<>();
for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
String alias = (String)e.nextElement();
if (ks.isCertificateEntry(alias)) {
@ -62,13 +72,21 @@ public class TestCACerts {
System.out.println("Signature algorithm: " + cert.getSigAlgName());
cert.verify(key, PROVIDER);
} else {
System.out.println("Skipping cert with key: " + alg);
System.out.println("Skipping cert with non-RSA key: " +
alg);
}
} else {
skippedCases.add(String.format("[alias: %s]",
alias));
System.out.println("Skipping alias " + alias);
}
}
long stop = System.currentTimeMillis();
if (!skippedCases.isEmpty()) {
throw new SkippedException("Some tests were skipped " +
skippedCases);
}
System.out.println("All tests passed (" + (stop - start) + " ms).");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@ -21,14 +21,17 @@
* questions.
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import jtreg.SkippedException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.util.ArrayList;
import java.util.HexFormat;
import java.util.List;
@ -37,15 +40,19 @@ import java.util.List;
* @test
* @bug 8146293
* @summary Known Answer Tests based on NIST 186-3 at:
* @library /test/lib/
* @compile SigRecord.java
* @run main/othervm TestSigGen15
*/
public class TestSigGen15 {
private static final String[] testFiles = {
"SigGen15_186-3.txt", "SigGen15_186-3_TruncatedSHAs.txt"
};
private static final List<String> skippedAlgs = new ArrayList<>();
public static void main(String[] args) throws Exception {
boolean success = true;
for (String f : testFiles) {
@ -62,6 +69,11 @@ public class TestSigGen15 {
if (!success) {
throw new RuntimeException("One or more test failed");
}
if (!skippedAlgs.isEmpty()) {
throw new SkippedException("Some algorithms were skipped " +
skippedAlgs);
}
System.out.println("Test passed");
}
@ -100,6 +112,7 @@ public class TestSigGen15 {
} catch (NoSuchAlgorithmException e) {
System.out.println("\tSkip " + sigAlgo +
" due to no support");
skippedAlgs.add(sigAlgo);
continue;
}
byte[] msgBytes = HexFormat.of().parseHex(v.msg);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@ -20,11 +20,33 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.security.*;
import jtreg.SkippedException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.PSSParameterSpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import static javax.crypto.Cipher.PRIVATE_KEY;
import static javax.crypto.Cipher.PUBLIC_KEY;
@ -35,6 +57,7 @@ import static javax.crypto.Cipher.PUBLIC_KEY;
* @summary Create a signature for RSASSA-PSS and get its signed data.
* re-initiate the signature with the public key. The signature
* can be verified by acquired signed data.
* @library /test/lib/
* @run main SignatureTest2 768
* @run main SignatureTest2 1024
* @run main SignatureTest2 1025
@ -75,8 +98,10 @@ public class SignatureTest2 {
private static final String SIG_ALG = "RSASSA-PSS";
private static final List<String> skippedAlgs = new ArrayList<>();
private static PSSParameterSpec genPSSParameter(String digestAlgo,
int digestLen, int keySize) {
int digestLen, int keySize) {
// pick a salt length based on the key length and digestAlgo
int saltLength = keySize/8 - digestLen - 2;
if (saltLength < 0) {
@ -109,6 +134,10 @@ public class SignatureTest2 {
}
)));
if (!skippedAlgs.isEmpty()) {
throw new SkippedException("Some algorithms were skipped " +
skippedAlgs);
}
}
private static KeyPair generateKeys(String keyalg, int size)
@ -151,7 +180,14 @@ public class SignatureTest2 {
int digestLen = MessageDigest.getInstance(digestAlg).getDigestLength();
PSSParameterSpec params = genPSSParameter(digestAlg, digestLen, keySize);
if (params == null) {
System.out.println("Skip test due to short key size");
final String algDescription =
String.format("[digestAlg: %s, digestLen: %d, " +
"keysize: %d]",
digestAlg,
digestLen,
keySize);
skippedAlgs.add(algDescription);
System.out.println("Skip test due to short key size: " + algDescription);
return;
}
sig.setParameter(params);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@ -21,9 +21,20 @@
* questions.
*/
import jtreg.SkippedException;
import java.io.IOException;
import java.security.*;
import java.security.spec.*;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.SecureRandom;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PSSParameterSpec;
import java.util.HexFormat;
import java.util.List;
@ -31,6 +42,7 @@ import java.util.List;
* @test
* @bug 8146293
* @summary Known Answer Tests based on NIST 186-3 at:
* @library /test/lib/
* @compile SigRecord.java
* @run main/othervm TestSigGenPSS
*/
@ -61,16 +73,14 @@ public class TestSigGenPSS {
}
public static void main(String[] args) throws Exception {
//for (Provider provider : Security.getProviders()) {
Provider p = Security.getProvider(
System.getProperty("test.provider.name", "SunRsaSign"));
Signature sig;
try {
sig = Signature.getInstance("RSASSA-PSS", p);
} catch (NoSuchAlgorithmException e) {
System.out.println("Skip testing RSASSA-PSS" +
" due to no support");
return;
throw new SkippedException("Skip testing RSASSA-PSS" +
" due to no support");
}
boolean success = true;