Skip to content

Commit 21c65a9

Browse files
committed
JDK-8373016: Passes instead of skips/ignoring the platform in sun/security/mscapi, jarsigner, keytool and pkcs12 tests
1 parent f5eecc4 commit 21c65a9

File tree

8 files changed

+88
-47
lines changed

8 files changed

+88
-47
lines changed

test/jdk/sun/security/mscapi/IsSunMSCAPIAvailable.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 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
@@ -26,11 +26,18 @@
2626
* @bug 6318171 6931562
2727
* @requires os.family == "windows"
2828
* @modules jdk.crypto.mscapi/sun.security.mscapi
29+
* @library /test/lib/
2930
* @run main/othervm IsSunMSCAPIAvailable
3031
*/
3132

33+
import jtreg.SkippedException;
34+
35+
import java.security.GeneralSecurityException;
36+
import java.security.KeyPairGenerator;
3237
import java.security.Provider;
33-
import java.security.*;
38+
import java.security.SecureRandom;
39+
import java.security.Security;
40+
import java.security.Signature;
3441
import javax.crypto.Cipher;
3542

3643
public class IsSunMSCAPIAvailable {
@@ -105,7 +112,7 @@ public static void main(String[] args) throws Exception {
105112
cipher.getClass().getName());
106113

107114
} catch (GeneralSecurityException e) {
108-
System.out.println("Cipher not supported by provider, skipping...");
115+
throw new SkippedException("Cipher not supported by provider");
109116
}
110117
}
111118
}

test/jdk/sun/security/mscapi/RSAEncryptDecrypt.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 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,8 +29,11 @@
2929
* RSA cipher in the SunMSCAPI crypto provider. NOTE: The RSA cipher is
3030
* absent from the SunMSCAPI provider in OpenJDK builds.
3131
* @requires os.family == "windows"
32+
* @library /test/lib/
3233
*/
3334

35+
import jtreg.SkippedException;
36+
3437
import javax.crypto.Cipher;
3538
import java.security.GeneralSecurityException;
3639
import java.security.KeyPairGenerator;
@@ -55,8 +58,7 @@ public static void main(String[] args) throws Exception {
5558
cipher = Cipher.getInstance("RSA", "SunMSCAPI");
5659

5760
} catch (GeneralSecurityException e) {
58-
System.out.println("Cipher not supported by provider, skipping...");
59-
return;
61+
throw new SkippedException("Cipher not supported by provider");
6062
}
6163

6264
cipher.init(Cipher.ENCRYPT_MODE, publicKey);

test/jdk/sun/security/mscapi/SignUsingNONEwithRSA.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 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
@@ -28,12 +28,24 @@
2828
* java.base/sun.security.tools.keytool
2929
* @requires os.family == "windows"
3030
* @summary Sign using the NONEwithRSA signature algorithm from SunMSCAPI
31+
* @library /test/lib/
3132
*/
3233

33-
import java.security.*;
34+
import java.security.KeyPair;
35+
import java.security.KeyPairGenerator;
36+
import java.security.PrivateKey;
37+
import java.security.Provider;
38+
import java.security.PublicKey;
39+
import java.security.Security;
40+
import java.security.Signature;
41+
import java.security.SignatureException;
3442
import java.security.cert.X509Certificate;
3543
import java.security.interfaces.RSAPrivateCrtKey;
36-
import java.util.*;
44+
import java.util.ArrayList;
45+
import java.util.Enumeration;
46+
import java.util.List;
47+
48+
import jtreg.SkippedException;
3749
import sun.security.tools.keytool.CertAndKeyGen;
3850
import sun.security.x509.X500Name;
3951

