chiark / gitweb /
scd: Fix use case of PC/SC.
authorNIIBE Yutaka <gniibe@fsij.org>
Mon, 13 Feb 2017 02:09:13 +0000 (11:09 +0900)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Mon, 18 Sep 2017 20:41:12 +0000 (21:41 +0100)
* scd/apdu.c (apdu_open_reader): Add an argument APP_EMPTY.
When CCID driver fails to open, try PC/SC if APP is nothing.
* scd/app.c (select_application): Supply arg if APP is nothing.

--

After scanning available card readers by CCID driver, scdaemon should
try PC/SC service if no APP is registered yet.  Also, when the slot
is allocated for PC/SC (ccid.handle==NULL), it should not call
ccid_compare_BAI, otherwise scdaemon crashes.

Debian-bug-id: 852702, 854005, 854595, 854616

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Gbp-Pq: Name 0029-scd-Fix-use-case-of-PC-SC.patch

scd/apdu.c
scd/apdu.h
scd/app.c

index 38ebd2be5b4f62c57ab8b17f97e8751918b6c2b9..149154cf3f360b07b5467b95a3c1e87e8e0a5d78 100644 (file)
@@ -3117,7 +3117,7 @@ apdu_open_one_reader (const char *portstr)
 }
 
 int
-apdu_open_reader (struct dev_list *dl)
+apdu_open_reader (struct dev_list *dl, int app_empty)
 {
   int slot;
 
@@ -3167,6 +3167,7 @@ apdu_open_reader (struct dev_list *dl)
           /* Check identity by BAI against already opened HANDLEs.  */
           for (slot = 0; slot < MAX_READER; slot++)
             if (reader_table[slot].used
+                && reader_table[slot].ccid.handle
                 && ccid_compare_BAI (reader_table[slot].ccid.handle, bai))
               break;
 
@@ -3191,12 +3192,19 @@ apdu_open_reader (struct dev_list *dl)
             dl->idx++;
         }
 
-      slot = -1;
+      /* Not found.  Try one for PC/SC, only when it's the initial scan.  */
+      if (app_empty && dl->idx == dl->idx_max)
+        {
+          dl->idx++;
+          slot = apdu_open_one_reader (dl->portstr);
+        }
+      else
+        slot = -1;
     }
   else
 #endif
     { /* PC/SC readers.  */
-      if (dl->idx == 0)
+      if (app_empty && dl->idx == 0)
         {
           dl->idx++;
           slot = apdu_open_one_reader (dl->portstr);
index 473def518ac5beb26684556b2fb55c1d88886102..6751e8c9bb732ca6009ab1929b2e0e07258dcd85 100644 (file)
@@ -91,7 +91,7 @@ gpg_error_t apdu_dev_list_start (const char *portstr, struct dev_list **l_p);
 void apdu_dev_list_finish (struct dev_list *l);
 
 /* Note, that apdu_open_reader returns no status word but -1 on error. */
-int apdu_open_reader (struct dev_list *l);
+int apdu_open_reader (struct dev_list *l, int app_empty);
 int apdu_open_remote_reader (const char *portstr,
                              const unsigned char *cookie, size_t length,
                              int (*readfnc) (void *opaque,
index 989e0c06096cbfd4346559b0d38df85c3812244e..8fb0d45537fd96fc9dc574d79e5ea74f6c75d0cb 100644 (file)
--- a/scd/app.c
+++ b/scd/app.c
@@ -340,7 +340,7 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app,
           int slot;
           int sw;
 
-          slot = apdu_open_reader (l);
+          slot = apdu_open_reader (l, !app_top);
           if (slot < 0)
             break;