diff options
author | NIIBE Yutaka <[email protected]> | 2020-01-17 07:03:53 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2020-01-17 07:09:01 +0000 |
commit | 8748c50bfaa8df2b1e59c301d15fd6b9ddbd9c47 (patch) | |
tree | 49b162b00b8386b66d370005029e94494b661c12 /g10/getkey.c | |
parent | gpg: Prepare enhancement of agent_probe_secret_key. (diff) | |
download | gnupg-8748c50bfaa8df2b1e59c301d15fd6b9ddbd9c47.tar.gz gnupg-8748c50bfaa8df2b1e59c301d15fd6b9ddbd9c47.zip |
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 <[email protected]>
Diffstat (limited to 'g10/getkey.c')
-rw-r--r-- | g10/getkey.c | 21 |
1 files changed, 17 insertions, 4 deletions
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) |