SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

GPSecurityDomain - Reference Documentation

An instance of the GPSecurityDomain class represents an application that is a security domain on a smart card.

Instances of this class are created using the getApplicationInstance() method of the application factory.

Index of Methods

Properties

TypeNameDescription
ByteStringaidApplication identifier for this application.
CardcardCard object associated with application.
CardcryptoCrypto object associated with application.
Arraydata[]Associative array of data elements.
Arraykey[]Associative array of keys.
ObjectprofileDeserialized application profile.

Constructor

Prototype

GPSecurityDomain(String profile)

GPSecurityDomain(String profile, ByteString aid, Card card, Crypto crypto, Object dataMapper)

Description

Create a GPSecurityDomain object and initialize from profile.

This constructor is provided for special development and testing purposes. The preferred method is to use the getApplicationInstance() method of the ApplicationFactory.

Arguments

TypeNameDescription
StringprofileName of file containing Global Platform Application profile. The file name will be mapped to the file system of the runtime environment.
ByteStringaidApplication identifier for application.
CardcardCard object to associate Application with or null if none defined.
CryptocryptoCrypto object to associate Application with.
ObjectdataMapperData mapper object to be used for external data elements or null if none defined.

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments given
GPErrorGPError.INVALID_TYPEOn or more arguments are not of the expected type

Example


var sd = new GPSecurityDomain("profiles/ap_sample.xml");

assert(sd != null);

deleteAID()

Prototype

ByteString deleteAID(ByteString aid)

ByteString deleteAID(ByteString aid, Number[] sw)

Description

Delete application, module or load file stored under given aid using the Global Platform DELETE_FILE APDU.

Arguments

TypeNameDescription
ByteStringaidApplication identifier of application, module or load file.
Number[]swArray of acceptable SW1/SW2 status codes.

Return

ByteStringThe method returns the data returned by the ICC in response to the DELETE_FILE command.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation
GPErrorGPError.CARD_COMM_ERRORCommunication with the ICC failed
GPErrorGPError.CARD_INVALID_SWThe ICC returned an unexpected status word SW1/SW2

Example


var applAid = new ByteString("", HEX);
sd.deleteAID(applAid, [0x9000, 0x6A88] );

installForInstallAndSelectable()

Prototype

ByteString installForInstallAndSelectable(ByteString loadFileAID, ByteString executableModuleAID, ByteString applicationAID, ByteString privileges, ByteString installParam, ByteString installToken)

ByteString installForInstallAndSelectable(ByteString loadFileAID, ByteString executableModuleAID, ByteString applicationAID, ByteString privileges, ByteString installParam, ByteString installToken, Number[] sw)

Description

Create an instance of an application under the given AID using the executable module from the load file as the template.

After instantiating the applet, it is selectable with the select command.

The optional argument sw allows to define a list of acceptable status word returned by the ICC. If the argument is missing, then 9000 is the only acceptable status word.

Arguments

TypeNameDescription
ByteStringloadFileAIDApplication identifier of load file.
ByteStringexecutableModuleAIDApplication identifier of module in load file.
ByteStringapplicationAIDApplication identifier for instance to be created.
ByteStringprivilegesApplication privileges.
ByteStringinstallParamInstallation parameter.
ByteStringinstallTokenInstall token to authenticate install process or null if not defined.
Number[]swArray of acceptable SW1/SW2 status codes.

Return

ByteStringThe method returns the data returned by the ICC in response to the INSTALL command.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation
GPErrorGPError.CARD_COMM_ERRORCommunication with the ICC failed
GPErrorGPError.CARD_INVALID_SWThe ICC returned an unexpected status word SW1/SW2

Example


var loadFileAid = new ByteString("A000000001", HEX);
var moduleAid = new ByteString("A00000000101", HEX);
var applAid = new ByteString("A00000000102", HEX);
var applPrivileges = new ByteString("00", HEX);
var installParam = new ByteString("C900", HEX);

