From 255d33d65126df00bc036580d0b32735d7178c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 7 Dec 2020 15:10:25 +0100 Subject: [PATCH] gpg: Make quick-gen-key with algo "card" work for keys without keytime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * g10/keygen.c (quick_generate_keypair): Set pCARDKEY flag if algostr is "card" or "card/...". -- For keys stored on NetKey cards or PIV cards we do not necessarily know the creation time. Therefore set the cardkey flag if the generation of a key from the keys available on the currently inserted smartcard is requested with the special algo "card" or, in case of the extended unattended mode, with an algo like "card/sign". GnuPG-bug-id: 5141 Signed-off-by: Ingo Klöcker --- g10/keygen.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/g10/keygen.c b/g10/keygen.c index b510525e3..01eec57ac 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -4548,7 +4548,6 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr, struct para_data_s *r; struct output_control_s outctrl; int use_tty; - u32 keytime = 0; memset (&outctrl, 0, sizeof outctrl); @@ -4631,7 +4630,7 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr, unsigned int keyuse, subkeyuse; const char *curve, *subcurve; char *keygrip, *subkeygrip; - u32 subkeytime; + u32 keytime, subkeytime; err = parse_key_parameter_string (ctrl, algostr, -1, 0, &algo, &size, &keyuse, &curve, &version, @@ -4681,6 +4680,7 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr, unsigned int nbits; const char *curve; char *keygrip; + u32 keytime; err = parse_algo_usage_expire (ctrl, 0, algostr, usagestr, expirestr, &algo, &use, &expire, &nbits, &curve, @@ -4717,10 +4717,8 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr, para = r; } - - /* If KEYTIME is set we know that the key has been taken from the - * card. Store that flag in the parameters. */ - if (keytime) + if (!ascii_strcasecmp (algostr, "card") + || !ascii_strncasecmp (algostr, "card/", 5)) { r = xmalloc_clear (sizeof *r); r->key = pCARDKEY;