Skip to content

Commit ec7361e

Browse files
myankelevRajan Halade
authored andcommitted
8365660: test/jdk/sun/security/pkcs11/KeyAgreement/ tests skipped without SkipExceprion
Reviewed-by: rhalade
1 parent a005301 commit ec7361e

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, 2024, 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
@@ -30,6 +30,8 @@
3030
* @run main/othervm SupportedDHKeys
3131
*/
3232

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

6970
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
@@ -38,14 +38,14 @@
3838
import javax.crypto.KeyAgreement;
3939
import javax.crypto.SecretKey;
4040
import jdk.test.lib.security.SecurityUtils;
41+
import jtreg.SkippedException;
4142

4243
public class TestDH extends PKCS11Test {
4344

4445
@Override
4546
public void main(Provider p) throws Exception {
4647
if (p.getService("KeyAgreement", "DH") == null) {
47-
System.out.println("DH not supported, skipping");
48-
return;
48+
throw new SkippedException("DH not supported, skipping");
4949
}
5050
String kpgAlgorithm = "DH";
5151
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
@@ -40,6 +40,7 @@
4040
import javax.crypto.spec.DHPublicKeySpec;
4141
import jdk.test.lib.security.DiffieHellmanGroup;
4242
import jdk.test.lib.security.SecurityUtils;
43+
import jtreg.SkippedException;
4344

4445
public class TestInterop extends PKCS11Test {
4546

@@ -76,8 +77,7 @@ public class TestInterop extends PKCS11Test {
7677
@Override
7778
public void main(Provider prov) throws Exception {
7879
if (prov.getService("KeyAgreement", "DH") == null) {
79-
System.out.println("DH not supported, skipping");
80-
return;
80+
throw new SkippedException("DH not supported, skipping");
8181
}
8282
try {
8383
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, 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
@@ -31,6 +31,8 @@
3131
* @run main/othervm TestShort
3232
*/
3333

34+
import jtreg.SkippedException;
35+
3436
import java.math.BigInteger;
3537
import java.security.KeyFactory;
3638
import java.security.PrivateKey;
@@ -90,12 +92,10 @@ public class TestShort extends PKCS11Test {
9092
@Override
9193
public void main(Provider provider) throws Exception {
9294
if (provider.getService("KeyAgreement", "DH") == null) {
93-
System.out.println("DH not supported, skipping");
94-
return;
95+
throw new SkippedException("DH not supported, skipping");
9596
}
97+
9698
try {
97-
DHPublicKeySpec publicSpec;
98-
DHPrivateKeySpec privateSpec;
9999
KeyFactory kf = KeyFactory.getInstance("DH", provider);
100100
KeyAgreement ka = KeyAgreement.getInstance("DH", provider);
101101

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

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

149128
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, 2024, 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
@@ -30,6 +30,8 @@
3030
* @run main/othervm UnsupportedDHKeys
3131
*/
3232

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

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

0 commit comments

Comments
 (0)