aboutsummaryrefslogtreecommitdiffstats
path: root/agent/divert-scd.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-02-22 12:03:52 +0000
committerWerner Koch <[email protected]>2017-02-22 14:48:33 +0000
commite3944f34e3220f96fb1be449eb6f3d7360bc2d0b (patch)
treef7614197895a39fb69e9279c2f89e6911b0affd9 /agent/divert-scd.c
parentagent: Prepend the description to a PIN prompt. (diff)
downloadgnupg-e3944f34e3220f96fb1be449eb6f3d7360bc2d0b.tar.gz
gnupg-e3944f34e3220f96fb1be449eb6f3d7360bc2d0b.zip
scd: Improve the prompts for OpenPGP cards.
* scd/app-openpgp.c (get_disp_name): New. (get_disp_serialno): New. (get_prompt_info): New. (build_enter_admin_pin_prompt): Rework the prompt texts. Factor some code out to ... (get_remaining_tries): New. (verify_a_chv): Print a remaining counter also for the standard PIN. Rework the prompt texts. * agent/divert-scd.c (ask_for_card): Pretty format an OpenPGP serial no. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'agent/divert-scd.c')
-rw-r--r--agent/divert-scd.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/agent/divert-scd.c b/agent/divert-scd.c
index 316440495..d9d734c64 100644
--- a/agent/divert-scd.c
+++ b/agent/divert-scd.c
@@ -39,22 +39,39 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
char *serialno;
int no_card = 0;
char *desc;
- char *want_sn, *want_kid;
- int want_sn_displen;
+ char *want_sn, *want_kid, *want_sn_disp;
+ int len;
*r_kid = NULL;
rc = parse_shadow_info (shadow_info, &want_sn, &want_kid, NULL);
if (rc)
return rc;
+ want_sn_disp = xtrystrdup (want_sn);
+ if (!want_sn_disp)
+ {
+ rc = gpg_error_from_syserror ();
+ xfree (want_sn);
+ return rc;
+ }
- /* We assume that a 20 byte serial number is a standard one which
- has the property to have a zero in the last nibble (Due to BCD
- representation). We don't display this '0' because it may
- confuse the user. */
- want_sn_displen = strlen (want_sn);
- if (want_sn_displen == 20 && want_sn[19] == '0')
- want_sn_displen--;
+ len = strlen (want_sn_disp);
+ if (len == 32 && !strncmp (want_sn_disp, "D27600012401", 12))
+ {
+ /* This is an OpenPGP card - reformat */
+ memmove (want_sn_disp, want_sn_disp+16, 4);
+ want_sn_disp[4] = ' ';
+ memmove (want_sn_disp+5, want_sn_disp+20, 8);
+ want_sn_disp[13] = 0;
+ }
+ else if (len == 20 && want_sn_disp[19] == '0')
+ {
+ /* We assume that a 20 byte serial number is a standard one
+ * which has the property to have a zero in the last nibble (Due
+ * to BCD representation). We don't display this '0' because it
+ * may confuse the user. */
+ want_sn_disp[19] = 0;
+ }
for (;;)
{
@@ -93,12 +110,12 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
{
if (asprintf (&desc,
"%s:%%0A%%0A"
- " \"%.*s\"",
+ " %s",
no_card
? L_("Please insert the card with serial number")
: L_("Please remove the current card and "
"insert the one with serial number"),
- want_sn_displen, want_sn) < 0)
+ want_sn_disp) < 0)
{
rc = out_of_core ();
}
@@ -114,6 +131,7 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
}
if (rc)
{
+ xfree (want_sn_disp);
xfree (want_sn);
xfree (want_kid);
return rc;
@@ -312,7 +330,8 @@ getpin_cb (void *opaque, const char *desc_text, const char *info,
info, NULL);
else
desc2 = NULL;
- rc = agent_askpin (ctrl, desc2, prompt, again_text, pi, NULL, 0);
+ rc = agent_askpin (ctrl, desc2? desc2 : info,
+ prompt, again_text, pi, NULL, 0);
xfree (desc2);
}
again_text = NULL;
@@ -401,6 +420,8 @@ divert_pksign (ctrl_t ctrl, const char *desc_text,
size_t siglen;
unsigned char *sigval = NULL;
+ (void)desc_text;
+
rc = ask_for_card (ctrl, shadow_info, &kid);
if (rc)
return rc;
@@ -409,7 +430,7 @@ divert_pksign (ctrl_t ctrl, const char *desc_text,
{
int save = ctrl->use_auth_call;
ctrl->use_auth_call = 1;
- rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, desc_text,
+ rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, NULL,
algo, digest, digestlen, &sigval, &siglen);
ctrl->use_auth_call = save;
}
@@ -421,7 +442,7 @@ divert_pksign (ctrl_t ctrl, const char *desc_text,
rc = encode_md_for_card (digest, digestlen, algo, &data, &ndata);
if (!rc)
{
- rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, desc_text,
+ rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, NULL,
algo, data, ndata, &sigval, &siglen);
xfree (data);
}
@@ -458,6 +479,8 @@ divert_pkdecrypt (ctrl_t ctrl, const char *desc_text,
char *plaintext;
size_t plaintextlen;
+ (void)desc_text;
+
*r_padding = -1;
s = cipher;
@@ -523,7 +546,7 @@ divert_pkdecrypt (ctrl_t ctrl, const char *desc_text,
if (rc)
return rc;
- rc = agent_card_pkdecrypt (ctrl, kid, getpin_cb, ctrl, desc_text,
+ rc = agent_card_pkdecrypt (ctrl, kid, getpin_cb, ctrl, NULL,
ciphertext, ciphertextlen,
&plaintext, &plaintextlen, r_padding);
if (!rc)