mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-02 21:11:05 +01:00
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 <gniibe@fsij.org>
This commit is contained in:
parent
cdd6747e1e
commit
4817825511
@ -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
|
||||
|
@ -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. */
|
||||
|
@ -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,
|
||||
|
22
g10/getkey.c
22
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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user