IASECC/CPX: parse EF.ATR from ASN1 2F01 object

2F01 is:
./opensc-explorer -r 0
OpenSC [3F00]> cat 2F01
00000000: 80 43 01 B8 46 04 04 B0 EC C1 47 03 94 01 80 4F .C..F.....G....O
00000010: 08 80 25 00 00 01 FF 01 00 E0 10 02 02 01 04 02 ..%.............
00000020: 02 01 04 02 02 01 00 02 02 01 00 78 08 06 06 2B ...........x...+
00000030: 81 22 F8 78 02 82 02 90 00                      .".x.....

so the ASN1 decoder gets confused because it assumes that two bytes are
needed before getting the first tag 43/ISO7816_TAG_II_CARD_SERVICE.
In order to avoid such confusion, whenever the content of the EF.ATR/2F01 starts
with ISO7816_II_CATEGORY_TLV, we skip the first byte in order to parse
the ASN1 payload.

Fix: issue #2220
This commit is contained in:
Vincent JARDIN 2021-02-05 23:17:11 +00:00 committed by Frank Morgner
parent 6efd7b3029
commit fd83e885f7
1 changed files with 11 additions and 2 deletions

View File

@ -143,6 +143,7 @@ int sc_parse_ef_atr(struct sc_card *card)
int rv;
unsigned char *buf = NULL;
size_t size;
size_t off = 0;
LOG_FUNC_CALLED(ctx);
@ -162,8 +163,16 @@ int sc_parse_ef_atr(struct sc_card *card)
}
rv = sc_read_binary(card, 0, buf, size, 0);
LOG_TEST_GOTO_ERR(ctx, rv, "Cannot read EF(ATR) file");
rv = sc_parse_ef_atr_content(card, buf, rv);
/* Workaround: Some cards seem to have a buggy storage of the EF.ATR */
if ((card->type == SC_CARD_TYPE_IASECC_CPX) ||
(card->type == SC_CARD_TYPE_IASECC_CPXCL)) {
/* Let's keep the first byte */
if ((rv > 1) &&
(buf[0] == ISO7816_II_CATEGORY_TLV))
off++;
}
rv = sc_parse_ef_atr_content(card, buf + off, rv - off);
LOG_TEST_GOTO_ERR(ctx, rv, "EF(ATR) parse error");
rv = SC_SUCCESS;