Skip to content

Commit ef7532e

Browse files
committed
8367994: test/jdk/sun/security/pkcs11/Signature/ tests pass when they should skip
Reviewed-by: rhalade
1 parent b19163b commit ef7532e

File tree

7 files changed

+160
-60
lines changed

7 files changed

+160
-60
lines changed

test/jdk/sun/security/pkcs11/Signature/InitAgainPSS.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -20,8 +20,15 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
import java.security.*;
24-
import java.security.spec.*;
23+
import jtreg.SkippedException;
24+
25+
import java.security.KeyPair;
26+
import java.security.KeyPairGenerator;
27+
import java.security.NoSuchAlgorithmException;
28+
import java.security.Provider;
29+
import java.security.Signature;
30+
import java.security.spec.MGF1ParameterSpec;
31+
import java.security.spec.PSSParameterSpec;
2532

2633
/**
2734
* @test
@@ -46,9 +53,7 @@ private void test(String sigAlg, Provider p) throws Exception {
4653
try {
4754
s1 = Signature.getInstance(sigAlg, p);
4855
} catch (NoSuchAlgorithmException e) {
49-
System.out.println("Skip testing " + sigAlg +
50-
" due to no support");
51-
return;
56+
throw new SkippedException("No support " + sigAlg);
5257
}
5358

5459
byte[] msg = "hello".getBytes();

test/jdk/sun/security/pkcs11/Signature/KeyAndParamCheckForPSS.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -20,9 +20,18 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
import java.security.*;
24-
import java.security.interfaces.*;
25-
import java.security.spec.*;
23+
import java.security.InvalidAlgorithmParameterException;
24+
import java.security.InvalidKeyException;
25+
import java.security.KeyPair;
26+
import java.security.PrivateKey;
27+
import java.security.Provider;
28+
import java.security.PublicKey;
29+
import java.security.Signature;
30+
import java.security.spec.AlgorithmParameterSpec;
31+
import java.security.spec.MGF1ParameterSpec;
32+
import java.security.spec.PSSParameterSpec;
33+
import java.util.ArrayList;
34+
import java.util.List;
2635

2736
import jtreg.SkippedException;
2837

@@ -43,7 +52,7 @@ public static void main(String[] args) throws Exception {
4352
main(new KeyAndParamCheckForPSS(), args);
4453
}
4554

46-
private static boolean skipTest = true;
55+
private static final List<String> skippedAlgs = new ArrayList<>();
4756

4857
@Override
4958
public void main(Provider p) throws Exception {
@@ -73,8 +82,8 @@ public void main(Provider p) throws Exception {
7382
runTest(p, 1040, "SHA3-512", "SHA3-384");
7483
runTest(p, 1040, "SHA3-512", "SHA3-512");
7584

76-
if (skipTest) {
77-
throw new SkippedException("Test Skipped");
85+
if (!skippedAlgs.isEmpty()) {
86+
throw new SkippedException("Tests Skipped: " + skippedAlgs);
7887
}
7988
}
8089

@@ -84,7 +93,17 @@ private static void runTest(Provider p, int keySize, String hashAlg,
8493
System.out.println("Testing " + hashAlg + " and MGF1" + mgfHashAlg);
8594
PSSUtil.AlgoSupport s = PSSUtil.isHashSupported(p, hashAlg, mgfHashAlg);
8695
if (s == PSSUtil.AlgoSupport.NO) {
87-
System.out.println("=> Skip; no support");
96+
System.out.printf("=> Skip; no support keysize: %d, hash alg: %s, mgf Hash Alg: %s%n",
97+
keySize,
98+
hashAlg,
99+
mgfHashAlg);
100+
skippedAlgs.add(
101+
String.format(
102+
"[keysize: %s, hash alg: %s, mgf Hash Alg: %s]",
103+
keySize,
104+
hashAlg,
105+
mgfHashAlg)
106+
);
88107
return;
89108
}
90109

@@ -108,7 +127,6 @@ private static void runTest(Provider p, int keySize, String hashAlg,
108127
sig.setParameter(paramsGood);
109128
sig.initSign(priv);
110129
// algorithm support confirmed
111-
skipTest = false;
112130
} catch (Exception ex) {
113131
if (s == PSSUtil.AlgoSupport.MAYBE) {
114132
// confirmed to be unsupported; skip the rest of the test

test/jdk/sun/security/pkcs11/Signature/SigInteropPSS.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -21,9 +21,15 @@
2121
* questions.
2222
*/
2323

