CAC issues (#1120)
* cac: Make the retransmitted APDU valid by restoring the resplen * cac: Check SWs for all the APDUs and report the errors to underlying layers * cac: Fallback from CACv1 to CACv2 when CACv1 instruction is not recognized for the lack of other pointers how to recongnize them * avoid goto
This commit is contained in:
parent
9b772ebdc4
commit
0dcf673296
|
@ -390,9 +390,7 @@ static int cac_apdu_io(sc_card_t *card, int ins, int p1, int p2,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apdu.sw1 == 0x61) {
|
|
||||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||||
}
|
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Card returned error ");
|
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Card returned error ");
|
||||||
|
@ -606,9 +604,14 @@ static int cac_read_binary(sc_card_t *card, unsigned int idx,
|
||||||
/* SPICE smart card emulator only presents CAC-1 cards with the old CAC-1 interface as
|
/* SPICE smart card emulator only presents CAC-1 cards with the old CAC-1 interface as
|
||||||
* certs. If we are a cac 1 card, use the old interface */
|
* certs. If we are a cac 1 card, use the old interface */
|
||||||
r = cac_cac1_get_certificate(card, &val, &val_len);
|
r = cac_cac1_get_certificate(card, &val, &val_len);
|
||||||
if (r < 0)
|
if (r == SC_ERROR_INS_NOT_SUPPORTED) {
|
||||||
|
/* The CACv1 instruction is not recognized. Try with CACv2 */
|
||||||
|
card->type = SC_CARD_TYPE_CAC_II;
|
||||||
|
} else if (r < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((card->type == SC_CARD_TYPE_CAC_I) && (priv->object_type == CAC_OBJECT_TYPE_CERT)) {
|
||||||
r = cac_cac1_get_cert_tag(card, val_len, &tl, &tl_len);
|
r = cac_cac1_get_cert_tag(card, val_len, &tl, &tl_len);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -1106,6 +1109,7 @@ static int cac_select_file_by_type(sc_card_t *card, const sc_path_t *in_path, sc
|
||||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||||
if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86) {
|
if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86) {
|
||||||
apdu.p2 = 0x00;
|
apdu.p2 = 0x00;
|
||||||
|
apdu.resplen = sizeof(buf);
|
||||||
if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
|
if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
|
||||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue