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.

--

GnuPG-bug-id: 3416
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2020-01-17 15:11:02 +09:00
parent bd85f9232a
commit 853d5b7677
8 changed files with 32 additions and 26 deletions

View File

@ -1928,8 +1928,8 @@ agent_get_s2k_count (void)
/* 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;
@ -1948,7 +1948,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

View File

@ -164,8 +164,8 @@ gpg_error_t gpg_agent_get_confirmation (const char *desc);
unsigned long agent_get_s2k_count (void);
/* 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. */

View File

@ -232,7 +232,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,

View File

@ -610,9 +610,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;
@ -1882,10 +1884,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)));
@ -3523,7 +3527,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");
@ -4219,7 +4223,7 @@ have_secret_key_with_kid (ctrl_t ctrl, 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;

View File

@ -663,12 +663,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

View File

@ -1454,7 +1454,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;
@ -2324,7 +2324,8 @@ quick_find_keyblock (ctrl_t ctrl, const char *username,
/* 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)
@ -3229,7 +3230,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);

View File

@ -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;
@ -713,9 +712,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;

View File

@ -426,12 +426,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