From c31266716dd69fee7bd64cf1e33d7631cd328e72 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 13 Jan 2020 16:43:53 +0900 Subject: agent: Extend agent_card_getattr with KEYGRIP. * agent/agent.h (struct card_key_info_s): KEYGRIP null terminated. (agent_card_getattr): Add KEYGRIP argument. * agent/call-scd.c (agent_card_getattr): Handle KEYGRIP argument. (card_keyinfo_cb): Make KEYGRIP null terminated. * agent/command.c (cmd_readkey): Follow the change. Signed-off-by: NIIBE Yutaka --- agent/agent.h | 5 +++-- agent/call-scd.c | 9 +++++++-- agent/command.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'agent') diff --git a/agent/agent.h b/agent/agent.h index b47cf4dc9..49cc2fd98 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -366,7 +366,7 @@ typedef int (*lookup_ttl_t)(const char *hexgrip); struct card_key_info_s { struct card_key_info_s *next; - char keygrip[40]; + char keygrip[41]; char *serialno; char *idstr; }; @@ -613,7 +613,8 @@ gpg_error_t agent_card_writekey (ctrl_t ctrl, int force, const char *serialno, int (*getpin_cb)(void *, const char *, const char *, char*, size_t), void *getpin_cb_arg); -gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result); +gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result, + const char *keygrip); int agent_card_scd (ctrl_t ctrl, const char *cmdline, int (*getpin_cb)(void *, const char *, const char *, char*, size_t), diff --git a/agent/call-scd.c b/agent/call-scd.c index cacf1f483..b4a2974b4 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -1300,7 +1300,8 @@ card_getattr_cb (void *opaque, const char *line) NULL is never stored in this case. On error an error code is returned and NULL stored at RESULT. */ gpg_error_t -agent_card_getattr (ctrl_t ctrl, const char *name, char **result) +agent_card_getattr (ctrl_t ctrl, const char *name, char **result, + const char *keygrip) { int err; struct card_getattr_parm_s parm; @@ -1318,7 +1319,10 @@ agent_card_getattr (ctrl_t ctrl, const char *name, char **result) /* We assume that NAME does not need escaping. */ if (8 + strlen (name) > DIM(line)-1) return gpg_error (GPG_ERR_TOO_LARGE); - stpcpy (stpcpy (line, "GETATTR "), name); + if (keygrip == NULL) + stpcpy (stpcpy (line, "GETATTR "), name); + else + snprintf (line, sizeof line, "GETATTR %s %s", name, keygrip); err = start_scd (ctrl); if (err) @@ -1393,6 +1397,7 @@ card_keyinfo_cb (void *opaque, const char *line) } memcpy (keyinfo->keygrip, line, 40); + keyinfo->keygrip[40] = 0; line = s; diff --git a/agent/command.c b/agent/command.c index e38685c11..10eac94bd 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1010,7 +1010,7 @@ cmd_readkey (assuan_context_t ctx, char *line) { const char *keyid = opt_card; - rc = agent_card_getattr (ctrl, "SERIALNO", &serialno); + rc = agent_card_getattr (ctrl, "SERIALNO", &serialno, NULL); if (rc) { log_error (_("error getting serial number of card: %s\n"), -- cgit v1.2.3