mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
gpgsm: Extend --learn-card by an optional s/n argument.
* agent/command.c (cmd_learn): Allow for s/n argument. * agent/learncard.c (agent_handle_learn): Ditto. * agent/call-scd.c (agent_card_learn): Ditto. Pass it on to scd. * scd/command.c (cmd_switchcard): Factor most code out to ... (switchcard_core): new. (cmd_learn): Add option --demand to specify a s/n. * sm/gpgsm.c (main): Allow a s/n argument for --learn-card. -- This help Kleopatra to get a stable certificate listing. GnuPG-bug-id: 7379
This commit is contained in:
parent
5420c4ebde
commit
f463586a96
9 changed files with 99 additions and 39 deletions
|
@ -731,7 +731,7 @@ int agent_tpm2d_pkdecrypt (ctrl_t ctrl, const unsigned char *cipher,
|
|||
char **r_buf, size_t *r_len);
|
||||
|
||||
/*-- call-scd.c --*/
|
||||
int agent_card_learn (ctrl_t ctrl,
|
||||
int agent_card_learn (ctrl_t ctrl, const char *demand_sn,
|
||||
void (*kpinfo_cb)(void*, const char *),
|
||||
void *kpinfo_cb_arg,
|
||||
void (*certinfo_cb)(void*, const char *),
|
||||
|
@ -780,7 +780,8 @@ gpg_error_t agent_card_keyinfo (ctrl_t ctrl, const char *keygrip,
|
|||
int cap, struct card_key_info_s **result);
|
||||
|
||||
/*-- learncard.c --*/
|
||||
int agent_handle_learn (ctrl_t ctrl, int send, void *assuan_context, int force);
|
||||
int agent_handle_learn (ctrl_t ctrl, int send, void *assuan_context,
|
||||
int force, const char *demand_sn);
|
||||
|
||||
|
||||
/*-- cvt-openpgp.c --*/
|
||||
|
|
|
@ -260,10 +260,14 @@ learn_status_cb (void *opaque, const char *line)
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* Perform the LEARN command and return a list of all private keys
|
||||
stored on the card. */
|
||||
* stored on the card. If DEMAND_SN is given the info is returned for
|
||||
* the card with that S/N instead of the current card. This may then
|
||||
* switch the current card. */
|
||||
int
|
||||
agent_card_learn (ctrl_t ctrl,
|
||||
const char *demand_sn,
|
||||
void (*kpinfo_cb)(void*, const char *),
|
||||
void *kpinfo_cb_arg,
|
||||
void (*certinfo_cb)(void*, const char *),
|
||||
|
@ -273,6 +277,7 @@ agent_card_learn (ctrl_t ctrl,
|
|||
{
|
||||
int rc;
|
||||
struct learn_parm_s parm;
|
||||
char line[ASSUAN_LINELENGTH];
|
||||
|
||||
rc = start_scd (ctrl);
|
||||
if (rc)
|
||||
|
@ -285,7 +290,13 @@ agent_card_learn (ctrl_t ctrl,
|
|||
parm.certinfo_cb_arg = certinfo_cb_arg;
|
||||
parm.sinfo_cb = sinfo_cb;
|
||||
parm.sinfo_cb_arg = sinfo_cb_arg;
|
||||
rc = assuan_transact (daemon_ctx (ctrl), "LEARN --force",
|
||||
|
||||
if (demand_sn && *demand_sn)
|
||||
snprintf (line, sizeof line, "LEARN --demand=%s --force", demand_sn);
|
||||
else
|
||||
snprintf (line, sizeof line, "LEARN --force");
|
||||
|
||||
rc = assuan_transact (daemon_ctx (ctrl), line,
|
||||
NULL, NULL, NULL, NULL,
|
||||
learn_status_cb, &parm);
|
||||
if (rc)
|
||||
|
|
|
@ -2376,27 +2376,31 @@ cmd_get_confirmation (assuan_context_t ctx, char *line)
|
|||
|
||||
|
||||
static const char hlp_learn[] =
|
||||
"LEARN [--send] [--sendinfo] [--force]\n"
|
||||
"LEARN [--send] [--sendinfo] [--force] [SERIALNO]\n"
|
||||
"\n"
|
||||
"Learn something about the currently inserted smartcard. With\n"
|
||||
"--sendinfo information about the card is returned; with --send\n"
|
||||
"the available certificates are returned as D lines; with --force\n"
|
||||
"private key storage will be updated by the result.";
|
||||
"private key storage will be updated by the result. With SERIALNO\n"
|
||||
"given the current card is first switched to the specified one.";
|
||||
static gpg_error_t
|
||||
cmd_learn (assuan_context_t ctx, char *line)
|
||||
{
|
||||
ctrl_t ctrl = assuan_get_pointer (ctx);
|
||||
gpg_error_t err;
|
||||
int send, sendinfo, force;
|
||||
const char *demand_sn;
|
||||
|
||||
send = has_option (line, "--send");
|
||||
sendinfo = send? 1 : has_option (line, "--sendinfo");
|
||||
force = has_option (line, "--force");
|
||||
line = skip_options (line);
|
||||
demand_sn = *line? line : NULL;
|
||||
|
||||
if (ctrl->restricted)
|
||||
return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN));
|
||||
|
||||
err = agent_handle_learn (ctrl, send, sendinfo? ctx : NULL, force);
|
||||
err = agent_handle_learn (ctrl, send, sendinfo? ctx : NULL, force, demand_sn);
|
||||
return leave_cmd (ctx, err);
|
||||
}
|
||||
|
||||
|
|
|
@ -295,10 +295,14 @@ send_cert_back (ctrl_t ctrl, const char *id, void *assuan_context)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Perform the learn operation. If ASSUAN_CONTEXT is not NULL and
|
||||
SEND is true all new certificates are send back via Assuan. */
|
||||
* SEND is true all new certificates are send back via Assuan. If
|
||||
* DEMAND_SN is not NULL it has a string with the serial number of the
|
||||
* card requested. */
|
||||
int
|
||||
agent_handle_learn (ctrl_t ctrl, int send, void *assuan_context, int force)
|
||||
agent_handle_learn (ctrl_t ctrl, int send, void *assuan_context, int force,
|
||||
const char *demand_sn)
|
||||
{
|
||||
int rc;
|
||||
struct kpinfo_cb_parm_s parm;
|
||||
|
@ -328,7 +332,7 @@ agent_handle_learn (ctrl_t ctrl, int send, void *assuan_context, int force)
|
|||
cparm.ctrl = ctrl;
|
||||
|
||||
/* Now gather all the available info. */
|
||||
rc = agent_card_learn (ctrl, kpinfo_cb, &parm, certinfo_cb, &cparm,
|
||||
rc = agent_card_learn (ctrl, demand_sn, kpinfo_cb, &parm, certinfo_cb, &cparm,
|
||||
sinfo_cb, &sparm);
|
||||
if (!rc && (parm.error || cparm.error || sparm.error))
|
||||
rc = parm.error? parm.error : cparm.error? cparm.error : sparm.error;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue