File: multiple-pkcs11-library-init.diff

package info (click to toggle)
openjdk-22 22.0.2%2B9-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 804,256 kB
  • sloc: java: 5,596,301; cpp: 1,293,691; xml: 1,241,820; ansic: 419,447; asm: 404,850; objc: 20,892; sh: 15,423; javascript: 11,361; python: 6,802; makefile: 2,311; perl: 357; awk: 351; sed: 172; jsp: 24; csh: 3
file content (73 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# HG changeset patch
# User andrew
# Date 1352129932 0
# Node ID e9c857dcb964dbfa5eef3a3590244cb4d999cf7a
# Parent  1406789608b76d0906881979335d685855f44190
Allow multiple PKCS11 library initialisation to be a non-critical error.

--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java
@@ -52,6 +52,7 @@
     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
@@ -1038,6 +1039,7 @@
             case "ignoreAll" -> ERR_IGNORE_ALL;
             case "ignoreMissingLibrary" -> ERR_IGNORE_LIB;
             case "halt" -> ERR_HALT;
+            case "ignoreMultipleInitialisation" -> ERR_IGNORE_MULTI_INIT;
             default -> throw excToken("Invalid value for handleStartupErrors:");
         };
         if (DEBUG) {
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
@@ -184,26 +184,37 @@
                 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))) {
-                            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))) {
-                            throw new ProviderException("NSS library directory "
-                                + nssLibraryDirectory
-                                + " invalid, NSS already initialized with "
-                                + s);
+                            String msg = "NSS library directory "
+                                 + nssLibraryDirectory
+                                 + " 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);
+                             }
                         }
                     }
                 } else {