@@ -91,9 +103,8 @@ public static void main(String[] args) throws Exception {
91103
if (providers == null) {
92104
System.out.println("No JCE providers support the " +
93105
"'Signature.NONEwithRSA' algorithm");
94-
System.out.println("Skipping this test...");
95-
return;
96-
106+
throw new SkippedException("No JCE providers support the " +
107+
"'Signature.NONEwithRSA' algorithm");
97108
} else {
98109
System.out.println("The following JCE providers support the " +
99110
"'Signature.NONEwithRSA' algorithm: ");
@@ -109,7 +120,8 @@ public static void main(String[] args) throws Exception {
109120
ckg.generate(1024);
110121
RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey();
111122
ks.setKeyEntry("6578658", k, null, new X509Certificate[]{
112-
ckg.getSelfCertificate(new X500Name("cn=6578658,c=US"), 1000)
123+
ckg.getSelfCertificate(
124+
new X500Name("cn=6578658,c=US"), 1000)
113125
});
114126
ks.store(null, null);
115127

test/jdk/sun/security/mscapi/SignUsingSHA2withRSA.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@
2626
* @bug 6753664 8180570
2727
* @summary Support SHA256 (and higher) in SunMSCAPI
2828
* @requires os.family == "windows"
29+
* @library /test/lib/
2930
* @modules java.base/sun.security.tools.keytool
3031
* java.base/sun.security.x509
3132
*/
3233

34+
import jtreg.SkippedException;
3335
import sun.security.tools.keytool.CertAndKeyGen;
3436
import sun.security.x509.X500Name;
3537

36-
import java.security.*;
38+
import java.security.PrivateKey;
39+
import java.security.Provider;
40+
import java.security.PublicKey;
41+
import java.security.Security;
42+
import java.security.Signature;
43+
import java.security.SignatureException;
3744
import java.security.cert.Certificate;
38-
import java.util.*;
45+
import java.util.ArrayList;
46+
import java.util.Enumeration;
47+
import java.util.List;
3948

4049
public class SignUsingSHA2withRSA {
4150

@@ -57,7 +66,8 @@ public static void main(String[] args) throws Exception {
5766

5867
ks.setKeyEntry("6753664", gen.getPrivateKey(), null,
5968
new Certificate[] {
60-
gen.getSelfCertificate(new X500Name("cn=localhost,c=US"), 100)
69+
gen.getSelfCertificate(
70+
new X500Name("cn=localhost,c=US"), 100)
6171
});
6272

6373
try {
@@ -74,9 +84,8 @@ static void run() throws Exception {
7484
if (providers == null) {
7585
System.out.println("No JCE providers support the " +
7686
"'Signature.SHA256withRSA' algorithm");
77-
System.out.println("Skipping this test...");
78-
return;
79-
87+
throw new SkippedException("No JCE providers support the " +
88+
"'Signature.SHA256withRSA' algorithm");
8089
} else {
8190
System.out.println("The following JCE providers support the " +
8291
"'Signature.SHA256withRSA' algorithm: ");

test/jdk/sun/security/pkcs12/StoreSecretKeyTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2015, 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
@@ -25,16 +25,23 @@
2525
* @test
2626
* @bug 8005408 8079129 8048830
2727
* @summary KeyStore API enhancements
28-
* @run main StoreSecretKeyTest
28+
* @library /test/lib/
2929
*/
3030

31-
import java.io.*;
32-
import java.security.*;
33-
import java.security.cert.*;
31+
import jtreg.SkippedException;
32+
33+
import java.io.File;
34+
import java.io.FileInputStream;
35+
import java.io.FileOutputStream;
36+
import java.security.KeyStoreException;
37+
import java.security.NoSuchAlgorithmException;
38+
import java.security.UnrecoverableKeyException;
3439
import java.security.cert.Certificate;
35-
import java.util.*;
36-
import javax.crypto.*;
37-
import javax.crypto.spec.*;
40+
import java.security.cert.CertificateFactory;
41+
import javax.crypto.KeyGenerator;
42+
import javax.crypto.SecretKey;
43+
import javax.crypto.SecretKeyFactory;
44+
import java.security.KeyStore;
3845

3946
// Store a secret key in a keystore and retrieve it again.
4047

@@ -63,8 +70,7 @@ public static void main(String[] args) throws Exception {
6370
try {
6471
SecretKeyFactory.getInstance("AES");
6572
} catch (NoSuchAlgorithmException nsae) {
66-
System.out.println("AES is unavailable. Skipping test...");
67-
return;
73+
throw new SkippedException("AES is unavailable");
6874
}
6975

7076
for (ALGORITHM alg : ALGORITHM.values()) {
@@ -137,7 +143,6 @@ private static SecretKey generateSecretKey(String algorithm, int size)
137143

138144
private static Certificate loadCertificate(String certFile)
139145
throws Exception {
140-
X509Certificate cert = null;
141146
try (FileInputStream certStream = new FileInputStream(certFile)) {
142147
CertificateFactory factory =
143148
CertificateFactory.getInstance("X.509");

test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@
2727
* @summary InputStream should be closed in sun.security.tools.jarsigner.Main
2828
* @modules java.base/sun.security.tools.keytool
2929
* jdk.jartool/sun.security.tools.jarsigner
30+
* @requires os.family == "windows"
31+
* @library /test/lib/
3032
* @run main/othervm CertChainUnclosed
3133
*/
3234

3335
import java.nio.file.Files;
3436
import java.nio.file.Paths;
35-
import java.util.Locale;
3637

3738
public class CertChainUnclosed {
3839

3940
public static void main(String[] args) throws Exception {
40-
String os = System.getProperty("os.name");
41-
if (!os.toUpperCase(Locale.US).contains("WINDOWS")) {
42-
System.out.println("Not Windows. Skip test.");
43-
return;
44-
}
4541

4642
kt("-genkeypair -alias a -dname CN=A");
4743
kt("-exportcert -file a.crt -alias a");

test/jdk/sun/security/tools/keytool/StorePasswords.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, 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
@@ -30,12 +30,21 @@
3030

3131
import jdk.test.lib.SecurityTools;
3232
import jdk.test.lib.process.OutputAnalyzer;
33-
34-
import java.io.*;
35-
import java.security.*;
36-
import java.util.*;
37-
import javax.crypto.*;
38-
import javax.crypto.spec.*;
33+
import jtreg.SkippedException;
34+
35+
import java.io.File;
36+
import java.io.FileInputStream;
37+
import java.io.FileOutputStream;
38+
import java.security.InvalidAlgorithmParameterException;
39+
import java.security.InvalidKeyException;
40+
import java.security.KeyStoreException;
41+
import java.security.UnrecoverableKeyException;
42+
import javax.crypto.SecretKey;
43+
import java.security.KeyStore;
44+
import javax.crypto.SecretKeyFactory;
45+
import javax.crypto.spec.PBEKeySpec;
46+
import javax.crypto.spec.PBEParameterSpec;
47+
import java.util.Arrays;
3948

4049
/*
4150
* Store and retrieve passwords protected by a selection of PBE algorithms,
@@ -148,11 +157,9 @@ private static int store() throws Exception {
148157
algorithm, specWithEightByteSalt));
149158
count++;
150159

151-
} else if (inner2 instanceof InvalidKeyException) {
152-
System.out.println("...skipping due to: " +
153-
inner2.getMessage());
160+
} else if (inner2 instanceof InvalidKeyException) {
161+
throw new SkippedException(inner2.getMessage());
154162
// Unsupported crypto keysize
155-
continue;
156163
}
157164
} else {
158165
throw e;

test/jdk/sun/security/util/ManifestDigester/FindSection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
import java.util.concurrent.Callable;
2929
import java.util.function.Consumer;
3030

31+
import sun.security.tools.jarsigner.resources.jarsigner;
32+
import sun.security.tools.keytool.resources.keytool;
3133
import sun.security.util.ManifestDigester;
3234

3335
import org.testng.annotations.Test;
3436
import org.testng.annotations.BeforeClass;
3537
import org.testng.annotations.BeforeMethod;
3638
import org.testng.annotations.DataProvider;
3739
import org.testng.annotations.Factory;
40+
import sun.security.util.resources.security;
3841

3942
import static java.nio.charset.StandardCharsets.UTF_8;
4043
import static org.testng.Assert.*;

0 commit comments

Comments
 (0)