Skip to content

Commit

Permalink
IASECC/CPX: opensc-explorer asn1 EF.ATR parsing
Browse files Browse the repository at this point in the history
Let's the advance users be able to parse the ASN1 contant
for any offset.

OpenSC [3F00]> asn1 2F01 0
Error in decoding.
OpenSC [3F00]> asn1 2F01 1
43 Application 3  (1 byte): decode error, : B8 .
46 Application 6  (4 bytes): decode error: 04 B0 EC C1 ....
47 Application 7  (3 bytes): 94 01 80 ...
4F Application 15 (8 bytes): 80 25 00 00 01 FF 01 00 .%......
E0 Private 0  (16 bytes)
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 260
   02 INTEGER (2 bytes): 256
   02 INTEGER (2 bytes): 256
78 Application 24 (8 bytes)
   06 OBJECT IDENTIFIER (6 bytes):  1.3.162.15480.2
82 Context 2  (2 bytes): 36864: 90 00 ..

Fix: issue #2220
  • Loading branch information
vjardin committed Feb 8, 2021
1 parent c3614cc commit 064746c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/tools/opensc-explorer.c
Expand Up @@ -2086,6 +2086,7 @@ static int do_asn1(int argc, char **argv)
{
int r, err = 1;
unsigned int offs = 0;
int offsu = 0; /* offset updated, set from argv */
sc_path_t path;
sc_file_t *file = NULL;
int not_current = 1;
Expand Down Expand Up @@ -2127,8 +2128,10 @@ static int do_asn1(int argc, char **argv)
goto err;
}

if (argc > 1)
if (argc > 1) {
offs = (unsigned int) strtoul(argv[1], NULL, 10);
offsu = 1;
}

r = sc_lock(card);
if (r == SC_SUCCESS)
Expand Down Expand Up @@ -2157,8 +2160,10 @@ static int do_asn1(int argc, char **argv)
}

rec = (unsigned int) strtoul(argv[1], NULL, 10);
if (argc > 2)
if (argc > 2) {
offs = (unsigned int) strtoul(argv[2], NULL, 10);
offsu = 1;
}

if (rec < 1 || rec > file->record_count) {
fprintf(stderr, "Invalid record number %u.\n", rec);
Expand All @@ -2178,7 +2183,9 @@ static int do_asn1(int argc, char **argv)
}

/* workaround when the issuer of a card does prefix the EF.ATR payload with 0x80 */
if ((buf[0] == ISO7816_II_CATEGORY_TLV) &&
if ((offsu == 0) && /* do not apply the workaround if any offset */
(buf[0] == ISO7816_II_CATEGORY_TLV) &&
(path.len >= 4) &&
(memcmp(path.value, "\x3f\x00\x2f\x01", 4) == 0))
offs++;
/* if offset does not exceed the length read from file/record, ... */
Expand Down

0 comments on commit 064746c

Please sign in to comment.