Skip to content

Commit 223cc64

Browse files
author
Matthew Donovan
committed
8343316: Review and update tests using explicit provider names
Reviewed-by: rhalade
1 parent 9ea8201 commit 223cc64

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

test/jdk/com/sun/crypto/provider/KeyAgreement/DHGenSharedSecret.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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,6 +39,9 @@
3939

4040
public class DHGenSharedSecret {
4141

42+
private static final String PROVIDER_NAME =
43+
System.getProperty("test.provider.name", "SunJCE");
44+
4245
public static void main(String[] args) throws Exception {
4346
DHGenSharedSecret test = new DHGenSharedSecret();
4447
test.run();
@@ -57,7 +60,7 @@ public void run() throws Exception {
5760

5861
// generate keyPairs using parameters
5962
KeyPairGenerator keyGen =
60-
KeyPairGenerator.getInstance("DH", "SunJCE");
63+
KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
6164
keyGen.initialize(spec);
6265

6366
// Alice generates her key pairs
@@ -77,11 +80,11 @@ public void run() throws Exception {
7780
// bob uses it to generate Secret
7881
X509EncodedKeySpec x509Spec =
7982
new X509EncodedKeySpec(alicePubKeyEnc);
80-
KeyFactory bobKeyFac = KeyFactory.getInstance("DH", "SunJCE");
83+
KeyFactory bobKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME);
8184
PublicKey alicePubKey = bobKeyFac.generatePublic(x509Spec);
8285

8386

84-
KeyAgreement bobAlice = KeyAgreement.getInstance("DH", "SunJCE");
87+
KeyAgreement bobAlice = KeyAgreement.getInstance("DH", PROVIDER_NAME);
8588
start = System.currentTimeMillis();
8689
bobAlice.init(keyB.getPrivate());
8790
bobAlice.doPhase(alicePubKey, true);

test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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
@@ -53,7 +53,8 @@
5353

5454
public class DHKeyAgreement2 {
5555

56-
private static final String SUNJCE = "SunJCE";
56+
private static final String PROVIDER_NAME = System.getProperty(
57+
"test.provider.name", "SunJCE");
5758

5859
// Hex formatter to upper case with ":" delimiter
5960
private static final HexFormat HEX_FORMATTER = HexFormat.ofDelimiter(":").withUpperCase();
@@ -90,7 +91,7 @@ private void run(String mode) throws Exception {
9091
// Some central authority creates new DH parameters
9192
System.err.println("Creating Diffie-Hellman parameters ...");
9293
AlgorithmParameterGenerator paramGen
93-
= AlgorithmParameterGenerator.getInstance("DH", SUNJCE);
94+
= AlgorithmParameterGenerator.getInstance("DH", PROVIDER_NAME);
9495
paramGen.init(primeSize);
9596
AlgorithmParameters params = paramGen.generateParameters();
9697
dhParameterSpec = (DHParameterSpec)params.getParameterSpec
@@ -108,7 +109,7 @@ private void run(String mode) throws Exception {
108109
* above
109110
*/
110111
System.err.println("ALICE: Generate DH keypair ...");
111-
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", SUNJCE);
112+
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
112113
aliceKpairGen.initialize(dhParameterSpec);
113114
KeyPair aliceKpair = aliceKpairGen.generateKeyPair();
114115
System.out.println("Alice DH public key:\n" +
@@ -117,14 +118,14 @@ private void run(String mode) throws Exception {
117118
aliceKpair.getPrivate().toString());
118119
DHParameterSpec dhParamSpec =
119120
((DHPublicKey)aliceKpair.getPublic()).getParams();
120-
AlgorithmParameters algParams = AlgorithmParameters.getInstance("DH", SUNJCE);
121+
AlgorithmParameters algParams = AlgorithmParameters.getInstance("DH", PROVIDER_NAME);
121122
algParams.init(dhParamSpec);
122123
System.out.println("Alice DH parameters:\n"
123124
+ algParams.toString());
124125

125126
// Alice executes Phase1 of her version of the DH protocol
126127
System.err.println("ALICE: Execute PHASE1 ...");
127-
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", SUNJCE);
128+
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME);
128129
aliceKeyAgree.init(aliceKpair.getPrivate());
129130

130131
// Alice encodes her public key, and sends it over to Bob.
@@ -135,7 +136,7 @@ private void run(String mode) throws Exception {
135136
* in encoded format.
136137
* He instantiates a DH public key from the encoded key material.
137138
*/
138-
KeyFactory bobKeyFac = KeyFactory.getInstance("DH", SUNJCE);
139+
KeyFactory bobKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME);
139140
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec
140141
(alicePubKeyEnc);
141142
PublicKey alicePubKey = bobKeyFac.generatePublic(x509KeySpec);
@@ -149,7 +150,7 @@ private void run(String mode) throws Exception {
149150

150151
// Bob creates his own DH key pair
151152
System.err.println("BOB: Generate DH keypair ...");
152-
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", SUNJCE);
153+
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
153154
bobKpairGen.initialize(dhParamSpec);
154155
KeyPair bobKpair = bobKpairGen.generateKeyPair();
155156
System.out.println("Bob DH public key:\n" +
@@ -159,7 +160,7 @@ private void run(String mode) throws Exception {
159160

160161
// Bob executes Phase1 of his version of the DH protocol
161162
System.err.println("BOB: Execute PHASE1 ...");
162-
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", SUNJCE);
163+
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME);
163164
bobKeyAgree.init(bobKpair.getPrivate());
164165

165166
// Bob encodes his public key, and sends it over to Alice.
@@ -171,7 +172,7 @@ private void run(String mode) throws Exception {
171172
* Before she can do so, she has to instanticate a DH public key
172173
* from Bob's encoded key material.
173174
*/
174-
KeyFactory aliceKeyFac = KeyFactory.getInstance("DH", SUNJCE);
175+
KeyFactory aliceKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME);
175176
x509KeySpec = new X509EncodedKeySpec(bobPubKeyEnc);
176177
PublicKey bobPubKey = aliceKeyFac.generatePublic(x509KeySpec);
177178
System.err.println("ALICE: Execute PHASE2 ...");

test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement3.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 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
@@ -50,6 +50,9 @@
5050

5151
public class DHKeyAgreement3 {
5252

53+
private static final String PROVIDER_NAME =
54+
System.getProperty("test.provider.name", "SunJCE");
55+
5356
// Hex formatter to upper case with ":" delimiter
5457
private static final HexFormat HEX_FORMATTER = HexFormat.ofDelimiter(":").withUpperCase();
5558

@@ -70,36 +73,36 @@ private void run() throws Exception {
7073

7174
// Alice creates her own DH key pair
7275
System.err.println("ALICE: Generate DH keypair ...");
73-
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
76+
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
7477
aliceKpairGen.initialize(dhParamSpec);
7578
KeyPair aliceKpair = aliceKpairGen.generateKeyPair();
7679

7780
// Bob creates his own DH key pair
7881
System.err.println("BOB: Generate DH keypair ...");
79-
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
82+
KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
8083
bobKpairGen.initialize(dhParamSpec);
8184
KeyPair bobKpair = bobKpairGen.generateKeyPair();
8285

8386
// Carol creates her own DH key pair
8487
System.err.println("CAROL: Generate DH keypair ...");
85-
KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE");
88+
KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME);
8689
carolKpairGen.initialize(dhParamSpec);
8790
KeyPair carolKpair = carolKpairGen.generateKeyPair();
8891

8992

9093
// Alice initialize
9194
System.err.println("ALICE: Initialize ...");
92-
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
95+
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME);
9396
aliceKeyAgree.init(aliceKpair.getPrivate());
9497

9598
// Bob initialize
9699
System.err.println("BOB: Initialize ...");
97-
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
100+
KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME);
98101
bobKeyAgree.init(bobKpair.getPrivate());
99102

100103
// Carol initialize
101104
System.err.println("CAROL: Initialize ...");
102-
KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH", "SunJCE");
105+
KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME);
103106
carolKeyAgree.init(carolKpair.getPrivate());
104107

105108

test/jdk/java/security/Provider/ProviderVersionCheck.java

Lines changed: 6 additions & 1 deletion
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
@@ -42,6 +42,11 @@ public static void main(String arg[]) throws Exception{
4242

4343
for (Provider p: Security.getProviders()) {
4444
System.out.print(p.getName() + " ");
45+
if (p.getName().equals(System.getProperty("test.provider.name"))) {
46+
// Version numbers of non JDK-providers do not match JDK version number.
47+
continue;
48+
}
49+
4550
String specVersion = System.getProperty("java.specification.version");
4651
if (p.getVersion() != Double.parseDouble(specVersion)) {
4752
System.out.println("failed. " + "Version received was " +

0 commit comments

Comments
 (0)