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

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