Blame SOURCES/mod_nss-pcache_nodbinit.patch

49b7d4
From 395280a1e87ce876f3a601c00a429e852bfc9f3b Mon Sep 17 00:00:00 2001
49b7d4
From: Rob Crittenden <rcritten@redhat.com>
49b7d4
Date: Wed, 23 Nov 2016 09:53:02 -0500
49b7d4
Subject: [PATCH] Don't use same NSS db in nss_pcache as mod_nss, use
49b7d4
 NSS_NoDB_Init()
49b7d4
49b7d4
This is to avoid doing the wrapping within an HSM. There have been
49b7d4
reports of disconnects which causes future mod_nss children to fail
49b7d4
to spawn because the PIN cannot be retrieved.
49b7d4
49b7d4
A side-effect is that nss_pcache is only used for storage now. It used
49b7d4
to also verify that the PIN was correct since it had the NSS database
49b7d4
with the token available.
49b7d4
49b7d4
mod_nss will be responsible for validating the PIN which it already
49b7d4
does.
49b7d4
49b7d4
This move is also needed if mod_nss eventually moves to using
49b7d4
NSS Contexts because multiple databases may be configured at once.
49b7d4
---
49b7d4
 docs/mod_nss.html |  4 ++--
49b7d4
 nss_engine_init.c |  6 ++----
49b7d4
 nss_pcache.c      | 34 ++++++----------------------------
49b7d4
 nss_pcache.h      |  2 +-
49b7d4
 4 files changed, 11 insertions(+), 35 deletions(-)
49b7d4
49b7d4
diff --git a/docs/mod_nss.html b/docs/mod_nss.html
49b7d4
index 655d2f2..c3ae924 100644
49b7d4
--- a/docs/mod_nss.html
49b7d4
+++ b/docs/mod_nss.html
49b7d4
@@ -1811,7 +1811,7 @@ httpd.service - The Apache HTTP Server
49b7d4
    Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
49b7d4
    CGroup: name=systemd:/system/httpd.service
49b7d4
            |_____20807 /usr/sbin/httpd -DFOREGROUND
49b7d4
-           |_____20808 /usr/libexec/nss_pcache 10027086 off /etc/httpd/alias
49b7d4
+           |_____20808 /usr/libexec/nss_pcache 10027086 off
49b7d4
            |_____20809 /usr/sbin/httpd -DFOREGROUND
49b7d4
            |_____20810 /usr/sbin/httpd -DFOREGROUND
49b7d4
            |_____20811 /usr/sbin/httpd -DFOREGROUND
49b7d4
@@ -1972,7 +1972,7 @@ httpd.service - The Apache HTTP Server
49b7d4
    Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
49b7d4
    CGroup: name=systemd:/system/httpd.service
49b7d4
            |_____21299 /usr/sbin/httpd -DFOREGROUND
49b7d4
-           |_____21300 /usr/libexec/nss_pcache 10289231 on /etc/httpd/alias
49b7d4
+           |_____21300 /usr/libexec/nss_pcache 10289231 on
49b7d4
            |_____21340 /usr/sbin/httpd -DFOREGROUND
49b7d4
            |_____21341 /usr/sbin/httpd -DFOREGROUND
49b7d4
            |_____21342 /usr/sbin/httpd -DFOREGROUND
