aboutsummaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2025-03-17 16:37:08 +0000
committerWerner Koch <[email protected]>2025-03-17 16:37:08 +0000
commitf463586a9617392f68305a1059045ece1243475b (patch)
treeb53d5936f09ebddd1b769149424b3b7e1b19bdc7 /agent
parentgpgconf: Fix reload and kill of keyboxd. (diff)
downloadgnupg-f463586a9617392f68305a1059045ece1243475b.tar.gz
gnupg-f463586a9617392f68305a1059045ece1243475b.zip
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
Diffstat (limited to 'agent')
-rw-r--r--agent/agent.h5
-rw-r--r--agent/call-scd.c15
-rw-r--r--agent/command.c10
-rw-r--r--agent/learncard.c10
4 files changed, 30 insertions, 10 deletions
diff --git a/agent/agent.h b/agent/agent.h
index 42b167726..5d426f6b8 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -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 --*/
diff --git a/agent/call-scd.c b/agent/call-scd.c
index de5d86271..28669206c 100644
--- a/agent/call-scd.c
+++ b/agent/call-scd.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)
diff --git a/agent/command.c b/agent/command.c
index b61ab9354..ff018dde7 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -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);
}
diff --git a/agent/learncard.c b/agent/learncard.c
index 83945b8be..351f59a2b 100644
--- a/agent/learncard.c
+++ b/agent/learncard.c
@@ -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;