chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0029-scd-Fix-use-case-of-PC-SC.patch
1 From: NIIBE Yutaka <gniibe@fsij.org>
2 Date: Mon, 13 Feb 2017 11:09:13 +0900
3 Subject: scd: Fix use case of PC/SC.
4
5 * scd/apdu.c (apdu_open_reader): Add an argument APP_EMPTY.
6 When CCID driver fails to open, try PC/SC if APP is nothing.
7 * scd/app.c (select_application): Supply arg if APP is nothing.
8
9 --
10
11 After scanning available card readers by CCID driver, scdaemon should
12 try PC/SC service if no APP is registered yet.  Also, when the slot
13 is allocated for PC/SC (ccid.handle==NULL), it should not call
14 ccid_compare_BAI, otherwise scdaemon crashes.
15
16 Debian-bug-id: 852702, 854005, 854595, 854616
17
18 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
19 ---
20  scd/apdu.c | 14 +++++++++++---
21  scd/apdu.h |  2 +-
22  scd/app.c  |  2 +-
23  3 files changed, 13 insertions(+), 5 deletions(-)
24
25 diff --git a/scd/apdu.c b/scd/apdu.c
26 index 38ebd2be5..149154cf3 100644
27 --- a/scd/apdu.c
28 +++ b/scd/apdu.c
29 @@ -3117,7 +3117,7 @@ apdu_open_one_reader (const char *portstr)
30  }
31  
32  int
33 -apdu_open_reader (struct dev_list *dl)
34 +apdu_open_reader (struct dev_list *dl, int app_empty)
35  {
36    int slot;
37  
38 @@ -3167,6 +3167,7 @@ apdu_open_reader (struct dev_list *dl)
39            /* Check identity by BAI against already opened HANDLEs.  */
40            for (slot = 0; slot < MAX_READER; slot++)
41              if (reader_table[slot].used
42 +                && reader_table[slot].ccid.handle
43                  && ccid_compare_BAI (reader_table[slot].ccid.handle, bai))
44                break;
45  
46 @@ -3191,12 +3192,19 @@ apdu_open_reader (struct dev_list *dl)
47              dl->idx++;
48          }
49  
50 -      slot = -1;
51 +      /* Not found.  Try one for PC/SC, only when it's the initial scan.  */
52 +      if (app_empty && dl->idx == dl->idx_max)
53 +        {
54 +          dl->idx++;
55 +          slot = apdu_open_one_reader (dl->portstr);
56 +        }
57 +      else
58 +        slot = -1;
59      }
60    else
61  #endif
62      { /* PC/SC readers.  */
63 -      if (dl->idx == 0)
64 +      if (app_empty && dl->idx == 0)
65          {
66            dl->idx++;
67            slot = apdu_open_one_reader (dl->portstr);
68 diff --git a/scd/apdu.h b/scd/apdu.h
69 index 473def518..6751e8c9b 100644
70 --- a/scd/apdu.h
71 +++ b/scd/apdu.h
72 @@ -91,7 +91,7 @@ gpg_error_t apdu_dev_list_start (const char *portstr, struct dev_list **l_p);
73  void apdu_dev_list_finish (struct dev_list *l);
74  
75  /* Note, that apdu_open_reader returns no status word but -1 on error. */
76 -int apdu_open_reader (struct dev_list *l);
77 +int apdu_open_reader (struct dev_list *l, int app_empty);
78  int apdu_open_remote_reader (const char *portstr,
79                               const unsigned char *cookie, size_t length,
80                               int (*readfnc) (void *opaque,
81 diff --git a/scd/app.c b/scd/app.c
82 index 989e0c060..8fb0d4553 100644
83 --- a/scd/app.c
84 +++ b/scd/app.c
85 @@ -340,7 +340,7 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app,
86            int slot;
87            int sw;
88  
89 -          slot = apdu_open_reader (l);
90 +          slot = apdu_open_reader (l, !app_top);
91            if (slot < 0)
92              break;
93