Skip to content

Commit

Permalink
reader-pcsc: allow fixing the length of a PIN
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Apr 6, 2018
1 parent 0911982 commit a17fc89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions etc/opensc.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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)
Expand Down
11 changes: 11 additions & 0 deletions src/libopensc/reader-pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -1887,10 +1891,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;

Expand Down

0 comments on commit a17fc89

Please sign in to comment.