multiple-pkcs11-library-init
authorOpenJDK Team <openjdk-17@packages.debian.org>
Wed, 22 Jan 2025 09:17:58 +0000 (10:17 +0100)
committerMatthias Klose <doko@ubuntu.com>
Wed, 22 Jan 2025 09:17:58 +0000 (10:17 +0100)
# HG changeset patch
# User andrew
# Date 1352129932 0
# Node ID e9c857dcb964dbfa5eef3a3590244cb4d999cf7a
# Parent  1406789608b76d0906881979335d685855f44190
Allow multiple PKCS11 library initialisation to be a non-critical error.

Gbp-Pq: Name multiple-pkcs11-library-init.diff

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java
src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java

index 00fedc8d0e003fe8ae1197a07ca1d5678e6c85a7..c904450106db46966fb2a2c3f29966e3442822c4 100644 (file)
@@ -52,6 +52,7 @@ final class Config {
     static final int ERR_HALT       = 1;
     static final int ERR_IGNORE_ALL = 2;
     static final int ERR_IGNORE_LIB = 3;
+    static final int ERR_IGNORE_MULTI_INIT = 4;
 
     // same as allowSingleThreadedModules but controlled via a system property
     // and applied to all providers. if set to false, no SunPKCS11 instances
@@ -1023,6 +1024,8 @@ final class Config {
             handleStartupErrors = ERR_IGNORE_LIB;
         } else if (val.equals("halt")) {
             handleStartupErrors = ERR_HALT;
+        } else if (val.equals("ignoreMultipleInitialisation")) {
+            handleStartupErrors = ERR_IGNORE_MULTI_INIT;
         } else {
             throw excToken("Invalid value for handleStartupErrors:");
         }
index aa35e8fa66850d50de818964c51d0f2e219c9e18..c22721ecd19596dad392788b4b662f981390aa05 100644 (file)
@@ -179,26 +179,37 @@ public final class SunPKCS11 extends AuthProvider {
                 String nssLibraryDirectory = config.getNssLibraryDirectory();
                 String nssSecmodDirectory = config.getNssSecmodDirectory();
                 boolean nssOptimizeSpace = config.getNssOptimizeSpace();
+                int errorHandling = config.getHandleStartupErrors();
 
                 if (secmod.isInitialized()) {
                     if (nssSecmodDirectory != null) {
                         String s = secmod.getConfigDir();
                         if ((s != null) &&
                                 (s.equals(nssSecmodDirectory) == false)) {
-                            throw new ProviderException("Secmod directory "
-                                + nssSecmodDirectory
-                                + " invalid, NSS already initialized with "
-                                + s);
+                            String msg = "Secmod directory " + nssSecmodDirectory
+                                + " invalid, NSS already initialized with " + s;
+                            if (errorHandling == Config.ERR_IGNORE_MULTI_INIT ||
+                                errorHandling == Config.ERR_IGNORE_ALL) {
+                                throw new UnsupportedOperationException(msg);
+                            } else {
+                                throw new ProviderException(msg);
+                            }
                         }
                     }
                     if (nssLibraryDirectory != null) {
                         String s = secmod.getLibDir();
                         if ((s != null) &&
                                 (s.equals(nssLibraryDirectory) == false)) {
-                            throw new ProviderException("NSS library directory "
+                            String msg = "NSS library directory "
                                 + nssLibraryDirectory
                                 + " invalid, NSS already initialized with "
-                                + s);
+                                + s;
+                            if (errorHandling == Config.ERR_IGNORE_MULTI_INIT ||
+                                errorHandling == Config.ERR_IGNORE_ALL) {
+                                throw new UnsupportedOperationException(msg);
+                            } else {
+                                throw new ProviderException(msg);
+                            }
                         }
                     }
                 } else {