Skip to content

Commit 31ce4c0

Browse files
author
duke
committed
Backport 993babb326f937dc1630a5a8fa5e469a64c51206
1 parent 5e07074 commit 31ce4c0

16 files changed

+187
-156
lines changed

test/jdk/sun/security/pkcs11/Cipher/ReinitCipher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -32,6 +32,8 @@
3232
* @run main/othervm ReinitCipher
3333
*/
3434

35+
import jtreg.SkippedException;
36+
3537
import java.security.Provider;
3638
import java.util.Random;
3739
import javax.crypto.Cipher;
@@ -46,8 +48,7 @@ public static void main(String[] args) throws Exception {
4648
@Override
4749
public void main(Provider p) throws Exception {
4850
if (p.getService("Cipher", "ARCFOUR") == null) {
49-
System.out.println("Not supported by provider, skipping");
50-
return;
51+
throw new SkippedException("Algorithm ARCFOUR is not supported by provider, skipping");
5152
}
5253
Random random = new Random();
5354
byte[] data1 = new byte[10 * 1024];

test/jdk/sun/security/pkcs11/Cipher/Test4512704.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -29,14 +29,16 @@
2929
* @run main Test4512704
3030
* @summary Verify that AES cipher can generate default IV in encrypt mode
3131
*/
32-
import java.io.PrintStream;
33-
import java.security.*;
34-
import java.security.spec.*;
35-
import java.util.Random;
32+
import jtreg.SkippedException;
3633

37-
import javax.crypto.*;
38-
import javax.crypto.spec.*;
34+
import java.security.GeneralSecurityException;
35+
import java.security.InvalidAlgorithmParameterException;
36+
37+
import javax.crypto.Cipher;
38+
import javax.crypto.SecretKey;
39+
import javax.crypto.spec.SecretKeySpec;
3940
import java.security.Provider;
41+
import java.security.spec.AlgorithmParameterSpec;
4042

4143
public class Test4512704 extends PKCS11Test {
4244

@@ -48,9 +50,8 @@ public void test(String mode, Provider p) throws Exception {
4850
transformation = "AES/" + mode + "/NoPadding";
4951
c = Cipher.getInstance(transformation, p);
5052
} catch (GeneralSecurityException e) {
51-
System.out.println("Skip testing " + p.getName() +
52-
", no support for " + mode);
53-
return;
53+
throw new SkippedException("Skip testing " + p.getName() +
54+
", no support for " + mode);
5455
}
5556
SecretKey key = new SecretKeySpec(new byte[16], "AES");
5657

test/jdk/sun/security/pkcs11/Cipher/TestCICOWithGCM.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -31,13 +31,21 @@
3131
* @key randomness
3232
*/
3333

34-
import java.security.*;
35-
import javax.crypto.*;
36-
import javax.crypto.spec.*;
37-
import java.math.*;
38-
import java.io.*;
34+
import jtreg.SkippedException;
35+
36+
import java.io.ByteArrayInputStream;
37+
import java.io.ByteArrayOutputStream;
38+
import javax.crypto.Cipher;
39+
import javax.crypto.CipherInputStream;
40+
import javax.crypto.CipherOutputStream;
41+
import javax.crypto.SecretKey;
42+
import javax.crypto.spec.SecretKeySpec;
43+
44+
import java.security.GeneralSecurityException;
45+
import java.security.Provider;
46+
import java.util.Arrays;
47+
import java.util.Random;
3948

40-
import java.util.*;
4149

4250
public class TestCICOWithGCM extends PKCS11Test {
4351
public static void main(String[] args) throws Exception {
@@ -55,9 +63,8 @@ public void test(String mode, Provider p) throws Exception {
5563
String transformation = "AES/" + mode + "/NoPadding";
5664
c = Cipher.getInstance(transformation, p);
5765
} catch (GeneralSecurityException e) {
58-
System.out.println("Skip testing " + p.getName() +
59-
", no support for " + mode);
60-
return;
66+
throw new SkippedException("Skip testing " + p.getName() +
67+
", no support for " + mode);
6168
}
6269

6370
SecretKey key = new SecretKeySpec(new byte[16], "AES");

test/jdk/sun/security/pkcs11/Cipher/TestCICOWithGCMAndAAD.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -30,6 +30,8 @@
3030
* @summary Test CipherInputStream/OutputStream with AES GCM mode with AAD.
3131
* @key randomness
3232
*/
33+
import jtreg.SkippedException;
34+
3335
import java.io.*;
3436
import java.security.*;
3537
import java.util.*;
@@ -44,7 +46,6 @@ public static void main(String[] args) throws Exception {
4446
@Override
4547
public void main(Provider p) throws Exception {
4648
test("GCM", p);
47-
// test("CCM", p);
4849
}
4950

5051
public void test(String mode, Provider p) throws Exception {
@@ -53,9 +54,8 @@ public void test(String mode, Provider p) throws Exception {
5354
String transformation = "AES/" + mode + "/NoPadding";
5455
c = Cipher.getInstance(transformation, p);
5556
} catch (GeneralSecurityException e) {
56-
System.out.println("Skip testing " + p.getName() +
57-
", no support for " + mode);
58-
return;
57+
throw new SkippedException("Skip testing " + p.getName() +
58+
", no support for " + mode);
5959
}
6060
SecretKey key = new SecretKeySpec(new byte[16], "AES");
6161

test/jdk/sun/security/pkcs11/Cipher/TestChaChaPoly.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -47,7 +47,7 @@
4747
import javax.crypto.spec.SecretKeySpec;
4848
import javax.crypto.NoSuchPaddingException;
4949

50-
import jdk.test.lib.Utils;
50+
import jtreg.SkippedException;
5151

5252
public class TestChaChaPoly extends PKCS11Test {
5353

@@ -70,8 +70,7 @@ public void main(Provider p) throws Exception {
7070
try {
7171
Cipher.getInstance(ALGO, p);
7272
} catch (NoSuchAlgorithmException nsae) {
73-
System.out.println("Skip; no support for " + ALGO);
74-
return;
73+
throw new SkippedException("Skip; no support for " + ALGO);
7574
}
7675
this.p = p;
7776
testTransformations();

test/jdk/sun/security/pkcs11/Cipher/TestChaChaPolyKAT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -26,22 +26,25 @@
2626
* @bug 8255410
2727
* @library /test/lib ..
2828
* @modules jdk.crypto.cryptoki
29-
* @build jdk.test.lib.Convert
3029
* @run main/othervm TestChaChaPolyKAT
3130
* @summary ChaCha20-Poly1305 Cipher Implementation (KAT)
3231
*/
3332

34-
import java.util.*;
33+
import jtreg.SkippedException;
34+
3535
import java.security.GeneralSecurityException;
3636
import java.security.Provider;
3737
import java.security.NoSuchAlgorithmException;
3838
import javax.crypto.Cipher;
39-
import javax.crypto.spec.ChaCha20ParameterSpec;
4039
import javax.crypto.spec.IvParameterSpec;
4140
import javax.crypto.spec.SecretKeySpec;
4241
import javax.crypto.AEADBadTagException;
4342
import java.nio.ByteBuffer;
44-
import jdk.test.lib.Convert;
43+
import java.util.Arrays;
44+
import java.util.HexFormat;
45+
import java.util.LinkedList;
46+
import java.util.List;
47+
import java.util.Objects;
4548

4649
public class TestChaChaPolyKAT extends PKCS11Test {
4750
public static class TestData {
@@ -126,8 +129,7 @@ public void main(Provider p) throws Exception {
126129
try {
127130
Cipher.getInstance(ALGO, p);
128131
} catch (NoSuchAlgorithmException nsae) {
129-
System.out.println("Skip; no support for " + ALGO);
130-
return;
132+
throw new SkippedException("Skip; no support for " + ALGO);
131133
}
132134

133135
int testsPassed = 0;

test/jdk/sun/security/pkcs11/Cipher/TestChaChaPolyNoReuse.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -30,18 +30,22 @@
3030
* (key/nonce reuse check)
3131
*/
3232

33-
import java.util.*;
33+
import jtreg.SkippedException;
34+
3435
import javax.crypto.Cipher;
3536
import java.security.spec.AlgorithmParameterSpec;
3637
import java.security.Provider;
3738
import java.security.NoSuchAlgorithmException;
38-
import javax.crypto.spec.ChaCha20ParameterSpec;
3939
import javax.crypto.spec.IvParameterSpec;
4040
import javax.crypto.spec.SecretKeySpec;
41-
import javax.crypto.AEADBadTagException;
4241
import javax.crypto.SecretKey;
4342
import java.security.InvalidKeyException;
4443
import java.security.InvalidAlgorithmParameterException;
44+
import java.util.Arrays;
45+
import java.util.HexFormat;
46+
import java.util.LinkedList;
47+
import java.util.List;
48+
import java.util.Objects;
4549

4650
public class TestChaChaPolyNoReuse extends PKCS11Test {
4751

@@ -238,8 +242,7 @@ public void main(Provider p) throws Exception {
238242
try {
239243
Cipher.getInstance(CIPHER_ALGO, p);
240244
} catch (NoSuchAlgorithmException nsae) {
241-
System.out.println("Skip; no support for " + CIPHER_ALGO);
242-
return;
245+
throw new SkippedException("Skip; no support for " + CIPHER_ALGO);
243246
}
244247

245248
int testsPassed = 0;

test/jdk/sun/security/pkcs11/Cipher/TestChaChaPolyOutputSize.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -30,14 +30,14 @@
3030
* @run main TestChaChaPolyOutputSize
3131
*/
3232

33+
import jtreg.SkippedException;
34+
3335
import java.nio.ByteBuffer;
3436
import java.security.GeneralSecurityException;
35-
import java.security.Key;
3637
import java.security.SecureRandom;
3738
import java.security.Provider;
3839
import java.security.NoSuchAlgorithmException;
3940
import javax.crypto.Cipher;
40-
import javax.crypto.spec.ChaCha20ParameterSpec;
4141
import javax.crypto.spec.IvParameterSpec;
4242
import javax.crypto.spec.SecretKeySpec;
4343

@@ -60,8 +60,7 @@ public void main(Provider p) throws GeneralSecurityException {
6060
try {
6161
Cipher.getInstance(ALGO, p);
6262
} catch (NoSuchAlgorithmException nsae) {
63-
System.out.println("Skip; no support for " + ALGO);
64-
return;
63+
throw new SkippedException("Skip; no support for " + ALGO);
6564
}
6665
testGetOutSize(p);
6766
testMultiPartAEADDec(p);

test/jdk/sun/security/pkcs11/Cipher/TestCipherMode.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -30,6 +30,8 @@
3030
* @run main/othervm TestCipherMode
3131
*/
3232

33+
import jtreg.SkippedException;
34+
3335
import java.security.Provider;
3436
import java.security.Key;
3537
import java.security.KeyPair;
@@ -38,20 +40,22 @@
3840
import java.security.PublicKey;
3941
import java.security.InvalidParameterException;
4042
import java.security.NoSuchAlgorithmException;
43+
import java.util.ArrayList;
4144
import java.util.Arrays;
45+
import java.util.List;
4246
import javax.crypto.Cipher;
4347
import javax.crypto.SecretKey;
4448
import javax.crypto.spec.SecretKeySpec;
4549

4650
public class TestCipherMode extends PKCS11Test {
4751

48-
private static String[] TRANSFORMATIONS = {
49-
"AES/ECB/PKCS5Padding", "AES/GCM/NoPadding",
50-
"RSA/ECB/PKCS1Padding"
52+
private static final String[] TRANSFORMATIONS = {
53+
"AES/ECB/PKCS5Padding", "AES/GCM/NoPadding",
54+
"RSA/ECB/PKCS1Padding"
5155
};
5256

53-
private static byte[] BYTES16 =
54-
Arrays.copyOf(TRANSFORMATIONS[0].getBytes(), 16);
57+
private static final byte[] BYTES16 =
58+
Arrays.copyOf("AES/ECB/PKCS5Padding".getBytes(), 16);
5559
private static SecretKey AES_KEY = new SecretKeySpec(BYTES16, "AES");
5660
private static PublicKey RSA_PUBKEY = null;
5761
private static PrivateKey RSA_PRIVKEY = null;
@@ -97,18 +101,29 @@ public void main(Provider p) throws Exception {
97101

98102
// test all cipher impls, e.g. P11Cipher, P11AEADCipher, and
99103
// P11RSACipher
100-
for (String t : TRANSFORMATIONS) {
101-
checkModes(t, p);
104+
List<String> skipped = new ArrayList<>();
105+
for (final String t : TRANSFORMATIONS) {
106+
try {
107+
checkModes(t, p);
108+
} catch (SkippedException skippedException) {
109+
// printing to System.out, so it's easier to see which test it relates to
110+
skippedException.printStackTrace(System.out);
111+
skipped.add(t);
112+
}
113+
}
114+
115+
if (!skipped.isEmpty()) {
116+
throw new SkippedException("Some tests skipped: " + skipped);
117+
} else {
118+
System.out.println("All tests passed");
102119
}
103-
System.out.println("All tests passed");
104120
}
105121

106122
private static void checkModes(String t, Provider p) throws Exception {
107123
try {
108124
Cipher.getInstance(t, p);
109125
} catch (Exception e) {
110-
System.out.println("Skip " + t + " due to " + e.getMessage());
111-
return;
126+
throw new SkippedException("Skip " + t + " due to " + e.getMessage());
112127
}
113128

114129
for (CipherMode m : CipherMode.values()) {

0 commit comments

Comments
 (0)