From 8d000774dfebff00489b40fdcd07a69b1a4b818b Mon Sep 17 00:00:00 2001 From: Martin Paljak Date: Fri, 14 Feb 2014 11:50:20 +0000 Subject: [PATCH] EstEID: match card only based on presence of application. Contact cards have ATR-s, contactless not. Only contact cards should be broken so that they answer 0x9000 to application selection, so this should be failsafe. --- src/libopensc/card-mcrd.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libopensc/card-mcrd.c b/src/libopensc/card-mcrd.c index 4119be74..d0bedbed 100644 --- a/src/libopensc/card-mcrd.c +++ b/src/libopensc/card-mcrd.c @@ -3,7 +3,7 @@ * * Copyright (C) 2004 Martin Paljak * Copyright (C) 2004 Priit Randla - * Copyright (C) 2003 Marie Fischer + * Copyright (C) 2003 Marie Fischer * Copyright (C) 2001 Juha Yrjölä * Copyright (C) 2002 g10 Code GmbH * @@ -272,12 +272,29 @@ int is_esteid_card(sc_card_t *card) { } static int mcrd_match_card(sc_card_t * card) { - int i = 0; + int i = 0, r = 0; + sc_apdu_t apdu; + i = _sc_match_atr(card, mcrd_atrs, &card->type); if (i >= 0) { card->name = mcrd_atrs[i].name; return 1; } + + sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0xA4, 0x04, 0x00); + apdu.lc = sizeof(EstEID_v35_AID); + apdu.data = EstEID_v35_AID; + apdu.datalen = sizeof(EstEID_v35_AID); + apdu.resplen = 0; + apdu.le = 0; + r = sc_transmit_apdu(card, &apdu); + SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed"); + sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "SELECT AID: %02X%02X", apdu.sw1, apdu.sw2); + if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) { + sc_log(card->ctx, "AID found"); + card->type = SC_CARD_TYPE_MCRD_ESTEID_V30; + return 1; + } return 0; }