Skip to content

Commit 9bdf2a6

Browse files
committed
8341927: Replace hardcoded security providers with new test.provider.name system property
8343848: Fix typo of property name in TestOAEPPadding after 8341927 Reviewed-by: lucy Backport-of: 9a9ac1d0059438d33fe69ef51265dc7cff6ad2bd
1 parent 7869713 commit 9bdf2a6

File tree

230 files changed

+1006
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+1006
-699
lines changed

doc/testing.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ <h1 class="title">Testing the JDK</h1>
7272
<li><a href="#non-us-locale" id="toc-non-us-locale">Non-US
7373
locale</a></li>
7474
<li><a href="#pkcs11-tests" id="toc-pkcs11-tests">PKCS11 Tests</a></li>
75+
<li><a href="#testing-with-alternative-security-providers"
76+
id="toc-testing-with-alternative-security-providers">Testing with
77+
alternative security providers</a></li>
7578
<li><a href="#client-ui-tests" id="toc-client-ui-tests">Client UI
7679
Tests</a></li>
7780
</ul></li>
@@ -589,6 +592,18 @@ <h3 id="pkcs11-tests">PKCS11 Tests</h3>
589592
JTREG=&quot;JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs&quot;</code></pre>
590593
<p>For more notes about the PKCS11 tests, please refer to
591594
test/jdk/sun/security/pkcs11/README.</p>
595+
<h3 id="testing-with-alternative-security-providers">Testing with
596+
alternative security providers</h3>
597+
<p>Some security tests use a hardcoded provider for
598+
<code>KeyFactory</code>, <code>Cipher</code>,
599+
<code>KeyPairGenerator</code>, <code>KeyGenerator</code>,
600+
<code>AlgorithmParameterGenerator</code>, <code>KeyAgreement</code>,
601+
<code>Mac</code>, <code>MessageDigest</code>, <code>SecureRandom</code>,
602+
<code>Signature</code>, <code>AlgorithmParameters</code>,
603+
<code>Configuration</code>, <code>Policy</code>, or
604+
<code>SecretKeyFactory</code> objects. Specify the
605+
<code>-Dtest.provider.name=NAME</code> property to use a different
606+
provider for the service(s).</p>
592607
<h3 id="client-ui-tests">Client UI Tests</h3>
593608
<h4 id="system-key-shortcuts">System key shortcuts</h4>
594609
<p>Some Client UI tests use key sequences which may be reserved by the

doc/testing.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ $ make test TEST="jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java" \
615615
For more notes about the PKCS11 tests, please refer to
616616
test/jdk/sun/security/pkcs11/README.
617617

618+
### Testing with alternative security providers
619+
620+
Some security tests use a hardcoded provider for `KeyFactory`, `Cipher`,
621+
`KeyPairGenerator`, `KeyGenerator`, `AlgorithmParameterGenerator`,
622+
`KeyAgreement`, `Mac`, `MessageDigest`, `SecureRandom`, `Signature`,
623+
`AlgorithmParameters`, `Configuration`, `Policy`, or `SecretKeyFactory` objects.
624+
Specify the `-Dtest.provider.name=NAME` property to use a different provider for
625+
the service(s).
626+
618627
### Client UI Tests
619628

620629
#### System key shortcuts