sd.installForInstallAndSelectable(loadFileAid, moduleAid, applAid, applPrivileges, installParam, null);

installForLoad()

Prototype

ByteString installForLoad(ByteString loadFileAID, ByteString securityDomainAID, ByteString loadFileDataBlockHash, ByteString loadParam, ByteString loadToken)

Description

Prepare the download of a load file into the ICC with a subsequent load(), loadByName() or loadWithProfile() method.

The optional argument sw allows to define a list of acceptable status word returned by the ICC. If the argument is missing, then 9000 is the only acceptable status word.

Arguments

TypeNameDescription
ByteStringloadFileAIDApplication identifier of load file.
ByteStringsecurityDomainAIDApplication identifier of security domain or null if not used.
ByteStringloadFileDataBlockHashHash of load file data blocks or null if not used.
ByteStringloadParamLoad parameter or null if not used.
ByteStringloadTokenLoad token to authenticate load process or null if not used.
Number[]swArray of acceptable SW1/SW2 status codes.

Return

ByteStringThe method returns the data returned by the ICC in response to the INSTALL command.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation
GPErrorGPError.CARD_COMM_ERRORCommunication with the ICC failed
GPErrorGPError.CARD_INVALID_SWThe ICC returned an unexpected status word SW1/SW2

Example


var loadFileAid = new ByteString("A000000001", HEX);
var sdAid = new ByteString("A000000003000000", HEX);

sd.installForLoad(loadFileAid, sdAid, null, null, null);

loadByName()

Prototype

ByteString loadByName(String capFileName)

ByteString loadByName(ByteString capFileName)

ByteString loadByName(ByteString capFileName, [[aid, dap]])

Description

Read cap file and transfer into GP card using the LOAD command APDU.

Arguments

TypeNameDescription
StringcapFileNameName of cap file. Will be mapped to a file name in the runtime environment.
ByteStringcapFileNameName of cap file as ByteString. Will be mapped to a file name in the runtime environment.
[[ByteString,ByteString]][[aid,dap]]Pair of application identifier and data block signature - Not yet supported

Return

ByteStringData returned in last LOAD block

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation
GPErrorGPError.OBJECT_NOT_FOUNDCap file not found or invalid cap file structure
GPErrorGPError.CARD_COMM_ERRORCommunication with the ICC failed
GPErrorGPError.CARD_INVALID_SWThe ICC returned an unexpected status word SW1/SW2

Example


sd.loadByName("musclecard/CardEdge.cap");

select()

Prototype

ByteString select()

ByteString select(Boolean next, Boolean noData)

ByteString select(Boolean next, Number[] sw)

ByteString select(Boolean next, Boolean noData, Number[] sw)

Description

Select security domain on ICC.

Arguments

TypeNameDescription
BooleannextUsed to control parameter P1 in the select command. True will select next application with matching AID. Default is false.
BooleannoDataIgnore data returned from card. Default is false.
Number[]swArray of acceptable SW1/SW2 response codes.

Return

ByteStringData returned from card in response to select.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation
GPErrorGPError.CARD_COMM_ERRORCommunication with the ICC failed
GPErrorGPError.CARD_INVALID_SWThe ICC returned an unexpected status word SW1/SW2

Example


/*
var aid = new ByteString("D040000017010101", HEX);
var card = new Card(_scsh3.reader);
var crypto = new Crypto();

var application = new Application("profiles/ap_test.xml", aid, card, crypto, new Object());

var resp = application.select();
assert(resp instanceof ByteString);
print(resp);

var resp = application.select(false, false);
assert(resp instanceof ByteString);
print(resp);

var resp = application.select(false, [ 0x9000 ]);
assert(resp instanceof ByteString);
print(resp);

var resp = application.select(true, false, [ 0x6A86 ]);
assert(resp instanceof ByteString);
print(resp);
*/

sendApdu()

Prototype

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, Number[] sw)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, ByteString data)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, ByteString data, Number[] sw)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, Number le)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, Number le, Number[] sw)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, ByteString data, Number le)

