diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2020-02-19 03:02:55 +0100 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2020-02-19 03:05:25 +0100 |
commit | 41913d76f7db4a7dabab26c1bc439c96ad86712f (patch) | |
tree | 3ca4b2a322ee4f5f4cbb2afc3b0a5a808318f940 /g10/getkey.c | |
parent | Spelling cleanup. (diff) | |
download | gnupg2-41913d76f7db4a7dabab26c1bc439c96ad86712f.tar.xz gnupg2-41913d76f7db4a7dabab26c1bc439c96ad86712f.zip |
gpg: Fix default-key selection when card is available.
* g10/getkey.c (get_seckey_default_or_card): Handle the case
when card key is not suitable for requested usage.
--
Cherry-pick stable commit of:
1cdd9e57f701f0d99d118d32adffe5216a94b0b2
GnuPG-bug-id: 4850
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to '')
-rw-r--r-- | g10/getkey.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/g10/getkey.c b/g10/getkey.c index bc49782d3..0349a3858 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -3801,7 +3801,15 @@ get_seckey_default_or_card (ctrl_t ctrl, PKT_public_key *pk, if (def_secret_key) add_to_strlist (&namelist, def_secret_key); else if (fpr_card) - return get_pubkey_byfprint (ctrl, pk, NULL, fpr_card, fpr_len); + { + int rc = get_pubkey_byfprint (ctrl, pk, NULL, fpr_card, fpr_len); + + /* The key on card can be not suitable for requested usage. */ + if (rc == GPG_ERR_UNUSABLE_PUBKEY) + fpr_card = NULL; /* Fallthrough as no card. */ + else + return rc; + } if (!fpr_card || (def_secret_key && def_secret_key[strlen (def_secret_key)-1] == '!')) |