7190945: pkcs11 problem loading NSS libs on Ubuntu
authorvinnie
Mon, 13 Aug 2012 14:06:44 +0100
changeset 13565 6298d600104f
parent 13564 3571e232ab03
child 13566 4b4e31014e90
7190945: pkcs11 problem loading NSS libs on Ubuntu Reviewed-by: xuelei, alanb
jdk/src/share/classes/sun/security/pkcs11/Secmod.java
jdk/test/sun/security/pkcs11/PKCS11Test.java
jdk/test/sun/security/pkcs11/Secmod/keystore.jks
--- a/jdk/src/share/classes/sun/security/pkcs11/Secmod.java	Mon Aug 13 13:41:23 2012 +0100
+++ b/jdk/src/share/classes/sun/security/pkcs11/Secmod.java	Mon Aug 13 14:06:44 2012 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, 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
@@ -405,7 +405,16 @@
                         + "module: " + libraryName + ", " + commonName);
                 }
             }
-            this.libraryName = (new File(libraryDir, libraryName)).getPath();
+            // On Ubuntu the libsoftokn3 library is located in a subdirectory
+            // of the system libraries directory. (Since Ubuntu 11.04.)
+            File libraryFile = new File(libraryDir, libraryName);
+            if (!libraryFile.isFile()) {
+               File failover = new File(libraryDir, "nss/" + libraryName);
+               if (failover.isFile()) {
+                   libraryFile = failover;
+               }
+            }
+            this.libraryName = libraryFile.getPath();
             this.commonName = commonName;
             this.slot = slot;
             this.type = type;
--- a/jdk/test/sun/security/pkcs11/PKCS11Test.java	Mon Aug 13 13:41:23 2012 +0100
+++ b/jdk/test/sun/security/pkcs11/PKCS11Test.java	Mon Aug 13 14:06:44 2012 +0100
@@ -167,17 +167,23 @@
         }
         String osid = osName + "-"
                 + props.getProperty("os.arch") + "-" + props.getProperty("sun.arch.data.model");
-        String nssLibDir = osMap.get(osid);
-        if (nssLibDir == null) {
+        String[] nssLibDirs = osMap.get(osid);
+        if (nssLibDirs == null) {
             System.out.println("Unsupported OS, skipping: " + osid);
             return null;
-//          throw new Exception("Unsupported OS " + osName);
         }
-        if (nssLibDir.length() == 0) {
+        if (nssLibDirs.length == 0) {
             System.out.println("NSS not supported on this platform, skipping test");
             return null;
         }
-        System.setProperty("pkcs11test.nss.libdir", nssLibDir);
+        String nssLibDir = null;
+        for (String dir : nssLibDirs) {
+            if (new File(dir).exists()) {
+                nssLibDir = dir;
+                System.setProperty("pkcs11test.nss.libdir", nssLibDir);
+                break;
+            }
+        }
         return nssLibDir;
     }
 
@@ -234,21 +240,23 @@
     }
 
 
-    private static final Map<String,String> osMap;
+    private static final Map<String,String[]> osMap;
 
     // Location of the NSS libraries on each supported platform
     static {
-        osMap = new HashMap<String,String>();
-        osMap.put("SunOS-sparc-32", "/usr/lib/mps/");
-        osMap.put("SunOS-sparcv9-64", "/usr/lib/mps/64/");
-        osMap.put("SunOS-x86-32", "/usr/lib/mps/");
-        osMap.put("SunOS-amd64-64", "/usr/lib/mps/64/");
-        osMap.put("Linux-i386-32", "/usr/lib/");
-        osMap.put("Linux-amd64-64", "/usr/lib64/");
-        osMap.put("Windows-x86-32",
-            PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP));
-        osMap.put("Windows-amd64-64",
-            PKCS11_BASE + "/nss/lib/windows-amd64/".replace('/', SEP));
+        osMap = new HashMap<String,String[]>();
+        osMap.put("SunOS-sparc-32", new String[]{"/usr/lib/mps/"});
+        osMap.put("SunOS-sparcv9-64", new String[]{"/usr/lib/mps/64/"});
+        osMap.put("SunOS-x86-32", new String[]{"/usr/lib/mps/"});
+        osMap.put("SunOS-amd64-64", new String[]{"/usr/lib/mps/64/"});
+        osMap.put("Linux-i386-32", new String[]{
+            "/usr/lib/i386-linux-gnu/", "/usr/lib/"});
+        osMap.put("Linux-amd64-64", new String[]{
+            "/usr/lib/x86_64-linux-gnu/", "/usr/lib64/"});
+        osMap.put("Windows-x86-32", new String[]{
+            PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP)});
+        osMap.put("Windows-amd64-64", new String[]{
+            PKCS11_BASE + "/nss/lib/windows-amd64/".replace('/', SEP)});
     }
 
     private final static char[] hexDigits = "0123456789abcdef".toCharArray();
Binary file jdk/test/sun/security/pkcs11/Secmod/keystore.jks has changed