Blame SOURCES/mod_nss-pcache_nodbinit.patch

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