Skip to content

Commit

Permalink
8295343: sun/security/pkcs11 tests fail on Linux RHEL 8.6 and newer
Browse files Browse the repository at this point in the history
Reviewed-by: lucy
Backport-of: 6ce0ebb858d3112f136e12d3ad595f805f6871a0
  • Loading branch information
Andrew Lu committed Apr 19, 2024
1 parent 30a9a21 commit d4512fe
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 109 deletions.
4 changes: 2 additions & 2 deletions doc/testing.html
Expand Up @@ -237,10 +237,10 @@ <h3 id="non-us-locale">Non-US locale</h3>
<pre><code>$ export LANG=&quot;en_US&quot; &amp;&amp; make test TEST=...
$ make test JTREG=&quot;VM_OPTIONS=-Duser.language=en -Duser.country=US&quot; TEST=...</code></pre>
<h3 id="pkcs11-tests">PKCS11 Tests</h3>
<p>It is highly recommended to use the latest NSS version when running PKCS11 tests. Improper NSS version may lead to unexpected failures which are hard to diagnose. For example, sun/security/pkcs11/Secmod/AddTrustedCert.java may fail on Ubuntu 18.04 with the default NSS version in the system. To run these tests correctly, the system property <code>test.nss.lib.paths</code> is required on Ubuntu 18.04 to specify the alternative NSS lib directories.</p>
<p>It is highly recommended to use the latest NSS version when running PKCS11 tests. Improper NSS version may lead to unexpected failures which are hard to diagnose. For example, sun/security/pkcs11/Secmod/AddTrustedCert.java may fail on Ubuntu 18.04 with the default NSS version in the system. To run these tests correctly, the system property <<code>jdk.test.lib.artifacts.&lt;NAME&gt;</code> is required on Ubuntu 18.04 to specify the alternative NSS lib directories.The<code>&lt;NAME&gt;</code> component should be replaced with the name element of the appropriate <code>@Artifact</code> class. (See<code>test/jdk/sun/security/pkcs11/PKCS11Test.java</code>)</p>
<p>For example:</p>
<pre><code>$ make test TEST=&quot;jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java&quot; \
JTREG=&quot;JAVA_OPTIONS=-Dtest.nss.lib.paths=/path/to/your/latest/NSS-libs&quot;</code></pre>
JTREG=&quot;JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs&quot;</code></pre>
<p>For more notes about the PKCS11 tests, please refer to test/jdk/sun/security/pkcs11/README.</p>
<h3 id="client-ui-tests">Client UI Tests</h3>
<h4 id="system-key-shortcuts">System key shortcuts</h4>
Expand Down
8 changes: 5 additions & 3 deletions doc/testing.md
Expand Up @@ -536,14 +536,16 @@ It is highly recommended to use the latest NSS version when running PKCS11
tests. Improper NSS version may lead to unexpected failures which are hard to
diagnose. For example, sun/security/pkcs11/Secmod/AddTrustedCert.java may fail
on Ubuntu 18.04 with the default NSS version in the system. To run these tests
correctly, the system property `test.nss.lib.paths` is required on Ubuntu 18.04
to specify the alternative NSS lib directories.
correctly, the system property `jdk.test.lib.artifacts.<NAME>` is required on
Ubuntu 18.04 to specify the alternative NSS lib directory. The `<NAME>`
component should be replaced with the name element of the appropriate
`@Artifact` class. (See `test/jdk/sun/security/pkcs11/PKCS11Test.java`)

For example:

```
$ make test TEST="jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java" \
JTREG="JAVA_OPTIONS=-Dtest.nss.lib.paths=/path/to/your/latest/NSS-libs"
JTREG="JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs"
```

For more notes about the PKCS11 tests, please refer to
Expand Down
6 changes: 0 additions & 6 deletions test/jdk/ProblemList.txt
Expand Up @@ -653,12 +653,6 @@ sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 gene
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all

sun/security/tools/keytool/NssTest.java 8295343 linux-all
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343 linux-all
sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-all
sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all
sun/security/pkcs11/rsa/TestKeyFactory.java 8295343 linux-all
sun/security/pkcs11/KeyStore/Basic.java 8295343 linux-all
sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java 8316183 linux-ppc64le

