From 8748c50bfaa8df2b1e59c301d15fd6b9ddbd9c47 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 17 Jan 2020 16:03:53 +0900 Subject: gpg: Prefer card key on use in multiple subkeys situation. * g10/call-agent.c (keyinfo_status_cb): Parse more fields. (agent_probe_secret_key): Use KEYINFO and returns bigger value representing the preference. * g10/getkey.c (finish_lookup): For subkeys, select one by using value of agent_probe_secret_key. -- GnuPG-bug-id: 3416 Signed-off-by: NIIBE Yutaka --- g10/getkey.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'g10/getkey.c') diff --git a/g10/getkey.c b/g10/getkey.c index 2e1c79a1a..abd44d983 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -3470,6 +3470,7 @@ finish_lookup (kbnode_t keyblock, unsigned int req_usage, int want_exact, kbnode_t nextk; int n_subkeys = 0; int n_revoked_or_expired = 0; + int last_secret_key_avail = 0; /* Either start a loop or check just this one subkey. */ for (k = foundk ? foundk : keyblock; k; k = nextk) @@ -3527,11 +3528,23 @@ finish_lookup (kbnode_t keyblock, unsigned int req_usage, int want_exact, continue; } - if (want_secret && !agent_probe_secret_key (NULL, pk)) + if (want_secret) { - if (DBG_LOOKUP) - log_debug ("\tno secret key\n"); - continue; + int secret_key_avail = agent_probe_secret_key (NULL, pk); + + if (!secret_key_avail) + { + if (DBG_LOOKUP) + log_debug ("\tno secret key\n"); + continue; + } + + if (secret_key_avail > last_secret_key_avail) + { + /* Use this key. */ + last_secret_key_avail = secret_key_avail; + latest_date = 0; + } } if (DBG_LOOKUP) -- cgit v1.2.3