From a8aacaf2042a72760e6eaf35e65bfd6d42e642f0 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 1 Apr 2019 19:58:33 +0200 Subject: [PATCH] sm: Show the usage flags when generating a key from a card. * g10/call-agent.c (scd_keypairinfo_status_cb): Also store the usage flags. * sm/call-agent.c (scd_keypairinfo_status_cb): Ditto. * sm/certreqgen-ui.c (gpgsm_gencertreq_tty): Print the usage flags. Signed-off-by: Werner Koch (cherry picked from commit 9ed1aa56c4bbf44e00b731d6807ada9e95c91bd7) --- g10/call-agent.c | 20 ++++++++++++++++++-- sm/call-agent.c | 25 ++++++++++++++++++++----- sm/certreqgen-ui.c | 24 +++++++++++++++++++++++- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/g10/call-agent.c b/g10/call-agent.c index 49adc6c4d..574f6cada 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -794,7 +794,22 @@ scd_keypairinfo_status_cb (void *opaque, const char *line) p++; while (*p && !spacep (p)) p++; - *p = 0; + if (*p) + { + *p++ = 0; + while (spacep (p)) + p++; + while (*p && !spacep (p)) + { + switch (*p++) + { + case 'c': sl->flags |= GCRY_PK_USAGE_CERT; break; + case 's': sl->flags |= GCRY_PK_USAGE_SIGN; break; + case 'e': sl->flags |= GCRY_PK_USAGE_ENCR; break; + case 'a': sl->flags |= GCRY_PK_USAGE_AUTH; break; + } + } + } } } @@ -804,7 +819,8 @@ scd_keypairinfo_status_cb (void *opaque, const char *line) /* Read the keypairinfo lines of the current card directly from * scdaemon. The list is returned as a string made up of the keygrip, - * a space and the keyref. */ + * a space and the keyref. The flags of the string carry the usage + * bits. */ gpg_error_t agent_scd_keypairinfo (ctrl_t ctrl, strlist_t *r_list) { diff --git a/sm/call-agent.c b/sm/call-agent.c index d93f1e332..281e47902 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -760,9 +760,9 @@ scd_keypairinfo_status_cb (void *opaque, const char *line) { sl = append_to_strlist (listaddr, line); p = sl->d; - /* Make sure that we only have two tokes so that future - extensions of the format won't change the format expected by - the caller. */ + /* Make sure that we only have two tokens so that future + * extensions of the format won't change the format expected by + * the caller. */ while (*p && !spacep (p)) p++; if (*p) @@ -771,7 +771,22 @@ scd_keypairinfo_status_cb (void *opaque, const char *line) p++; while (*p && !spacep (p)) p++; - *p = 0; + if (*p) + { + *p++ = 0; + while (spacep (p)) + p++; + while (*p && !spacep (p)) + { + switch (*p++) + { + case 'c': sl->flags |= GCRY_PK_USAGE_CERT; break; + case 's': sl->flags |= GCRY_PK_USAGE_SIGN; break; + case 'e': sl->flags |= GCRY_PK_USAGE_ENCR; break; + case 'a': sl->flags |= GCRY_PK_USAGE_AUTH; break; + } + } + } } } @@ -781,7 +796,7 @@ scd_keypairinfo_status_cb (void *opaque, const char *line) /* Call the agent to read the keypairinfo lines of the current card. The list is returned as a string made up of the keygrip, a space - and the keyid. */ + and the keyid. The flags of the string carry the usage bits. */ int gpgsm_agent_scd_keypairinfo (ctrl_t ctrl, strlist_t *r_list) { diff --git a/sm/certreqgen-ui.c b/sm/certreqgen-ui.c index 11cf9b469..d75b017c7 100644 --- a/sm/certreqgen-ui.c +++ b/sm/certreqgen-ui.c @@ -249,6 +249,7 @@ gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t output_stream) gcry_sexp_t s_pkey; char *algostr = NULL; const char *keyref; + int any = 0; keyref = strchr (sl->d, ' '); if (keyref) @@ -262,7 +263,28 @@ gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t output_stream) } xfree (pkey); } - tty_printf (" (%d) %s %s\n", count, sl->d, algostr); + tty_printf (" (%d) %s %s", count, sl->d, algostr); + if ((sl->flags & GCRY_PK_USAGE_CERT)) + { + tty_printf ("%scert", any?",":" ("); + any = 1; + } + if ((sl->flags & GCRY_PK_USAGE_SIGN)) + { + tty_printf ("%ssign", any?",":" ("); + any = 1; + } + if ((sl->flags & GCRY_PK_USAGE_AUTH)) + { + tty_printf ("%sauth", any?",":" ("); + any = 1; + } + if ((sl->flags & GCRY_PK_USAGE_ENCR)) + { + tty_printf ("%sencr", any?",":" ("); + any = 1; + } + tty_printf ("%s\n", any?")":""); xfree (algostr); } xfree (answer);