1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-07-03 02:58:57 +02:00

scd: Fix pinpad input support (backport from master)

* app-openpgp.c (do_change_pin): Fix pincb messages when
use_keypad == 1.
This commit is contained in:
NIIBE Yutaka 2011-12-01 11:09:51 +09:00
parent 7cd8b12e25
commit b480f18e1d

View File

@ -1982,7 +1982,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
if (chvno == 2) if (chvno == 2)
set_resetcode = 1; set_resetcode = 1;
} }
else if (chvno == 1 || chvno == 3) else if (!use_keypad && (chvno == 1 || chvno == 3))
{ {
char *promptbuf = NULL; char *promptbuf = NULL;
const char *prompt; const char *prompt;
@ -1997,7 +1997,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
} }
else else
prompt = _("||Please enter the PIN"); prompt = _("||Please enter the PIN");
rc = pincb (pincb_arg, prompt, use_keypad ? NULL : &oldpinvalue); rc = pincb (pincb_arg, prompt, &oldpinvalue);
xfree (promptbuf); xfree (promptbuf);
promptbuf = NULL; promptbuf = NULL;
if (rc) if (rc)
@ -2007,7 +2007,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
goto leave; goto leave;
} }
if (!use_keypad && strlen (oldpinvalue) < minlen) if (strlen (oldpinvalue) < minlen)
{ {
log_info (_("PIN for CHV%d is too short;" log_info (_("PIN for CHV%d is too short;"
" minimum length is %d\n"), chvno, minlen); " minimum length is %d\n"), chvno, minlen);
@ -2042,6 +2042,8 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
goto leave; goto leave;
} }
if (!use_keypad)
{
rc = pincb (pincb_arg, rc = pincb (pincb_arg,
_("||Please enter the Reset Code for the card"), _("||Please enter the Reset Code for the card"),
&resetcode); &resetcode);
@ -2059,6 +2061,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
goto leave; goto leave;
} }
} }
}
else else
{ {
rc = gpg_error (GPG_ERR_INV_ID); rc = gpg_error (GPG_ERR_INV_ID);
@ -2089,6 +2092,23 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
if (resetcode) if (resetcode)
{
if (use_keypad)
{
rc = pincb (pincb_arg,
_("||Please enter the Reset Code for the card and New PIN"),
NULL);
if (rc)
{
log_info (_("PIN callback returned error: %s\n"),
gpg_strerror (rc));
goto leave;
}
rc = iso7816_reset_retry_counter_with_rc_kp (app->slot, 0x81,
&pininfo);
pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
}
else
{ {
char *buffer; char *buffer;
@ -2104,6 +2124,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
xfree (buffer); xfree (buffer);
} }
} }
}
else if (set_resetcode) else if (set_resetcode)
{ {
if (strlen (pinvalue) < 8) if (strlen (pinvalue) < 8)
@ -2111,11 +2132,40 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
log_error (_("Reset Code is too short; minimum length is %d\n"), 8); log_error (_("Reset Code is too short; minimum length is %d\n"), 8);
rc = gpg_error (GPG_ERR_BAD_PIN); rc = gpg_error (GPG_ERR_BAD_PIN);
} }
else
{
if (use_keypad)
{
rc = pincb (pincb_arg, _("|RN|New Reset Code"), NULL);
if (rc)
{
log_info (_("PIN callback returned error: %s\n"),
gpg_strerror (rc));
goto leave;
}
rc = iso7816_put_data_kp (app->slot, 0xD3, &pininfo);
pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
}
else else
rc = iso7816_put_data (app->slot, 0, 0xD3, rc = iso7816_put_data (app->slot, 0, 0xD3,
pinvalue, strlen (pinvalue)); pinvalue, strlen (pinvalue));
} }
}
else if (reset_mode) else if (reset_mode)
{
if (use_keypad)
{
rc = pincb (pincb_arg, _("|N|New PIN"), NULL);
if (rc)
{
log_info (_("PIN callback returned error: %s\n"),
gpg_strerror (rc));
goto leave;
}
rc = iso7816_reset_retry_counter_kp (app->slot, 0x81, &pininfo);
pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
}
else
{ {
rc = iso7816_reset_retry_counter (app->slot, 0x81, rc = iso7816_reset_retry_counter (app->slot, 0x81,
pinvalue, strlen (pinvalue)); pinvalue, strlen (pinvalue));
@ -2123,6 +2173,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
rc = iso7816_reset_retry_counter (app->slot, 0x82, rc = iso7816_reset_retry_counter (app->slot, 0x82,
pinvalue, strlen (pinvalue)); pinvalue, strlen (pinvalue));
} }
}
else if (!app->app_local->extcap.is_v2) else if (!app->app_local->extcap.is_v2)
{ {
/* Version 1 cards. */ /* Version 1 cards. */
@ -2147,6 +2198,16 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
if (use_keypad) if (use_keypad)
{ {
rc = pincb (pincb_arg,
chvno == 3 ?
_("||Please enter the Admin PIN and New Admin PIN") :
_("||Please enter the PIN and New PIN"), NULL);
if (rc)
{
log_info (_("PIN callback returned error: %s\n"),
gpg_strerror (rc));
goto leave;
}
rc = iso7816_change_reference_data_kp (app->slot, 0x80 + chvno, rc = iso7816_change_reference_data_kp (app->slot, 0x80 + chvno,
&pininfo); &pininfo);
/* Dismiss the prompt. */ /* Dismiss the prompt. */