Blame SOURCES/mod_nss-pcache_nodbinit.patch

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