Thứ Bảy, 25 tháng 10, 2008

JavaCard BK: 6 - Working with APDU

This chapter describes the techiniques of handling Application Protocol Data Units (APDU) in an applet. APDUs are data packets; they are the application-level commutication protocol between the application software ont he card and the application software on the host side. JavaCard technology provides the class javacard.frameworkd.APDU, which defines a powerfull yet simple interface to help applets handle APDUs easily. Therefore, applet developers can concentrate their efforts on processing the contents of APDU messages rather than on the details of how APDUs are constructed and transmitted.
APDU class:
The APDU class in the JavaCard APIs provides a powerfull and flexible interface for handling APDUs whose command and response structures conform to the ISO 7816-4 specification. Two transpot protocols are in primary use with smart card systems today: T=0 and T=1, the new protocol is T=CL is specified for contactless smart cards.
In the JavaCard environment, the APDU object can be viewed as a communication object. The applet do not allow to communicate directly with the application on the host. It interact with the JCRE, which in turn uses serial I/O protocol to communicate with the host. The JCRE will create APDU object that encapsulates APDU message (APDU buffer) to transmit (send request and receive response) the command.

APDU's buffer:
The minimum size of APDU buffer is 37 bytes. It's consists of 5 bytes of header and 32 default bytes is called information field size on card (IFSC). A smart card with more memory can allocate a bigger APDU buffer. The reason of the minimum size of APDU buffer is specified for TPDU T=1 (block-oriented). This buffer will handle all the received bytes, after that, it will be used as a buffer data for sending any result.

Working with APDU in Applets:
The Applet handle APDU object in the "process()" method, the content of the APDU is the command which was requested by the host. And it's all handled in APDU buffer. To retrieve the APDU buffer:
public void process(APDU apdu) {
//retrieve the APDU buffer
byte[] buffer = apdu.getBuffer();

This buffer is an array of bytes that holding all the CLA, INS, P1, P2, Lc and all data bytes which were sent from the host. YOur responsibility is only catch it, seperate it out and do you activities.
Note that, the JCRE requires that the reference to the APDU object or the reference to the APDU buffer CANNOT be stored in class variables, instance variables, or array components.
The structure of APDU command in APDU buffer:

take a break for dinner!!!

Không có nhận xét nào:

Đăng nhận xét