############################################################################
Expand Down
97 changes: 10 additions & 87 deletions test/jdk/sun/security/pkcs11/PKCS11Test.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -45,7 +45,6 @@
import java.security.spec.ECParameterSpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -257,30 +256,19 @@ private static Path getNSSLibPath() throws Exception {

static Path getNSSLibPath(String library) throws Exception {
String osid = getOsId();
String[] nssLibDirs = getNssLibPaths(osid);
if (nssLibDirs == null) {
System.out.println("Warning: unsupported OS: " + osid
String nssLibDir = fetchNssLib(osid);
if (nssLibDir == null) {
throw new SkippedException("Warning: unsupported OS: " + osid
+ ", please initialize NSS library location, skipping test");
return null;
}
if (nssLibDirs.length == 0) {
System.out.println("Warning: NSS not supported on this platform, skipping test");
return null;
}

Path nssLibPath = null;
for (String dir : nssLibDirs) {
Path libPath = Paths.get(dir).resolve(System.mapLibraryName(library));
if (Files.exists(libPath)) {
nssLibPath = libPath;
break;
}
String libraryName = System.mapLibraryName(library);
Path libPath = Paths.get(nssLibDir).resolve(libraryName);
if (!Files.exists(libPath)) {
throw new SkippedException("NSS library \"" + libraryName + "\" was not found in " + nssLibDir);
}
if (nssLibPath == null) {
System.out.println("Warning: can't find NSS library on this machine, skipping test");
return null;
}
return nssLibPath;

return libPath;
}

private static String getOsId() {
Expand Down Expand Up @@ -604,71 +592,6 @@ private static ECParameterSpec getECParameterSpec(Provider p, String name)
return parameters.getParameterSpec(ECParameterSpec.class);
}

// Location of the NSS libraries on each supported platform
private static Map<String, String[]> getOsMap() {
if (osMap != null) {
return osMap;
}

osMap = new HashMap<>();
osMap.put("Linux-i386-32", new String[]{
"/usr/lib/i386-linux-gnu/",
"/usr/lib32/",
"/usr/lib/"});
osMap.put("Linux-amd64-64", new String[]{
"/usr/lib/x86_64-linux-gnu/",
"/usr/lib/x86_64-linux-gnu/nss/",
"/usr/lib64/"});
osMap.put("Linux-ppc64-64", new String[]{"/usr/lib64/"});
osMap.put("Linux-ppc64le-64", new String[]{"/usr/lib64/"});
osMap.put("Linux-s390x-64", new String[]{"/usr/lib64/"});
osMap.put("Windows-x86-32", new String[]{});
osMap.put("Windows-amd64-64", new String[]{});
osMap.put("MacOSX-x86_64-64", new String[]{});
osMap.put("Linux-arm-32", new String[]{
"/usr/lib/arm-linux-gnueabi/nss/",
"/usr/lib/arm-linux-gnueabihf/nss/"});
osMap.put("Linux-aarch64-64", new String[] {
"/usr/lib/aarch64-linux-gnu/",
"/usr/lib/aarch64-linux-gnu/nss/",
"/usr/lib64/" });
return osMap;
}

private static String[] getNssLibPaths(String osId) {
String[] preferablePaths = getPreferableNssLibPaths(osId);
if (preferablePaths.length != 0) {
return preferablePaths;
} else {
return getOsMap().get(osId);
}
}

private static String[] getPreferableNssLibPaths(String osId) {
List<String> nssLibPaths = new ArrayList<>();

String customNssLibPaths = System.getProperty("test.nss.lib.paths");
if (customNssLibPaths == null) {
// If custom local NSS lib path is not provided,
// try to download NSS libs from artifactory
String path = fetchNssLib(osId);
if (path != null) {
nssLibPaths.add(path);
}
} else {
String[] paths = customNssLibPaths.split(",");
for (String path : paths) {
if (!path.endsWith(File.separator)) {
nssLibPaths.add(path + File.separator);
} else {
nssLibPaths.add(path);
}
}
}

return nssLibPaths.toArray(new String[0]);
}

public static String toString(byte[] b) {
if (b == null) {
return "(null)";
Expand Down
13 changes: 7 additions & 6 deletions test/jdk/sun/security/pkcs11/README
Expand Up @@ -4,14 +4,15 @@ perform as a result of bugs or features in NSS or other pkcs11 libraries.
- How to get NSS libraries?
The libraries come from the following sources.

1. Specified by system property test.nss.lib.paths
System property test.nss.lib.paths can specify a set of absolute paths to
the local NSS library directories. The paths are separated by comma.
1. Specified by system property jdk.test.lib.artifacts.<NAME>
The system property, jdk.test.lib.artifacts.<NAME>, can specify an absolute path
to the local NSS library directory. The <NAME> component should be replaced with
the name element of the appropriate @Artifact class.
(See `test/jdk/sun/security/pkcs11/PKCS11Test.java`)

2. Pre-built NSS libraries from artifactory server
If the value of system property test.nss.lib.paths is not set, the tests will try
to download pre-built NSS libraries from artifactory server. Currently, the
tests only looks for libraries for Windows and MacOSX platforms on artifactory.
If the value of system property jdk.test.lib.artifacts.<NAME> is not set, the
tests will try to download pre-built NSS libraries from artifactory server.
Please note that JIB jar MUST be present in classpath when downloading the
libraries.

Expand Down
9 changes: 5 additions & 4 deletions test/jdk/sun/security/tools/keytool/NssTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -58,8 +58,9 @@ private static void copyFiles() throws IOException {

Path dbPath = srcPath.getParent().getParent()
.resolve("pkcs11").resolve("nss").resolve("db");
Files.copy(dbPath.resolve("cert8.db"), Paths.get("cert8.db"));
Files.copy(dbPath.resolve("key3.db"), Paths.get("key3.db"));
Files.copy(dbPath.resolve("secmod.db"), Paths.get("secmod.db"));
Path destDir = Path.of( "tmpdb");
Files.createDirectory(destDir);
Files.copy(dbPath.resolve("cert9.db"), destDir.resolve("cert9.db"));
Files.copy(dbPath.resolve("key4.db"), destDir.resolve("key4.db"));
}
}
2 changes: 1 addition & 1 deletion test/jdk/sun/security/tools/keytool/p11-nss.txt
Expand Up @@ -6,7 +6,7 @@ slot = 2

library = ${nss.lib}

nssArgs = "configdir='.' certPrefix='' keyPrefix='' secmod='secmod.db'"
nssArgs = "configdir='sql:./tmpdb' certPrefix='' keyPrefix='' secmod='secmod.db'"

#forceLogin = true

Expand Down

1 comment on commit d4512fe

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.