From ba6d7cd01765bdb3ebc18381825d78fca2be7eda Mon Sep 17 00:00:00 2001 From: vinnie Date: Mon, 13 Aug 2012 14:06:44 +0100 Subject: [PATCH] 7190945: pkcs11 problem loading NSS libs on Ubuntu Reviewed-by: xuelei, alanb --- .../classes/sun/security/pkcs11/Secmod.java | 13 +++++- test/sun/security/pkcs11/PKCS11Test.java | 42 +++++++++++------- test/sun/security/pkcs11/Secmod/keystore.jks | Bin 4288 -> 3486 bytes 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/share/classes/sun/security/pkcs11/Secmod.java b/src/share/classes/sun/security/pkcs11/Secmod.java index a87273956..de4d12ef3 100644 --- a/src/share/classes/sun/security/pkcs11/Secmod.java +++ b/src/share/classes/sun/security/pkcs11/Secmod.java @@ -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 @@ public final class Secmod { + "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; diff --git a/test/sun/security/pkcs11/PKCS11Test.java b/test/sun/security/pkcs11/PKCS11Test.java index 3fc5d86f4..deb7302a2 100644 --- a/test/sun/security/pkcs11/PKCS11Test.java +++ b/test/sun/security/pkcs11/PKCS11Test.java @@ -167,17 +167,23 @@ public abstract class PKCS11Test { } 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 @@ public abstract class PKCS11Test { } - private static final Map osMap; + private static final Map osMap; // Location of the NSS libraries on each supported platform static { - osMap = new HashMap(); - 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(); + 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(); diff --git a/test/sun/security/pkcs11/Secmod/keystore.jks b/test/sun/security/pkcs11/Secmod/keystore.jks index b59a2ab43c61b99c5d72a943aec13b090f111b62..d195b4dadd5fdf6ab7f611c897f3150e3fcd984e 100644 GIT binary patch delta 47 zcmX@0I8U1A-`jt085kItfS7snI_`fg8+jTyM1F`Z(D;+Hrno|D!_s@px!f$SdYb_N Dy4n)} delta 609 zcmbOyeL#`t-`jt085kItfS6@77i$AYJ&?u7AX%K6Tw-WxTx3|BT2z)=q+3*+XlP($ zlAH*X<(%nm>k3p>Vo+qj$Ht}2#>m2`#U#kc$jZQyz+I4$^)XA|ry>4Md9ERIqUzb$ zz9riuWW^m1@BC;Oe28wcwYA?Ge1 zb~625{zgGYt$5wZqZ_3+?~c%E2-&fX^^C%?-_5mP_pwIknHpFE-CbhP#8hC=#CVg5 zlVQPKf1cv4hvE%***LY@JlekV0-eOlV9+>!G9QQ7YUX=!ca?*V_{IsdBEPH^>z#F) zQJL>Mo7>*qOBNn#ux+`|+aBZ1Ua+EiiaVOum>U}z>Lt&}UcMT7;%VpV>m1Cp6SBWK zCUc1IfAYP8RYYia^_CO`{@CxEHm2$O$WPsU=gOX(X;D|@&o%nkhm;w<-Z;ltDPAMd z`P~(**z<2#jO_ikEb4W(-x8*M;Ll=v4$;TIwq0A~#=cg#B3;%;`dIPyi`$dT*SeG@ q1YfYKyRf@IiLbYOBhNn;k<*_yO*zrBw5L_&@Hq}1_0lbx=7|6muG