1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Fix gpg-preset-passphrase bug.

Cleanups
This commit is contained in:
Werner Koch 2008-09-03 09:37:32 +00:00
parent 72110961f1
commit 5a8bf0bec6
44 changed files with 5963 additions and 5922 deletions

View file

@ -1,3 +1,11 @@
2008-09-03 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* 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.

View file

@ -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));

View file

@ -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;
}