24-
import java.security.*;
25-
import java.security.spec.*;
26-
import java.security.interfaces.*;
24+
import jtreg.SkippedException;
25+
26+
import java.security.KeyPair;
27+
import java.security.KeyPairGenerator;
28+
import java.security.NoSuchAlgorithmException;
29+
import java.security.Provider;
30+
import java.security.Signature;
31+
import java.security.spec.MGF1ParameterSpec;
32+
import java.security.spec.PSSParameterSpec;
2733

2834
/*
2935
* @test
@@ -53,9 +59,7 @@ public void main(Provider p) throws Exception {
5359
try {
5460
sigPkcs11 = Signature.getInstance("RSASSA-PSS", p);
5561
} catch (NoSuchAlgorithmException e) {
56-
System.out.println("Skip testing RSASSA-PSS" +
57-
" due to no support");
58-
return;
62+
throw new SkippedException("No support for RSASSA-PSS");
5963
}
6064

6165
Signature sigSunRsaSign =

test/jdk/sun/security/pkcs11/Signature/SigInteropPSS2.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, 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
@@ -21,9 +21,16 @@
2121
* questions.
2222
*/
2323

24-
import java.security.*;
25-
import java.security.spec.*;
26-
import java.security.interfaces.*;
24+
import jtreg.SkippedException;
25+
26+
import java.security.AlgorithmParameters;
27+
import java.security.KeyPair;
28+
import java.security.KeyPairGenerator;
29+
import java.security.NoSuchAlgorithmException;
30+
import java.security.Provider;
31+
import java.security.Security;
32+
import java.security.Signature;
33+
import java.security.spec.PSSParameterSpec;
2734

2835
/*
2936
* @test
@@ -67,9 +74,7 @@ public void main(Provider p) throws Exception {
6774
try {
6875
sigPkcs11 = Signature.getInstance(digest + "withRSASSA-PSS", p);
6976
} catch (NoSuchAlgorithmException e) {
70-
System.out.println("Skip testing " + digest + "withRSASSA-PSS" +
71-
" due to no support");
72-
continue;
77+
throw new SkippedException("No support for " + digest + "withRSASSA-PSS");
7378
}
7479

7580
runTest(sigPkcs11, sigSunRsaSign, kp);

test/jdk/sun/security/pkcs11/Signature/SignatureTestPSS.java

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -20,29 +20,55 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
import java.security.*;
24-
import java.security.interfaces.*;
25-
import java.security.spec.*;
26-
import java.util.stream.IntStream;
23+
import java.security.InvalidAlgorithmParameterException;
24+
import java.security.InvalidKeyException;
25+
import java.security.KeyPair;
26+
import java.security.NoSuchAlgorithmException;
27+
import java.security.PrivateKey;
28+
import java.security.Provider;
29+
import java.security.PublicKey;
30+
import java.security.Signature;
31+
import java.security.SignatureException;
32+
import java.security.spec.AlgorithmParameterSpec;
33+
import java.security.spec.MGF1ParameterSpec;
34+
import java.security.spec.PSSParameterSpec;
35+
import java.util.ArrayList;
36+
import java.util.List;
37+
2738
import jtreg.SkippedException;
2839

2940
/**
30-
* @test
41+
* @test id=sha
3142
* @bug 8080462 8226651 8242332
3243
* @summary Generate a RSASSA-PSS signature and verify it using PKCS11 provider
3344
* @library /test/lib ..
3445
* @modules jdk.crypto.cryptoki
3546
* @run main SignatureTestPSS
3647
*/
48+
49+
/**
50+
* @test id=sha3
51+
* @bug 8080462 8226651 8242332
52+
* @summary Generate a RSASSA-PSS signature and verify it using PKCS11 provider
53+
* @library /test/lib ..
54+
* @modules jdk.crypto.cryptoki
55+
* @run main SignatureTestPSS sha3
56+
*/
3757
public class SignatureTestPSS extends PKCS11Test {
3858

3959
private static final String SIGALG = "RSASSA-PSS";
4060

4161
private static final int[] KEYSIZES = { 2048, 3072 };
42-
private static final String[] DIGESTS = {
62+
63+
private static String[] DIGESTS = null;
64+
65+
private static final String[] SHA_DIGESTS = {
4366
"SHA-224", "SHA-256", "SHA-384" , "SHA-512",
44-
"SHA3-224", "SHA3-256", "SHA3-384" , "SHA3-512",
4567
};
68+
private static final String[] SHA3_DIGESTS = {
69+
"SHA3-224", "SHA3-256", "SHA3-384" , "SHA3-512"
70+
};
71+
4672
private static final byte[] DATA = generateData(100);
4773

4874
/**
@@ -55,9 +81,12 @@ public class SignatureTestPSS extends PKCS11Test {
5581
*/
5682
private static final int UPDATE_TIMES_HUNDRED = 100;
5783

58-
private static boolean skipTest = true;
84+
private static final List<String> skippedAlgs = new ArrayList<>();
5985

6086
public static void main(String[] args) throws Exception {
87+
DIGESTS = (args.length > 0 && "sha3".equals(args[0])) ?
88+
SHA3_DIGESTS : SHA_DIGESTS;
89+
6190
main(new SignatureTestPSS(), args);
6291
}
6392

@@ -80,24 +109,24 @@ public void main(Provider p) throws Exception {
80109
PSSUtil.isHashSupported(p, hash, mgfHash);
81110
if (s == PSSUtil.AlgoSupport.NO) {
82111
System.out.println(" => Skip; no support");
112+
skippedAlgs.add("[Hash = " + hash +
113+
", MGF1 Hash = " + mgfHash + "]");
83114
continue;
84115
}
85116
checkSignature(p, DATA, pubKey, privKey, hash, mgfHash, s);
86117
}
87118
};
88119
}
89120

