Blame jdk8195607-pr3776-rh1760437-nss_sqlite_db_config.patch

0e6069c
# HG changeset patch
0e6069c
# User mbalao
0e6069c
# Date 1529971845 -28800
0e6069c
#      Tue Jun 26 08:10:45 2018 +0800
0e6069c
# Node ID e9c20b7250cd98d16a67f2a30b34284c2caa01dc
0e6069c
# Parent  9f1aa2e38d90dd60522237d7414af6bdcf03c4ff
0e6069c
8195607, PR3776: sun/security/pkcs11/Secmod/TestNssDbSqlite.java failed with "NSS initialization failed" on NSS 3.34.1
0e6069c
Reviewed-by: valeriep, weijun
0e6069c
0e6069c
diff --git openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/Secmod.java openjdk/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
0e6069c
--- openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
0e6069c
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/Secmod.java
0e6069c
@@ -197,7 +197,7 @@
0e6069c
 
0e6069c
         if (configDir != null) {
0e6069c
             String configDirPath = null;
0e6069c
-            String sqlPrefix = "sql:/";
0e6069c
+            String sqlPrefix = "sql:";
0e6069c
             if (!configDir.startsWith(sqlPrefix)) {
0e6069c
                 configDirPath = configDir;
0e6069c
             } else {
0e6069c
diff --git openjdk.orig/jdk/src/share/native/sun/security/pkcs11/j2secmod.c openjdk/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
0e6069c
--- openjdk.orig/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
0e6069c
+++ openjdk/jdk/src/share/native/sun/security/pkcs11/j2secmod.c
0e6069c
@@ -69,9 +69,14 @@
0e6069c
     int res = 0;
0e6069c
     FPTR_Initialize initialize =
0e6069c
         (FPTR_Initialize)findFunction(env, jHandle, "NSS_Initialize");
0e6069c
+    #ifdef SECMOD_DEBUG
0e6069c
+    FPTR_GetError getError =
0e6069c
+        (FPTR_GetError)findFunction(env, jHandle, "PORT_GetError");
0e6069c
+    #endif // SECMOD_DEBUG
0e6069c
     unsigned int flags = 0x00;
0e6069c
     const char *configDir = NULL;
0e6069c
     const char *functionName = NULL;
0e6069c
+    const char *configFile = NULL;
0e6069c
 
0e6069c
     /* If we cannot initialize, exit now */
0e6069c
     if (initialize == NULL) {
0e6069c
@@ -97,13 +102,18 @@
0e6069c
         flags = 0x20; // NSS_INIT_OPTIMIZESPACE flag
0e6069c
     }
0e6069c
 
0e6069c
+    configFile = "secmod.db";
0e6069c
+    if (configDir != NULL && strncmp("sql:", configDir, 4U) == 0) {
0e6069c
+        configFile = "pkcs11.txt";
0e6069c
+    }
0e6069c
+
0e6069c
     /*
0e6069c
      * If the NSS_Init function is requested then call NSS_Initialize to
0e6069c
      * open the Cert, Key and Security Module databases, read only.
0e6069c
      */
0e6069c
     if (strcmp("NSS_Init", functionName) == 0) {
0e6069c
         flags = flags | 0x01; // NSS_INIT_READONLY flag
0e6069c
-        res = initialize(configDir, "", "", "secmod.db", flags);
0e6069c
+        res = initialize(configDir, "", "", configFile, flags);
0e6069c
 
0e6069c
     /*
0e6069c
      * If the NSS_InitReadWrite function is requested then call
0e6069c
@@ -111,7 +121,7 @@
0e6069c
      * read/write.
0e6069c
      */
0e6069c
     } else if (strcmp("NSS_InitReadWrite", functionName) == 0) {
0e6069c
-        res = initialize(configDir, "", "", "secmod.db", flags);
0e6069c
+        res = initialize(configDir, "", "", configFile, flags);
0e6069c
 
0e6069c
     /*
0e6069c
      * If the NSS_NoDB_Init function is requested then call
0e6069c
@@ -137,6 +147,13 @@
0e6069c
         (*env)->ReleaseStringUTFChars(env, jConfigDir, configDir);
0e6069c
     }
0e6069c
     dprintf1("-res: %d\n", res);
0e6069c
+    #ifdef SECMOD_DEBUG
0e6069c
+    if (res == -1) {
0e6069c
+        if (getError != NULL) {
0e6069c
+            dprintf1("-NSS error: %d\n", getError());
0e6069c
+        }
0e6069c
+    }
0e6069c
+    #endif // SECMOD_DEBUG
0e6069c
 
0e6069c
     return (res == 0) ? JNI_TRUE : JNI_FALSE;
0e6069c
 }
0e6069c
diff --git openjdk.orig/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h openjdk/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
0e6069c
--- openjdk.orig/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
0e6069c
+++ openjdk/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.h
0e6069c
@@ -34,6 +34,10 @@
0e6069c
         const char *certPrefix, const char *keyPrefix,
0e6069c
         const char *secmodName, unsigned int flags);
0e6069c
 
0e6069c
+#ifdef SECMOD_DEBUG
0e6069c
+typedef int (*FPTR_GetError)(void);
0e6069c
+#endif //SECMOD_DEBUG
0e6069c
+
0e6069c
 // in secmod.h
0e6069c
 //extern SECMODModule *SECMOD_LoadModule(char *moduleSpec,SECMODModule *parent,
0e6069c
 //                                                      PRBool recurse);
0e6069c
diff --git openjdk.orig/jdk/test/sun/security/pkcs11/Secmod/pkcs11.txt openjdk/jdk/test/sun/security/pkcs11/Secmod/pkcs11.txt
0e6069c
new file mode 100644
0e6069c
--- /dev/null
0e6069c
+++ openjdk/jdk/test/sun/security/pkcs11/Secmod/pkcs11.txt
0e6069c
@@ -0,0 +1,4 @@
0e6069c
+library=
0e6069c
+name=NSS Internal PKCS #11 Module
0e6069c
+parameters=configdir='sql:./tmpdb' certPrefix='' keyPrefix='' secmod='' flags= updatedir='' updateCertPrefix='' updateKeyPrefix='' updateid='' updateTokenDescription='' 
0e6069c
+NSS=Flags=internal,critical trustOrder=75 cipherOrder=100 slotParams=(1={slotFlags=[RSA,DSA,DH,RC2,RC4,DES,RANDOM,SHA1,MD5,MD2,SSL,TLS,AES,Camellia,SEED,SHA256,SHA512] askpw=any timeout=30})
0e6069c
diff --git openjdk.orig/jdk/test/sun/security/pkcs11/SecmodTest.java openjdk/jdk/test/sun/security/pkcs11/SecmodTest.java
0e6069c
--- openjdk.orig/jdk/test/sun/security/pkcs11/SecmodTest.java
0e6069c
+++ openjdk/jdk/test/sun/security/pkcs11/SecmodTest.java
0e6069c
@@ -55,7 +55,7 @@
0e6069c
 
0e6069c
         DBDIR = System.getProperty("test.classes", ".") + SEP + "tmpdb";
0e6069c
         if (useSqlite) {
0e6069c
-            System.setProperty("pkcs11test.nss.db", "sql:/" + DBDIR);
0e6069c
+            System.setProperty("pkcs11test.nss.db", "sql:" + DBDIR);
0e6069c
         } else {
0e6069c
             System.setProperty("pkcs11test.nss.db", DBDIR);
0e6069c
         }
0e6069c
@@ -67,6 +67,7 @@
0e6069c
         if (useSqlite) {
0e6069c
             copyFile("key4.db", BASE, DBDIR);
0e6069c
             copyFile("cert9.db", BASE, DBDIR);
0e6069c
+            copyFile("pkcs11.txt", BASE, DBDIR);
0e6069c
         } else {
0e6069c
             copyFile("secmod.db", BASE, DBDIR);
0e6069c
             copyFile("key3.db", BASE, DBDIR);