Tuesday, 12 December 2017

Application Protocol Data Unit (APDU)

Application Protocol Data Unit i.e. APDU is a communication Protocol between the smart card and smart card reader.
APDU can be divided into two subcategories -

  • Command APDU
           Command APDU will hold data unit, which will be sent from smart card reader to smart card.
           After receiving such APDU on smart card, it will be executed on smart card based on                           implementation and command sent.

  • Response APDU
          Response APDU will hold the data, of executed Command APDU by smart card, and sent to              smart card reader.


The structure of command and response of APDU defined in ISO 7816-4

Command APDU will contain 4 mandatory bytes in it, those are CLS, INS, P1 and P2


CLASS - CLS - APDU Class - denotes type of command. This can be standard or proprietary.
INSTRUCTION - INS - Instruction Code - denotes specific command, e.g. Update Data, Delete Data etc.
P1 - P2 - Indicates parameters (offsets) for data to be written or updated.
Lc - Indicates length of data passed.
DATA - Will contain actual data, of length specified by Lc.

Response APDU will at least contain 2 bytes
SW1 - Status Word first byte
SW2 - Status Word second byte

Based on SW1 and SW2, card reader will come to know, if given Command APDU is executed on Card successfully or not, and if not what is error.
In notmal scenario, Status word for Success is 90 00.


No comments:

Post a Comment