Skip to content

Commit

Permalink
IASECC/CPX: asn1 of EF.ATR objects
Browse files Browse the repository at this point in the history
Support the parsing of EF.ATR objects, for instance:

./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.....

OpenSC [3F00]> info 2F01
Working Elementary File  ID 2F01, SFI E8

File path:               3F00/2F01
File size:               57 bytes
EF structure:            Transparent
ACL for READ:            NONE
ACL for UPDATE:          SecOx45
ACL for DELETE:          SecOx45
ACL for WRITE:           N/A
ACL for REHABILITATE:    N/A
ACL for INVALIDATE:      N/A
ACL for LIST FILES:      N/A
ACL for CRYPTO:          N/A
Type attributes:         01
Life cycle:              Operational, activated

OpenSC [3F00]> asn1 2F01
80 Context 0  (0 bytes)
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 ..
OpenSC [3F00]>

which means:
 ef-atr.c:49:sc_parse_ef_atr_content: EF.ATR: card service 0xB8
 ef-atr.c:59:sc_parse_ef_atr_content: EF.ATR: Pre-Issuing data '04B0ECC1'
 ef-atr.c:67:sc_parse_ef_atr_content: EF.ATR: DF selection 94, unit_size 1, card caps 80
 ef-atr.c:95:sc_parse_ef_atr_content: EF.ATR: AID '8025000001FF0100'
 ef-atr.c:106:sc_parse_ef_atr_content: EF.ATR: Issuer data '02020104020201040202010002020100'
 ef-atr.c:111:sc_parse_ef_atr_content: EF.ATR: DER encoded OID 06062B8122F87802
 ef-atr.c:114:sc_parse_ef_atr_content: EF.ATR: OID 2B8122F87802
 ef-atr.c:123:sc_parse_ef_atr_content: EF.ATR: status word 0x9000

Fix: issue #2220
  • Loading branch information
vjardin committed Feb 3, 2021
1 parent 5173dc9 commit 4d316a0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/tools/opensc-explorer.c
Expand Up @@ -48,6 +48,7 @@
#include "libopensc/cards.h"
#include "libopensc/log.h"
#include "libopensc/internal.h"
#include "libopensc/iso7816.h"
#include "common/compat_strlcpy.h"
#include <getopt.h>
#include "util.h"
Expand Down Expand Up @@ -2088,7 +2089,7 @@ static int do_asn1(int argc, char **argv)
sc_path_t path;
sc_file_t *file = NULL;
int not_current = 1;
u8 buf[SC_MAX_EXT_APDU_DATA_SIZE];
u8 buf[SC_MAX_EXT_APDU_DATA_SIZE + 1];

if (argc > 3)
return usage(do_asn1);
Expand Down Expand Up @@ -2131,7 +2132,7 @@ static int do_asn1(int argc, char **argv)

r = sc_lock(card);
if (r == SC_SUCCESS)
r = sc_read_binary(card, 0, buf, MIN(size, sizeof(buf)), 0);
r = sc_read_binary(card, 0, buf + 1, MIN(size, sizeof(buf)), 0);
sc_unlock(card);
if (r < 0) {
check_ret(r, SC_AC_OP_READ, "read failed", file);
Expand Down Expand Up @@ -2166,7 +2167,7 @@ static int do_asn1(int argc, char **argv)

r = sc_lock(card);
if (r == SC_SUCCESS)
r = sc_read_record(card, rec, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
r = sc_read_record(card, rec, buf + 1, sizeof(buf), SC_RECORD_BY_REC_NR);
else
r = SC_ERROR_READER_LOCKED;
sc_unlock(card);
Expand All @@ -2179,7 +2180,12 @@ static int do_asn1(int argc, char **argv)
/* if offset does not exceed the length read from file/record, ... */
if (offs <= (unsigned int) r) {
/* ... perform the ASN.1 dump */
sc_asn1_print_tags(buf + offs, (unsigned int) r - offs);
if (buf[1] == ISO7816_II_CATEGORY_TLV) {
buf[0] = ISO7816_II_CATEGORY_TLV;
sc_asn1_print_tags(buf + offs, (unsigned int) r - offs + 1);
} else {
sc_asn1_print_tags(buf + 1 + offs, (unsigned int) r - offs);
}

err = 0;
}
Expand Down

0 comments on commit 4d316a0

Please sign in to comment.