[coolkey/f19] Fix insertion/removal detection
Ray Strode
rstrode at fedoraproject.org
Wed May 22 21:13:04 UTC 2013
commit 216e2df1e35c4a4ac63575ddd79a590ee31216e0
Author: Ray Strode <rstrode at redhat.com>
Date: Wed May 22 17:11:45 2013 -0400
Fix insertion/removal detection
pcscd now errors out of the SCardGetStatusChange call with
SCARD_E_UNKNOWN_READER if any of the passed readers aren't known.
This includes readers that were very recently forgotton about because a user just disconnected them.
Unfortunately, this means SECMOD_WaitForAnyTokenEvent will fail with a
SC_NO_EVENT error if a user removes their smartcard at the wrong time.
This patch changes coolkey to detect removed readers before calling
SCardGetStatusChange, so that it can handle the removal itself.
coolkey-fix-token-removal-failure.patch | 81 +++++++++++++++++++++++++++++++
coolkey.spec | 9 +++-
2 files changed, 88 insertions(+), 2 deletions(-)
---
diff --git a/coolkey-fix-token-removal-failure.patch b/coolkey-fix-token-removal-failure.patch
new file mode 100644
index 0000000..29600f7
--- /dev/null
+++ b/coolkey-fix-token-removal-failure.patch
@@ -0,0 +1,81 @@
+Fix insertion/removal detection
+
+pcscd now errors out of the SCardGetStatusChange call with
+SCARD_E_UNKNOWN_READER if any of the passed readers aren't known.
+This includes readers that were very recently forgotton about because a user just disconnected them.
+
+Unfortunately, this means SECMOD_WaitForAnyTokenEvent will fail with a
+SC_NO_EVENT error if a user removes their smartcard at the wrong time.
+
+This patch changes coolkey to detect removed readers before calling
+SCardGetStatusChange, so that it can handle the removal itself.
+
+diff -up coolkey-1.1.0/src/coolkey/slot.cpp.fix coolkey-1.1.0/src/coolkey/slot.cpp
+--- coolkey-1.1.0/src/coolkey/slot.cpp.fix 2013-05-22 16:23:41.728846957 -0400
++++ coolkey-1.1.0/src/coolkey/slot.cpp 2013-05-22 17:09:59.813958927 -0400
+@@ -279,24 +279,22 @@ SlotList::updateReaderList()
+ * don't recognize.
+ */
+
+- /* first though, let's check to see if any previously removed readers have
+- * come back from the dead. If the ignored bit has been set, we do not need
+- * it any more.
+- */
++ /* Iterate through all the readers to see if we need to make unavailable any
++ * freshly removed readers. Also, see if any previously removed
++ * readers have come back from the dead and don't need to be ignored.
++ */
+
+ const char *curReaderName = NULL;
+ unsigned long knownState = 0;
+ for(int ri = 0 ; ri < numReaders; ri ++) {
+-
+ knownState = CKYReader_GetKnownState(&readerStates[ri]);
+- if( !(knownState & SCARD_STATE_IGNORE)) {
+- continue;
+- }
+-
++
+ curReaderName = CKYReader_GetReaderName(&readerStates[ri]);
+ if(readerNameExistsInList(curReaderName,&readerNames)) {
+ CKYReader_SetKnownState(&readerStates[ri], knownState & ~SCARD_STATE_IGNORE);
+-
++ } else {
++ if (!(knownState & SCARD_STATE_UNAVAILABLE))
++ CKYReader_SetKnownState(&readerStates[ri], knownState | SCARD_STATE_UNAVAILABLE | SCARD_STATE_CHANGED);
+ }
+ }
+
+@@ -1238,6 +1236,32 @@ SlotList::waitForSlotEvent(CK_FLAGS flag
+ throw;
+ }
+
++ /* Before round-tripping to the daemon for the duration of the
++ * timeout, first see if we lost any readers, and pick a slot
++ * from that set to return
++ */
++ for (i=0; i < numReaders; i++) {
++ unsigned long knownState = CKYReader_GetKnownState(&readerStates[i]);
++
++ if ((knownState & SCARD_STATE_UNAVAILABLE) &&
++ (knownState & SCARD_STATE_CHANGED)) {
++ CKYReader_SetKnownState(&readerStates[i], knownState & ~SCARD_STATE_CHANGED);
++ readerListLock.releaseLock();
++ *slotp = slotIndexToID(i);
++ found = TRUE;
++ break;
++ }
++ }
++
++ if (found) {
++ break;
++ }
++
++ if (shuttingDown) {
++ readerListLock.releaseLock();
++ break;
++ }
++
+ if (myNumReaders != numReaders) {
+ if (myReaderStates) {
+ delete [] myReaderStates;
diff --git a/coolkey.spec b/coolkey.spec
index c8b1562..54e1ab2 100644
--- a/coolkey.spec
+++ b/coolkey.spec
@@ -22,7 +22,7 @@
Name: coolkey
Version: 1.1.0
-Release: 22%{?dist}
+Release: 23%{?dist}
Summary: CoolKey PKCS #11 module
License: LGPLv2
URL: http://directory.fedora.redhat.com/wiki/CoolKey
@@ -35,6 +35,7 @@ Patch5: coolkey-thread-fix.patch
Patch6: coolkey-cac.patch
Patch7: coolkey-cac-1.patch
Patch8: coolkey-pcsc-lite-fix.patch
+Patch9: coolkey-fix-token-removal-failure.patch
Group: System Environment/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: autoconf
@@ -71,11 +72,12 @@ Linux Driver support to access the CoolKey applet.
%patch6 -b .cac
%patch7 -b .cac-1
%patch8 -b .reader-state-fix
+%patch9 -p1 -b .fix-token-removal-failure
%build
autoconf
%configure --with-debug --disable-dependency-tracking --enable-pk11install
-make %{?_smp_mflags} CFLAGS="$CFLAGS -g -O2 -fno-strict-aliasing" CXXFLAGS="$CXXFLAGS -g -O2 -fno-strict-aliasing"
+make %{?_smp_mflags} CFLAGS="$CFLAGS -g -O2 -fno-strict-aliasing $CFLAGS " CXXFLAGS="$CXXFLAGS -g -O2 -fno-strict-aliasing $CFLAGS"
%install
rm -rf $RPM_BUILD_ROOT
@@ -119,6 +121,9 @@ fi
%changelog
+* Wed May 22 2013 Ray Strode <rstrode at redhat.com> 1.1.0-23
+- Fix token removal issue
+
* Wed Feb 13 2013 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.1.0-22
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild
More information about the scm-commits
mailing list