Skip to content

Commit cea617d

Browse files
committed
8365660: test/jdk/sun/security/pkcs11/KeyAgreement/ tests skipped without SkipExceprion
Backport-of: ec7361e082eff3859d9f0dd732f39ae9abd5089a
1 parent 1043c48 commit cea617d

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

test/jdk/sun/security/pkcs11/KeyAgreement/SupportedDHKeys.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 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,6 +31,8 @@
3131
* @run main/othervm -Djava.security.manager=allow SupportedDHKeys sm
3232
*/
3333

34+
import jtreg.SkippedException;
35+
3436
import java.math.BigInteger;
3537
import java.security.KeyPair;
3638
import java.security.KeyPairGenerator;
@@ -63,8 +65,7 @@ private enum SupportedKeySize {
6365
@Override
6466
public void main(Provider provider) throws Exception {
6567
if (provider.getService("KeyPairGenerator", "DiffieHellman") == null) {
66-
System.out.println("No support of DH KeyPairGenerator, skipping");
67-
return;
68+
throw new SkippedException("No support of DH KeyPairGenerator, skipping");
6869
}
6970

7071
for (SupportedKeySize keySize : SupportedKeySize.values()) {

test/jdk/sun/security/pkcs11/KeyAgreement/TestDH.java

Lines changed: 3 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
@@ -39,14 +39,14 @@
3939
import javax.crypto.KeyAgreement;
4040
import javax.crypto.SecretKey;
4141
import jdk.test.lib.security.SecurityUtils;
42+
import jtreg.SkippedException;
4243

4344
public class TestDH extends PKCS11Test {
4445

4546
@Override
4647
public void main(Provider p) throws Exception {
4748
if (p.getService("KeyAgreement", "DH") == null) {
48-
System.out.println("DH not supported, skipping");
49-
return;
49+
throw new SkippedException("DH not supported, skipping");
5050
}
5151
String kpgAlgorithm = "DH";
5252
KeyPairGenerator kpg = KeyPairGenerator.getInstance(kpgAlgorithm, p);

test/jdk/sun/security/pkcs11/KeyAgreement/TestInterop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -41,6 +41,7 @@
4141
import javax.crypto.spec.DHPublicKeySpec;
4242
import jdk.test.lib.security.DiffieHellmanGroup;
4343
import jdk.test.lib.security.SecurityUtils;
44+
import jtreg.SkippedException;
4445

4546
public class TestInterop extends PKCS11Test {
4647

@@ -77,8 +78,7 @@ public class TestInterop extends PKCS11Test {
7778
@Override
7879
public void main(Provider prov) throws Exception {
7980
if (prov.getService("KeyAgreement", "DH") == null) {
80-
System.out.println("DH not supported, skipping");
81-
return;
81+
throw new SkippedException("DH not supported, skipping");
8282
}
8383
try {
8484
System.out.println("testing generateSecret()");

test/jdk/sun/security/pkcs11/KeyAgreement/TestShort.java

Lines changed: 7 additions & 28 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
@@ -32,6 +32,8 @@
3232
* @run main/othervm -Djava.security.manager=allow TestShort sm
3333
*/
3434

35+
import jtreg.SkippedException;
36+
3537
import java.math.BigInteger;
3638
import java.security.KeyFactory;
3739
import java.security.PrivateKey;
@@ -91,12 +93,10 @@ public class TestShort extends PKCS11Test {
9193
@Override
9294
public void main(Provider provider) throws Exception {
9395
if (provider.getService("KeyAgreement", "DH") == null) {
94-
System.out.println("DH not supported, skipping");
95-
return;
96+
throw new SkippedException("DH not supported, skipping");
9697
}
98+
9799
try {
98-
DHPublicKeySpec publicSpec;
99-
DHPrivateKeySpec privateSpec;
100100
KeyFactory kf = KeyFactory.getInstance("DH", provider);
101101
KeyAgreement ka = KeyAgreement.getInstance("DH", provider);
102102

@@ -107,15 +107,15 @@ public void main(Provider provider) throws Exception {
107107
ka.init(pr1);
108108
ka.doPhase(pu2, true);
109109
byte[] n2 = ka.generateSecret();
110-
if (Arrays.equals(s2, n2) == false) {
110+
if (!Arrays.equals(s2, n2)) {
111111
throw new Exception("mismatch 2");
112112
}
113113
System.out.println("short ok");
114114

115115
ka.init(pr1);
116116
ka.doPhase(pu3, true);
117117
byte[] n3 = ka.generateSecret();
118-
if (Arrays.equals(s3, n3) == false) {
118+
if (!Arrays.equals(s3, n3)) {
119119
throw new Exception("mismatch 3");
120120
}
121121
System.out.println("normal ok");
@@ -124,27 +124,6 @@ public void main(Provider provider) throws Exception {
124124
ex.printStackTrace();
125125
throw ex;
126126
}
127-
128-
/*
129-
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", provider);
130-
kpg.initialize(512);
131-
// KeyPair kp1 = kpg.generateKeyPair();
132-
// System.out.println(kp1.getPublic());
133-
// System.out.println(kp1.getPrivate());
134-
while (true) {
135-
KeyAgreement ka = KeyAgreement.getInstance("DH", provider);
136-
ka.init(pr1);
137-
KeyPair kp2 = kpg.generateKeyPair();
138-
ka.doPhase(kp2.getPublic(), true);
139-
byte[] sec = ka.generateSecret();
140-
if (sec.length == 64) {
141-
System.out.println(kp2.getPrivate());
142-
System.out.println(kp2.getPublic());
143-
System.out.println(toString(sec));
144-
break;
145-
}
146-
}
147-
/**/
148127
}
149128

150129
public static void main(String[] args) throws Exception {

test/jdk/sun/security/pkcs11/KeyAgreement/UnsupportedDHKeys.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 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,6 +31,8 @@
3131
* @run main/othervm -Djava.security.manager=allow UnsupportedDHKeys sm
3232
*/
3333

34+
import jtreg.SkippedException;
35+
3436
import java.security.InvalidParameterException;
3537
import java.security.KeyPairGenerator;
3638
import java.security.Provider;
@@ -60,8 +62,7 @@ private enum UnsupportedKeySize {
6062
@Override
6163
public void main(Provider provider) throws Exception {
6264
if (provider.getService("KeyPairGenerator", "DiffieHellman") == null) {
63-
System.out.println("No supported of DH KeyPairGenerator, skipping");
64-
return;
65+
throw new SkippedException("DH (DiffieHellman) is not supported in KeyPairGenerator, skipping");
6566
}
6667

6768
for (UnsupportedKeySize keySize : UnsupportedKeySize.values()) {

0 commit comments

Comments
 (0)