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

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