reader-pcsc: allow fixing the length of a PIN

fixes https://github.com/OpenSC/OpenSC/issues/1221
closes https://github.com/OpenSC/OpenSC/pull/1288
This commit is contained in:
Frank Morgner 2018-04-06 13:33:09 +02:00
parent 078e99fdca
commit 36b88c3ad7
2 changed files with 17 additions and 0 deletions

View File

@ -93,6 +93,12 @@ app default {
# Default: true
# enable_pinpad = false;
#
# Some pinpad readers can only handle one exact length of the PIN.
# fixed_pinlength sets this value so that OpenSC expands the padding to
# this length.
# Default: 0 (i.e. not fixed)
# fixed_pinlength = 6;
#
# Detect reader capabilities with escape commands (wrapped APDUs with
# CLA=0xFF as defined by PC/SC pt. 3 and BSI TR-03119, e.g. for getting
# the UID, escaped PIN commands and the reader's firmware version)

View File

@ -82,6 +82,7 @@ struct pcsc_global_private_data {
SCARDCONTEXT pcsc_ctx;
SCARDCONTEXT pcsc_wait_ctx;
int enable_pinpad;
int fixed_pinlength;
int enable_pace;
size_t force_max_recv_size;
size_t force_max_send_size;
@ -766,6 +767,7 @@ static int pcsc_init(sc_context_t *ctx)
gpriv->transaction_end_action = SCARD_LEAVE_CARD;
gpriv->reconnect_action = SCARD_LEAVE_CARD;
gpriv->enable_pinpad = 1;
gpriv->fixed_pinlength = 0;
gpriv->enable_pace = 1;
gpriv->pcsc_ctx = -1;
gpriv->pcsc_wait_ctx = -1;
@ -788,6 +790,8 @@ static int pcsc_init(sc_context_t *ctx)
pcsc_reset_action(scconf_get_str(conf_block, "reconnect_action", "leave"));
gpriv->enable_pinpad = scconf_get_bool(conf_block, "enable_pinpad",
gpriv->enable_pinpad);
gpriv->fixed_pinlength = scconf_get_bool(conf_block, "fixed_pinlength",
gpriv->fixed_pinlength);
gpriv->enable_pace = scconf_get_bool(conf_block, "enable_pace",
gpriv->enable_pace);
gpriv->force_max_send_size = scconf_get_int(conf_block,
@ -1889,10 +1893,17 @@ part10_check_pin_min_max(sc_reader_t *reader, struct sc_pin_cmd_data *data)
unsigned char buffer[256];
size_t length = sizeof buffer;
struct pcsc_private_data *priv = reader->drv_data;
struct pcsc_global_private_data *gpriv = (struct pcsc_global_private_data *) reader->ctx->reader_drv_data;
struct sc_pin_cmd_pin *pin_ref =
data->flags & SC_PIN_CMD_IMPLICIT_CHANGE ?
&data->pin1 : &data->pin2;
if (gpriv->fixed_pinlength != 0) {
pin_ref->min_length = gpriv->fixed_pinlength;
pin_ref->max_length = gpriv->fixed_pinlength;
return 0;
}
if (!priv->get_tlv_properties)
return 0;