aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-06-17 12:35:21 +0000
committerWerner Koch <[email protected]>2019-06-17 12:35:21 +0000
commit70f7b262877b1e751d8557dc04a09a420e9d8a8f (patch)
tree76037c7364eeb515ed129767d06c4ef82c38baf7
parentscd: Use the correct gpg for the v1.0 OpenPGP card hack. (diff)
downloadgnupg-70f7b262877b1e751d8557dc04a09a420e9d8a8f.tar.gz
gnupg-70f7b262877b1e751d8557dc04a09a420e9d8a8f.zip
scd: Slight change to app->fnc.do_with_keygrip.
* scd/app-openpgp.c (do_with_keygrip): Return a real error code to avoid misinterpretation of the result. Also fix the case for a too small buffer. -- The only real chnage is the case for a too small buffer. That should in general never happen but if so we now return an error instead of success. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--scd/app-common.h7
-rw-r--r--scd/app-openpgp.c18
-rw-r--r--scd/app.c24
3 files changed, 36 insertions, 13 deletions
diff --git a/scd/app-common.h b/scd/app-common.h
index 8a25cda55..cf51d26fe 100644
--- a/scd/app-common.h
+++ b/scd/app-common.h
@@ -126,11 +126,13 @@ struct app_ctx_s {
gpg_error_t (*check_pin) (app_t app, const char *keyidstr,
gpg_error_t (*pincb)(void*, const char *, char **),
void *pincb_arg);
- int (*with_keygrip) (app_t app, ctrl_t ctrl, int action,
- const char *keygrip_str);
+ gpg_error_t (*with_keygrip) (app_t app, ctrl_t ctrl, int action,
+ const char *keygrip_str);
} fnc;
};
+
+/* Action values for app_do_with_keygrip. */
enum
{
KEYGRIP_ACTION_SEND_DATA,
@@ -138,6 +140,7 @@ enum
KEYGRIP_ACTION_LOOKUP
};
+
/*-- app-help.c --*/
unsigned int app_help_count_bits (const unsigned char *a, size_t len);
gpg_error_t app_help_get_keygrip_string_pk (const void *pk, size_t pklen,
diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c
index f174e2e2a..5e67a7b53 100644
--- a/scd/app-openpgp.c
+++ b/scd/app-openpgp.c
@@ -4913,7 +4913,7 @@ do_check_pin (app_t app, const char *keyidstr,
return verify_chv2 (app, pincb, pincb_arg);
}
-static int
+static gpg_error_t
do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str)
{
int i;
@@ -4925,14 +4925,12 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str)
if (action == KEYGRIP_ACTION_LOOKUP)
{
if (keygrip_str == NULL)
- return 1;
+ return gpg_error (GPG_ERR_NOT_FOUND);
for (i = 0; i < 3; i++)
if (app->app_local->pk[i].read_done
&& !strcmp (keygrip_str, app->app_local->pk[i].keygrip_str))
- return 0; /* Found */
-
- return 1;
+ return 0; /* Found */
}
else
{
@@ -4941,7 +4939,7 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str)
int data = (action == KEYGRIP_ACTION_SEND_DATA);
if (DIM (buf) < 2 * app->serialnolen + 1)
- return 0;
+ return gpg_error (GPG_ERR_BUFFER_TOO_SHORT);
bin2hex (app->serialno, app->serialnolen, buf);
@@ -4954,6 +4952,10 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str)
send_keyinfo (ctrl, data,
app->app_local->pk[i].keygrip_str,buf, idbuf);
}
+ /* Return an error so that the dispatcher keeps on looping
+ * over the other applications. Only for clarity we use a
+ * different error code than for the not_found case. */
+ return gpg_error (GPG_ERR_TRUE);
}
else
{
@@ -4966,9 +4968,9 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str)
return 0;
}
}
-
- return 1;
}
+
+ return gpg_error (GPG_ERR_NOT_FOUND);
}
/* Show information about card capabilities. */
diff --git a/scd/app.c b/scd/app.c
index 4fe60cbbb..9640c8015 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -1292,9 +1292,27 @@ app_send_card_list (ctrl_t ctrl)
}
/* Execute an action for each app. ACTION can be one of:
- KEYGRIP_ACTION_SEND_DATA: send data if KEYGRIP_STR matches
- KEYGRIP_ACTION_WRITE_STATUS: write status if KEYGRIP_STR matches
- KEYGRIP_ACTION_LOOKUP: Return matching APP
+ *
+ * - KEYGRIP_ACTION_SEND_DATA
+ *
+ * If KEYGRIP_STR matches a public key of any active application
+ * send information as LF terminated data lines about the public
+ * key. The format of these lines is
+ * <keygrip> T <serialno> <idstr>
+ * If a match was found a pointer to the matching application is
+ * returned. With the KEYGRIP_STR given as NULL, lines for all
+ * keys will be send and the return value is NULL.
+ *
+ * - KEYGRIP_ACTION_WRITE_STATUS
+ *
+ * Same as KEYGRIP_ACTION_SEND_DATA but uses status lines instead
+ * of data lines.
+ *
+ * - KEYGRIP_ACTION_LOOKUP
+ *
+ * Returns a pointer to the application matching KEYGRIP_STR but
+ * does not emit any status or data lines. If no key with that
+ * keygrip is available or KEYGRIP_STR is NULL, NULL is returned.
*/
app_t
app_do_with_keygrip (ctrl_t ctrl, int action, const char *keygrip_str)