card-piv: 'emulate' MF selection by selection of the PIV applet ...

so that, PIV card can be used with the 'opensc-explorer' interactive tool


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5317 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-04-10 08:47:35 +00:00
parent 3169f14b32
commit 5102e4d882
1 changed files with 15 additions and 6 deletions

View File

@ -676,7 +676,7 @@ static int piv_select_aid(sc_card_t* card, u8* aid, size_t aidlen, u8* response,
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
"Got args: aid=%x, aidlen=%d, response=%x, responselen=%d\n", "Got args: aid=%x, aidlen=%d, response=%x, responselen=%d\n",
aid, aidlen, response, *responselen); aid, aidlen, response, responselen ? *responselen : 0);
sc_format_apdu(card, &apdu, sc_format_apdu(card, &apdu,
response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, 0x00); response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, 0x00);
@ -684,11 +684,12 @@ static int piv_select_aid(sc_card_t* card, u8* aid, size_t aidlen, u8* response,
apdu.data = aid; apdu.data = aid;
apdu.datalen = aidlen; apdu.datalen = aidlen;
apdu.resp = response; apdu.resp = response;
apdu.resplen = *responselen; apdu.resplen = responselen ? *responselen : 0;
apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */ apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
r = sc_transmit_apdu(card, &apdu); r = sc_transmit_apdu(card, &apdu);
*responselen = apdu.resplen; if (responselen)
*responselen = apdu.resplen;
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "PIV select failed"); SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "PIV select failed");
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2)); SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
} }
@ -2103,9 +2104,17 @@ static int piv_select_file(sc_card_t *card, const sc_path_t *in_path,
/* only support single EF in current application */ /* only support single EF in current application */
if (pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) { if (memcmp(path, "\x3F\x00", 2) == 0) {
path += 2; if (pathlen == 2) {
pathlen -= 2; r = piv_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, NULL, NULL);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot select PIV AID");
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, r);
}
else if (pathlen > 2) {
path += 2;
pathlen -= 2;
}
} }
i = piv_find_obj_by_containerid(card, path); i = piv_find_obj_by_containerid(card, path);