|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
30 | 30 | * @run main/othervm TestCipherMode |
31 | 31 | */ |
32 | 32 |
|
| 33 | +import jtreg.SkippedException; |
| 34 | + |
33 | 35 | import java.security.Provider; |
34 | 36 | import java.security.Key; |
35 | 37 | import java.security.KeyPair; |
|
38 | 40 | import java.security.PublicKey; |
39 | 41 | import java.security.InvalidParameterException; |
40 | 42 | import java.security.NoSuchAlgorithmException; |
| 43 | +import java.util.ArrayList; |
41 | 44 | import java.util.Arrays; |
| 45 | +import java.util.List; |
42 | 46 | import javax.crypto.Cipher; |
43 | 47 | import javax.crypto.SecretKey; |
44 | 48 | import javax.crypto.spec.SecretKeySpec; |
45 | 49 |
|
46 | 50 | public class TestCipherMode extends PKCS11Test { |
47 | 51 |
|
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" |
51 | 55 | }; |
52 | 56 |
|
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); |
55 | 59 | private static SecretKey AES_KEY = new SecretKeySpec(BYTES16, "AES"); |
56 | 60 | private static PublicKey RSA_PUBKEY = null; |
57 | 61 | private static PrivateKey RSA_PRIVKEY = null; |
@@ -97,18 +101,29 @@ public void main(Provider p) throws Exception { |
97 | 101 |
|
98 | 102 | // test all cipher impls, e.g. P11Cipher, P11AEADCipher, and |
99 | 103 | // 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"); |
102 | 119 | } |
103 | | - System.out.println("All tests passed"); |
104 | 120 | } |
105 | 121 |
|
106 | 122 | private static void checkModes(String t, Provider p) throws Exception { |
107 | 123 | try { |
108 | 124 | Cipher.getInstance(t, p); |
109 | 125 | } 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()); |
112 | 127 | } |
113 | 128 |
|
114 | 129 | for (CipherMode m : CipherMode.values()) { |
|
0 commit comments