diff options
author | NIIBE Yutaka <[email protected]> | 2020-01-17 06:11:02 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2023-09-06 00:24:35 +0000 |
commit | 4817825511311951a0c1deeaab04102917cca2a1 (patch) | |
tree | 95f921f1042299b696e55cc4d8972c9c15ce587b | |
parent | gpgsm: Add --always-trust feature. (diff) | |
download | gnupg-4817825511311951a0c1deeaab04102917cca2a1.tar.gz gnupg-4817825511311951a0c1deeaab04102917cca2a1.zip |
gpg: Prepare enhancement of agent_probe_secret_key.
* g10/call-agent.c (agent_probe_secret_key): Change semantics of
return value.
* g10/call-agent.h (agent_probe_secret_key): Change comment.
* g10/delkey.c (do_delete_key): Follow the change.
* g10/getkey.c (get_seckey, parse_def_secret_key): Likewise.
(finish_lookup, have_secret_key_with_kid): Likewise.
* g10/gpgv.c (agent_probe_secret_key): Likewise.
* g10/keyedit.c (keyedit_menu, quick_find_keyblock): Likewise.
(show_key_with_all_names_colon): Likewise.
* g10/revoke.c (gen_desig_revoke, gen_revoke): Likewise
* g10/test-stubs.c (agent_probe_secret_key): Likewise.
--
Cherry picked from 2.4 branch of:
853d5b7677ea01f65c9bc5160cd8509b62f486f7
GnuPG-bug-id: 3416
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r-- | g10/call-agent.c | 8 | ||||
-rw-r--r-- | g10/call-agent.h | 4 | ||||
-rw-r--r-- | g10/delkey.c | 2 | ||||
-rw-r--r-- | g10/getkey.c | 22 | ||||
-rw-r--r-- | g10/gpgv.c | 4 | ||||
-rw-r--r-- | g10/keyedit.c | 7 | ||||
-rw-r--r-- | g10/revoke.c | 7 | ||||
-rw-r--r-- | g10/test-stubs.c | 4 |
8 files changed, 32 insertions, 26 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c index abd6eb34d..4a8a463b6 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -1783,8 +1783,8 @@ agent_get_s2k_count (unsigned long *r_count) /* Ask the agent whether a secret key for the given public key is - available. Returns 0 if available. */ -gpg_error_t + available. Returns 0 if not available. */ +int agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk) { gpg_error_t err; @@ -1803,7 +1803,9 @@ agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk) xfree (hexgrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); - return err; + if (err) + return 0; + return 1; } /* Ask the agent whether a secret key is available for any of the diff --git a/g10/call-agent.h b/g10/call-agent.h index dbc6e2fe9..3728c5ff1 100644 --- a/g10/call-agent.h +++ b/g10/call-agent.h @@ -153,8 +153,8 @@ gpg_error_t gpg_agent_get_confirmation (const char *desc); gpg_error_t agent_get_s2k_count (unsigned long *r_count); /* Check whether a secret key for public key PK is available. Returns - 0 if the secret key is available. */ -gpg_error_t agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk); + 0 if not available, positive value if the secret key is available. */ +int agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk); /* Ask the agent whether a secret key is availabale for any of the keys (primary or sub) in KEYBLOCK. Returns 0 if available. */ diff --git a/g10/delkey.c b/g10/delkey.c index 13dbcf062..83dbeb0f4 100644 --- a/g10/delkey.c +++ b/g10/delkey.c @@ -239,7 +239,7 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force, if (thiskeyonly && targetnode != node) continue; - if (agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) + if (!agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) continue; /* No secret key for that public (sub)key. */ prompt = gpg_format_keydesc (ctrl, diff --git a/g10/getkey.c b/g10/getkey.c index a72545a71..20b717b50 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -767,9 +767,11 @@ get_seckey (ctrl_t ctrl, PKT_public_key *pk, u32 *keyid) if (!err) { - err = agent_probe_secret_key (/*ctrl*/NULL, pk); - if (err) - release_public_key_parts (pk); + if (!agent_probe_secret_key (/*ctrl*/NULL, pk)) + { + release_public_key_parts (pk); + err = gpg_error (GPG_ERR_NO_SECKEY); + } } return err; @@ -2157,10 +2159,12 @@ parse_def_secret_key (ctrl_t ctrl) continue; } - err = agent_probe_secret_key (ctrl, pk); - if (! err) - /* This is a valid key. */ - break; + if (agent_probe_secret_key (ctrl, pk)) + { + /* This is a valid key. */ + err = 0; + break; + } } while ((node = find_next_kbnode (node, PKT_PUBLIC_SUBKEY))); @@ -3816,7 +3820,7 @@ 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 && !agent_probe_secret_key (NULL, pk)) { if (DBG_LOOKUP) log_debug ("\tno secret key\n"); @@ -4565,7 +4569,7 @@ have_secret_key_with_kid (u32 *keyid) log_assert (node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_PUBLIC_SUBKEY); - if (!agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) + if (agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) result = 1; /* Secret key available. */ else result = 0; diff --git a/g10/gpgv.c b/g10/gpgv.c index 4e9c35de5..df2f70047 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -706,12 +706,12 @@ dotlock_remove_lockfiles (void) { } -gpg_error_t +int agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk) { (void)ctrl; (void)pk; - return gpg_error (GPG_ERR_NO_SECKEY); + return 0; } gpg_error_t diff --git a/g10/keyedit.c b/g10/keyedit.c index f2bf6a4d6..01de7bb48 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1457,7 +1457,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, { have_anyseckey = !agent_probe_any_secret_key (ctrl, keyblock); if (have_anyseckey - && !agent_probe_secret_key (ctrl, keyblock->pkt->pkt.public_key)) + && agent_probe_secret_key (ctrl, keyblock->pkt->pkt.public_key)) { /* The primary key is also available. */ have_seckey = 1; @@ -2359,7 +2359,8 @@ quick_find_keyblock (ctrl_t ctrl, const char *username, int want_secret, /* We require the secret primary key to set the primary UID. */ node = find_kbnode (keyblock, PKT_PUBLIC_KEY); log_assert (node); - err = agent_probe_secret_key (ctrl, node->pkt->pkt.public_key); + if (!agent_probe_secret_key (ctrl, node->pkt->pkt.public_key)) + err = gpg_error (GPG_ERR_NO_SECKEY); } } else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND) @@ -3460,7 +3461,7 @@ show_key_with_all_names_colon (ctrl_t ctrl, estream_t fp, kbnode_t keyblock) } keyid_from_pk (pk, keyid); - have_seckey = !agent_probe_secret_key (ctrl, pk); + have_seckey = agent_probe_secret_key (ctrl, pk); if (node->pkt->pkttype == PKT_PUBLIC_KEY) es_fputs (have_seckey? "sec:" : "pub:", fp); diff --git a/g10/revoke.c b/g10/revoke.c index 035a2e9e6..7c01149a8 100644 --- a/g10/revoke.c +++ b/g10/revoke.c @@ -315,8 +315,7 @@ gen_desig_revoke (ctrl_t ctrl, const char *uname, strlist_t locusr) tty_printf(_("(This is a sensitive revocation key)\n")); tty_printf("\n"); - rc = agent_probe_secret_key (ctrl, pk2); - if (rc) + if (!agent_probe_secret_key (ctrl, pk2)) { tty_printf (_("Secret key is not available.\n")); continue; @@ -714,9 +713,9 @@ gen_revoke (ctrl_t ctrl, const char *uname) BUG (); psk = node->pkt->pkt.public_key; - rc = agent_probe_secret_key (NULL, psk); - if (rc) + if (!agent_probe_secret_key (NULL, psk)) { + rc = gpg_error (GPG_ERR_NO_SECKEY); log_error (_("secret key \"%s\" not found: %s\n"), uname, gpg_strerror (rc)); goto leave; diff --git a/g10/test-stubs.c b/g10/test-stubs.c index 2ae4a4183..9c4596199 100644 --- a/g10/test-stubs.c +++ b/g10/test-stubs.c @@ -463,12 +463,12 @@ dotlock_remove_lockfiles (void) { } -gpg_error_t +int agent_probe_secret_key (ctrl_t ctrl, PKT_public_key *pk) { (void)ctrl; (void)pk; - return gpg_error (GPG_ERR_NO_SECKEY); + return 0; } gpg_error_t |