|C H A P T E R 12|
Sending and Receiving APDU Commands
The apdutool reads a script file containing Application Protocol Data Unit commands (APDUs) and sends them to the C-language Java Card RE (or other Java Card RE) or the Java Card WDE. Each APDU is processed and returned to apdutool, which displays both the command and response APDUs on the console. Optionally, apdutool can write this information to a log file.
The file to invoke apdutool is a shell script (apdutool) on the Solaris or Linux platform, and a batch file (apdutool.bat) on the Microsoft Windows platform.
apdutool starts listening to APDUs in T=1 as the default format, unless otherwise specified, on the TCP/IP port specified by the -p portNumber parameter for contacted and portNumber+1 for contactless. The default port is 9025.
The command line usage for apdutool is:
apdutool [-h hostname] [-nobanner] [-noatr] [-o <outputFile>] [-p portNumber] [-s serialPort] [-t0|-pcsc] [-version] <inputFile> [<inputFile> ...]
The option values and their actions are shown in TABLE 12-1.
To use this option, the javax.comm package must be installed on your system. For more information on installing this package, see Prerequisites for Installing the Binary Release.
The following examples show how to use apdutool.
This command runs apdutool with the file example.scr as input. Output is sent to the console. The default TCP port (9025) is used.
This command runs apdutool with the file example.scr as input. Output is written to the file example.scr.out.
apdutool -o example.scr.out example.scr
An APDU script file is a protocol-independent APDU format containing comments, script file commands, and C-APDUs. Script file commands and C-APDUs are terminated with a semicolon (;). Comments can be of any of the three Java-language style comment formats (//, /*, or /**).
APDUs are represented by decimal, hex or octal digits, UTF-8 quoted literals or UTF-8 quoted strings. C-APDUs may extend across multiple lines.
C-APDU syntax for apdutool is as follows:
<CLA> <INS> <P1> <P2> <LC> [<byte 0> <byte 1> ... <byte LC-1>] <LE> ;
<CLA> :: ISO 7816-4 class byte.
<INS> :: ISO 7816-4 instruction byte.
<P1> :: ISO 7816-4 P1 parameter byte.
<P2> :: ISO 7816-4 P2 parameter byte.
<LC> :: ISO 7816-4 input byte count. 1 byte in non-extended mode,
2 bytes in extended mode.
<byte 0> ... <byte LC-1> :: input data bytes.
<LE> :: ISO 7816- 4 expected output length. 1 byte in non-extended mode,
2 bytes in extended mode.
The script file commands shown in TABLE 12-2 are supported:
These packages provide a convenient API for writing client-side applications that communicate with Java Card technology enabled smart cards and are used by all RMI demos included with this development kit.