1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

card: New subcommand "checkkeys".

* agent/command.c (cmd_havekey): Add new option --info.
* tools/card-call-scd.c (scd_readkey): Allow using without result arg.
(struct havekey_status_parm_s): New.
(havekey_status_cb): New.
(scd_havekey_info): New.
(scd_delete_key): New.
* tools/gpg-card.c (print_keygrip): Add arg with_lf.
(cmd_checkkeys): New.
(cmdCHECKKEYS): New.
(cmds): Add command "checkkeys".
(dispatch_command, interactive_loop): Call cmd_checkkeys.
--

GnuPG-bug-id: 6943
This commit is contained in:
Werner Koch 2024-01-16 18:05:46 +01:00
parent c8060a8f23
commit adeb17e375
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
4 changed files with 265 additions and 11 deletions

View file

@ -1529,14 +1529,16 @@ scd_readkey (const char *keyrefstr, int create_shadow, gcry_sexp_t *r_result)
unsigned char *buf;
size_t len, buflen;
*r_result = NULL;
if (r_result)
*r_result = NULL;
err = start_agent (0);
if (err)
return err;
init_membuf (&data, 1024);
if (create_shadow)
snprintf (line, DIM(line), "READKEY --card -- %s", keyrefstr);
snprintf (line, DIM(line), "READKEY %s--card -- %s",
r_result? "" : "--no-data ", keyrefstr);
else
snprintf (line, DIM(line), "SCD READKEY %s", keyrefstr);
err = assuan_transact (agent_ctx, line,
@ -1552,7 +1554,7 @@ scd_readkey (const char *keyrefstr, int create_shadow, gcry_sexp_t *r_result)
if (!buf)
return gpg_error_from_syserror ();
err = gcry_sexp_new (r_result, buf, buflen, 0);
err = r_result ? gcry_sexp_new (r_result, buf, buflen, 0) : 0;
xfree (buf);
return err;
@ -1769,6 +1771,90 @@ agent_get_s2k_count (void)
}
struct havekey_status_parm_s
{
char *string;
};
static gpg_error_t
havekey_status_cb (void *opaque, const char *line)
{
struct havekey_status_parm_s *parm = opaque;
const char *s;
char *p;
if ((s = has_leading_keyword (line, "KEYFILEINFO")))
{
xfree (parm->string);
parm->string = xtrystrdup (s);
if (!parm->string)
return gpg_error_from_syserror ();
p = strchr (parm->string, ' ');
if (p)
*p = 0;
}
return 0;
}
/* Run the HAVEKEY --info command and stores the retrieved string at
* R_RESULT. Caller must free that string. If an error is returned
* R_RESULT is set to NULL. */
gpg_error_t
scd_havekey_info (const unsigned char *grip, char **r_result)
{
gpg_error_t err;
char line[ASSUAN_LINELENGTH];
struct havekey_status_parm_s parm = {NULL};
*r_result = NULL;
err = start_agent (0);
if (err)
return err;
snprintf (line, sizeof line, "HAVEKEY --info ");
log_assert (ASSUAN_LINELENGTH > strlen(line) + 2*KEYGRIP_LEN + 10);
bin2hex (grip, KEYGRIP_LEN, line+strlen(line));
err = assuan_transact (agent_ctx, line,
NULL, NULL, NULL, NULL,
havekey_status_cb, &parm);
if (err)
xfree (parm.string);
else
*r_result = parm.string;
return err;
}
/* Run the DELETE_KEY command. If FORCE is given the user will not be
* asked for confirmation. */
gpg_error_t
scd_delete_key (const unsigned char *grip, int force)
{
gpg_error_t err;
char line[ASSUAN_LINELENGTH];
struct default_inq_parm_s dfltparm = {NULL};
err = start_agent (0);
if (err)
return err;
dfltparm.ctx = agent_ctx;
snprintf (line, sizeof line, "DELETE_KEY%s ", force?" --force":"");
log_assert (ASSUAN_LINELENGTH > strlen(line) + 2*KEYGRIP_LEN + 10);
bin2hex (grip, KEYGRIP_LEN, line+strlen(line));
err = assuan_transact (agent_ctx, line,
NULL, NULL, default_inq_cb, &dfltparm, NULL, NULL);
return err;
}
/* Return a malloced string describing the statusword SW. On error
* NULL is returned. */
char *