diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c index 8610da8b6..83e9ba099 100644 --- a/tools/card-call-scd.c +++ b/tools/card-call-scd.c @@ -890,28 +890,59 @@ learn_status_cb (void *opaque, const char *line) else if (!memcmp (keyword, "KEYPAIRINFO", keywordlen)) { /* The format of such a line is: - * KEYPARINFO + * KEYPAIRINFO [usage] */ - const char *hexgrp = line; + char *hexgrp, *usage; - while (*line && !spacep (line)) - line++; - while (spacep (line)) - line++; + line_buffer = pline = xstrdup (line); - keyref = line; + hexgrp = pline; + while (*pline && !spacep (pline)) + pline++; + while (spacep (pline)) + pline++; + + keyref = pline; + while (*pline && !spacep (pline)) + pline++; + if (*pline) + { + *pline++ = 0; + while (spacep (pline)) + pline++; + usage = pline; + while (*pline && !spacep (pline)) + pline++; + *pline = 0; + } + else + usage = ""; /* Check whether we already have an item for the keyref. */ kinfo = find_kinfo (parm, keyref); if (!kinfo) /* New entry. */ kinfo = create_kinfo (parm, keyref); - else /* Existing entry - clear the grip. */ - memset (kinfo->grip, 0, sizeof kinfo->grip); + else /* Existing entry - clear grip and usage */ + { + memset (kinfo->grip, 0, sizeof kinfo->grip); + kinfo->usage = 0; + } /* Set or update the grip. Note that due to the * calloc/memset an erroneous too short grip will be nul * padded on the right. */ unhexify_fpr (hexgrp, kinfo->grip, sizeof kinfo->grip); + /* Parse and set the usage. */ + for (; *usage; usage++) + { + switch (*usage) + { + case 's': kinfo->usage |= GCRY_PK_USAGE_SIGN; break; + case 'c': kinfo->usage |= GCRY_PK_USAGE_CERT; break; + case 'a': kinfo->usage |= GCRY_PK_USAGE_AUTH; break; + case 'e': kinfo->usage |= GCRY_PK_USAGE_ENCR; break; + } + } } break; diff --git a/tools/card-tool.h b/tools/card-tool.h index f83ebf983..5598ae5fd 100644 --- a/tools/card-tool.h +++ b/tools/card-tool.h @@ -127,7 +127,7 @@ struct key_info_s unsigned char fprlen; /* Use length of the next item. */ unsigned char fpr[32]; /* The binary fingerprint of length FPRLEN. */ u32 created; /* The time the key was created. */ - + unsigned int usage; /* Usage flags. (GCRY_PK_USAGE_*) */ char keyref[1]; /* String with the keyref (e.g. OPENPGP.1). */ }; typedef struct key_info_s *key_info_t; diff --git a/tools/gpg-card-tool.c b/tools/gpg-card-tool.c index a13a6bdaf..eb723d7ab 100644 --- a/tools/gpg-card-tool.c +++ b/tools/gpg-card-tool.c @@ -621,6 +621,7 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, estream_t fp) key_info_t ki; const char *s; gcry_sexp_t s_pkey; + int any; if (firstkinfo && kinfo) { @@ -630,8 +631,25 @@ list_one_kinfo (key_info_t firstkinfo, key_info_t kinfo, estream_t fp) tty_fprintf (fp, "[none]\n"); goto leave; } + print_keygrip (fp, kinfo->grip); - tty_fprintf (fp, " keyref .....: %s\n", kinfo->keyref); + tty_fprintf (fp, " keyref .....: %s", kinfo->keyref); + if (kinfo->usage) + { + any = 0; + tty_fprintf (fp, " ("); + if ((kinfo->usage & GCRY_PK_USAGE_SIGN)) + { tty_fprintf (fp, "sign"); any=1; } + if ((kinfo->usage & GCRY_PK_USAGE_CERT)) + { tty_fprintf (fp, "%scert", any?",":""); any=1; } + if ((kinfo->usage & GCRY_PK_USAGE_AUTH)) + { tty_fprintf (fp, "%sauth", any?",":""); any=1; } + if ((kinfo->usage & GCRY_PK_USAGE_ENCR)) + { tty_fprintf (fp, "%sencr", any?",":""); any=1; } + tty_fprintf (fp, ")"); + } + tty_fprintf (fp, "\n"); + if (!scd_readkey (kinfo->keyref, &s_pkey)) { char *tmp = pubkey_algo_string (s_pkey);