Skip to content

Commit

Permalink
IASECC/CPX: parse EF.ATR from ASN1 2F01 object
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vjardin committed Feb 6, 2021
1 parent 06dd8b7 commit b7b5cde
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/libopensc/ef-atr.c
Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit b7b5cde

Please sign in to comment.