90-
// start testing below
91-
if (skipTest) {
92-
throw new SkippedException("Test Skipped");
121+
if (!skippedAlgs.isEmpty()) {
122+
throw new SkippedException("Test Skipped :" + skippedAlgs);
93123
}
94124
}
95125

96126
private static void checkSignature(Provider p, byte[] data, PublicKey pub,
97127
PrivateKey priv, String hash, String mgfHash, PSSUtil.AlgoSupport s)
98128
throws NoSuchAlgorithmException, InvalidKeyException,
99-
SignatureException, NoSuchProviderException,
100-
InvalidAlgorithmParameterException {
129+
SignatureException {
101130

102131
// only test RSASSA-PSS signature against the supplied hash/mgfHash
103132
// if they are supported; otherwise PKCS11 library will throw
@@ -112,14 +141,27 @@ private static void checkSignature(Provider p, byte[] data, PublicKey pub,
112141
} catch (InvalidAlgorithmParameterException iape) {
113142
if (s == PSSUtil.AlgoSupport.MAYBE) {
114143
// confirmed to be unsupported; skip the rest of the test
115-
System.out.println(" => Skip; no PSS support");
144+
System.out.printf(" => Skip; no PSS support public key: %s, private key: %s, " +
145+
"hash: %s, mgf hash: %s, Algo Support: %s%n",
146+
pub,
147+
priv,
148+
hash,
149+
mgfHash,
150+
s);
151+
skippedAlgs.add(String.format(
152+
"[public key: %s, private key: %s, " +
153+
"hash: %s, mgf hash: %s, Algo Support: %s]",
154+
pub,
155+
priv,
156+
hash,
157+
mgfHash,
158+
s)
159+
);
116160
return;
117161
} else {
118162
throw new RuntimeException("Unexpected Exception", iape);
119163
}
120164
}
121-
// start testing below
122-
skipTest = false;
123165

124166
for (int i = 0; i < UPDATE_TIMES_HUNDRED; i++) {
125167
sig.update(data);

0 commit comments

Comments
 (0)