49b7d4
diff --git a/nss_engine_init.c b/nss_engine_init.c
49b7d4
index 2571591..bf90994 100644
49b7d4
--- a/nss_engine_init.c
49b7d4
+++ b/nss_engine_init.c
49b7d4
@@ -582,7 +582,7 @@ int nss_init_Module(apr_pool_t *p, apr_pool_t *plog,
49b7d4
 
49b7d4
     /* Do we need to fire up our password helper? */
49b7d4
     if (mc->nInitCount == 1) {
49b7d4
-        const char * child_argv[6];
49b7d4
+        const char * child_argv[4];
49b7d4
         apr_status_t rv;
49b7d4
         struct sembuf sb;
49b7d4
         char sembuf[32];
49b7d4
@@ -615,9 +615,7 @@ int nss_init_Module(apr_pool_t *p, apr_pool_t *plog,
49b7d4
         child_argv[0] = mc->pphrase_dialog_helper;
49b7d4
         child_argv[1] = sembuf;
49b7d4
         child_argv[2] = fipsenabled ? "on" : "off";
49b7d4
-        child_argv[3] = mc->pCertificateDatabase;
49b7d4
-        child_argv[4] = mc->pDBPrefix;
49b7d4
-        child_argv[5] = NULL;
49b7d4
+        child_argv[3] = NULL;
49b7d4
 
49b7d4
         rv = apr_procattr_create(&mc->procattr, mc->pPool);
49b7d4
 
49b7d4
diff --git a/nss_pcache.c b/nss_pcache.c
49b7d4
index 5e98adb..d0e457b 100644
49b7d4
--- a/nss_pcache.c
49b7d4
+++ b/nss_pcache.c
49b7d4
@@ -131,7 +131,7 @@ void signalhandler(int signo) {
49b7d4
  * CreatePk11PinStore
49b7d4
  */
49b7d4
 int
49b7d4
-CreatePk11PinStore(Pk11PinStore **out, const char *tokenName, const char *pin)
49b7d4
+CreatePk11PinStore(Pk11PinStore **out, const char *pin)
49b7d4
 {
49b7d4
     int err = PIN_SUCCESS;
49b7d4
     Pk11PinStore *store;
49b7d4
@@ -146,29 +146,9 @@ CreatePk11PinStore(Pk11PinStore **out, const char *tokenName, const char *pin)
49b7d4
         store->params = 0;
49b7d4
         store->crypt = 0;
49b7d4
 
49b7d4
-        /* Use the tokenName to find a PKCS11 slot */
49b7d4
-        store->slot = PK11_FindSlotByName((char *)tokenName);
49b7d4
+        store->slot = PK11_GetInternalSlot();
49b7d4
         if (store->slot == 0) { err = PIN_NOSUCHTOKEN; break; }
49b7d4
 
49b7d4
-        /* Check the password/PIN.  This allows access to the token */
49b7d4
-        {
49b7d4
-            SECStatus rv = PK11_CheckUserPassword(store->slot, (char *)pin);
49b7d4
-
49b7d4
-            if (rv == SECSuccess)
49b7d4
-                ;
49b7d4
-            else if (rv == SECWouldBlock)
49b7d4
-            {
49b7d4
-                /* NSS returns a blocking error when the pin is wrong */
49b7d4
-                err = PIN_INCORRECTPW;
49b7d4
-                break;
49b7d4
-            }
49b7d4
-            else
49b7d4
-            {
49b7d4
-                err = PIN_SYSTEMERROR;
49b7d4
-                break;
49b7d4
-            }
49b7d4
-        }
49b7d4
-
49b7d4
         /* Find the mechanism that this token can do */
49b7d4
         {
49b7d4
             const mech_item *tp;
49b7d4
@@ -349,8 +329,8 @@ int main(int argc, char ** argv)
49b7d4
     int fipsmode = 0;
49b7d4
     union semun semarg;
49b7d4
 
49b7d4
-    if (argc < 4 || argc > 5) {
49b7d4
-        fprintf(stderr, "Usage: nss_pcache <semid> <fips on/off> <directory> [prefix]\n");
49b7d4
+    if (argc != 3) {
49b7d4
+        fprintf(stderr, "Usage: nss_pcache <semid> <fips on/off>\n");
49b7d4
         exit(1);
49b7d4
     }
49b7d4
 
49b7d4
@@ -368,8 +348,7 @@ int main(int argc, char ** argv)
49b7d4
     /* Set the PKCS #11 strings for the internal token. */
49b7d4
     PK11_ConfigurePKCS11(NULL,NULL,NULL, INTERNAL_TOKEN_NAME, NULL, NULL,NULL,NULL,8,1);
49b7d4
 
49b7d4
-    /* Initialize NSS and open the certificate database read-only. */
49b7d4
-    rv = NSS_Initialize(argv[3], argc == 5 ? argv[4] : NULL, argc == 5 ? argv[4] : NULL, "secmod.db", NSS_INIT_READONLY);
49b7d4
+    rv = NSS_NoDB_Init(NULL);
49b7d4
 
49b7d4
     if (rv != SECSuccess) {
49b7d4
         fprintf(stderr, "Unable to initialize NSS database: %d\n", rv);
49b7d4
@@ -436,8 +415,7 @@ int main(int argc, char ** argv)
49b7d4
                         node->next = 0;
49b7d4
 
49b7d4
                         if (err == PIN_SUCCESS)
49b7d4
-                            err = CreatePk11PinStore(&node->store,
49b7d4
-                                                     tokenName, tokenpw);
49b7d4
+                            err = CreatePk11PinStore(&node->store, tokenpw);
49b7d4
                         memset(tokenpw, 0, strlen(tokenpw));
49b7d4
                     }
49b7d4
                 } else
49b7d4
diff --git a/nss_pcache.h b/nss_pcache.h
49b7d4
index 74cb19d..a0b8e62 100644
49b7d4
--- a/nss_pcache.h
49b7d4
+++ b/nss_pcache.h
49b7d4
@@ -21,7 +21,7 @@
49b7d4
 
49b7d4
 typedef struct Pk11PinStore Pk11PinStore;
49b7d4
 
49b7d4
-int CreatePk11PinStore(Pk11PinStore **out, const char *tokenName, const char *pin);
49b7d4
+int CreatePk11PinStore(Pk11PinStore **out, const char *pin);
49b7d4
 
49b7d4
 int Pk11StoreGetPin(char **out, Pk11PinStore *store);
49b7d4
 
49b7d4
-- 
49b7d4
2.9.3
49b7d4