aboutsummaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2008-09-03 09:37:32 +0000
committerWerner Koch <[email protected]>2008-09-03 09:37:32 +0000
commit5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3 (patch)
tree187e260d1af072d35a529fd43b765e71bab34108 /agent
parent2008-08-30 Moritz <[email protected]> (diff)
downloadgnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.tar.gz
gnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.zip
Fix gpg-preset-passphrase bug.
Cleanups
Diffstat (limited to 'agent')
-rw-r--r--agent/ChangeLog10
-rw-r--r--agent/command.c19
-rw-r--r--agent/preset-passphrase.c40
3 files changed, 27 insertions, 42 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog
index a60c85b71..0a5e6afb4 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -1,3 +1,11 @@
+2008-09-03 Werner Koch <[email protected]>
+
+ * command.c (parse_keygrip): Use hex2bin.
+ (cmd_preset_passphrase): Decode the passphrase. Reported by Kiss
+ Gabor. Fixes #679 again.
+ * preset-passphrase.c (make_hexstring): Remove.
+ (preset_passphrase): Use bin2hex.
+
2008-05-27 Werner Koch <[email protected]>
* trustlist.c (insert_colons): Fix stupidly wrong allocation size
@@ -12,7 +20,7 @@
* gpg-agent.c (main, agent_deinit_default_ctrl): Always use xfree
because our asprintf is mapped to an xmalloc style function in
- util.h. Replace xtrdup by xtrystrdup.
+ util.h. Replace xstrdup by xtrystrdup.
* w32main.c (build_argv): Ditto.
* preset-passphrase.c (preset_passphrase): Ditto.
* divert-scd.c (ask_for_card): Ditto.
diff --git a/agent/command.c b/agent/command.c
index 92e12e22c..c7853a92c 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -271,7 +271,6 @@ parse_keygrip (assuan_context_t ctx, const char *string, unsigned char *buf)
{
int rc;
size_t n;
- const unsigned char *p;
rc = parse_hexstring (ctx, string, &n);
if (rc)
@@ -280,8 +279,8 @@ parse_keygrip (assuan_context_t ctx, const char *string, unsigned char *buf)
if (n != 20)
return set_error (GPG_ERR_ASS_PARAMETER, "invalid length of keygrip");
- for (p=(const unsigned char*)string, n=0; n < 20; p += 2, n++)
- buf[n] = xtoi_2 (p);
+ if (hex2bin (string, buf, 20) < 0)
+ return set_error (GPG_ERR_BUG, "hex2bin");
return 0;
}
@@ -1100,7 +1099,7 @@ cmd_preset_passphrase (assuan_context_t ctx, char *line)
size_t len;
if (!opt.allow_preset_passphrase)
- return gpg_error (GPG_ERR_NOT_SUPPORTED);
+ return set_error (GPG_ERR_NOT_SUPPORTED, "no --allow-preset-passphrase");
rc = parse_keygrip (ctx, line, grip);
if (rc)
@@ -1135,11 +1134,17 @@ cmd_preset_passphrase (assuan_context_t ctx, char *line)
/* If there is a passphrase, use it. Currently, a passphrase is
required. */
if (*line)
- passphrase = line;
+ {
+ /* Do in-place conversion. */
+ passphrase = line;
+ if (!hex2str (passphrase, passphrase, strlen (passphrase)+1, NULL))
+ rc = set_error (GPG_ERR_ASS_PARAMETER, "invalid hexstring");
+ }
else
- return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+ rc = set_error (GPG_ERR_NOT_IMPLEMENTED, "passphrase is required");
- rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl);
+ if (!rc)
+ rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl);
if (rc)
log_error ("command preset_passwd failed: %s\n", gpg_strerror (rc));
diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c
index 42c7d6c95..cb906ad89 100644
--- a/agent/preset-passphrase.c
+++ b/agent/preset-passphrase.c
@@ -113,37 +113,6 @@ my_strusage (int level)
/* Include the implementation of map_spwq_error. */
MAP_SPWQ_ERROR_IMPL
-/* Convert the string SRC into HEX encoding. Caller needs to xfree
- the returned string. */
-static char *
-make_hexstring (const char *src)
-{
- int len = 2 * strlen (src) + 1;
- char *dst;
- char *res;
-
- res = dst = xtrymalloc (len);
- if (!dst)
- {
- log_error ("can not escape string: %s\n",
- gpg_strerror (gpg_error_from_syserror ()));
- return NULL;
- }
-
-#define _tohex(nr) ((nr) < 10 ? ((nr) + '0') : (((nr) - 10) + 'A'))
-#define tohex1(p) _tohex (*((unsigned char *) p) & 15)
-#define tohex2(p) _tohex ((*((unsigned char *) p) >> 4) & 15)
-
- while (*src)
- {
- *(dst++) = tohex2 (src);
- *(dst++) = tohex1 (src);
- src++;
- }
- *dst = '\0';
- return res;
-}
-
static void
preset_passphrase (const char *keygrip)
@@ -175,11 +144,14 @@ preset_passphrase (const char *keygrip)
/* FIXME: How to handle empty passwords? */
}
- passphrase_esc = make_hexstring (opt_passphrase
- ? opt_passphrase : passphrase);
+ {
+ const char *s = opt_passphrase ? opt_passphrase : passphrase;
+ passphrase_esc = bin2hex (s, strlen (s), NULL);
+ }
if (!passphrase_esc)
{
- /* Error message printed by callee. */
+ log_error ("can not escape string: %s\n",
+ gpg_strerror (gpg_error_from_syserror ()));
return;
}