Smart Card Shell

CardSimulationAdapter - Reference Documentation

Class to control a card simulation adapter that forwards APDUs to a script implementation

Index of Methods

Constructor

Prototype

CardSimulationAdapter(String adapter, String parameter)

Description

Create a new card simulation adapter.

Currently only the JCOP Simulation adapter is available. It is configured as adapter name "JCOPSimulation" with the port number as parameter.

Arguments

Type Name Description
String adapter Name of the simulation adapter
String source The parameter used to initialise the adapter

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


var sa = new CardSimulationAdapter("JCOPSimulation", "8050");

setSimulationObject()

Prototype

void setSimulationObject(Object simulation)

Description

Set the object that receives reset() and processAPDU() calls from the card simulation adapter.

The simulation object must implement the following methods:

void reset(Number coldOrWarm); ByteString processAPDU(ByteString capdu);

The parameter coldOrWarm allows to differentiate between a cold and a warm reset. This parameter is currently always 0 (cold reset).

The parameter capdu contains the raw command APDU, including CLA, INS, P1, P2 and conditionally the Lc, Command Data and Le field.

The processAPDU() method must return the response APDU as ByteString object, with the conditional response data field and the trailer bytes SW1/SW2.

Arguments

Type Name Description
Object simulation The object that implements the card simulation

Return

Exceptions

Name Value Description
GPError GPError.ARGUMENTS_MISSING Too few arguments in call
GPError GPError.INVALID_ARGUMENTS Too many arguments in call
GPError GPError.INVALID_TYPE Type of argument is invalid for call

Example


// Create a very simple card simulator
var simulationObject = new Object();

// The simulator needs a processAPDU method
simulationObject.processAPDU = function(capdu) {
	print("Received APDU: " + capdu);
	var rapdu = capdu.concat(new ByteString("9000", HEX));
	return rapdu;
}

// The simulator needs a reset method
simulationObject.reset = function(type) {
	print("Reset type: " + type);
	var atr = new ByteString("3B600000", HEX);
	return atr;
}

sa.setSimulationObject(simulationObject);

start()

Prototype

void start()

Description

Starts the simulator adapter.

If the adapter is already running, it is stopped first.

Return

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


sa.start();

var card = new Card("JCOPSimulation");

var atr = card.reset(Card.RESET_COLD);

print(atr);

assert(atr.toByteString().toString(HEX) == "3B600000");

var rapdu = card.sendApdu(0x00, 0x10, 0x01, 0x02, new ByteString("1234", HEX), [0x9000]);

assert(rapdu.toString(HEX) == "00100102021234");

stop()

Prototype

void stop()

Description

Stops the simulator adapter.

Return

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


sa.stop();