ByteString sendApdu (Number cla, Number ins, Number p1, Number p2, ByteString data, Number le, Number[] sw)

Description

Transmit a Command-APDU to the ICC and receive the Response-APDU.

The method updates the fields SW, SW1, SW2 and response of the associated card object with the values received from the ICC.

An array of valid return codes can be passed as argument sw. If the SW1/SW2 from the ICC does not match with one of the entries in the array, then an GPError.CARD_COMM_ERROR exception is raised.

The method supports ISO7816-4 extended format. This is automatically used, if the length of the data argument exceeds 255 or if the argument le exceeds 256.

Arguments

TypeNameDescription
NumberclaThe CLA byte for the Command-APDU
NumberinsThe INS byte for the Command-APDU
Numberp1The P1 byte for the Command-APDU
Numberp2The P2 byte for the Command-APDU
ByteStringdataThe data bytes to be send in the Command-APDU for case 3 or case 4 commands
NumberleThe number of bytes expected in the response. 256 is encoded as '00' in short format. 65536 is encoded as '0000' in extended format.
Number[]swArray of acceptable SW1/SW2 return codes

Return

ByteStringResponse APDU received from ICC

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call or SW array contain a type other than Number
GPErrorGPError.CARD_COMM_ERRORA communication error with the ICC occured
GPErrorGPError.CARD_INVALID_SWThe status word return by the ICC does not match one of the expected result
GPErrorGPError.DATA_TOO_LARGEThe data for the command APDU exceeds 65536
GPErrorGPError.INVALID_LENGTHThe value given for Le is out of range

Example

/*
// Case 1: 0022F3A4 - MANAGE SE

resp = application.sendApdu(0x00, 0x22, 0xF3, 0xA4);
assert(resp instanceof ByteString);
print(application.card.SW.toString(16) + " - " + resp);

resp = card.sendApdu(0x00, 0x22, 0xF3, 0xA4, [0x9000]);
assert(resp instanceof ByteString);


// Case 2: 00B201F400 - READ RECORD from EF_STATUS

resp = card.sendApdu(0x00, 0xB2, 0x01, 0x24, 0);
assert(resp instanceof ByteString);
print(card.SW.toString(16) + " - " + resp);

assert(resp.length > 0);
assert(application.card.SW == 0x9000);

resp = card.sendApdu(0x00, 0xB2, 0x01, 0x24, 0, [0x9000]);
assert(resp.length > 0);


// Case 3: 002A90A008 - HASH

resp = application.sendApdu(0x00, 0x2A, 0x90, 0xA0, new ByteString("9000800431323334", HEX));
assert(resp instanceof ByteString);
print(application.card.SW.toString(16) + " - " + resp);

assert(card.SW == 0x9000);

resp = application.sendApdu(0x00, 0x2A, 0x90, 0xA0, new ByteString("9000800431323334", HEX),[0x9000]);


// Case 4: 00A40204022F0000 - SELECT EF_STATUS

resp = application.sendApdu(0x00, 0xA4, 0x02, 0x04, new ByteString("EF04", HEX), 0);
assert(resp instanceof ByteString);
print(application.card.SW.toString(16) + " - " + resp);

assert(application.card.SW == 0x9000);
assert(resp.length > 0);

resp = application.sendApdu(0x00, 0xA4, 0x02, 0x04, new ByteString("EF04", HEX), 0, [0x9000]);
assert(resp.length > 0);
*/

run()

Prototype

Void run(String scriptName)

Description

Locate and execute script fragment in application profile.

This method does the complete initialization of the key and data properties according to the declarations for this script fragment

Key profiles are obtained from the ApplicationFactory that created the Application object.

External data elements are mapped using the data mapper defined in the constructor or the getApplicationInstance() method of the application factory.

Warning: This method is an extension to the methods defined in the Global Platform Scripting specification. It is provided as development and test aid.

Arguments

TypeNameDescription
StringscriptNameName of script fragment to execute.

Return

VoidThe method does not return a value

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for method invocation

Example