1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-03 12:11:33 +01:00

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>
This commit is contained in:
NIIBE Yutaka 2020-01-13 16:43:53 +09:00
parent 0cfded4bb1
commit c31266716d
3 changed files with 11 additions and 5 deletions

View File

@ -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),

View File

@ -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;

View File

@ -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"),