test/jdk/com/sun/crypto/provider/CICO/CICODESFuncTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -66,7 +66,8 @@ public class CICODESFuncTest {
6666
private static final int IV_LENGTH = 8;
6767

6868
public static void main(String[] args) throws Exception {
69-
Provider provider = Security.getProvider("SunJCE");
69+
Provider provider = Security.getProvider(
70+
System.getProperty("test.provider.name", "SunJCE"));
7071
if (provider == null) {
7172
throw new RuntimeException("SunJCE provider does not exist.");
7273
}

test/jdk/com/sun/crypto/provider/CICO/CICOSkipTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -204,9 +204,10 @@ private void initCiphers(String algo, SecretKey key,
204204
AlgorithmParameterSpec aps) throws NoSuchAlgorithmException,
205205
NoSuchPaddingException, InvalidKeyException,
206206
InvalidAlgorithmParameterException {
207-
Provider provider = Security.getProvider("SunJCE");
207+
String providerName = System.getProperty("test.provider.name", "SunJCE");
208+
Provider provider = Security.getProvider(providerName);
208209
if (provider == null) {
209-
throw new RuntimeException("SunJCE provider does not exist.");
210+
throw new RuntimeException(providerName + " provider does not exist.");
210211
}
211212
Cipher ci1 = Cipher.getInstance(algo, provider);
212213
ci1.init(Cipher.ENCRYPT_MODE, key, aps);

test/jdk/com/sun/crypto/provider/CICO/PBEFunc/AESPBEWrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -69,9 +69,10 @@ public AESPBEWrapper(PBEAlgorithm algo, String passwd)
6969
*/
7070
@Override
7171
protected Cipher initCipher(int mode) throws GeneralSecurityException {
72-
Provider provider = Security.getProvider("SunJCE");
72+
String providerName = System.getProperty("test.provider.name", "SunJCE");
73+
Provider provider = Security.getProvider(providerName);
7374
if (provider == null) {
74-
throw new RuntimeException("SunJCE provider does not exist.");
75+
throw new RuntimeException(providerName + ": provider does not exist.");
7576
}
7677
// get Cipher instance
7778
Cipher ci = Cipher.getInstance(transformation, provider);

test/jdk/com/sun/crypto/provider/CICO/PBEFunc/DefaultPBEWrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -58,9 +58,10 @@ public DefaultPBEWrapper(PBEAlgorithm algo, String passwd) {
5858
*/
5959
@Override
6060
protected Cipher initCipher(int mode) throws GeneralSecurityException {
61-
Provider provider = Security.getProvider("SunJCE");
61+
String providerName = System.getProperty("test.provider.name", "SunJCE");
62+
Provider provider = Security.getProvider(providerName);
6263
if (provider == null) {
63-
throw new RuntimeException("SunJCE provider does not exist.");
64+
throw new RuntimeException(providerName + ": provider does not exist.");
6465
}
6566
SecretKey key = SecretKeyFactory.getInstance(baseAlgo)
6667
.generateSecret(new PBEKeySpec(password.toCharArray()));

test/jdk/com/sun/crypto/provider/CICO/PBEFunc/PBKDF2Wrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -89,9 +89,10 @@ public PBKDF2Wrapper(PBEAlgorithm algo, String passwd)
8989
*/
9090
@Override
9191
protected Cipher initCipher(int mode) throws GeneralSecurityException {
92-
Provider provider = Security.getProvider("SunJCE");
92+
String providerName = System.getProperty("test.provider.name", "SunJCE");
93+
Provider provider = Security.getProvider(providerName);
9394
if (provider == null) {
94-
throw new RuntimeException("SunJCE provider does not exist.");
95+
throw new RuntimeException(providerName + ": provider does not exist.");
9596
}
9697
// Generate secret key
9798
PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(),

test/jdk/com/sun/crypto/provider/Cipher/AEAD/Encrypt.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -122,7 +122,8 @@ public Encrypt(Provider provider, String algorithm, String mode,
122122
}
123123

124124
public static void main(String[] args) throws Exception {
125-
Provider p = Security.getProvider("SunJCE");
125+
Provider p = Security.getProvider(
126+
System.getProperty("test.provider.name", "SunJCE"));
126127
for (String alg : ALGORITHMS) {
127128
for (int keyStrength : KEY_STRENGTHS) {
128129
if (keyStrength > Cipher.getMaxAllowedKeyLength(alg)) {

test/jdk/com/sun/crypto/provider/Cipher/AEAD/GCMLargeDataKAT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, 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
@@ -102,7 +102,8 @@ public class GCMLargeDataKAT {
102102

103103
byte[] encrypt(int inLen) {
104104
try {
105-
cipher = Cipher.getInstance("AES/GCM/NoPadding", "SunJCE");
105+
cipher = Cipher.getInstance("AES/GCM/NoPadding",
106+
System.getProperty("test.provider.name", "SunJCE"));
106107
cipher.init(Cipher.ENCRYPT_MODE, key, spec);
107108
return cipher.doFinal(plaintext, 0, inLen);
108109
} catch (Exception e) {
@@ -125,7 +126,8 @@ boolean decrypt(byte[] data) {
125126
return false;
126127
}
127128
try {
128-
cipher = Cipher.getInstance("AES/GCM/NoPadding", "SunJCE");
129+
cipher = Cipher.getInstance("AES/GCM/NoPadding",
130+
System.getProperty("test.provider.name", "SunJCE"));
129131
cipher.init(Cipher.DECRYPT_MODE, key, spec);
130132
result = cipher.doFinal(data);
131133
} catch (Exception e) {

test/jdk/com/sun/crypto/provider/Cipher/AEAD/GCMParameterSpecTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -87,7 +87,8 @@ public GCMParameterSpecTest(int keyLength, int tagLength, int IVlength,
8787
AAD = Helper.generateBytes(AADLength);
8888

8989
// init a secret key
90-
KeyGenerator kg = KeyGenerator.getInstance("AES", "SunJCE");
90+
KeyGenerator kg = KeyGenerator.getInstance("AES",
91+
System.getProperty("test.provider.name", "SunJCE"));
9192
kg.init(keyLength);
9293
key = kg.generateKey();
9394
}
@@ -211,7 +212,8 @@ private byte[] recoverCipherText(byte[] cipherText, GCMParameterSpec spec)
211212

212213
private Cipher createCipher(int mode, GCMParameterSpec spec)
213214
throws Exception {
214-
Cipher cipher = Cipher.getInstance(TRANSFORMATION, "SunJCE");
215+
Cipher cipher = Cipher.getInstance(TRANSFORMATION,
216+
System.getProperty("test.provider.name", "SunJCE"));
215217
cipher.init(mode, key, spec);
216218
return cipher;
217219
}

0 commit comments

Comments
 (0)