summaryrefslogtreecommitdiffstats
path: root/g10/call-agent.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-01-26 23:10:38 +0100
committerWerner Koch <wk@gnupg.org>2019-01-26 23:10:38 +0100
commitec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1 (patch)
tree33ad3af6094e2a64625772e0f60104e48e8b917e /g10/call-agent.c
parentscd: Improve app selection for app "undefined". (diff)
downloadgnupg2-ec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1.tar.xz
gnupg2-ec13b1c562e34c0fcbc7b848ab6dc187b79cf2c1.zip
gpg: Move S2K encoding function to a shared file.
* g10/passphrase.c (encode_s2k_iterations): Move function to ... * common/openpgp-s2k.c: new file. Remove default intialization code. * common/openpgpdefs.h (S2K_DECODE_COUNT): New to keep only one copy. * g10/call-agent.c (agent_get_s2k_count): Change to return the count and print an error. * agent/protect.c: Include openpgpdefs.h * g10/card-util.c (gen_kdf_data): Adjust for changes * g10/gpgcompose.c: Include call-agent.h. (sk_esk): Adjust for changes. * g10/passphrase (passphrase_to_dek): Adjust for changes. * g10/main.h (S2K_DECODE_COUNT): Remove macro. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10/call-agent.c')
-rw-r--r--g10/call-agent.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c
index c958b84b7..91af2be39 100644
--- a/g10/call-agent.c
+++ b/g10/call-agent.c
@@ -1461,19 +1461,19 @@ gpg_agent_get_confirmation (const char *desc)
}
-/* Return the S2K iteration count as computed by gpg-agent. */
-gpg_error_t
-agent_get_s2k_count (unsigned long *r_count)
+/* Return the S2K iteration count as computed by gpg-agent. On error
+ * print a warning and return a default value. */
+unsigned long
+agent_get_s2k_count (void)
{
gpg_error_t err;
membuf_t data;
char *buf;
-
- *r_count = 0;
+ unsigned long count = 0;
err = start_agent (NULL, 0);
if (err)
- return err;
+ goto leave;
init_membuf (&data, 32);
err = assuan_transact (agent_ctx, "GETINFO s2k_count",
@@ -1489,10 +1489,22 @@ agent_get_s2k_count (unsigned long *r_count)
err = gpg_error_from_syserror ();
else
{
- *r_count = strtoul (buf, NULL, 10);
+ count = strtoul (buf, NULL, 10);
xfree (buf);
}
}
+
+ leave:
+ if (err || count < 65536)
+ {
+ /* Don't print an error if an older agent is used. */
+ if (err && gpg_err_code (err) != GPG_ERR_ASS_PARAMETER)
+ log_error (_("problem with the agent: %s\n"), gpg_strerror (err));
+
+ /* Default to 65536 which was used up to 2.0.13. */
+ return 65536;
+ }
+
return err;
}