summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2020-01-17 07:11:02 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2020-01-17 08:09:01 +0100
commit853d5b7677ea01f65c9bc5160cd8509b62f486f7 (patch)
tree848bb0adc423a9abbd67d716a641eb6b7849815f
parentcard: Allow switching of cards and applications. (diff)
downloadgnupg2-853d5b7677ea01f65c9bc5160cd8509b62f486f7.tar.xz
gnupg2-853d5b7677ea01f65c9bc5160cd8509b62f486f7.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. -- GnuPG-bug-id: 3416 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--g10/call-agent.c8
-rw-r--r--g10/call-agent.h4
-rw-r--r--g10/delkey.c2
-rw-r--r--g10/getkey.c22
-rw-r--r--g10/gpgv.c4
-rw-r--r--g10/keyedit.c7
-rw-r--r--g10/revoke.c7
-rw-r--r--g10/test-stubs.c4
8 files changed, 32 insertions, 26 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c
index c71d50a56..f4ee3cdae 100644
--- a/g10/call-agent.c
+++ b/g10/call-agent.c
@@ -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
diff --git a/g10/call-agent.h b/g10/call-agent.h
index 0d333fd40..9d865b90f 100644
--- a/g10/call-agent.h
+++ b/g10/call-agent.h
@@ -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. */
diff --git a/g10/delkey.c b/g10/delkey.c
index 167a7bcaf..b89451089 100644
--- a/g10/delkey.c
+++ b/g10/delkey.c
@@ -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,
diff --git a/g10/getkey.c b/g10/getkey.c
index 3f1bd7e70..2e1c79a1a 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -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;
diff --git a/g10/gpgv.c b/g10/gpgv.c
index b33590655..88b348125 100644
--- a/g10/gpgv.c
+++ b/g10/gpgv.c
@@ -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
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 2ac52d315..1391b6b7a 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -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);
diff --git a/g10/revoke.c b/g10/revoke.c
index 0e39eca61..5262c17bf 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;
@@ -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;
diff --git a/g10/test-stubs.c b/g10/test-stubs.c
index a2b0d2906..d5b6d4f02 100644
--- a/g10/test-stubs.c
+++ b/g10/test-stubs.c
@@ -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