aboutsummaryrefslogtreecommitdiffstats
path: root/scd
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 /scd
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 'scd')
-rw-r--r--scd/command.c71
1 files changed, 52 insertions, 19 deletions
diff --git a/scd/command.c b/scd/command.c
index b386b9c5f..792a347b4 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -384,28 +384,14 @@ cmd_serialno (assuan_context_t ctx, char *line)
-static const char hlp_switchcard[] =
- "SWITCHCARD [<serialno>]\n"
- "\n"
- "Make the card with SERIALNO the current card.\n"
- "The command \"getinfo card_list\" can be used to list\n"
- "the serial numbers of inserted and known cards. Note\n"
- "that the command \"SERIALNO\" can be used to refresh\n"
- "the list of known cards. A simple SERIALNO status\n"
- "is printed on success.";
+/* Helper for cmd_swicthcard and cmd_learn. */
static gpg_error_t
-cmd_switchcard (assuan_context_t ctx, char *line)
+switchcard_core (ctrl_t ctrl, const char *line)
{
- ctrl_t ctrl = assuan_get_pointer (ctx);
gpg_error_t err = 0;
unsigned char *sn_bin = NULL;
size_t sn_bin_len = 0;
- if ((err = open_card (ctrl)))
- return err;
-
- line = skip_options (line);
-
if (*line)
{
sn_bin = hex_to_buffer (line, &sn_bin_len);
@@ -425,6 +411,30 @@ cmd_switchcard (assuan_context_t ctx, char *line)
}
+static const char hlp_switchcard[] =
+ "SWITCHCARD [<serialno>]\n"
+ "\n"
+ "Make the card with SERIALNO the current card.\n"
+ "The command \"getinfo card_list\" can be used to list\n"
+ "the serial numbers of inserted and known cards. Note\n"
+ "that the command \"SERIALNO\" can be used to refresh\n"
+ "the list of known cards. A simple SERIALNO status\n"
+ "is printed on success.";
+static gpg_error_t
+cmd_switchcard (assuan_context_t ctx, char *line)
+{
+ ctrl_t ctrl = assuan_get_pointer (ctx);
+ gpg_error_t err;
+
+ if ((err = open_card (ctrl)))
+ return err;
+
+ line = skip_options (line);
+
+ return switchcard_core (ctrl, line);
+}
+
+
static const char hlp_switchapp[] =
"SWITCHAPP [<appname>]\n"
"\n"
@@ -458,7 +468,8 @@ cmd_switchapp (assuan_context_t ctx, char *line)
static const char hlp_learn[] =
- "LEARN [--force] [--keypairinfo] [--reread] [--multi]\n"
+ "LEARN [--force] [--keypairinfo] [--reread] [--multi] KEYGRIP\n"
+ "LEARN [--demand=<serialno>] [--force] [--keypairinfo] [--reread] [--multi]\n"
"\n"
"Learn all useful information of the currently inserted card. When\n"
"used without the force options, the command might do an INQUIRE\n"
@@ -529,6 +540,8 @@ static const char hlp_learn[] =
"\n"
"The URL to be used for locating the entire public key.\n"
" \n"
+ "If KEYGRIP is given the card holding a key with that keygrip is used.\n"
+ "If --demand is used the card with the specified S/N is used.\n"
"Note, that this function may even be used on a locked card.";
static gpg_error_t
cmd_learn (assuan_context_t ctx, char *line)
@@ -539,17 +552,37 @@ cmd_learn (assuan_context_t ctx, char *line)
int opt_multi = has_option (line, "--multi");
int opt_reread = has_option (line, "--reread");
int opt_force = has_option (line, "--force");
+ const char *opt_demand;
unsigned int flags;
card_t card;
const char *keygrip = NULL;
- if ((rc = open_card (ctrl)))
- return rc;
+ opt_demand = has_option_name (line, "--demand");
+ if (opt_demand)
+ {
+ if (*opt_demand != '=')
+ return set_error (GPG_ERR_ASS_PARAMETER, "missing value for option");
+ line = (char *)++opt_demand;
+ while (*line && !spacep (line))
+ line++;
+ if (*line)
+ *line++ = 0;
+ }
line = skip_options (line);
if (strlen (line) == 40)
keygrip = line;
+ if ((rc = open_card (ctrl)))
+ return rc;
+
+ if (opt_demand)
+ {
+ rc = switchcard_core (ctrl, opt_demand);
+ if (rc)
+ return rc;
+ }
+
card = card_get (ctrl, keygrip);
if (!card)
return gpg_error (GPG_ERR_CARD_NOT_PRESENT);