Last updated January 14, 2010 18:28, by Anki Nelaturu
Feedicon  

(TBD) APDUTool2 - With Enhanced APDU Script support


Its been a decade I guess the apdu script has got any enhancements in the JCDK.

JavaCard dev kit v3.0.2 has introduced some enhancements in the script. Example:

#define walletApplet //aid/A000000062/03010C0101
#define purseApplet //aid/A000000062/03010C0102
#define walletCommand 0x80 0xCA 0x00 0x00 0x02 0xAB 0x08 0x7F
powerup;
select purseApplet;
send walletCommand to walletApplet on 19;
powerdown;

Just thinking of what enhancements would make it more interesting, and came up with the following ideas. I am thinking of starting this project here on kenai. Lets call it apdutool2 (or something else) because this is a new tool using the APDU I/O api. Not trying to create a programming language here, but just some more readability and a bit more control in the script itself.

We will have directives to tell the tool to change the behavior, and commands that are actually sent to the RI and some expressions. The APDU script might look like the following

//defines
#define ONE 1
// directives
@echo off
@output on
@extended off

$apdu1 = [1,2,3,4] with "test".bytes expecting 10;
$applet1 = //aid/1122334455/6677;

@contacted
powerup;
$response = send $apdu1 to $applet1;
if $response.status != 0x9090 goto end;
// some this else here    
end:
powerdown;

print "Switching to contactless";

@contactless
powerup;
// ....
powerdown;

Defines

Like C preprocessor symbols.

 #define ABCD 1234

A String literal replacement happens in the script. Not so advanced as C language.

Directives

These tells the tool to change few things.

@echo <on | off>echo each command along with it's result
@print <on | off>Should display print messages or not
@extended <on | off>extended mode on/off
@contactedswitch to contacted interface
@contactlessswitch to contactless interface

Variables

each variable is prefixed with $ symbol.

 $x = 23;
 $y = "aaa";
 $z = //aid/1111111111/222;

type is implicite based on what we store.

Data Types

boolean
byte*
bytes*
int
ints
string
date*
time*
aid
capdu
rapdu*

* -> can only be created as a result of some methods. For example

 $x = 34; -> creates int type
 $y = $x.byte; -> will return the byte (In terms of Java it is same as (byte)x )

Each datatype will have accessor methods which are prefixed by . A common accessor .type will return string which represents it's type.

boolean (.type -> "boolean")

 ex: true | yes | false | no
 .byte -> 0 or 1

int (.type -> "int")

    ex: 23, 0x23, 0b11011010101 (Octals not supported)
    .boolean -> false if 0, true if non zero
    .byte -> int by truncating to byte
    .bytes -> total 4 bytes (Ex: 0x10.bytes   ->  0, 0, 0, 16)

ints (.type -> "ints") index 0 based array of ints (as in Java)

    ex: [1,2,3,4,5]
    .bytes  -> ints with each value truncated to its byte
    .allbytes -> each int into 4 bytes. So if the array has 5 ints, then the result will be 20 element array
    .length -> int
    .0  .1  .2  .3  .4  -> int at given index
    .[0, 2] -> slice of the ints from index to count
    .reverse

string (.type -> "string")

    ex: "abcd"
    .length
    .bytes -> [ascii values of characters] -- byte for each character
    .date -> date
    .time -> time

date (.type -> "date")

    "08/14/1976".date
    .year -> int
    .month -> int
    .day -> int
    .monthname -> string "January"
    .dayname -> "Sunday"
    .bytes -> [0, 8, 1, 4, 1, 9, 7, 6]

time (.type -> "time")

    "12:34:45".time
    .hour
    .minute
    .second
    .hourOfTheDay
    .am
    .pm
    .bytes

aid (.type -> "aid")

    ex: //aid/1122334455/6677
    .rid -> bytes
    .pix -> bytes

command apdu (C-APDU) (.type -> "capdu")

    ex: [2,3,4,5] with [4,5,7,8] (expecting 34)?;
    .cla -> byte
    .ins -> byte
    .p1 -> byte
    .p2 -> byte
    .lc -> int
    .le -> int
    .data -> bytes

response apdu (R-APDU) (.type -> "rapdu")

    Can only be captured by send or select or ... commands. Cannot construct directly
    .sw1 -> byte
    .sw2 -> byte
    .status -> int
    .data -> bytes

Commands

print delay powerup powerdown select ...... send ..... open channel ..... close channel ....

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close