8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
Reviewed-by: vinnie
diff --git a/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.java b/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.java
index 42d4655..4f80a59 100644
--- a/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.java
+++ b/test/sun/security/pkcs11/KeyStore/SecretKeysBasic.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, 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
@@ -139,6 +139,13 @@
}
private static void doTest() throws Exception {
+ // Make sure both NSS libraries are the same version.
+ if (isNSS(provider) &&
+ (getLibsoftokn3Version() != getLibnss3Version())) {
+ System.out.println("libsoftokn3 and libnss3 versions do not match. Aborting test...");
+ return;
+ }
+
if (ks == null) {
ks = KeyStore.getInstance(KS_TYPE, provider);
ks.load(null, tokenPwd);
diff --git a/test/sun/security/pkcs11/PKCS11Test.java b/test/sun/security/pkcs11/PKCS11Test.java
index f1b179b..ca836f0 100644
--- a/test/sun/security/pkcs11/PKCS11Test.java
+++ b/test/sun/security/pkcs11/PKCS11Test.java
@@ -66,6 +66,11 @@
// The other is "libnss3.so", listed as "nss3".
static String nss_library = "softokn3";
+ // NSS versions of each library. It is simplier to keep nss_version
+ // for quick checking for generic testing than many if-else statements.
+ static double softoken3_version = -1;
+ static double nss3_version = -1;
+
static Provider getSunPKCS11(String config) throws Exception {
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor cons = clazz.getConstructor(new Class[] {String.class});
@@ -175,6 +180,10 @@
}
public static String getNSSLibDir() throws Exception {
+ return getNSSLibDir(nss_library);
+ }
+
+ static String getNSSLibDir(String library) throws Exception {
Properties props = System.getProperties();
String osName = props.getProperty("os.name");
if (osName.startsWith("Win")) {
@@ -195,7 +204,7 @@
String nssLibDir = null;
for (String dir : nssLibDirs) {
if (new File(dir).exists() &&
- new File(dir + System.mapLibraryName(nss_library)).exists()) {
+ new File(dir + System.mapLibraryName(library)).exists()) {
nssLibDir = dir;
System.setProperty("pkcs11test.nss.libdir", nssLibDir);
break;
@@ -241,16 +250,37 @@
return nss_ecc_status;
}
+ public static double getLibsoftokn3Version() {
+ if (softoken3_version == -1)
+ return getNSSInfo("softokn3");
+ return softoken3_version;
+ }
+
+ public static double getLibnss3Version() {
+ if (nss3_version == -1)
+ return getNSSInfo("nss3");
+ return nss3_version;
+ }
+
/* Read the library to find out the verison */
static void getNSSInfo() {
+ getNSSInfo(nss_library);
+ }
+
+ static double getNSSInfo(String library) {
String nssHeader = "$Header: NSS";
boolean found = false;
String s = null;
int i = 0;
String libfile = "";
+ if (library.compareTo("softokn3") == 0 && softoken3_version > -1)
+ return softoken3_version;
+ if (library.compareTo("nss3") == 0 && nss3_version > -1)
+ return nss3_version;
+
try {
- libfile = getNSSLibDir() + System.mapLibraryName(nss_library);
+ libfile = getNSSLibDir() + System.mapLibraryName(library);
FileInputStream is = new FileInputStream(libfile);
byte[] data = new byte[1000];
int read = 0;
@@ -284,9 +314,10 @@
}
if (!found) {
- System.out.println("NSS version not found, set to 0.0: "+libfile);
+ System.out.println("lib" + library +
+ " version not found, set to 0.0: " + libfile);
nss_version = 0.0;
- return;
+ return nss_version;
}
// the index after whitespace after nssHeader
@@ -306,11 +337,12 @@
try {
nss_version = Double.parseDouble(version);
} catch (NumberFormatException e) {
- System.out.println("Failed to parse NSS version. Set to 0.0");
+ System.out.println("Failed to parse lib" + library +
+ " version. Set to 0.0");
e.printStackTrace();
}
- System.out.print("NSS version = "+version+". ");
+ System.out.print("lib" + library + " version = "+version+". ");
// Check for ECC
if (s.indexOf("Basic") > 0) {
@@ -319,7 +351,17 @@
} else if (s.indexOf("Extended") > 0) {
nss_ecc_status = ECCState.Extended;
System.out.println("ECC Extended.");
+ } else {
+ System.out.println("ECC None.");
}
+
+ if (library.compareTo("softokn3") == 0) {
+ softoken3_version = nss_version;
+ } else if (library.compareTo("nss3") == 0) {
+ nss3_version = nss_version;
+ }
+
+ return nss_version;
}
// Used to set the nss_library file to search for libsoftokn3.so