* command.c (cmd_passwd): Take acount of a key description.

* genkey.c (reenter_compare_cb): Do not set the error text.
(agent_protect_and_store, agent_genkey): Force a re-enter after a
non-matching passphrase.
* query.c (agent_askpin): Add new arg INITIAL_ERRTEXT; changed
all callers.
This commit is contained in:
Werner Koch 2004-02-21 13:05:22 +00:00
parent ffd5cd0368
commit a425334f48
7 changed files with 59 additions and 12 deletions

View File

@ -1,3 +1,13 @@
2004-02-21 Werner Koch <wk@gnupg.org>
* command.c (cmd_passwd): Take acount of a key description.
* genkey.c (reenter_compare_cb): Do not set the error text.
(agent_protect_and_store, agent_genkey): Force a re-enter after a
non-matching passphrase.
* query.c (agent_askpin): Add new arg INITIAL_ERRTEXT; changed
all callers.
2004-02-19 Werner Koch <wk@gnupg.org>
* protect-tool.c: New options --have-cert and --prompt.

View File

@ -141,7 +141,8 @@ int agent_key_available (const unsigned char *grip);
/*-- query.c --*/
int agent_askpin (ctrl_t ctrl,
const char *desc_text, struct pin_entry_info_s *pininfo);
const char *desc_text, const char *inital_errtext,
struct pin_entry_info_s *pininfo);
int agent_get_passphrase (ctrl_t ctrl, char **retpass,
const char *desc, const char *prompt,
const char *errtext);

View File

@ -664,7 +664,8 @@ cmd_passwd (ASSUAN_CONTEXT ctx, char *line)
return rc; /* we can't jump to leave because this is already an
Assuan error code. */
rc = agent_key_from_file (ctrl, NULL, grip, &shadow_info, 1, &s_skey);
rc = agent_key_from_file (ctrl, ctrl->server_local->keydesc,
grip, &shadow_info, 1, &s_skey);
if (rc)
;
else if (!s_skey)
@ -675,6 +676,8 @@ cmd_passwd (ASSUAN_CONTEXT ctx, char *line)
else
rc = agent_protect_and_store (ctrl, s_skey);
xfree (ctrl->server_local->keydesc);
ctrl->server_local->keydesc = NULL;
gcry_sexp_release (s_skey);
xfree (shadow_info);
if (rc)

View File

@ -202,7 +202,7 @@ getpin_cb (void *opaque, const char *info, char *buf, size_t maxbuf)
info? info:"",
info? "')":"") < 0)
desc = NULL;
rc = agent_askpin (ctrl, desc?desc:info, pi);
rc = agent_askpin (ctrl, desc?desc:info, NULL, pi);
free (desc);
if (!rc)
{

View File

@ -185,7 +185,7 @@ unprotect (CTRL ctrl, const char *desc_text,
arg.unprotected_key = NULL;
pi->check_cb_arg = &arg;
rc = agent_askpin (ctrl, desc_text, pi);
rc = agent_askpin (ctrl, desc_text, NULL, pi);
if (!rc)
{
assert (arg.unprotected_key);

View File

@ -1,5 +1,5 @@
/* pksign.c - Generate a keypair
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -79,7 +79,6 @@ reenter_compare_cb (struct pin_entry_info_s *pi)
if (!strcmp (pin1, pi->pin))
return 0; /* okay */
pi->cb_errtext = _("does not match - try again");
return -1;
}
@ -109,6 +108,7 @@ agent_genkey (CTRL ctrl, const char *keyparam, size_t keyparamlen,
const char *text1 = _("Please enter the passphrase to%0A"
"to protect your new key");
const char *text2 = _("Please re-enter this passphrase");
const char *initial_errtext = NULL;
pi = gcry_calloc_secure (2, sizeof (*pi) + 100);
pi2 = pi + (sizeof *pi + 100);
@ -119,9 +119,19 @@ agent_genkey (CTRL ctrl, const char *keyparam, size_t keyparamlen,
pi2->check_cb = reenter_compare_cb;
pi2->check_cb_arg = pi->pin;
rc = agent_askpin (ctrl, text1, pi);
next_try:
rc = agent_askpin (ctrl, text1, initial_errtext, pi);
initial_errtext = NULL;
if (!rc)
rc = agent_askpin (ctrl, text2, pi2);
{
rc = agent_askpin (ctrl, text2, NULL, pi2);
if (rc == -1)
{ /* The re-entered one did not match and the user did not
hit cancel. */
initial_errtext = _("does not match - try again");
goto next_try;
}
}
if (rc)
return rc;
if (!*pi->pin)
@ -212,6 +222,7 @@ agent_protect_and_store (CTRL ctrl, gcry_sexp_t s_skey)
{
const char *text1 = _("Please enter the new passphrase");
const char *text2 = _("Please re-enter this passphrase");
const char *initial_errtext = NULL;
pi = gcry_calloc_secure (2, sizeof (*pi) + 100);
pi2 = pi + (sizeof *pi + 100);
@ -222,9 +233,18 @@ agent_protect_and_store (CTRL ctrl, gcry_sexp_t s_skey)
pi2->check_cb = reenter_compare_cb;
pi2->check_cb_arg = pi->pin;
rc = agent_askpin (ctrl, text1, pi);
next_try:
rc = agent_askpin (ctrl, text1, initial_errtext, pi);
if (!rc)
rc = agent_askpin (ctrl, text2, pi2);
{
rc = agent_askpin (ctrl, text2, NULL, pi2);
if (rc == -1)
{ /* The re-entered one did not match and the user did not
hit cancel. */
initial_errtext = _("does not match - try again");
goto next_try;
}
}
if (rc)
return rc;
if (!*pi->pin)

View File

@ -250,7 +250,8 @@ all_digitsp( const char *s)
numbers. */
int
agent_askpin (CTRL ctrl,
const char *desc_text, struct pin_entry_info_s *pininfo)
const char *desc_text, const char *initial_errtext,
struct pin_entry_info_s *pininfo)
{
int rc;
char line[ASSUAN_LINELENGTH];
@ -289,6 +290,17 @@ agent_askpin (CTRL ctrl,
if (rc)
return unlock_pinentry (map_assuan_err (rc));
if (initial_errtext)
{
snprintf (line, DIM(line)-1, "SETERROR %s", initial_errtext);
line[DIM(line)-1] = 0;
rc = assuan_transact (entry_ctx, line,
NULL, NULL, NULL, NULL, NULL, NULL);
if (rc)
return unlock_pinentry (map_assuan_err (rc));
}
for (;pininfo->failed_tries < pininfo->max_tries; pininfo->failed_tries++)
{
memset (&parm, 0, sizeof parm);
@ -301,7 +313,8 @@ agent_askpin (CTRL ctrl,
snprintf (line, DIM(line)-1, "SETERROR %s (try %d of %d)",
errtext, pininfo->failed_tries+1, pininfo->max_tries);
line[DIM(line)-1] = 0;
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
rc = assuan_transact (entry_ctx, line,
NULL, NULL, NULL, NULL, NULL, NULL);
if (rc)
return unlock_pinentry (map_assuan_err (rc));
errtext = NULL;