Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions test/jdk/sun/security/pkcs11/KeyStore/ClientAuth.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2025, 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
Expand Down Expand Up @@ -260,8 +260,7 @@ public void main(Provider p) throws Exception {
try {
javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
} catch (GeneralSecurityException e) {
System.out.println("Not supported by provider, skipping");
return;
throw new SkippedException("Not supported by provider, skipping");
}

this.provider = p;
Expand Down
51 changes: 34 additions & 17 deletions test/jdk/sun/security/pkcs11/SecretKeyFactory/TestGeneral.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, 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
Expand Down Expand Up @@ -30,10 +30,14 @@
* @run main/othervm TestGeneral
*/

import jtreg.SkippedException;

import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.crypto.SecretKeyFactory;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -57,8 +61,11 @@ private void test(String algorithm, SecretKey key, Provider p,
try {
skf = SecretKeyFactory.getInstance(algorithm, p);
} catch (NoSuchAlgorithmException e) {
System.out.println("Not supported, skipping: " + e);
return;
throw new SkippedException("[algorithm: " + algorithm +
", key: " + key.getAlgorithm() + "]" +
", provider: " + p.getName() + "]" +
", expectedTestResult: " + expected + "]" +
"Not supported, skipping: " + e);
}
try {
SecretKey key2 = skf.translateKey(key);
Expand Down Expand Up @@ -99,21 +106,31 @@ public void main(Provider p) throws Exception {
SecretKey bf_128Key = new SecretKeySpec(rawBytes, 0, 16, "Blowfish");
SecretKey cc20Key = new SecretKeySpec(rawBytes, 0, 32, "ChaCha20");

// fixed key length
test("AES", aes_128Key, p, TestResult.PASS);
test("AES", aes_256Key, p, TestResult.PASS);
test("AES", cc20Key, p, TestResult.FAIL);
List<String> skippedList = new ArrayList<>();
try {
// fixed key length
test("AES", aes_128Key, p, TestResult.PASS);
test("AES", aes_256Key, p, TestResult.PASS);
test("AES", cc20Key, p, TestResult.FAIL);

test("ChaCha20", aes_128Key, p, TestResult.FAIL);
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
test("ChaCha20", cc20Key, p, TestResult.PASS);
test("ChaCha20", aes_128Key, p, TestResult.FAIL);
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
test("ChaCha20", cc20Key, p, TestResult.PASS);

// variable key length
// Different PKCS11 impls may have different ranges
// of supported key sizes for variable-key-length
// algorithms.
test("Blowfish", aes_128Key, p, TestResult.FAIL);
test("Blowfish", cc20Key, p, TestResult.FAIL);
test("Blowfish", bf_128Key, p, TestResult.PASS);
// variable key length
// Different PKCS11 impls may have different ranges
// of supported key sizes for variable-key-length
// algorithms.
test("Blowfish", aes_128Key, p, TestResult.FAIL);
test("Blowfish", cc20Key, p, TestResult.FAIL);
test("Blowfish", bf_128Key, p, TestResult.PASS);
} catch (SkippedException skippedException){
skippedException.printStackTrace();
skippedList.add(skippedException.getMessage());
}

if (!skippedList.isEmpty()) {
throw new SkippedException("One or more tests skipped " + skippedList);
}
}
}
7 changes: 4 additions & 3 deletions test/jdk/sun/security/pkcs11/SecureRandom/Basic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, 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
Expand Down Expand Up @@ -33,6 +33,8 @@
* @run main/othervm -Djava.security.manager=allow Basic sm
*/

import jtreg.SkippedException;

import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.SecureRandom;
Expand All @@ -45,9 +47,8 @@ public void main(Provider p) throws Exception {
try {
random = SecureRandom.getInstance("PKCS11");
} catch (NoSuchAlgorithmException e) {
System.out.println("Provider " + p + " does not support SecureRandom, skipping");
e.printStackTrace();
return;
throw new SkippedException("Provider " + p + " does not support SecureRandom, skipping", e);
}
byte[] b = new byte[32];
random.nextBytes(b);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2025, 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
Expand Down Expand Up @@ -29,6 +29,8 @@
* @modules jdk.crypto.cryptoki
*/

import jtreg.SkippedException;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
Expand All @@ -43,18 +45,16 @@ public class TestDeserialization extends PKCS11Test {
public void main(Provider p) throws Exception {
// Skip this test for providers not found by java.security.Security
if (Security.getProvider(p.getName()) != p) {
System.out.println("Skip test for provider " + p.getName());
return;
throw new SkippedException("Skip test for provider " + p.getName());
}
SecureRandom r;
try {
r = SecureRandom.getInstance("PKCS11", p);
System.out.println("SecureRandom instance " + r);
} catch (NoSuchAlgorithmException e) {
System.out.println("Provider " + p +
" does not support SecureRandom, skipping");
e.printStackTrace();
return;
throw new SkippedException("Provider " + p +
" does not support SecureRandom, skipping");
}
r.setSeed(System.currentTimeMillis());
byte[] buf = new byte[16];
Expand Down