Blame SOURCES/0001-nss-pem-1.0.3-drop-wait-for-slot-event-cb.patch

8c90a8
From c7783ffebee147c3491c58656d9b77c74cdf3667 Mon Sep 17 00:00:00 2001
8c90a8
From: Kamil Dudka <kdudka@redhat.com>
8c90a8
Date: Fri, 21 Apr 2017 13:32:25 +0200
8c90a8
Subject: [PATCH] remove implementation of the WaitForSlotEvent callback
8c90a8
8c90a8
This reverts commit eefef2286183f1c895f408202367a0e4cb3b44c8.
8c90a8
---
8c90a8
 src/ckpem.h   |  1 -
8c90a8
 src/pinst.c   | 13 +------------
8c90a8
 src/pobject.c | 19 ++++++++++++-------
8c90a8
 3 files changed, 13 insertions(+), 20 deletions(-)
8c90a8
8c90a8
diff --git a/src/ckpem.h b/src/ckpem.h
8c90a8
index b4fff2c..e6ecc5f 100644
8c90a8
--- a/src/ckpem.h
8c90a8
+++ b/src/ckpem.h
8c90a8
@@ -211,7 +211,6 @@ struct pemInternalObjectStr {
8c90a8
 NSS_EXTERN_DATA pemInternalObject **pem_objs;
8c90a8
 NSS_EXTERN_DATA int pem_nobjs;
8c90a8
 NSS_EXTERN_DATA int token_needsLogin[];
8c90a8
-NSS_EXTERN_DATA NSSCKMDSlot *lastEventSlot;
8c90a8
 
8c90a8
 struct pemTokenStr {
8c90a8
   PRBool          logged_in;
8c90a8
diff --git a/src/pinst.c b/src/pinst.c
8c90a8
index 9cfbf45..5ac0ff3 100644
8c90a8
--- a/src/pinst.c
8c90a8
+++ b/src/pinst.c
8c90a8
@@ -53,7 +53,6 @@ static PRBool pemInitialized = PR_FALSE;
8c90a8
 pemInternalObject **pem_objs;
8c90a8
 int pem_nobjs = 0;
8c90a8
 int token_needsLogin[NUM_SLOTS];
8c90a8
-NSSCKMDSlot *lastEventSlot;
8c90a8
 
8c90a8
 /*
8c90a8
  * simple cert decoder to avoid the cost of asn1 engine
8c90a8
@@ -833,16 +832,6 @@ pem_mdInstance_ModuleHandlesSessionObjects
8c90a8
     return CK_TRUE;
8c90a8
 }
8c90a8
 
8c90a8
-static NSSCKMDSlot *
8c90a8
-pem_mdInstance_WaitForSlotEvent(
8c90a8
-    NSSCKMDInstance * mdInstance,
8c90a8
-    NSSCKFWInstance * fwInstance,
8c90a8
-    CK_BBOOL block,
8c90a8
-    CK_RV * pError)
8c90a8
-{
8c90a8
-    return lastEventSlot;
8c90a8
-}
8c90a8
-
8c90a8
 NSS_IMPLEMENT_DATA const NSSCKMDInstance
8c90a8
 pem_mdInstance = {
8c90a8
     (void *) NULL, /* etc */
8c90a8
@@ -855,6 +844,6 @@ pem_mdInstance = {
8c90a8
     pem_mdInstance_GetLibraryVersion,
8c90a8
     pem_mdInstance_ModuleHandlesSessionObjects,
8c90a8
     pem_mdInstance_GetSlots,
8c90a8
-    pem_mdInstance_WaitForSlotEvent,
8c90a8
+    NULL, /* WaitForSlotEvent */
8c90a8
     (void *) NULL /* null terminator */
8c90a8
 };
8c90a8
diff --git a/src/pobject.c b/src/pobject.c
8c90a8
index 6551d06..1227737 100644
8c90a8
--- a/src/pobject.c
8c90a8
+++ b/src/pobject.c
8c90a8
@@ -1212,6 +1212,7 @@ pem_CreateObject
8c90a8
         /* Brute force: find the id of the certificate, if any, in this slot */
8c90a8
         int i;
8c90a8
         SECItem certDER;
8c90a8
+        CK_SESSION_HANDLE hSession;
8c90a8
         PRBool added;
8c90a8
 
8c90a8
         nobjs = ReadDERFromFile(&derlist, filename, PR_TRUE, &cipher, &ivstring, PR_FALSE /* keys only */);
8c90a8
@@ -1259,14 +1260,18 @@ pem_CreateObject
8c90a8
          * the token was removed so we can force a login.
8c90a8
          */
8c90a8
         if (cipher && added) {
8c90a8
-            /* remember the slot for pem_mdInstance_WaitForSlotEvent() */
8c90a8
-            lastEventSlot = NSSCKFWSlot_GetMDSlot(fwSlot);
8c90a8
-
8c90a8
+            /* FIXME: Why 1.0s? Is it enough? Isn't it too much?
8c90a8
+             * What about e.g. 3.14s? */
8c90a8
+            PRIntervalTime onesec = PR_SecondsToInterval(1);
8c90a8
             token_needsLogin[slotID - 1] = PR_TRUE;
8c90a8
-            /* FIXME: dirty hack relying on NSS internals */
8c90a8
-            CK_SESSION_HANDLE hSession =
8c90a8
-                NSSCKFWInstance_FindSessionHandle(fwInstance, fwSession);
8c90a8
-            NSSCKFWInstance_DestroySessionHandle(fwInstance, hSession);
8c90a8
+
8c90a8
+            /* We have to sleep so that NSS will notice that the token was
8c90a8
+             * removed.
8c90a8
+             */
8c90a8
+            PR_Sleep(onesec);
8c90a8
+            hSession =
8c90a8
+                NSSCKFWInstance_FindSessionHandle(fwInstance, fwSession);
8c90a8
+            NSSCKFWInstance_DestroySessionHandle(fwInstance, hSession);
8c90a8
         } else {
8c90a8
             *pError = CKR_KEY_UNEXTRACTABLE;
8c90a8
         }
8c90a8
-- 
8c90a8
2.9.3
8c90a8