1

I am trying to write a data of length 0x2CF0 bytes using extended length APDU on to the card and it works fine. But i am unable to read the same amount of data back from the card using extended length apdu.

I get the following error, "sun.security.smartcardio.PCSCException: Unknown error 0x4d3".

When i try to load a relatively smaller data of size 0x1af0 bytes i am able to successfully write and read from the card using extended length apdu.

Is there any limitation with respect to read data from the card in extended length apdu? Is there a workaround without the use of command chaining?

PS: I use a JCOP 2.4.2 R2 card.

Narasimha
  • 41
  • 2

1 Answers1

2

A typical smart card stores the data to be sent to the reader in RAM. (Among others this makes it easier to ensure, that no secret data from non-volatile memory is sent). Smart card chips have limited RAM and you can feel lucky, that your smaller attempt (more than 6 k) still works.

Unfortunately in the ATR the card can only indicate, that it supports extended length APDUs at all, but not up to which boundary (which also may vary, if output is subjected to secure messaging processing).

The typical approach is, to provide a command with some kind of internal partitioning, e. g. in file system based files the concept of binary files is used, and the command may specify a start offset, see this question.

Chaining will typically not help; since for MAC calculation the whole data needs to be present, the architecture typically enforces this in all other cases too.

Community
  • 1
  • 1
guidot
  • 5,095
  • 2
  • 25
  • 37
  • 1
    The latest ISO 7816 should be able to indicate buffer sizes, even for specific AID's etc. Of course without client / reader & smart card support that may not matter much. – Maarten Bodewes Jul 23 '16 at 09:19
  • Hi Guidot, Is it possible to read such large data from the card using the .apdu.setOutgoing(); apdu.setOutgoingLength(); apdu.sendBytesLong() command combination? Can i set the out going length to 0x2CF0 and call multiple apdu.sendBytesLong() ?? – Narasimha Jul 03 '17 at 13:29
  • @Narasimha: No, you have to check your card, what it supports as maximum output size and make a loop with respective startiong offset increment. – guidot Jul 03 '17 at 13:37
  • @guidot, My Card supports 8090 bytes if i use Extended length APDU. If i try to call apdu.SendBytesLong 3 times with 4096 bytes still i get the PCSC Exception. If i send 255 bytes at a time in an incremental loop still i get the PCSC Exception. Do you have a sample code to return large data using multiple SendBytesLong Call? – Narasimha Jul 04 '17 at 04:31
  • FYI, If i try to read the data using pyapdutool or using the SCComm terminal in JCShell it works fine. It fails only in java SmartCardIO libraries and PCSC Terminal. – Narasimha Jul 04 '17 at 11:47