IASECC/CPX: opensc-explorer asn1 EF.ATR parsing

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
This commit is contained in:
Vincent JARDIN 2021-02-08 19:59:43 +00:00 committed by Frank Morgner
parent 20f359ea04
commit b508349010
1 changed files with 10 additions and 3 deletions

View File

@ -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;
@ -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)
@ -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);
@ -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, ... */