Smartcard Seminar : Assignment 2 : Applet Loading

How to compile, download, and run software on Cyberflex Access smartcard
1/6/2000, Naomaru Itoi (itoi@eecs.umich.edu)
Updated, 11/5/2000, Naomaru Itoi

In this assignment, you are to learn how to compile a sample Java applet called "Wallet.java", download it into your smartcard, and communicate with it.

Compilation of an applet is done by two steps. The first is javac -g. This compiles a .java file to a .class file. javac is available on Sun workstation in CAEN labs. Make sure to use /usr/um/jdk-1.2.2/bin/javac, not /usr/um/bin/javac nor /usr/bin/javac. Also, do not forget -g. You can use javac version 1.2 on other machines.

The second is mksolo (in /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/bin), which converts a .class file to a Cyberflex Access loadable applet. Compile your applet, and download it to your Cyberflex Access smartcard. This is done by pay commands "jl" which loads the applet, and "jp" which selects it.

Once the applet is downloaded and selected, you can communicate with the applet with APDUs. Wallet.java (which is in /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/src) takes four types of APDUs, i.e., deposit (03 10), debit (03 20), balance (03 30), and validate PIN (03 40).

When finished communicating with it, use "jq" to unselect the applet, and "ju" to unload it.

Now the step-by-step example.

/* First, compile your applet with -g and appropriate class path. */

xnor% /usr/um/jdk-1.2.2/bin/javac -g -classpath /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/lib Wallet.java
-> Wallet.class
/* Second, run mksolo on the .class file and get .bin file */
xnor% /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/bin/mksolo -usemap=/afs/engin.umich.edu/u/i/t/itoi/sc_seminar/lib/Access.map -v -d Wallet.class
-> Wallet.bin
/* Start pay */
xnor% /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/bin/pay -d /afs/engin.umich.edu/u/i/t/itoi/sc_seminar/bin/libtodos_ag.so
/* Help is available by typing 'h' in pay. */
pay> h
/* Choose the serial port. If you put your smartcard to serial port A, type '1'. If it is on port B, type '2'. */
pay> 2
1:3b 2:16 3:94 4:81 5:10 6:6 7:1 8:81 9:2f /* this is answer to reset */
/* download "Wallet.bin" to the card */
pay> jl Wallet.bin
applet file "Wallet.bin"
program ID 77.77 /* program installed in file 3f00/7777 */
container ID 77.78 /* data container installed in file 3f00/7777 */
instance container size 2048
instance data size 1024
AID 7777777777 /* Application ID is 7777777777 */
signature eed461e31de414c1
90 00 ok
/* select the applet */
pay> jp
select applet
AID 7777777777
90 00 ok
/* Now applet "Wallet.bin" is ready to take your APDUs. */
/* first, validate PIN (it is 00 00 00 00) */
pay> ic 03 40 00 00 04
Enter 4 data bytes (hex):
00 00 00 00
90 00 ok
/* check the balance (default value = 0x20) */
>pay> oc 03 30 00 00 01
1:20
90 00 ok
/* debit 0x8 */
>pay> ic 03 20 00 00 01
Enter 1 data bytes (hex):
8
90 00 ok
/* check balance. 0x20 - 0x08 = 0x18. :) */
pay> oc 03 30 00 00 01
1:18
90 00 ok
/* unselect and unload the applet */
pay> jq
90 00 ok
pay> ju
90 00 ok
Now try changing the program slightly. For example, take $1 away whenever the user debits money.

That's it!! You are welcome to modify Wallet.java and play with it further.