mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
agent: Prepend the description to a PIN prompt.
* agent/divert-scd.c (has_percent0A_suffix): New. (getpin_cb): Prepend DESC_TEXT to the prompt. * agent/findkey.c (modify_description): Rename to ... (agent_modify_description): this. MAke global. Add kludge to remove empty parentheses from the end. (agent_key_from_file, agent_delete_key): Adjust for above change. * agent/pksign.c (agent_pksign_do): Modify DESC_TEXT also when diverting to a card. -- Now that we have support for multiple tokens, it is important to show information on which key has been requested. Without that it may happen that the PIN for a wrong card is accidentally entered. The texts are a bit ugly, because they talk about "passphrase" but later about entering a PIN. A quick hack would be to s/passphrase/PIN/ in the description but that is complicated due to i18n. Another solution might be never to talk about PINs in the description but always about "passphrase: and only use "PIN" or "passphrase" on the left of the entry field.
This commit is contained in:
parent
78d875a0f8
commit
6488ffb767
4 changed files with 96 additions and 19 deletions
|
@ -157,6 +157,18 @@ encode_md_for_card (const unsigned char *digest, size_t digestlen, int algo,
|
|||
}
|
||||
|
||||
|
||||
/* Return true if STRING ends in "%0A". */
|
||||
static int
|
||||
has_percent0A_suffix (const char *string)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
return (string
|
||||
&& (n = strlen (string)) >= 3
|
||||
&& !strcmp (string + n - 3, "%0A"));
|
||||
}
|
||||
|
||||
|
||||
/* Callback used to ask for the PIN which should be set into BUF. The
|
||||
buf has been allocated by the caller and is of size MAXBUF which
|
||||
includes the terminating null. The function should return an UTF-8
|
||||
|
@ -246,7 +258,7 @@ getpin_cb (void *opaque, const char *desc_text, const char *info,
|
|||
{
|
||||
if (info)
|
||||
{
|
||||
char *desc;
|
||||
char *desc, *desc2;
|
||||
|
||||
if ( asprintf (&desc,
|
||||
L_("%s%%0A%%0AUse the reader's pinpad for input."),
|
||||
|
@ -254,12 +266,22 @@ getpin_cb (void *opaque, const char *desc_text, const char *info,
|
|||
rc = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
rc = agent_popup_message_start (ctrl, desc, NULL);
|
||||
/* Prepend DESC_TEXT to INFO. */
|
||||
if (desc_text)
|
||||
desc2 = strconcat (desc_text,
|
||||
has_percent0A_suffix (desc_text)
|
||||
? "%0A" : "%0A%0A",
|
||||
desc, NULL);
|
||||
else
|
||||
desc2 = NULL;
|
||||
rc = agent_popup_message_start (ctrl,
|
||||
desc2? desc2:desc, NULL);
|
||||
xfree (desc2);
|
||||
xfree (desc);
|
||||
}
|
||||
}
|
||||
else
|
||||
rc = agent_popup_message_start (ctrl, NULL, NULL);
|
||||
rc = agent_popup_message_start (ctrl, desc_text, NULL);
|
||||
}
|
||||
else
|
||||
rc = gpg_error (GPG_ERR_INV_VALUE);
|
||||
|
@ -280,7 +302,19 @@ getpin_cb (void *opaque, const char *desc_text, const char *info,
|
|||
|
||||
if (any_flags)
|
||||
{
|
||||
rc = agent_askpin (ctrl, info, prompt, again_text, pi, NULL, 0);
|
||||
{
|
||||
char *desc2;
|
||||
|
||||
if (desc_text)
|
||||
desc2 = strconcat (desc_text,
|
||||
has_percent0A_suffix (desc_text)
|
||||
? "%0A" : "%0A%0A",
|
||||
info, NULL);
|
||||
else
|
||||
desc2 = NULL;
|
||||
rc = agent_askpin (ctrl, desc2, prompt, again_text, pi, NULL, 0);
|
||||
xfree (desc2);
|
||||
}
|
||||
again_text = NULL;
|
||||
if (!rc && newpin)
|
||||
{
|
||||
|
@ -319,14 +353,24 @@ getpin_cb (void *opaque, const char *desc_text, const char *info,
|
|||
}
|
||||
else
|
||||
{
|
||||
char *desc;
|
||||
char *desc, *desc2;
|
||||
|
||||
if ( asprintf (&desc,
|
||||
L_("Please enter the PIN%s%s%s to unlock the card"),
|
||||
info? " (":"",
|
||||
info? info:"",
|
||||
info? ")":"") < 0)
|
||||
desc = NULL;
|
||||
rc = agent_askpin (ctrl, desc?desc:info, prompt, NULL, pi, NULL, 0);
|
||||
if (desc_text)
|
||||
desc2 = strconcat (desc_text,
|
||||
has_percent0A_suffix (desc_text)
|
||||
? "%0A" : "%0A%0A",
|
||||
desc, NULL);
|
||||
else
|
||||
desc2 = NULL;
|
||||
rc = agent_askpin (ctrl, desc2? desc2 : desc? desc : info,
|
||||
prompt, NULL, pi, NULL, 0);
|
||||
xfree (desc2);
|
||||
xfree (desc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue