summaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2020-01-13 08:43:53 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2020-01-13 08:43:53 +0100
commitc31266716dd69fee7bd64cf1e33d7631cd328e72 (patch)
treec79922a836ab7a893afd283c66d4d66d89120090 /agent
parentscd: Implement direct access by KEYGRIP for GETATTR and READKEY. (diff)
downloadgnupg2-c31266716dd69fee7bd64cf1e33d7631cd328e72.tar.xz
gnupg2-c31266716dd69fee7bd64cf1e33d7631cd328e72.zip
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 <gniibe@fsij.org>
Diffstat (limited to 'agent')
-rw-r--r--agent/agent.h5
-rw-r--r--agent/call-scd.c9
-rw-r--r--agent/command.c2
3 files changed, 11 insertions, 5 deletions
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"),