Blame SOURCES/jdk8195607-pr3776-rh1760437-nss_sqlite_db_config.patch

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