From bb2d863e4f05f5871a9255e8a450a62cc065db76 Mon Sep 17 00:00:00 2001 From: Doug Engert Date: Sat, 30 Jul 2016 08:52:36 -0500 Subject: [PATCH] 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 --- src/libopensc/card-piv.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libopensc/card-piv.c b/src/libopensc/card-piv.c index e0b3c9cc..e3ad4da5 100644 --- a/src/libopensc/card-piv.c +++ b/src/libopensc/card-piv.c @@ -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; }