提交 5bfd1cd2 编写于 作者: A ascarpino

8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches

Reviewed-by: vinnie
上级 1d49124c
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -139,6 +139,13 @@ public class SecretKeysBasic extends PKCS11Test { ...@@ -139,6 +139,13 @@ public class SecretKeysBasic extends PKCS11Test {
} }
private static void doTest() throws Exception { 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) { if (ks == null) {
ks = KeyStore.getInstance(KS_TYPE, provider); ks = KeyStore.getInstance(KS_TYPE, provider);
ks.load(null, tokenPwd); ks.load(null, tokenPwd);
......
...@@ -66,6 +66,11 @@ public abstract class PKCS11Test { ...@@ -66,6 +66,11 @@ public abstract class PKCS11Test {
// The other is "libnss3.so", listed as "nss3". // The other is "libnss3.so", listed as "nss3".
static String nss_library = "softokn3"; 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 { static Provider getSunPKCS11(String config) throws Exception {
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11"); Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor cons = clazz.getConstructor(new Class[] {String.class}); Constructor cons = clazz.getConstructor(new Class[] {String.class});
...@@ -175,6 +180,10 @@ public abstract class PKCS11Test { ...@@ -175,6 +180,10 @@ public abstract class PKCS11Test {
} }
public static String getNSSLibDir() throws Exception { public static String getNSSLibDir() throws Exception {
return getNSSLibDir(nss_library);
}
static String getNSSLibDir(String library) throws Exception {
Properties props = System.getProperties(); Properties props = System.getProperties();
String osName = props.getProperty("os.name"); String osName = props.getProperty("os.name");
if (osName.startsWith("Win")) { if (osName.startsWith("Win")) {
...@@ -195,7 +204,7 @@ public abstract class PKCS11Test { ...@@ -195,7 +204,7 @@ public abstract class PKCS11Test {
String nssLibDir = null; String nssLibDir = null;
for (String dir : nssLibDirs) { for (String dir : nssLibDirs) {
if (new File(dir).exists() && if (new File(dir).exists() &&
new File(dir + System.mapLibraryName(nss_library)).exists()) { new File(dir + System.mapLibraryName(library)).exists()) {
nssLibDir = dir; nssLibDir = dir;
System.setProperty("pkcs11test.nss.libdir", nssLibDir); System.setProperty("pkcs11test.nss.libdir", nssLibDir);
break; break;
...@@ -241,16 +250,37 @@ public abstract class PKCS11Test { ...@@ -241,16 +250,37 @@ public abstract class PKCS11Test {
return nss_ecc_status; 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 */ /* Read the library to find out the verison */
static void getNSSInfo() { static void getNSSInfo() {
getNSSInfo(nss_library);
}
static double getNSSInfo(String library) {
String nssHeader = "$Header: NSS"; String nssHeader = "$Header: NSS";
boolean found = false; boolean found = false;
String s = null; String s = null;
int i = 0; int i = 0;
String libfile = ""; 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 { try {
libfile = getNSSLibDir() + System.mapLibraryName(nss_library); libfile = getNSSLibDir() + System.mapLibraryName(library);
FileInputStream is = new FileInputStream(libfile); FileInputStream is = new FileInputStream(libfile);
byte[] data = new byte[1000]; byte[] data = new byte[1000];
int read = 0; int read = 0;
...@@ -284,9 +314,10 @@ public abstract class PKCS11Test { ...@@ -284,9 +314,10 @@ public abstract class PKCS11Test {
} }
if (!found) { 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; nss_version = 0.0;
return; return nss_version;
} }
// the index after whitespace after nssHeader // the index after whitespace after nssHeader
...@@ -306,11 +337,12 @@ public abstract class PKCS11Test { ...@@ -306,11 +337,12 @@ public abstract class PKCS11Test {
try { try {
nss_version = Double.parseDouble(version); nss_version = Double.parseDouble(version);
} catch (NumberFormatException e) { } 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(); e.printStackTrace();
} }
System.out.print("NSS version = "+version+". "); System.out.print("lib" + library + " version = "+version+". ");
// Check for ECC // Check for ECC
if (s.indexOf("Basic") > 0) { if (s.indexOf("Basic") > 0) {
...@@ -319,7 +351,17 @@ public abstract class PKCS11Test { ...@@ -319,7 +351,17 @@ public abstract class PKCS11Test {
} else if (s.indexOf("Extended") > 0) { } else if (s.indexOf("Extended") > 0) {
nss_ecc_status = ECCState.Extended; nss_ecc_status = ECCState.Extended;
System.out.println("ECC 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 // Used to set the nss_library file to search for libsoftokn3.so
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册