Search code examples
javacardapdugetresponse

About Get Response command in javacard


I'm confused about Get Response command. I thought I know it but actually I don't.

I wanna know the mechanism in which the card returns 1000-bytes data in case 4. I guess the command is as follows. Please let me know the correct one if it is wrong.

(Card) <== [CLA] [INS] [P1] [P2] [Lc] [Data] [Le] // response data size is 1000 bytes
(Card) ==> 6100

(Card) <== 00 C0 00 00 00
(Card) ==> [Data(256)] 6100

(Card) <== 00 C0 00 00 00
(Card) ==> [Data(256)] 6100

(Card) <== 00 C0 00 00 00
(Card) ==> [Data(256)] 61E8

(Card) <== 00 C0 00 00 E8
(Card) ==> [Data(232)] 9000 (61E8 was my mistake)

Questions

  1. Is the above APDU correct ?
  2. What is the [Le] in first command ?
  3. How to implement the GET RESPONSE in java applet ?
  4. How is the method to implement different according to T=0/T=1 card ? (When I googled, I saw the information about the T=0/T=1 card but I don't understand.)

I hope any response or URL of the related information.


Solution

  • To answer your questions:

    1. It seems largely correct to me, except for (2) and the final remark;
    2. You don't send both a Lc and Le field for T=0, in a case 4 command (command data and response data) only Lc and the command data is send - you could also say that Le is empty as it is an encoding in bytes;
    3. T=0 is handled by the Java Card OS, you should not have to implement this yourself;
    4. T=1 does not use or need GET RESPONSE as both T=1 and T=CL are higher level protocols - the layer beneath APDU's already take care of this. Furthermore extended length support may have been implemented.

    Finally, the card should of course return 9000 or a status word indicating a warning or error instead of 61E8 for the last command (this was subsequently fixed in the question as mistake in the question).

    Note that you should not blindly assume that the response will contain the amount of bytes requested. An Le byte with value 00 for instance indicates a maximum response size of 256 bytes.

    This is all defined in ISO/IEC 7816-4, chapter 5.3.4: Response chaining

    The current version is 2013(E) at the time of writing. It's payware (but Google isn't).