piv: add a piv_card_reader_lock_obtained function

When sc_lock obtains a reader lock  this function is called
If the card was reset the PIV AID is seletcted and logged_in is reset.
This is need for some PIV cards where the default AID is not the PIV AID
and some other process has reset the card.

closes #842
This commit is contained in:
Doug Engert 2016-07-30 08:52:36 -05:00 committed by Viktor Tarasov
parent 84a69ce2ba
commit bb2d863e4f
1 changed files with 21 additions and 0 deletions

View File

@ -3301,6 +3301,26 @@ static int piv_logout(sc_card_t *card)
}
static int piv_card_reader_lock_obtained(sc_card_t *card, int was_reset)
{
int r = 0;
u8 temp[2000];
size_t templen = sizeof(temp);
piv_private_data_t * priv = PIV_DATA(card); /* may be null */
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
if (was_reset > 0) {
if (priv)
priv->logged_in = SC_PIN_STATE_UNKNOWN;
r = piv_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
}
LOG_FUNC_RETURN(card->ctx, r);
}
static struct sc_card_driver * sc_get_driver(void)
{
struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
@ -3322,6 +3342,7 @@ static struct sc_card_driver * sc_get_driver(void)
piv_ops.check_sw = piv_check_sw;
piv_ops.card_ctl = piv_card_ctl;
piv_ops.pin_cmd = piv_pin_cmd;
piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
return &piv_drv;
}