agent: Fix cancellation handling for scdaemon.
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 20 Sep 2017 01:42:28 +0000 (10:42 +0900)
committerPeter Michael Green <plugwash@raspbian.org>
Wed, 25 Jul 2018 10:25:32 +0000 (11:25 +0100)
* agent/call-scd.c (cancel_inquire): Remove.
(agent_card_pksign, agent_card_pkdecrypt, agent_card_writekey)
(agent_card_scd): Don't call cancel_inquire.

--

Since libassuan 2.1.0, cancellation command "CAN" is handled within
the library, by assuan_transact.  So, cancel_inquire just caused
spurious "CAN" command to scdaemon which resulted an error.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
(cherry picked from commit 9f5e50e7c85aa8b847d38010241ed570ac114fc3)

Gbp-Pq: Topic from-master
Gbp-Pq: Name agent-Fix-cancellation-handling-for-scdaemon.patch

agent/call-scd.c

index bf7732bf06a48f4fc1185c3e92e084b7fd8c7c60..e852c0d9e8a2b875c3e13bb921f79ece1d9be5b6 100644 (file)
@@ -89,7 +89,6 @@ struct inq_needpin_parm_s
   const char *getpin_cb_desc;
   assuan_context_t passthru;  /* If not NULL, pass unknown inquiries
                                  up to the caller.  */
-  int any_inq_seen;
 
   /* The next fields are used by inq_writekey_parm.  */
   const unsigned char *keydata;
@@ -729,7 +728,6 @@ inq_needpin (void *opaque, const char *line)
   size_t pinlen;
   int rc;
 
-  parm->any_inq_seen = 1;
   if ((s = has_leading_keyword (line, "NEEDPIN")))
     {
       line = s;
@@ -813,30 +811,6 @@ hash_algo_option (int algo)
 }
 
 
-static gpg_error_t
-cancel_inquire (ctrl_t ctrl, gpg_error_t rc)
-{
-  gpg_error_t oldrc = rc;
-
-  /* The inquire callback was called and transact returned a
-     cancel error.  We assume that the inquired process sent a
-     CANCEL.  The passthrough code is not able to pass on the
-     CANCEL and thus scdaemon would stuck on this.  As a
-     workaround we send a CANCEL now.  */
-  rc = assuan_write_line (ctrl->scd_local->ctx, "CAN");
-  if (!rc) {
-    char *line;
-    size_t len;
-
-    rc = assuan_read_line (ctrl->scd_local->ctx, &line, &len);
-    if (!rc)
-      rc = oldrc;
-  }
-
-  return rc;
-}
-
-
 /* Create a signature using the current card.  MDALGO is either 0 or
  * gives the digest algorithm.  DESC_TEXT is an additional parameter
  * passed to GETPIN_CB. */
@@ -877,7 +851,6 @@ agent_card_pksign (ctrl_t ctrl,
   inqparm.getpin_cb_arg = getpin_cb_arg;
   inqparm.getpin_cb_desc = desc_text;
   inqparm.passthru = 0;
-  inqparm.any_inq_seen = 0;
   inqparm.keydata = NULL;
   inqparm.keydatalen = 0;
 
@@ -890,9 +863,6 @@ agent_card_pksign (ctrl_t ctrl,
                         put_membuf_cb, &data,
                         inq_needpin, &inqparm,
                         NULL, NULL);
-  if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
-       gpg_err_code(rc) == GPG_ERR_ASS_CANCELED))
-    rc = cancel_inquire (ctrl, rc);
 
   if (rc)
     {
@@ -976,7 +946,6 @@ agent_card_pkdecrypt (ctrl_t ctrl,
   inqparm.getpin_cb_arg = getpin_cb_arg;
   inqparm.getpin_cb_desc = desc_text;
   inqparm.passthru = 0;
-  inqparm.any_inq_seen = 0;
   inqparm.keydata = NULL;
   inqparm.keydatalen = 0;
   snprintf (line, DIM(line), "PKDECRYPT %s", keyid);
@@ -984,9 +953,6 @@ agent_card_pkdecrypt (ctrl_t ctrl,
                         put_membuf_cb, &data,
                         inq_needpin, &inqparm,
                         padding_info_cb, r_padding);
-  if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
-       gpg_err_code(rc) == GPG_ERR_ASS_CANCELED))
-    rc = cancel_inquire (ctrl, rc);
 
   if (rc)
     {
@@ -1113,15 +1079,11 @@ agent_card_writekey (ctrl_t ctrl,  int force, const char *serialno,
   parms.getpin_cb_arg = getpin_cb_arg;
   parms.getpin_cb_desc= NULL;
   parms.passthru = 0;
-  parms.any_inq_seen = 0;
   parms.keydata = keydata;
   parms.keydatalen = keydatalen;
 
   rc = assuan_transact (ctrl->scd_local->ctx, line, NULL, NULL,
                         inq_writekey_parms, &parms, NULL, NULL);
-  if (parms.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
-                             gpg_err_code(rc) == GPG_ERR_ASS_CANCELED))
-    rc = cancel_inquire (ctrl, rc);
   return unlock_scd (ctrl, rc);
 }
 
@@ -1346,7 +1308,6 @@ agent_card_scd (ctrl_t ctrl, const char *cmdline,
   inqparm.getpin_cb_arg = getpin_cb_arg;
   inqparm.getpin_cb_desc = NULL;
   inqparm.passthru = assuan_context;
-  inqparm.any_inq_seen = 0;
   inqparm.keydata = NULL;
   inqparm.keydatalen = 0;
 
@@ -1356,8 +1317,6 @@ agent_card_scd (ctrl_t ctrl, const char *cmdline,
                         pass_data_thru, assuan_context,
                         inq_needpin, &inqparm,
                         pass_status_thru, assuan_context);
-  if (inqparm.any_inq_seen && gpg_err_code(rc) == GPG_ERR_ASS_CANCELED)
-    rc = cancel_inquire (ctrl, rc);
 
   assuan_set_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS, saveflag);
   if (rc)