Blame SOURCES/multiple-pkcs11-library-init.patch

045ef6
# HG changeset patch
045ef6
# User andrew
045ef6
# Date 1352129932 0
045ef6
# Node ID e9c857dcb964dbfa5eef3a3590244cb4d999cf7a
045ef6
# Parent  1406789608b76d0906881979335d685855f44190
045ef6
Allow multiple PKCS11 library initialisation to be a non-critical error.
045ef6
045ef6
diff -r 1406789608b7 -r e9c857dcb964 src/share/classes/sun/security/pkcs11/Config.java
045ef6
--- jdk8/jdk/src/share/classes/sun/security/pkcs11/Config.java Tue Oct 30 13:05:14 2012 +0000
045ef6
+++ jdk8/jdk/src/share/classes/sun/security/pkcs11/Config.java Mon Nov 05 15:38:52 2012 +0000
045ef6
@@ -52,6 +52,7 @@
045ef6
     static final int ERR_HALT       = 1;
045ef6
     static final int ERR_IGNORE_ALL = 2;
045ef6
     static final int ERR_IGNORE_LIB = 3;
045ef6
+    static final int ERR_IGNORE_MULTI_INIT = 4;
045ef6
 
045ef6
     // same as allowSingleThreadedModules but controlled via a system property
045ef6
     // and applied to all providers. if set to false, no SunPKCS11 instances
045ef6
@@ -980,6 +981,8 @@
045ef6
             handleStartupErrors = ERR_IGNORE_LIB;
045ef6
         } else if (val.equals("halt")) {
045ef6
             handleStartupErrors = ERR_HALT;
045ef6
+        } else if (val.equals("ignoreMultipleInitialisation")) {
045ef6
+            handleStartupErrors = ERR_IGNORE_MULTI_INIT;
045ef6
         } else {
045ef6
             throw excToken("Invalid value for handleStartupErrors:");
045ef6
         }
045ef6
diff -r 1406789608b7 -r e9c857dcb964 src/share/classes/sun/security/pkcs11/SunPKCS11.java
045ef6
--- jdk8/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java  Tue Oct 30 13:05:14 2012 +0000
045ef6
+++ jdk8/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java  Mon Nov 05 15:38:52 2012 +0000
045ef6
@@ -168,26 +168,37 @@
045ef6
                 String nssLibraryDirectory = config.getNssLibraryDirectory();
045ef6
                 String nssSecmodDirectory = config.getNssSecmodDirectory();
045ef6
                 boolean nssOptimizeSpace = config.getNssOptimizeSpace();
045ef6
+                int errorHandling = config.getHandleStartupErrors();
045ef6
 
045ef6
                 if (secmod.isInitialized()) {
045ef6
                     if (nssSecmodDirectory != null) {
045ef6
                         String s = secmod.getConfigDir();
045ef6
                         if ((s != null) &&
045ef6
                                 (s.equals(nssSecmodDirectory) == false)) {
045ef6
-                            throw new ProviderException("Secmod directory "
045ef6
-                                + nssSecmodDirectory
045ef6
-                                + " invalid, NSS already initialized with "
045ef6
-                                + s);
045ef6
+                            String msg = "Secmod directory " + nssSecmodDirectory
045ef6
+                                + " invalid, NSS already initialized with " + s;
045ef6
+                            if (errorHandling == Config.ERR_IGNORE_MULTI_INIT ||
045ef6
+                                errorHandling == Config.ERR_IGNORE_ALL) {
045ef6
+                                throw new UnsupportedOperationException(msg);
045ef6
+                            } else {
045ef6
+                                throw new ProviderException(msg);
045ef6
+                            }
045ef6
                         }
045ef6
                     }
045ef6
                     if (nssLibraryDirectory != null) {
045ef6
                         String s = secmod.getLibDir();
045ef6
                         if ((s != null) &&
045ef6
                                 (s.equals(nssLibraryDirectory) == false)) {
045ef6
-                            throw new ProviderException("NSS library directory "
045ef6
+                            String msg = "NSS library directory "
045ef6
                                 + nssLibraryDirectory
045ef6
                                 + " invalid, NSS already initialized with "
045ef6
-                                + s);
045ef6
+                                + s;
045ef6
+                            if (errorHandling == Config.ERR_IGNORE_MULTI_INIT ||
045ef6
+                                errorHandling == Config.ERR_IGNORE_ALL) {
045ef6
+                                throw new UnsupportedOperationException(msg);
045ef6
+                            } else {
045ef6
+                                throw new ProviderException(msg);
045ef6
+                            }
045ef6
                         }
045ef6
                     }
045ef6
                 } else {