Skip to content

Commit a1d5dd1

Browse files
fitzsimPaul Hohensee
authored andcommitted
8361711: Add library name configurability to PKCS11Test.java
Backport-of: 1cb1267ce84dea2bfcb434b03c982b859997c6d2
1 parent 1471c20 commit a1d5dd1

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/jdk/sun/security/pkcs11/PKCS11Test.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public abstract class PKCS11Test {
8989
// The NSS library we need to search for in getNSSLibDir()
9090
// Default is "libsoftokn3.so", listed as "softokn3"
9191
// The other is "libnss3.so", listed as "nss3".
92-
static String nss_library = "softokn3";
92+
static String nss_library = System.getProperty("CUSTOM_P11_LIBRARY_NAME", "softokn3");
9393

9494
// NSS versions of each library. It is simpler to keep nss_version
9595
// for quick checking for generic testing than many if-else statements.
@@ -199,6 +199,17 @@ public static String getBase() throws Exception {
199199
if (PKCS11_BASE != null) {
200200
return PKCS11_BASE;
201201
}
202+
String customBaseDir = System.getProperty("CUSTOM_P11_CONFIG_BASE_DIR");
203+
if (customBaseDir != null) {
204+
File base = new File(customBaseDir);
205+
if (!base.exists()) {
206+
throw new RuntimeException(
207+
"Directory specified by CUSTOM_P11_CONFIG_BASE_DIR does not exist: "
208+
+ base.getAbsolutePath());
209+
}
210+
PKCS11_BASE = base.getAbsolutePath();
211+
return PKCS11_BASE;
212+
}
202213
File cwd = new File(System.getProperty("test.src", ".")).getCanonicalFile();
203214
while (true) {
204215
File file = new File(cwd, "TEST.ROOT");
@@ -454,6 +465,40 @@ public static void testNSS(PKCS11Test test) throws Exception {
454465
System.out.println("testNSS: Completed");
455466
}
456467

468+
/**
469+
* Prepares the NSS configuration file hierarchy, then returns the
470+
* path of the configuration file that should be used to configure
471+
* the PKCS11 provider.
472+
*
473+
* By default, the contents of the directory
474+
* "test/jdk/sun/security/pkcs11/nss" are copied to the jtreg
475+
* scratch directory ("."), and "./nss/p11-nss.txt" is returned.
476+
*
477+
* The following system properties modify the default behavior:
478+
*
479+
* CUSTOM_P11_CONFIG_BASE_DIR: The path of a custom configuration
480+
* file hierarchy; overrides the default,
481+
* "test/jdk/sun/security/pkcs11".
482+
*
483+
* CUSTOM_P11_CONFIG_NAME: The name of a custom configuration
484+
* file; overrides the default, "p11-nss.txt". Note that some
485+
* test cases set CUSTOM_P11_CONFIG_NAME using -D in jtreg @run
486+
* tags; for those test cases, setting this property on the
487+
* top-level jtreg command line has no effect.
488+
*
489+
* CUSTOM_P11_CONFIG: The path of a custom configuration file;
490+
* overrides the default "./nss/p11-nss.txt". This takes
491+
* precedence over CUSTOM_P11_CONFIG_NAME. Tests that hard-code
492+
* CUSTOM_P11_CONFIG_NAME in jtreg @run tags may not work
493+
* correctly when CUSTOM_P11_CONFIG is set on the top-level jtreg
494+
* command line.
495+
*
496+
* CUSTOM_DB_DIR: The path of a custom database directory;
497+
* overrides the default, "./nss/db".
498+
*
499+
* CUSTOM_P11_LIBRARY_NAME: The name of a custom provider library
500+
* to load; overrides the default, "softokn3".
501+
*/
457502
public static String getNssConfig() throws Exception {
458503
String libdir = getNSSLibDir();
459504
if (libdir == null) {

0 commit comments

Comments
 (0)