Skip to content

Commit 9689017

Browse files
committed
8366342: Key generator and key pair generator tests skipping, but showing as passed
Backport-of: 7690a45f77a2da47fa912fe7a2b2faa589f259f0
1 parent 6d97a5e commit 9689017

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

test/jdk/sun/security/pkcs11/KeyGenerator/DESParity.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2018, 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
@@ -33,6 +33,8 @@
3333
* @run main/othervm -Djava.security.manager=allow DESParity sm
3434
*/
3535

36+
import jtreg.SkippedException;
37+
3638
import java.security.Provider;
3739
import java.util.Random;
3840
import javax.crypto.SecretKey;
@@ -46,8 +48,7 @@ public class DESParity extends PKCS11Test {
4648
@Override
4749
public void main(Provider p) throws Exception {
4850
if (p.getService("SecretKeyFactory", "DES") == null) {
49-
System.out.println("Not supported by provider, skipping");
50-
return;
51+
throw new SkippedException("Not supported by provider, skipping");
5152
}
5253
Random random = new Random();
5354
SecretKeyFactory kf;
@@ -58,7 +59,7 @@ public void main(Provider p) throws Exception {
5859
random.nextBytes(b);
5960
SecretKeySpec spec = new SecretKeySpec(b, "DES");
6061
SecretKey key = kf.generateSecret(spec);
61-
if (DESKeySpec.isParityAdjusted(key.getEncoded(), 0) == false) {
62+
if (!DESKeySpec.isParityAdjusted(key.getEncoded(), 0)) {
6263
throw new Exception("DES key not parity adjusted");
6364
}
6465
}
@@ -69,7 +70,7 @@ public void main(Provider p) throws Exception {
6970
random.nextBytes(b);
7071
SecretKeySpec spec = new SecretKeySpec(b, "DESede");
7172
SecretKey key = kf.generateSecret(spec);
72-
if (DESedeKeySpec.isParityAdjusted(key.getEncoded(), 0) == false) {
73+
if (!DESedeKeySpec.isParityAdjusted(key.getEncoded(), 0)) {
7374
throw new Exception("DESede key not parity adjusted");
7475
}
7576
}

test/jdk/sun/security/pkcs11/KeyGenerator/TestAES.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 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,13 +30,14 @@
3030
* @library /test/lib ..
3131
* @run main TestAES
3232
*/
33+
import jtreg.SkippedException;
34+
import sun.security.util.SecurityProviderConstants;
35+
3336
import java.security.Provider;
34-
import java.security.InvalidAlgorithmParameterException;
3537
import java.security.InvalidParameterException;
3638
import java.security.NoSuchAlgorithmException;
3739
import javax.crypto.KeyGenerator;
3840
import javax.crypto.SecretKey;
39-
import static sun.security.util.SecurityProviderConstants.*;
4041

4142
public class TestAES extends PKCS11Test {
4243

@@ -53,17 +54,16 @@ public void main(Provider p) throws Exception {
5354
try {
5455
kg = KeyGenerator.getInstance(ALGO, p);
5556
} catch (NoSuchAlgorithmException nsae) {
56-
System.out.println("Skip; no support for " + ALGO);
57-
return;
57+
throw new SkippedException("Skip; no support for " + ALGO, nsae);
5858
}
5959

6060
// first try w/o setting a key length and check if the generated key
6161
// length matches
6262
SecretKey key = kg.generateKey();
6363
byte[] keyValue = key.getEncoded();
64-
if (key.getEncoded().length != getDefAESKeySize() >> 3) {
64+
if (key.getEncoded().length != SecurityProviderConstants.getDefAESKeySize() >> 3) {
6565
throw new RuntimeException("Default AES key length should be " +
66-
getDefAESKeySize());
66+
SecurityProviderConstants.getDefAESKeySize());
6767
}
6868

6969
for (int keySize : new int[] { 16, 32, 64, 128, 256, 512, 1024 }) {

test/jdk/sun/security/pkcs11/KeyGenerator/TestChaCha20.java

Lines changed: 4 additions & 3 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
@@ -29,6 +29,8 @@
2929
* @library /test/lib ..
3030
* @run main/othervm TestChaCha20
3131
*/
32+
import jtreg.SkippedException;
33+
3234
import java.security.Provider;
3335
import java.security.InvalidAlgorithmParameterException;
3436
import java.security.InvalidParameterException;
@@ -54,8 +56,7 @@ public void main(Provider p) throws Exception {
5456
try {
5557
kg = KeyGenerator.getInstance(ALGO, p);
5658
} catch (NoSuchAlgorithmException nsae) {
57-
System.out.println("Skip; no support for " + ALGO);
58-
return;
59+
throw new SkippedException("Skip; no support for " + ALGO, nsae);
5960
}
6061

6162
try {

test/jdk/sun/security/pkcs11/KeyGenerator/TestKeyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, 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

test/jdk/sun/security/pkcs11/KeyPairGenerator/TestDH2048.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 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 -Djava.security.manager=allow TestDH2048 sm
3333
*/
3434

35+
import jtreg.SkippedException;
36+
3537
import java.security.InvalidParameterException;
3638
import java.security.KeyPair;
3739
import java.security.KeyPairGenerator;
@@ -51,8 +53,7 @@ private static void checkUnsupportedKeySize(KeyPairGenerator kpg, int ks)
5153
@Override
5254
public void main(Provider p) throws Exception {
5355
if (p.getService("KeyPairGenerator", "DH") == null) {
54-
System.out.println("KPG for DH not supported, skipping");
55-
return;
56+
throw new SkippedException("KPG for DH not supported, skipping");
5657
}
5758
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", p);
5859
kpg.initialize(512);

test/jdk/sun/security/pkcs11/KeyPairGenerator/TestDefaultDHPrivateExpSize.java

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

24-
import java.security.KeyPair;
2524
import java.security.KeyPairGenerator;
2625
import java.security.Provider;
27-
import java.security.PrivateKey;
2826
import javax.crypto.spec.DHParameterSpec;
2927
import javax.crypto.interfaces.DHPrivateKey;
28+
29+
import jtreg.SkippedException;
3030
import sun.security.util.SecurityProviderConstants;
3131
import sun.security.provider.ParameterCache;
3232

@@ -47,8 +47,7 @@ public void main(Provider p) throws Exception {
4747
System.out.println("Testing " + p.getName());
4848

4949
if (p.getService("KeyPairGenerator", "DH") == null) {
50-
System.out.println("Skip, no support for DH KeyPairGenerator");
51-
return;
50+
throw new SkippedException("Skip, no support for DH KeyPairGenerator");
5251
}
5352

5453
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", p);

0 commit comments

Comments
 (0)