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

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