Search code examples
smartcardapduiso-7816-4

ReadBinary APDU always returning invalid length (SW1=0x67) [ISO7816]


I try to read a file from a smart card (via PCSC). I can successfully SELECT the MF and the desired EF, then I execute a ReadBinary APDU, but the result is always SW1=0x67, SW2=0x00 (invalid LE).

I know, that the file is there and that it is valid. I know its size (84bytes) and I know that it is selectable and readable without permissions (ALWAYS).

My understanding is, that I provide 0 to the LE parameter for a full length result, or I provide the effective length (plus 4 bytes for the header), but neither parameters work.

I tinkered a lot with the parametrization without success. The result is always (0x67). My general approach for reading the file after successfully selecting it (0x9000) is as follows:

CLA: depending of the logical channel, 0x00 for me
Instruction: 0xB0
P1: 0
P2: 0
LE: 0 or length of the file +4 
Data: empty
IsoCase: Case4Short

Can anybody hint me in the right direction, what I’m doing wrong? I'm an absolute beginner, probably I made some silly mistakes.

Here is my command sequence:

00-A4-00-00-02-3F-00-00  : 9000
00-A4-00-00-02-2F-06-00  : 9000
00-B0-00-00-00-00        : 6700

Solution

  • You need to send 00-B0-00-00-00 instead of 00-B0-00-00-00-00 (it is CLA-INS-P1-P2-Le -- there is no extra Lc) as READ BINARY is a case 2 command in this case.

    Please note that many cards do not conform to ISO-7816-4 and it is always better to refer to the respective card manual.

    Good luck with your project!