GP Systems Scripting Language 1.1.0 (FINAL)
GP Systems Scripting Language 1.1.0 (FINAL)
Table of Contents
1. INTRODUCTION....................................................................................................................................... 1
1.1 SUMMARY ......................................................................................................................................... 1
1.2 SCOPE ............................................................................................................................................. 1
1.3 AUDIENCE ........................................................................................................................................ 2
1.4 NORMATIVE REFERENCES ................................................................................................................. 2
1.4.1 List of References ................................................................................................................... 2
1.4.2 GlobalPlatform Document Navigation ..................................................................................... 5
1.5 TERMINOLOGY AND DEFINITIONS ....................................................................................................... 5
1.6 ABBREVIATIONS AND NOTATIONS ..................................................................................................... 11
1.7 CONVENTIONS ................................................................................................................................ 12
1.8 REVISIONS HISTORY ....................................................................................................................... 12
1.8.1 Overview of Changes in Version 1.1.0 over Version 1.0 ...................................................... 12
2. OVERVIEW............................................................................................................................................. 16
2.1 GLOBALPLATFORM INITIATIVE .......................................................................................................... 16
2.2 GLOBALPLATFORM CARD CUSTOMIZATION REQUIREMENTS .............................................................. 17
3. ECMASCRIPT LANGUAGE CHOICE.................................................................................................... 19
4. GLOBALPLATFORM SCRIPTS OVERVIEW........................................................................................ 21
4.1 SCRIPT LANGUAGE ......................................................................................................................... 21
4.2 SCRIPT PROCESSING ...................................................................................................................... 21
4.2.1 Creating Objects for an Application (excluding Security Domain) ........................................ 23
4.2.2 Creating Objects for a Security Domain Application (including Card Manager) ................... 26
4.2.3 Creating Objects for a Smart Card ........................................................................................ 32
4.3 SCRIPT OBJECT CATEGORIES .......................................................................................................... 34
4.3.1 Overview of GP Scripting Language Native ECMAScript Objects........................................ 34
4.4 DESERIALIZING PROFILE XML CONTENT INTO SCRIPTING OBJECTS .................................................. 42
4.4.1 Deserializing the XML Documents into the Profile Property ................................................. 42
4.4.1.1 Deserialization of Elements with Multiple Occurrances ................................................. 43
4.4.2 Deserializing DataElement and Declaration Elements into the Data Property ..................... 45
4.4.2.1 Impact of the ReadWrite Attribute on Deserialization .................................................... 47
4.4.2.2 Impact of the Encoding Attribute on Deserializiation ..................................................... 47
4.4.2.3 Impact of the Tag Attribute on Deserializiation .............................................................. 47
4.4.2.4 Impact of the Value, External and Optional Attributes on Deserializiation .................... 48
4.4.2.5 Executing Successive Scripts and Data Scoping Between Scripts ............................... 49
4.4.3 Deserializing Key and KeyDeclaration Elements into the Key Property ............................... 50
4.4.3.1 Executing Successive Scripts and Key Scoping Between Scripts................................. 51
4.4.4 Deserializing Function Elements into Scripting Language Functions ................................... 51
4.5 CREATING AND USING SECURE CHANNEL OBJECTS .......................................................................... 52
4.5.1 Creating Secure Channel Objects......................................................................................... 52
4.5.2 Opening Secure Channels .................................................................................................... 52
7.1.5.4.4 putKey()...................................................................................................................... 86
7.1.5.4.5 select()........................................................................................................................ 88
7.1.5.4.6 sendApdu()................................................................................................................. 89
7.1.5.4.7 setStatus() .................................................................................................................. 90
7.1.5.4.8 storeData() ................................................................................................................. 91
7.1.6 GPSecurityDomain................................................................................................................ 92
7.1.6.1 Summary ........................................................................................................................92
7.1.6.2 Constants ....................................................................................................................... 93
7.1.6.3 Properties ....................................................................................................................... 93
7.1.6.3.1 aid............................................................................................................................... 93
7.1.6.3.2 appSpecificInstallParams........................................................................................... 93
7.1.6.3.3 card ............................................................................................................................ 93
7.1.6.3.4 crypto.......................................................................................................................... 93
7.1.6.3.5 data[] .......................................................................................................................... 93
7.1.6.3.6 key[]............................................................................................................................ 94
7.1.6.3.7 lifecycle.name............................................................................................................. 94
7.1.6.3.8 lifecycle.value ............................................................................................................. 94
7.1.6.3.9 nonVolatileDataSpaceLimit ........................................................................................ 95
7.1.6.3.10 order ......................................................................................................................... 95
7.1.6.3.11 privilege .................................................................................................................... 95
7.1.6.3.12 profile........................................................................................................................ 95
7.1.6.3.13 secureChannel ......................................................................................................... 96
7.1.6.3.14 securityDomain ........................................................................................................ 96
7.1.6.3.15 volatileDataSpaceLimit............................................................................................. 96
7.1.6.4 Methods.......................................................................................................................... 96
7.1.6.4.1 Constructor................................................................................................................. 96
7.1.6.4.2 deleteAID() ................................................................................................................. 96
7.1.6.4.3 getData() .................................................................................................................... 97
7.1.6.4.4 getStatus().................................................................................................................. 97
7.1.6.4.5 installForExtradition() ................................................................................................. 98
7.1.6.4.6 installForInstall() ......................................................................................................... 99
7.1.6.4.7 installForInstallAndSelectable().................................................................................. 99
7.1.6.4.8 installForLoad() ........................................................................................................ 100
7.1.6.4.9 installForPersonalization()........................................................................................ 101
7.1.6.4.10 load() ...................................................................................................................... 101
7.1.6.4.11 loadByName() ........................................................................................................ 102
7.1.6.4.12 loadWithProfile()..................................................................................................... 103
7.1.6.4.13 openSecureChannel() ............................................................................................ 104
7.1.6.4.14 putKey().................................................................................................................. 105
7.1.6.4.15 select().................................................................................................................... 106
7.1.6.4.16 sendApdu().............................................................................................................107
7.1.6.4.17 setStatus() .............................................................................................................. 108
7.1.6.4.18 storeData() ............................................................................................................. 108
7.1.7 SecureChannel.................................................................................................................... 110
7.1.7.1 Summary ...................................................................................................................... 110
1. Introduction
1.1 Summary
The GlobalPlatform Systems Scripting Language Specification [GP_SYS_SCR] defines a
standard to which instructions for card customization purposes can be written. In this version, the
latest version of the ECMAScript language [ECMA 262] has been defined as the language
specification to which distinctive parcels of code, or scripts, can be developed by application
developers to perform card customization operations for their applet.
ECMAScript is more popularly known as JavaScript, which is implemented around the world in
Internet browsers by Microsoft and Netscape. While Microsoft and Netscape have augmented
the language with support for web browsing requirements, JavaScript consists of a core lanuage.
It is this core language which is based entirely on [ECMA_262].
By utilizing the ECMAScript scripting language and the smart card specific objects detailed in this
document, an application developer can create, for the most part, card independent scripts for
card customization operations. These card customization operations, when designed using the
ECMAScript language specified and the smart card specific scripting objects, become very
portable instruction sets for use by a variety of card issuers across any number of smart card
implementations.
Scripts developed according to this specification will often require access to external data and
keys supplied by the host environment. While the scripts will access the external data and keys
using objects defined in the scripting objects, the Application Profile, a container for information
about the application and its requirements, will define the external data and key requirements of
the application and its individual scripts. Therefore, scripts developed according to this
specification require the Application Profile in order to operate correctly. However, the converse
is not true. Application Profiles can be used to manage smart card products irrespective of
scripts.
This work presents a choice of ECMAScript and a set of objects for that language to facilitate the
standardized exchange of card customization instructions for applications. As well, by having the
language constructs of the scripting language ECMAScript at their disposal, application
developers are given a flexible tool to develop scripts according to the manner in which they
choose to prepare data and personalize smart cards. Hence, the GlobalPlatform scripting
approach, as a tool for card customization, can create and personalize off of any data format as
required, including widely adopted P3 and emerging Common Personalization formats.
The Card Configurator and Script Builder specification has been replaced with these
specifications, namely the GlobalPlatform Systems Scripting Language Specification 1.0
[GP_SYS_SCR] and GlobalPlatform Systems Profiles Specification 1.0 [GP_SYS_PRF].
In summary, in conjunction with the GlobalPlatform Systems Profiles Specification
[GP_SYS_PRF] and the GlobalPlatform Card Customization Guide [GP_SYS_CCG], this
specification provides a method for developing interoperable smart card implementations on the
card customization front. As the ECMAScript language evolves towards a truer object oriented
language, as is proposed for the next major release of ECMA 262, the GlobalPlatform
organization can migrate or adopt the scripting objects as necessary to meet the future needs of
the multi-application smart card industry.
1.2 Scope
The objectives of this document are:
To provide a description of the role of GlobalPlatform scripting in card customization
tasks;
1.3 Audience
This document is targeted towards audiences who have a requirement to understanding how card
customization tasks such as Data Preparation, Card Personalization, and Card Verification can
be facilitated using a language enabling a write once, use anywhere philosophy. Specific
audiences include but are not limited to:
Card Manufacturers who will couple Application Profiles with their Card Profiles in order
to describe core GlobalPlatform applications such as Card Manager, Security Domains.
In designing the Application Profiles, Card Manufacturers must either procure or create
the appropriate Scripts for these applications.
Application Developers who will create Application Profiles and Application Scripts
required for their applications. Application Developers will have the key investment in
ensuring that their applications are accompanied with the required Scripts for Data
Preparation, pre- and post-issuance personalization, and essential Card Verification
tasks. This will help them ensure that their applications reach the widest available
audience, and ensure that implementation of their applications can be performed as
seamlessly as possible.
Actors involved in the architecture, design, and implementation of data preparation
systems, personalization systems and devices, or verification systems, including both
smart card software and hardware vendors. These actors will be assuming the role of
Application Loader, Card Enabler, or any other roles providing card customization related
responsibilities.
Actors who need to understand how legitimate application portfolio and card
combinations can be constructed, and how scripts rely on information in GlobalPlatform
Profiles [GP_SYS_PRF] to correctly operate.
ISO/IEC 9797-1:1999 -
International Standard
Organization - Information
technology - Security techniques -- [IS9797]
Message Authentication Codes
(MACs) – Part 1: Messages using
a block cipher
PKCS #1 - RSA Laboratories -
RSA Encryption Standard - [PKCS#1]
Version 1.5
Rivest, R., Internet Engineering
Task Force RFC 132 - The MD5
Message-Digest Algorithm
The UniCode Consortium, The
[UNICODE] Defines the UTF-8 format.
Unicode Standard - Version 3.2
Term Definition
Application Developer Actor responsible for the development of Smart Card applications.
Application Protocol Data Unit Standard communication messaging protocol between a card
(APDU) accepting device and a smart card.
The link between the application and the external world during a Card
Application Session Session starting with the Application selection and ending with
Application de-selection or termination of the Card Session.
Term Definition
The current life cycle state of an application on a GlobalPlatform smart
Application State
card.
Entity that owns the card and is ultimately responsible for the behavior
Card Issuer
of the card.
Term Definition
The Card Profile describes a smart card. This card could be a
singularly unique card or a card that shares common characteristics, as
Card Profile defined in the Card Profile, with other cards. Depending on how it is
used, it either acts as a base template for a smart card or represents a
single smart card by itself.
The link between the card and the external world starting with the ATR
Card Session
and ending with a subsequent reset or a deactivation of the card.
A message sent by the host to the smart card that initiates an action
Command
and solicits a response from the smart card.
DAP Block Part of the Load File used for ensuring Load File Data Block verification
Data Authentication Pattern Used to authenticate and/or verify the integrity of the data. This can be
(DAP) done using a DES key or Public key mechanism.
Term Definition
Delegated Management allows an Application Provider to load and
Delegated Management install an application on a card, with the Card Issuer still retaining
control over the content of the card.
A logical term used to represent the back end systems that support the
GlobalPlatform system; hosts perform functions such as authorization
Host
and authentication, administration, post-issuance application code and
data downloading, and transactional processing.
Term Definition
The existence of Card Content on an GlobalPlatform card and the
Life Cycle
various stages of this existence where applicable.
Life Cycle State A specific state within the Life Cycle of the card or of Card Content.
Part of the Load File that contains one or more application(s) and
Load File Data Block libraries or support information for the application(s) as required by the
specific platform.
Load File Data Block Hash A value providing integrity for the Load File Data Block.
A value encompassing the Load File Data Block Hash and providing
Load File Data Block Signature
both integrity and authenticity of the Load File Data Block.
Scripts that are created by the scripting process and used for the Card
Personalization process. There are three types of scripts:
Data Preparation Script (DPS),
Card Creation Script (CCS),
Personalization Script Data Verification Script (DVS),
And other scripts used for post-issuance personalization activities.
Each script will be unique for each personalization run.
Term Definition
Combination of a set of applications selected by an card issuer with a
selected smart card platform. The product Profile is represented by a
Product Profile combination of Application Profiles (an application portfolio) and a Card
Profile. A product Profile will, at a minimum, contain Application
Profile(s) and a Card Profile.
A cryptographic technique that uses the same secret key for both the
Symmetric Cryptography
originator's and the recipient's transformation.
IC Integrated Circuit
LV Length Value
P1 Parameter 1
P2 Parameter 2
P3 Parameter 3
Abbreviation Meaning
PIN Personal Identification Number
SW Status Word
1.7 Conventions
Text in Lucida Console refers to GlobalPlatform scripting language, examples, or references
as defined in this specification to the GlobalPlatform Systems Scripting Language Specification
[GP_SYS_SCR].
Text in Verdana Bold refers to elements and attributes from XML document type definition
files, XML schema files, XML documents, XML elements, and XML attributes as defined in the
GlobalPlatform Systems Profiles Specification [GP_SYS_PRF].
2. Overview
GlobalPlatform scripting is used to enable a common, flexible, and extensible means of card
customization. Card customization is defined in this document as the process of producing a
card customized to a specific Cardholder and eventually modifying its contents after issuance to
add and delete functionality. In that broad sense, card customization starts as early as
application software is loaded onto a chip, ends temporarily with card issuance, and is re-enacted
as soon as a new application is added (or deleted) or when some on-card data is updated post-
issuance. Therefore, card customization includes loading applets, installing applets, data
preparation, card issuance or pre-issuance personalization, post-issuance personalization, as
well as verifying whether cards have been personalized correctly.
This GlobalPlatform Systems Scripting Language Specification [GP_SYS_SCR] forms, in
conjunction with GlobalPlatform Systems Profiles Specification [GP_SYS_PRF] and
GlobalPlatform Systems Card Customization Guide [GP_SYS_CCG], the backbone of the
GlobalPlatform card customization processes. The GlobalPlatformCard Systems Card
Customization Guide provides insight and a recommendation for delivering card customization
processes using scripts and profiles.
Today’s personalization environments have a number of limitations in the ability to deliver smart
cards supporting multiple applications in a cost-effective and timely manner. The major
limitations include:
Requirements of highly specialized and scarce skills;
Lengthy time to market for new applications;
Single application card focus;
Recurring development and testing costs;
Difficulty to provide customized solutions to Card Issuers and Application Providers.
The expected benefits of GlobalPlatform scripting in the GlobalPlatform card customization
architecture will include overcoming all these limitations and:
Facilitate the issuance of chip based applications by Card Issuers and Application
Providers through standardization and open standards driven selection of the language to
represent card customization instructions;
Enable the accelerated deployment of smart cards, including multiple payment and value-
added applications integrated into a single card, through the support of GlobalPlatform
scripting through different issuance delivery channels (e.g. Personalization Bureaus,
post-issuance systems);
Facilitate high levels of security through standardized interfaces to cryptography and
secure modules in the GlobalPlatform cryptographic object;
Minimize operational impact of new applications through consistent processes,
specifically the creation of scripts for a minimal set of card customization processes;
Reduce time and costs for smart card customization through standardization of
customization processes which traditionally have relied on proprietary processes and
substantial systems integration efforts.
Each of these objects would contain properties and methods as specified in the scripting objects.
Figure 4.2 – The GP Application Profile XML Document Contains GP Scripting Language Conforming Script Fragments
On e G P A p p l i c a t i o n o b je c t is c r e a t e d f o r t h e
A pplica tionProfile . It is the context f rom w hich the
script is executed, and can be accessed in the application's
script f ragments as this . The GPA pplication object is Function me t h o d s a s s u p p lie d in
c r e a t e d f r o m t h e A p p lic a t io n Pr o f ile X ML w h e r e t h e GPApplication object f rom the F unction XML
attributes Ty pe ="GP" and Subty pe ="A PP" . in t h e A p p l i c a t i o n P r o f i l e . In v o ke d v ia
this. function w here function is the name of
the f unction.
GPApplication
K e y o b je c t s a r e c r e a t e d f o r a ll t h e K e y X ML
elements def ined f or the A pplica tionProfile .
security function
The Ke y De cla ra tion child XML elements of the key data profile card crypto Clas s 1
Object1 Object2 Domain
ScriptF ra gm e nt provide inf ormation regarding
w hether the keys required by the script are supplied
ex ter nally . Key s ar e ac c es s ed as
th i s . k e y . k e y n a m e o r th i s . k e y [ k e y n a m e ]
w here keyname is the name of the Key . P o i n t e r t o a
Po i n t e r t o a
GPSecurityDomai
The GPApplication C r y p t o
n o b je c t c r e a t e d
object contains the XML object used by
Objects ( ByteString or TLV ) are created for, f rom a GP A pplication
elements and attributes, the application.
a t a m i n i m u m , th e De c la r a tio n XML Pr o f ile f o r t h e
e x c lu d in g t h e K e y ,
elements defined for the ScriptF ra gm e nt S e c u r it y Do ma in
Ke y De c l a r a ti o n ,
for the script unde r e x e cution. Po i n t e r t o a u n d e r w h ic h t h is
Da ta E le m e n t and
D a t a E l e m e n t elements are accessed as C a r d o b je c t a p plic a tion w as
D e c l a r a t i o n X ML ,
this.data. d ataname or this.data[ datana me ] c r eated f r om installed.
as native ECMA Script
whe r e d a ta na m e is the na m e o f the objects. th e GP Ca r d
Da ta Ele m e nt . The type of object created Prof ile.
d e p e n d s o n th e T y p e a ttr i b u te o f th e
Da ta Ele m e nt .
Figure 4.3 – Creating the GPApplication Object from the GP Application Profile
If the Security Domain is a Card Manager, then Figure 4.6 should be referred to. Thus, valid
references for a GPSecurityDomain representing the Card Manager inside script code
attached to the Application Profile for the Card Manager would be:
// Property to access to the array of Key objects
this.key;
// Property to access to the array of ByteString and/or TLV objects
this.data;
// Property to access to the elements and attributes of the
// Application Profile
this.profile;
// Property providing access to the target card object
// Created as in Figure 4.7 - Refer to Section 4.2.3 for what
// this.card can access
this.card;
Thus, when the Card Manager or Security Domain GPSecurityDomain object is a child object
of a GPApplication object, the following references would be valid inside script code attached
to the Application Profile for the application for which the GPApplication object is created:
// Property to access to the array of Key objects
this.securityDomain.key;
// for keys from the application profile for the Security Domain
// Property to access to the array of ByteString and/or TLV objects
this.securityDomain.data;
// for data elements from the application profile for the Security
// Domain
// Property to access to the elements and attributes of the
// Application Profile
this.securityDomain.profile;
// profile tree for the application profile for the Security
// Domain
Figure 4.4 – The GP Application Profile XML Document Contains GP Scripting Language Conforming Script Fragments
Figure 4.5 – Creating the GPSecurityDomain Object for a Security Domain from the GP Application Profile
Figure 4.6 – Creating the GPSecurityDomain Object for the Card Manager Application from the GP Application Profile
Figure 4.7 – Creating the Card Object from the GP Card Profile
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 34
GPError.ACCESS_DENIED
GPError.CARD_COMM_ERROR
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 35
GPError.CARD_INVALID_SW
GPError.CRYPTO_FAILED
GPError.DATA_TOO_LARGE
GPError.DEVICE_ERROR
GPError.INVALID_ARGUMENTS
GPError.INVALID_DATA
GPError.INVALID_ENCODING
GPError.INVALID_INDEX
GPError.INVALID_KEY
GPError.INVALID_LENGTH
GPError.INVALID_MECH
GPError.INVALID_TAG
GPError.INVALID_TYPE
GPError.INVALID_USAGE
GPError.KEY_NOT_FOUND
GPError.OBJECTCREATIONFAILED
GPError.SECURE_CHANNEL_WRONG_STATE
GPError.TAG_ALREADY_EXISTS
GPError.TAG_NOT_FOUND
GPError.UNDEFINED
GPError.UNSUPPORTED
GPError.USER_DEFINED
GPError.prototype.className
GPError.prototype.error
GPError.prototype.message
GPError.prototype.name
GPError.prototype.reason
GPError.prototype.constructor()
Crypto.DES
Crypto.DES_CBC
Crypto.DES_CBC_LP
Crypto.DES_CBC_P
Crypto.DES_ECB
Crypto.DES_ECB_LP
Crypto.DES_ECB_P
Crypto.DES_MAC
Crypto.DES_MAC_EMV
Crypto.DES2
Crypto.ISO9797_METHOD_1
Crypto.ISO9797_METHOD_2
Crypto.MD5
Crypto.RSA
Crypto.SHA_1
Crypto.prototype.decrypt()
Crypto.prototype.decryptEncrypt()
Crypto.prototype.deriveKey()
Crypto.prototype.digest()
Crypto.prototype.encrypt()
Crypto.prototype.generateKey()
Crypto.prototype.generateKeyPair()
Crypto.prototype.generateRandom()
Crypto.prototype.sign()
Crypto.prototype.unwrap()
Crypto.prototype.unwrapWrap()
Crypto.prototype.verify()
Crypto.prototype.wrap()
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 36
GPSystem.dateTimeByteString()
GPSystem.getSystemID()
GPSystem.getVendorObject()
GPSystem.getVersion()
GPSystem.trace()
GPSystem.wait()
Application.prototype.aid
Application.prototype.card
Application.prototype.crypto
Application.prototype.data[]
Application.prototype.key[]
Application.prototype.lifeCycle.name
Application.prototype.lifeCycle.value
Application.prototype.order
Application.prototype.profile
Application.prototype.secureChannel
Application.prototype.openSecureChannel()
Application.prototype.select()
Application.prototype.sendApdu()
GPScp01.prototype.cardChallenge
GPScp01.prototype.cardCryptogram
GPScp01.prototype.crypto
GPScp01.prototype.diversificationData
GPScp01.prototype.hostChallenge
GPScp01.prototype.keyIndex
GPScp01.prototype.keyVersion
GPScp01.prototype.mac
GPScp01.prototype.option
GPScp01.prototype.securityLevel
GPScp01.prototype.state
GPScp01.prototype.decryptEncryptKek()
GPScp01.prototype.encryptKek()
GPScp01.prototype.externalAuthenticate()
GPScp01.prototype.getDekKey()
GPScp01.prototype.initializeUpdate()
GPScp01.prototype.setDekKey()
GPScp01.prototype.setEncKey()
GPScp01.prototype.setMacKey()
GPScp01.prototype.unwrapWrapKek()
GPScp02.prototype.cardChallenge
GPScp02.prototype.cardCryptogram
GPScp02.prototype.crypto
GPScp02.prototype.diversificationData
GPScp02.prototype.hostChallenge
GPScp02.prototype.keyVersion
GPScp02.prototype.option
GPScp02.prototype.rmac
GPScp02.prototype.securityLevel
GPScp02.prototype.sequenceCounter
GPScp02.prototype.smac
GPScp02.prototype.state
GPScp02.prototype.beginRMac()
GPScp02.prototype.decryptEncryptDek()
GPScp02.prototype.encryptDek()
GPScp02.prototype.endRMac()
GPScp02.prototype.externalAuthenticate()
GPScp02.prototype.getDekKey()
GPScp02.prototype.initializeUpdate()
GPScp02.prototype.setBaseKey()
GPScp02.prototype.setDekKey()
GPScp02.prototype.setEncKey(()
GPScp02.prototype.setMacKey()
GPScp02.prototype.unwrapWrapDek()
Card is a built-in object used to represent the target smart card for the
Card
current personalization script
Card.OTHER
Card.PICCA
Card.PICCB
Card.RESET_COLD
Card.RESET_WARM
Card.T0
Card.T1
Card.T14
Card.prototype.profile
Card.prototype.response
Card.prototype.SW
Card.prototype.SW1
Card.prototype.SW2
Card.prototype.baudRate()
Card.prototype.clock()
Card.prototype.powerDown()
Card.prototype.pps()
Card.prototype.reset()
Card.prototype.sendApdu()
Card.prototype.vcc()
Key is a built-in object used to represent the keys defined in the Application
Key
Profile
Key.CRT_DP1
Key.CRT_DQ1
Key.CRT_P
Key.CRT_PQ
Key.CRT_Q
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 39
Key.DES
Key.EIGHTZEROS
Key.EXPONENT
Key.EXPORTABLE
Key.DECRYPT
Key.DECRYPT_ENCRYPT
Key.DERIVE
Key.ENCRYPT
Key.IMPORTABLE
Key.MODULUS
Key.PRIVATE
Key.PUBLIC
Key.SECRET
Key.SENSITIVE
Key.SIGN
Key.UNWRAP
Key.UNWRAP_WRAP
Key.VERIFY
Key.WRAP
Key.prototype.getAttribute()
Key.prototype.getComponent()
Key.prototype.getEnd()
Key.prototype.getKcv()
Key.prototype.getOwner()
Key.prototype.getProfileID()
Key.prototype.getSize()
Key.prototype.getStart()
Key.prototype.getType()
Key.prototype.getUsage()
Key.prototype.getVersion()
Key.prototype.getWrapKey()
Key.prototype.setAttribute()
Key.prototype.setComponent()
Key.prototype.setEnd()
Key.prototype.setOwner()
Key.prototype.setSize()
Key.prototype.setStart()
Key.prototype.setType()
Key.prototype.setUsage()
Key.prototype.setVersion()
The Atr object provides methods to return the value of the sequence of bytes
Atr
sent by the card to the interface device as the answer to a reset as defined in
[IS7816-3]
Atr.prototype.formatByte
Atr.prototype.historicalBytes
Atr.prototype.interfaceBytes
Atr.prototype.tckByte
Atr.prototype.toByteString()
ByteBuffer.prototype.length
ByteBuffer.prototype.constructor()
ByteBuffer.prototype.append()
ByteBuffer.prototype.byteAt()
ByteBuffer.prototype.clear()
ByteString.XOR
ByteString.prototype.length
ByteString.prototype.constructor()
ByteString.prototype.and()
ByteString.prototype.byteAt()
ByteString.prototype.bytes()
ByteString.prototype.concat()
ByteString.prototype.crc()
ByteString.prototype.equals()
ByteString.prototype.find()
ByteString.prototype.getL()
ByteString.prototype.getLV()
ByteString.prototype.left()
ByteString.prototype.neg()
ByteString.prototype.not()
ByteString.prototype.or()
ByteString.prototype.pad()
ByteString.prototype.right()
ByteString.prototype.startsWith()
ByteString.prototype.toBase64()
ByteString.prototype.toBcd()
ByteString.prototype.toHex()
ByteString.prototype.toSigned()
ByteString.prototype.toString()
ByteString.prototype.toUnsigned()
ByteString.prototype.xor()
The TLV object describes a single Tag Length Value (TLV) object
TLV
TLV.DGI
TLV.EMV
TLV.L16
TLV.prototype.encodingMode
TLV.prototype.size
TLV.prototype.constructor()
TLV.prototype.getL()
TLV.prototype.getLV()
TLV.prototype.getTag()
TLV.prototype.getTLV()
TLV.prototype.getTV()
TLV.prototype.getValue()
The TLVList object holds a collection of TLVs as they are created into the
TLVList
TLVList object
TLVList.prototype.encodingMode
TLVList.prototype.length
TLVList.prototype.constructor()
Data Type for Element Value or Attribute Object Created in GP Scripting Language
Data Type
ByteString
String (or String based Data Type)
with encoding as specified for Element or Attribute
Boolean
Boolean
Number
Integer
Table 4.1 - Profile Property Object Creation XML Mapping Table
Here is some example script code which illustrates the usage of the profile property:
// Will retrieve UniqueID of the ApplicationProfile element in the
// Application Profile
apUniqueID = GPApplication.profile.UniqueID;
// Will retrieve Version of the ApplicationInfo element in the
// Application Profile
apVersion = GPApplication.profile.ApplicationInfo.Version;
The Card object’s profile property is created in the same way, but for the Card Profile instead of
the Application Profile.
Here is some example script code which illustrates the usage of the Card object’s profile
property:
// Will retrieve UniqueID of the CardProfile element in the Card
// Profile
cpUniqueID = GPApplication.card.profile.UniqueID;
// Will retrieve Name of the CardManufacturerProduct element in the
// Card Profile
cpCmpName = GPApplication.card.profile.CardManufacturerProduct.Name;
For those elements which contain a value, the respective branch of the profile property will
contain the value of the property.
Here is some example script code which illustrates the deserialization of the following
Description element from a profile.
<Description>Sample GlobalPlatform Application</Description>
The Description element is one of the elements which contains a value not associated with an
attribute. The code to retrieve the text “Sample GlobalPlatform Application” is provided below:
// Will retrieve value of the Description element
text = this.profile.Description;
// text will contain an ASCII encoding ByteString with the
// contents “Sample GlobalPlatform Application”
4.4.1.1 Deserialization of Elements with Multiple Occurrances
For certain elements which occur a multiple of times, the requirement is that they be deserialized
as an array. In the [GP_SYS_PRF] specification, these elements possess the XML attributes
arrayElement and arrayIndex.
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 44
The arrayElement attribute identifies the name of the child element of the XML element of which
the attribute is associated with to deserialize as an array. If the child element is not defined, then
a deserialization error will occur. If the child element is present, the arrayIndex attribute
identifies the name of the attribute of this child element to use as the index when creating the
array. Likewise, if the attribute identified by arrayIndex is not found in the child element, a
deserialization error will occur.
Since an element may contain more than one child element which needs to be deserialized as an
array, the arrayElement and arrayIndex attributes will contain comma delimited lists of child
elements and child element attributes, respectively.
Furthermore, if the arrayIndex attribute contains a # for a particular child element, then this is an
indication that the array created for the child element needs to be indexed numerically starting at
zero. When using numeric indexing, as the order of deserialization is dependent on the how the
XML document is parsed, there is no guarantee that, when deserialized into an array, elements
with multiple occurrences will be indexed in the order they appear in the document. Therefore,
scripts should not be written with this expectation.
Note that these principles for creating arrays do not apply when deserializing DataElement,
Declaration, Key, and KeyDeclaration elements, which are not deserialized as part of the
profile property.
Here is an example which illustrates the representation of the following Revision element from
a profile. The Revision element can have multiple occurrences in the XML document.
<Revisions arrayElement="Revision" arrayIndex="#">
<Revision ProfileID="00001AAAAA" Version="1.0.0" Date="2003-03-01"
Time="12:34:56" By="Customer" Digest="0000"/>
<Revision ProfileID="00001AAAAA" Version="0.0.2" Date="2002-12-11"
Time="02:12:22" By="GP Application Vendor" Digest="0000"/>
<Revision ProfileID="00001AAAAA" Version="0.0.1" Date="2002-09-11"
Time="16:44:39" By="GlobalPlatform" Digest="0000"/>
</Revisions>
Since the arrayIndex attribute of Revisions specifies a #, the resultant array for the child
element Revision would be created using a numeric index starting at zero. Assuming that the
Revision element is deserialized in the order listed in the above XML excerpt, the following is
some example script code which illustrates the deserialization of the above Revisions element
and the three children Revision elements.
// Create a pointer to the Revisions element
myRevisions = this.profile.Revisions;
// Will retrieve the first Revision element
firstRev = myRevisions.Revision[0];
firstRevAuthor = myRevisions.Revision[0].by;
// firstRevAuthor will contain “Customer”
Alternatively, if arrayIndex specified another attribute, such as Version, then the corresponding
array would have three elements created:
firstRev = myRevisions.Revision[1.0.0];
DataElement XML elements occur at a higher hierarchical level of the Application Profile XML
document than do the Declaration elements, which are found at the same level as script code.
The intent of having both DataElement and Declaration is to ensure runtime execution
consistency amongst environments with different levels of external data availability, and runtime
execution efficiency where only data used by a particular script should need to be present.
DataElement XML elements represent all data populated externally or internally by the scripts
in an Application Profile (i.e., akin to global variables where the scope is the entire profile and all
the scripts contained within). Declaration XML elements are used by each individual script to
represent all data populated externally or internally by that particular script (i.e., akin to local
variables where the scope is the specific script for which they are specified).
To facilitate the balance of execution consistency and runtime efficiency, the rule to follow for
deserializing DataElement and Declaration elements is as follows:
For example, if in the Application Profile XML, there are DataElement XML elements named
AccountName and PAN, and for a particular script, Declaration elements for
AccountName and PAN with no attributes from the respective DataElement modified,
these can be accessed as follows in that script as follows:
// Assume that AccountName is specified as a DataElement element in
// the Application Profile and it has a Type attibute of
// ByteString, then the ByteString accountName can be created as:
accountName = this.data.AccountName;
// or alternatively using ECMAScript array by name capability
accountName = this.data[‘AccountName’];
// Assume that PAN is specified as a DataElement element in the
// Application Profile and it has a Type attibute of ByteString,
// and an encoding of HEX, then the ByteString object can
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 47
// be created as:
pan = this.data.PAN;
// or alternatively using ECMAScript array by name capability
pan = this.data[‘PAN’];
For DataElement elements (and the corresponding Declaration elements) in the Application
Profile which contain a Tag and a TagEncoding attribute, the resultant object created in the
GP scripting environment will be a TLV object. For example:
// Assume that Address is specified as a DataElement element in the
// Application Profile and it has a Type attibute of ByteString, an
// encoding of HEX, and has a Tag attribute of 0x1234 and a
// TagEncoding attribute of DGI, then the Tlv object address can be
// created as:
address = this.data.address;
// or alternatively using ECMAScript array by name capability
address = this.data[‘address’];
DataElement and Declaration XML elements in the ApplicationProfile are the only interface
to input and output data and parameters in the script environment. The following subsections
provide insight into how to handle the deserialization and subsequent manipulation of
DataElement XML elements in the script environment.
4.4.2.1 Impact of the ReadWrite Attribute on Deserialization
ReadWrite Attribute:
The ReadWrite attribute for a DataElement or Declaration will have an impact on how
the corresponding element of the this.data array can be manipulated by the script developer.
This is summarized in Table 4.3.
the this.data[]
property must be set to
an empty ByteString.
<DataElement Name=”data”
External=”true” Update=”true”>
value1 value2 value1
Step 2: Execute Script 1
<Declaration Name=”data”
External=”true” Update=”false”>
this.data.data = new ByteString(“value2”);
value1 value2 value2
Step 3: Execute Script 2
<Declaration Name=”data”
External=”true”>
<Declaration Name=”data”
External=”false” Update=”false”>
<Declaration Name=”data”
External=”true” Update=”true”>
this.data.data = new ByteString(“value2”);
value2 value3 value2
Script 4
<Declaration Name=”data”
External=”true”>
this.data.data = new ByteString(“value2”);
Table 4.5 - Example Successive Script Execution with Separate Runtime Contexts
Key XML elements occur at a higher hierarchical level of the Application Profile XML document
than do the KeyDeclaration elements, which are found at the same level as script code.
Although objects are created for every Key element, the KeyDeclaration element allows
specificity per script as to whether a key is provided externally or created within the script itself.
Runtime execution consistency is ensured by the fact that there is no constructor method for the
Key object, unlike the case for the DataElement and Declaration deserialization.
GPApplication
The GPApplication object represents a GP application and will be created if the
Application Profile specifies that the application Type is a GlobalPlatform application
(Type attribute has value GP) and the application Subtype is a GP compliant
application (Subtype attribute has value APP).
The establishment of a secure channel for a GP application is completed using a
single openSecureChannel() method call. Depending on the Security Domain
specified and the version of the GP platform on the smart card, either a GPScp01 or
GPScp02 secure channel object will be created. It is conceivable that the
GPApplication will be working with a non-GP card, in which case, a platform-
independent SecureChannel object is created.
GPSecurityDomain
The GPSecurityDomain object represents a GP security domain or card manager
application. This object will be created if the Application Profile specifies that the
application Type is a GlobalPlatform security domain or GlobalPlatform card
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 53
manager (Type attribute has value GP) and the application Subtype is a GP card
manager or security domain application (Subtype attribute has value CM or SD).
The establishment of a secure channel for a GP security domain, including card the
manager which is the issuer security domain, is completed using a single
openSecureChannel() method call. Depending on the security domain specified
and the GP secure channels supported on the smart card, either a GPScp01 or
GPScp02 secure channel object will be created.
The creation of a secure channel effectively affects the APDU commands which are sent to the
card. The design of the scripting objects is such that APDU commands for application type
objects (Application, GPApplication, and GPSecurityDomain) will be created according
to the requirements of the security domain. The APDU commands for the Card object remain
unaffected by the establishment of a secure channel, and can be utilized to ensure that APDU
commands are sent directly to the smart card without any alteration.
In the implementation of each of the APDU related commands for the application type objects,
confirmation of whether a secure channel is in existence needs to occur prior to constructing the
APDU and sending to the smart card.
Constant Usage
APPS_ONLY applications only
ASCII encoding value
BASE64 encoding value
CM_ONLY card manager only
CN encoding value
HEX encoding value
LF_ONLY load files only
LFE_ONLY load files and executables only
SC_CLOSE secure channel state
SC_INITIALIZE secure channel state
SC_OPEN secure channel state
UTF8 encoding value
Constant Usage
GPError.ACCESS_DENIED This property or method currently can’t be accessed.
GPError.INVALID_USAGE The key does not have the usage specified for the
operation specified.
GPError.SECURE_CHANNEL_WRONG_STATE The secure channel is not in the state expected for this
operation.
7.1.1 GPError
GPError is a native object in the GlobalPlatform Systems Scripting Language Specification
[GP_SYS_SCR]. In ECMAScript terminology, GPError is in effect a native and native object of
the GlobalPlatform scripting language which is available to all scripts at all times.
GPError objects are created when GlobalPlatform scripting language objects encounter an
exception.
7.1.1.1 Summary
GPError.ACCESS_DENIED
GPError.ARGUMENTS_MISSING
GPError.CARD_COMM_ERROR
GPError.CARD_INVALID_SW
GPError.CRYPTO_FAILED
GPError.DATA_TOO_LARGE
GPError.DEVICE_ERROR
GPError.INVALID_ARGUMENTS
GPError.INVALID_DATA
GPError.INVALID_ENCODING
GPError.INVALID_INDEX
GPError.INVALID_KEY
GPError.INVALID_LENGTH
GPError.INVALID_MECH
GPError.INVALID_TAG
GPError.INVALID_TYPE
GPError.INVALID_USAGE
GPError.KEY_NOT_FOUND
GPError.OBJECTCREATIONFAILED
GPError.SECURE_CHANNEL_WRONG_STATE
GPError.TAG_ALREADY_EXISTS
GPError.TAG_NOT_FOUND
GPError.UNDEFINED
GPError.UNSUPPORTED
GPError.USER_DEFINED
GPError.prototype.className
GPError.prototype.error
GPError.prototype.message
GPError.prototype.name
GPError.prototype.reason
GPError.prototype.constructor()
7.1.1.2 Constants
The error handling constants used by the GPError object are described in Section 0.
7.1.1.3 Properties
7.1.1.3.1 className
GPError.prototype.className String
The className property is an ECMAScript String object.
Name of the object which has generated the error condition. For example, if a Key object generated the error, the
className property should be Key.
GPError.prototype.error Number
The error property is an ECMAScript Number object.
The error property corresponds to the constant values defined for the GPError object.
7.1.1.3.3 message
GPError.prototype.message String
The message property is an ECMAScript String object.
Description of the error. This is an open text field.
7.1.1.3.4 name
GPError.prototype.name String
The name property is an ECMAScript String object.
The value of this property will always be “GPError”, and is ReadOnly.
7.1.1.3.5 reason
GPError.prototype.reason Number
The reason property is an ECMAScript Number object.
This is a property to place an implementation specific reason code for the error.
7.1.1.4 Methods
7.1.1.4.1 Constructor
GPError.prototype.constructor()
GPError new GPError(String className, Number error, Number reason, String message)
The constructor method for the GPError object can be used to construct a GPError object..
Example
sampleError = new GPError(“ByteString”, 0, 0, “An error with the ByteString”);
returns None
7.1.2 Crypto
In ECMAScript terminology, Crypto is in effect a native object of the GlobalPlatform scripting
language. The constants of this object are always available, and instances of the objects are
available through properties of the application type objects Application, GPApplication and
GPSecurityDomain. This means that no new Crypto objects can be created.
The Crypto object is responsible for performing cryptographic operations in scripts. There can
be several different cryptographic devices represented by different Crypto objects in a script
execution context. For example, the GPApplication.crypto property may refer to a different
cryptographic device than a GPApplication.card.crypto property.
7.1.2.1 Summary
Crypto.DES
Crypto.DES_CBC
Crypto.DES_CBC_LP
Crypto.DES_CBC_P
Crypto.DES_ECB
Crypto.DES_ECB_LP
Crypto.DES_ECB_P
Crypto.DES_MAC
Crypto.DES_MAC_EMV
Crypto.DES2
Crypto.ISO9797_METHOD_1
Crypto.ISO9797_METHOD_2
Crypto.MD5
Crypto.RSA
Crypto.SHA_1
Crypto.prototype.decrypt()
Crypto.prototype.decryptEncrypt()
Crypto.prototype.deriveKey()
Crypto.prototype.digest()
Crypto.prototype.encrypt()
Crypto.prototype.generateKey()
Crypto.prototype.generateKeyPair()
Crypto.prototype.generateRandom()
Crypto.prototype.sign()
Crypto.prototype.unwrap()
Crypto.prototype.unwrapWrap()
Crypto.prototype.verify()
Crypto.prototype.wrap()
7.1.2.2 Constants
Each of these constants must be assigned an unique value within the Crypto object.
Constant Usage
Crypto.DES Single length DES key for GenerateKey() method
Constant Usage
seven 0x00s
Variant of DES_ECB algorithm for wrap operations which
Crypto.DES_ECB_P will wrap key value + padding of 0x80 and up to seven
0x00s
Crypto.DES_MAC Sign and Verify methods
Full Triple DES MAC in GP Card Spec.
7.1.2.3 Properties
There are no properties for the Crypto object.
7.1.2.4 Methods
7.1.2.4.1 Constructor()
Crypto.prototype.constructor()
new Crypto()
new Crypto(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.2.4.2 decrypt()
Crypto.prototype.decrypt()
ByteString decrypt(Key value, Number mech, ByteString data)
ByteString decrypt(Key value, Number mech, ByteString data, ByteString iv)
Performs a decryption operation, using the key specified by the value parameter, and the algorithm specified by the
mech parameter. If the algorithm specified by the mech parameter requires an initial vector value, specifically the
algorithm Crypto.DES_CBC, the iv parameter will contain the initial vector. Otherwise it is ignored.
If the cryptographic device does not support certain values of mech, then an exception should be thrown.
Example
// myData will contain the value in dataToDecrypt decrypted using the
// sampleKey key, DES algorithm with CBC, and initial vector supplied
7.1.2.4.3 decryptEncrypt()
crypto.prototype.decryptEncrypt()
ByteString decryptEncrypt(Key decryptKey, Number decryptMech, Key encryptKey,
Number encryptMech, ByteString data)
ByteString decryptEncrypt(Key decryptKey, Number decryptMech, Key encryptKey,
Number encryptMech, ByteString data, ByteString decryptIV)
ByteString decryptEncrypt(Key decryptKey, Number decryptMech, Key encryptKey,
Number encryptMech, ByteString data, ByteString decryptIv,
ByteString encryptIV)
Performs a decryption operation using the key specified by the decryptKey parameter, the algorithm specified by the
decryptMech parameter, followed immediately by an encrypt operation using the key passed as encryptKey and the
mechanism passed as a encryptMech.
If the algorithm specified by the decryptMech property requires an initial value parameter, such as Crypto.DES_CBC
or Crypto.DES_EBC, the initial parameter is used as specified in decryptIV, otherwise it is ignored.
Also if the mechanism specified by the encryptMech parameter requires a parameter, the encryptIV parameter is
used, otherwise it is ignored.
Depending on the cryptographic device, certain combinations of decrypt algorithms and encrypt algorithms as specified
by the decryptMech and encryptMech parameters, respectively, may be incompatible. Likewise, certain algorithms
may not be supported at all by the cryptographic device. In both these cases, a GPError object should be thrown with a
vaule of GPError.INVALID_MECH.
If the cryptographic device does not support certain combinations of algorithm, then an exception should be thrown.
Example
// newData will contain the data produced in a decryption of the data
// in myData decrypted using the DES algorithm with ECB and the key
// myDecryptKey and a subsequent encryption of this result using the
// DES algorithm with ECB and the key myEncryptKey
myDecryptKey = this.key[“keyA”];
myEncryptKey = this.key[“keyB”];
myData = new ByteString(“0001020304050607”, HEX);
newData = this.crypto.decryptEncrypt(myDecryptKey, Crypto.DES_ECB,
encryptIV ByteString Initial vector to use for the encrypt operation if provided and
depending if Crypto.DES_CBC encryptMech value specified. If
provided and not required, this parameter will be ignored.
returns ByteString A new ByteString containing the result of the decrypt and
encrypt operations on data.
7.1.2.4.4 deriveKey()
Crypto.prototype.deriveKey()
deriveKey (Key masterKey, Number mech, ByteString data, Key derivedKey)
Derives the key derivedKey using the masterKey specified, and the algorithm specified by the mech parameter. The
data parameter is used to specify the diversification data to be used in the operation.
Example
myMasterKey = this.key[“masterKey”];
keyToDerive = this.key[“resultKey”];
myData = new ByteString(“0001020304050607”, HEX);
this.crypto.deriveKey(myMasterKey, Crypto.DES_ECB, myData, keyToDerive);
derivedKey Key Key object to derive. This parameter will be modified upon
successful execution of this method.
returns None
7.1.2.4.5 digest()
Crypto.prototype.digest()
ByteString digest(Number digestMech, ByteString data)
Creates a digest of the data specified, using the algorithm specified by the mech parameter
Example
// myDigest will contain the digest of myData using the MD5 algorithm
myData = new ByteString(“00010203”, HEX);
myDigest = this.crypto.digest (Crypto.MD5, myData);
7.1.2.4.6 encrypt()
Crypto.prototype.encrypt()
ByteString encrypt(Key value, Number mech, ByteString data)
ByteString encrypt(Key value, Number mech, ByteString data, ByteString iv)
Performs an encryption operation, using the key specified by the value parameter, the algorithm specified by the mech
parameter. If the algorithm specified by the mech parameter requires an initial vector, such as Crypto.DES_CBC, the
initial vector is provided. Otherwise, the iv, even if provided, is ignored.
If the cryptographic device does not support certain combinations of mech, then an exception should be thrown.
Example
// myData will contain the data specified in dataToEncrypt encrypted
// under the key sampleKey using the DES algorithm with CBC,
// and the initial vector value specified in initialVector
sampleKey = this.key[“keyA”];
dataToEncrypt = new ByteString(“0001020304050607”, HEX);
initialVector = new ByteString(“0000000000000000”, HEX);
myData = this.crypto.encrypt (sampleKey, Crypto.DES_CBC, dataToEncrypt,
initialVector);
7.1.2.4.7 generateKey()
Crypto.prototype.generateKey()
generateKey(Number mech, Key keyToGen)
Generates a secret key, using the algorithm specified by the mech parameter. The secret key to generate must already
exist as a key object. To ensure this, the key must be defined in the respective Application Profile for the script wishing
to use this method.
The features of the key to generate will have been specified by the Key Profile definition referenced by the key in the
Application Profile. The minimum feature is that the Key will have key generation as an allowed operation. As well, the
type of key must be compatible with the algorithm specified in the mech parameter.
Example
// The following operation will attempt to generate the key myKey using
// the DES algorithm.
myKey = this.key[“resultKey”];
generateKey(Crypto.DES, myKey);
returns None
7.1.2.4.8 generateKeyPair()
Crypto.prototype.generateKeyPair()
generateKeyPair(Number mech, Key publicKey, Key privateKey)
Generates a public/private key pair using the algorithm specified by the mech parameter and the key pair specified by
the publicKey and privateKey parameters. The two key parts to generate must already exist as Key objects. To
Example
// The following operation will generate the public key and private key
// components for the key parts keyPartA and keyPartB using the RSA
// algorithm.
keyPartA = this.key[“keyPartA”];
keyPartB = this.key[“keyPartB”];
generateKeyPair(Crypto.RSA, keyPartA, keyPartB);
returns None
7.1.2.4.9 generateRandom()
Crypto.prototype.generateRandom()
ByteString generateRandom(Number rdmLength);
Generates a string of random bytes of length specified
Example
// aRandomString will contain a randomly generated 12 byte field.
aRandomString = this.crypto.generateRandom(12);
7.1.2.4.10 sign()
Crypto.prototype.sign()
ByteString sign(Key signingKey, Number signingMech, ByteString data)
Example
// signedData will contain the data contained in myData signed using the
// RSA algorithm
mySigningKey = this.key[“keyA”];
myData = new ByteString(“00010203”, HEX);
signedData = this.crypto.sign (mySigningKey, Crypto.RSA, myData);
7.1.2.4.11 unwrap()
Crypto.prototype.unwrap()
unwrap(Key keyToUnwrap, Key keyResult)
Decrypts a previously wrapped key, implicitly using the wrap key Key object associated with the Key object specified for
keyToUnwrap. The algorithm required to unwrap the key and any required initial vector needs to be known by the
implementation of the scripting interpreter and/or associated key management system. The algorithm and initial vector
can be retrieved from the Key Profile for keyToUnwrap.
The key to unwrap must already exist as a Key object. To ensure this, the key must be defined in the respective
Application Profile for the script wishing to use this method.
The features of the key to unwrap will have been specified by the Key Profile definition referenced by the key in the
Application Profile. As well, the type of key must be compatible with the algorithm utilized by the scripting host
environment and/or key management system.
Example
// Wrap keyB with keyC using DES in ECB mode and place result in keyA
this.crypto.wrap(this.key[“keyC”], Crypto.DES_ECB, this.key[“keyB”], this.key[“keyA”]);
// Unwrap keyA and place in keyD
// The host environment knows that keyA has been wrapped by keyC using DES in ECB mode
this.crypto.unwrap(this.key[“keyA”], this.key[“keyD”]);
7.1.2.4.12 unwrapWrap()
Crypto.prototype.unwrapWrap()
unwrapWrap( Key wrapKey, Number wrapMech, Key keyToUW, Key keyResult)
unwrapWrap( Key wrapKey, Number wrapMech, Key keyToUW, Key keyResult, ByteString
wrapIV)
Unwraps the key specified in keyToUW using key returned by the getWrapKey() method of the keyToUW object, and
wraps the result using the key supplied in wrapKey, utilizing the algorithm specified by wrapMech. The algorithm
required to unwrap the key and any required initial vector needs to be known by the implementation of the scripting
interpreter and/or associated key management system. If the wrapMech algorithm requires an additional parameter, it
needs to be supplied as the ByteString wrapIV .
The key to unwrap and then wrap must already exist as a Key object. To ensure this, the key must be defined in the
respective Application Profile for the script wishing to use this method.
The features of the key to unwrap and then wrap will have been specified by the Key Profile definition referenced by the
key in the Application Profile. As well, the type of key must be compatible with the algorithms used for the unwrap and
wrap procedures.
If the wrapMech is specified as Crypto.DES_CBC_P, Crypto.DES_CBC_LP, Crypto.DES_EBC_P, or
Crypto.DES_EBC_LP, then the resultant getComponent() and setComponent() methods on the resultant keys will
retreive and set, respectively, the value which is modified as a result of this method invocation. For example, if
Crypto.DES_CBC_P is specified as the wrapMech, the resultant getComponent() on the wrapped key will return "key
value + padding".
Depending on the cryptographic device, certain combinations of unwrap algorithms and wrap algorithms, respectively,
may be incompatible. Likewise, certain algorithms may not be supported at all by the cryptographic device. In both
these cases, a GPError exception should be thrown.
Example
// Wrap keyB with keyC using DES in ECB mode and place result in keyA
this.crypto.wrap(this.key[“keyC”], Crypto.DES_ECB, this.key[“keyB”], this.key[“keyA”]);
// The host environment knows that keyA has been wrapped by keyC using DES in ECB mode
// Once the key has bee unwrapped, then it is subsequently wrapped using the key
// myWrapKey and the DES algorithm in ECB mode
wrapKey = this.key[“keyE”];
targetKey = this.key[“keyA”];
myWrappedKey = this.key[“keyD”];
this.crypto.unwrapWrap(myWrapKey, this.crypto.DES_ECB, targetKey, myWrappedKey, null);
// In effect, keyD will contain keyB wrapped with keyE (keyB wrapped with keyC then
// unwrapped with keyC and rewrapped with keyE)
keyResult Key The final result of the unwrapWrap operation on the keyToWU.
returns None
7.1.2.4.13 verify()
Crypto.prototype.verify()
Boolean verify(Key verifyKey, Number verifyMech, ByteString data,
ByteString signature)
Verifies that the signature specified is the correct signature for the data specified, using the key specified by
verifyKey, and the algorithm specified by verifyMech.
Example
// verifyResult will contain a true value if the signature created by
// applying the DES algorithm with MAC using the key myVerifyKey on the
// data in myData matches the value contained in signature
myVerifyKey = this.key[“keyA”];
mySigningKey = myVerifyKey;
myData = new ByteString(“00010203”, HEX);
mySignature = this.crypto.sign(mySigningKey, Crypto.DES_MAC, myData);
verifyResult = this.crypto.verify(myVerifyKey, Crypto.DES_MAC, myData,
mySignature);
7.1.2.4.14 wrap()
Crypto.prototype.wrap()
wrap(Key wrapKey, Number wrapMech, Key keyToWrap, key keyResult)
wrap(Key wrapKey, Number wrapMech, Key keyToWrap, Key keyResult, ByteString mechIV)
Example
// myKeyToWrap will be wrapped under the DES algorithm with ECB
// using the key myWrapKey
myWrapKey = this.key[“keyA”];
myKeyToWrap = this.key[“keyB”];
this.crypto.wrap(myWrapKey, Crypto.DES_ECB, myKeyToWrap, myKeyResult);
returns None
7.1.3 GPSystem
In ECMAScript terminology, GPSystem is in effect a native object of the GlobalPlatform scripting
language which is available to all scripts at all times. The GPSystem object is only available as
GPSystem and is not instantiable or created by any other methods.
GPSystem represents generic system functionality which may be available, depending on the
host environment’s capability, to all scripts.
7.1.3.1 Summary
GPSystem.dateTimeByteString()
GPSystem.getSystemID()
GPSystem.getVendorObject()
GPSystem.getVersion()
GPSystem.trace()
GPSystem.wait()
7.1.3.2 Constants
There are no constants for the GPSystem object.
7.1.3.3 Properties
There are no properties for the GPSystem object.
7.1.3.4 Methods
7.1.3.4.1 Constructor
GPSystem.prototype.constructor()
new GPSystem()
new GPSystem(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.3.4.2 dateTimeByteString()
GPSystem.dateTimeByteString()
ByteString dateTimeByteString()
Return a ByteString object containing the current date and time. The result will be seven bytes long, and will contain
the date and time formatted as follows:
Bytes 0 and 1: the year as four BCD digits, range 0x2001 to 0x9999.
Byte 2: the month as two BCD digits, range 0x01 to 0x12.
Byte 3: the day of the month as two BCD digits, range 0x01 to 0x31.
Byte 4: the hour as two BCD digits, range 0x00 to 0x23.
Byte 5: the minute as two BCD digits, range 0x00 to 0x59.
Byte 6: the second as two BCD digits, range 0x00 to 0x59.
Example
// returns in a 6 byte long ByteString object myDateTime the hexadecimal
// value 0x20010926124610 if the time at execution were 12:46:10
// on September 26, 2001.
myDateTime = GPSystem.dateTimeByteString();
returns ByteString A ByteString containing the date and time as described above.
exception None
7.1.3.4.3 getSystemID()
GPSystem.getSystemID()
ByteString getSystemID()
Returns the vendor dependent system ID value. Could be null if none available.
Example
myID = GPSystem.getSystemID();
exception
7.1.3.4.4 getVendorObject()
GPSystem.getVendorObject()
Object getVendorObject(String objectName)
Retrieve a vendor specific object specified by the parameter supplied in objectName. The advantage of this approach
over supplying vendor specific objects is that implementations do not have to check for supportability of vendor objects.
In particular, if an object isn’t found, a null could just be returned. Scripts need to be written to not rely on the presence
of vendor objects to ensure the greatest level of interoperability possible.
If the object is not implemented by the vendor, then a null is returned. The script writer should check to see if the
result of the method call is null before proceeding to use the vendor object returned in objectName.
Example
// If the vendor implemention offers a native object for “CPS Support”
// in its implementation of the GP scripting language, then the object
// CPSProcessing will map to this native object. This example shows
// that the vendor object returned possesses the method storeData to
// faciliate the processing of common personalization files. If the
// vendor object is not present, an alternate method of processing the
// common personalization file represented by myDGIStream will be used.
CPSProcessing = GPSystem.get
VendorObject("CPSSupport");
If (CPSProcessing <> null) CPSProcessing.storeData(myDGIStream)
else { // code to process myDGIStream }
7.1.3.4.5 getVersion()
GPSystem.getVersion()
String getVersion()
Retrieve as a String the version of GlobalPlatform scripting implemented by the scripting interpreter. This is not the
same as the version of the XML profiles. This latter information can be obtained by navigating the XML document for the
appropriate attribute.
This is the version of the specification being used by the interpreter when executing the script. For example, for a script
interpreter written to support this specification, the GPSystem.getVersion() method will return an ASCII encoded String
containing "1.1.0".
The version returned may contain a fourth number specifying the version of the errata implemented in the scripting
interpreter. If this fourth number is zero, then the original specification without any errata has been implemented. If this
number is not returned, the interpreter has implemented no errata for the specification.
Example
// Assume the version of the scripting language implemented by the
// interpreter is version 1.1.0
ScriptingVersion = GPSystem.getVersion();
// ScriptingVersion will contain the ASCII string “1.1.0”
// Likewise, if the interpreter supports version 1.1.0 with errata version 0.1 applied
ScriptingVersion = GPSystem.getVersion();
// ScriptingVersion will contain ASCII String "1.1.0.1"
exception None
7.1.3.4.6 trace()
GPSystem.trace()
Boolean trace(Object traceData)
Append data to vendor specific trace file as a String the value contained in the object specified by traceData using
the ECMAScript method toString().
The means in which trace() appends the data specified in the object is entirely vendor dependent. File access
operations for the trace file are handled by the vendor implementation of trace().
Example
// Log the value contained in dataToLog object to the trace file
7.1.3.4.7 wait()
GPSystem.wait()
wait(Number value)
Pause for a period of value milliseconds.
Example
// Pause script execution for 20 ms before proceeding with next script
// instruction
GPSystem.wait(20);
returns None
7.1.4 Application
Application is a native object used to represent the application, specifically a non-
GlobalPlatform application, for which the script is being run. When a script for the application is
being written, the application object is referred to as the this object.
As defined in the ECMAScript specification, native objects are present at the start of the
execution of an ECMAScript program.
An Application object should be created if in the Application Profile, the Type attribute of the
ApplicationInfo element has a non-GlobalPlatform value. For example,
<ApplicationInfo Type=”OTHER” />
The Application object implements methods providing support for platform independent
secure channel commands and a means to send APDUs. If a secure channel has been set for
the Application object, the APDU will be sent through the secure channel.
If a secure channel is opened for the Application object, then the resultant APDUs, except for
the select() method, sent from this object are affected as per the script provided in the Wrap
subelement of the Application Profile. Refer to Appendix C for an overview of which methods are
affected.
7.1.4.1 Summary
Application.prototype.aid
Application.prototype.card
Application.prototype.crypto
Application.prototype.data[]
Application.prototype.key[]
Application.prototype.lifeCycle.name
Application.prototype.lifeCycle.value
Application.prototype.order
Application.prototype.profile
Application.prototype.secureChannel
Application.prototype.openSecureChannel()
Application.prototype.select()
Application.prototype.sendApdu()
7.1.4.2 Constants
There are no constants for the Application object.
7.1.4.3 Properties
7.1.4.3.1 aid
Application.prototype.aid ByteString
The aid property is a GlobalPlatform scripting language ByteString object.
The aid property represents a ReadOnly, DontDelete property. It represents the application id of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then it will contain an empty value.
7.1.4.3.2 card
Application.prototype.card Card
The card property is a GlobalPlatform scripting language Card object.
The card property represents a ReadOnly, DontDelete property. Card object used by the application.
7.1.4.3.3 crypto
Application.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the application.
7.1.4.3.4 data[]
Application.prototype.data[] Object[]
The data property is an array of GlobalPlatform scripting language ByteString and/or TLV objects.
The Application object will be created with an array of objects which contains the deserialized data elements for an
Application Profile. Each object will be deseralized according to its type defined in the profile and with its name as an
index value. Refer to Section 4.4.2 for more information and examples.
The Type attribute in the DataElement element of the Application Profile determines the object type. The object type
is either a native GP scripting language or ECMAScript object. Specifically,
XML Application Profile DataElement Element GP Scripting Language
Type Attribute Encoding Attribute Scripting Object Created
ByteString HEX ByteString
ByteString UTF8 ByteString
ByteString ASCII ByteString
ByteString BASE64 ByteString
ByteString CN ByteString
ByteString TLV*
(and Tag and TagEncoding specified)
*with enough bytes to accommodate the Tag and the length of the data (if any) for the specified TagEncoding
Unless specified otherwise, this is a read only, don’t delete property. This property is an array of Objects for the
DataElement XML elements defined in the Application Profile. There is one element per DataElement element of
the Application Profile. The index value is the value of the Name attribute of a DataElement element. Each element
has it’s own attributes, based on the <DataElement> tag (i.e., an element can be ReadOnly or R/W depending of
the value of ReadWrite attribute in the profile) Note: a data object can also be retrieved by name using the . (dot)
notation.
7.1.4.3.5 key[]
Application.prototype.key[] Key[]
The key property is an array of GlobalPlatform scripting language Key objects.
The Application object will be created with an array of Key objects which contains the deserialized keys for an
Application Profile. Each key will be deseralized according to its name as its index. Refer to Section 4.4.3 for more
information and examples.
This is a ReadOnly, DontDelete property. This property is an array of Keys defined in the Application Profile. There is
one element per Key Tag of the application. The index value is the value of the Name attribute of a Key Tag. Note: a
Key can also be retrieved by name using the . (dot) notation.
Application.prototype.lifecycle.name ByteString
The lifecycle.name property is a GlobalPlatform scripting language ByteString object.
The lifecycle.name property represents a ReadOnly, DontDelete property. It represents the name of the lifecycle of
the application instance for the script being executed. It is populated from the ApplicationInstance subelement of
the Card Profile whose ProfileID matches the UniqueID of the current application profile. If it is not available or
applicable, then it will contain an empty value.
7.1.4.3.7 lifecycle.value
Application.prototype.lifecycle.value Number
The lifecycle.value property is a GlobalPlatform scripting language ByteString object.
The lifecycle.value property represents a ReadOnly, DontDelete property. It represents the value of the lifecycle
value of the application instance for the script being executed. It is populated from the Value property of the
ApplicationInfo.LifeCycle subelement of the Application Profile that matches the lifecycle.name property. If it
is not available or applicable, then it will contain an empty value.
7.1.4.3.8 order
Application.prototype.order Number
The order property is an ECMAScript Number object.
The order property represents a ReadOnly, DontDelete property. It represents the order on the card of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then its value will contain an empty valuebe undefined.
7.1.4.3.9 profile
Application.prototype.profile Object
The profile property is a tree of GlobalPlatform scripting language ByteString and ECMAScript Boolean and
Number objects.
The Application object will be created with a series of objects which replicate, except for Key,
KeyDeclararation, Declaration, and DataElement elements, the GlobalPlatform XML formatted Application
Profile for the application deserialized into a tree of objects. The root XML element of the Application Profile will form the
contents of this root Application.profile object. Refer to Section 4.4.1 for more information and examples.
The data type of the attribute determines the object type to create. The object type is a ByteString or a native
ECMAScript object. Specifically,
GP Systems Profiles Specification GP Scripting Language
XML Attribute Data Type Scripting Object Created
String (or String based Data Type) ByteString
Boolean Boolean
Integer Number
Elements in the XML which can have multiple occurences are created as arrays, which can be indexed by the name of
the first attribute of the element.
For elements which are specified as String data types in the Profiles specification, a ByteString object with the
encoding specified in the Encoding column in the Profiles specification will be created. For those attributes which are
enumerated lists of Strings, then they will be created as ByteString objects with ASCII encoding.
7.1.4.3.10 secureChannel
Application.prototype.secureChannel SecureChannel
7.1.4.4 Methods
7.1.4.4.1 Constructor
Application.prototype.constructor()
new Application()
new Application(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.4.4.2 openSecureChannel()
Application.prototype.openSecureChannel()
Object openSecureChannel(arguments)
Open a secure channel on the card. This method should call implicitly the OpenSecureChannel script fragment
defined in the Security Domain or equivalent Application Profile. Once the secure channel is opened, all APDU’s are
sent through the secure channel using the Wrap script specified in the Application Profile.
Example
mySC = this.openSecureChannel(...);
7.1.4.4.3 select()
Application.prototype.select()
ByteString select()
ByteString select(Boolean next, Boolean noData)
ByteString select(Boolean next, Number[] sw)
ByteString select(Boolean next, Boolean noData, Number[] sw)
Send a select APDU with the AID of the application (AID value is retrieved from the Card Profile). If a secure channel
exists, the select() method should implicitly reset the application’s secure channel security level. If the select()
method invocation is used without parameters, then the next parameter is assumed to be false.
The select() method is used for selecting an application. This refers to the [IS7816-4] SELECT command.
Example
this.select(true);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.4.4.4 sendApdu()
Application.prototype.sendApdu()
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)
Send an APDU to the card. If the application doesn’t use a secure channel the APDU is sent to the card directly (i.e.
same as Application.card.sendApdu()). If the application uses a secure channel, this method should call
implicitly the Wrap script fragment defined in the appropriate Application Profile for a Security Domain unless Card
Specification defined secure channels and implementation options are used. The APDU field Lc is not specified in the
sendApdu() method, but must be calculated by the method implicitly (see [IS7816-4]).
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
responseAPDU = this.sendApdu(sampleCLA, sampleINS, sampleP1, sampleP2);
// A sendApdu() method sends a command APDU message to the smart card
returnSW = this.card.SW;
// Retrieve the status word returned from the command APDU
p1 Number P1 parameter.
p2 Number P2 parameter.
data ByteString Optional data field to use with an APDU. This will be a ByteString
object. If a Case 2 command is being constructed, this must be
provided as null.
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.5 GPApplication
GPApplication is a native object used to represent the GlobalPlatform application, where that
application is not a Security Domain or a Card Manager application, for which the script is being
run. When a script for the application is being written, the GPApplication object is referred to
as the this object.
As defined in the ECMAScript specification, native objects are present at the start of the
execution of an ECMAScript program.
A GPApplication object should be created if in the Application Profile, the Type and
SubType attributes of the ApplicationInfo element has a value of “GP” and “APP”
respectively:
<ApplicationInfo Type=“GP” SubType=”APP” />
The GPApplication object implements methods, which support the APDUs in the
GlobalPlatform Card Specification v2.1, and also supplies several additional functions, helping
simplify repetitive or common operations involving these GlobalPlatform APDUs. If a secure
channel exists, the APDU methods will be sent through the secure channel.
The methods and associated properties which represent the commands found in the APDU
Command Reference of the GlobalPlatform Card Specification v2.1 are not extensively
elaborated in this document as to the values to use for properties and which CLA byte to use. It
is expected that the reader understand in which context the method is being used, and format
and supply the properties as required by the GlobalPlatform Card Specification v2.1.
Furthermore, it is expected that an implementation of a GlobalPlatform scripting Interpreter will
make decisions based on what is required by the GlobalPlatform Card Specification v2.1. These
decisions would include which CLA byte to use, where appropriate, whether the supplied property
values are valid, and which additional fields must be populated and or calculated in order for the
command to properly function.
7.1.5.1 Summary
GPApplication.prototype.aid
GPApplication.prototype.appSpecificInstallParams
GPApplication.prototype.card
GPApplication.prototype.crypto
GPApplication.prototype.data[]
GPApplication.prototype.key[]
GPApplication.prototype.lifeCycle.name
GPApplication.prototype.lifeCycle.value
GPApplication.prototype.nonVolatileDataSpaceLimit
GPApplication.prototype.order
GPApplication.prototype.privilege
GPApplication.prototype.profile
GPApplication.prototype.securityDomain
GPApplication.prototype.volatileDataSpaceLimit
GPApplication.prototype.getData()
GPApplication.prototype.getStatus()
GPApplication.prototype.putKey()
GPApplication.prototype.select()
GPApplication.prototype.sendApdu()
GPApplication.prototype.setStatus()
GPApplication.prototype.storeData()
7.1.5.2 Constants
There are no constants for the GPApplication object.
7.1.5.3 Properties
7.1.5.3.1 aid
GPApplication.prototype.aid ByteString
The aid property is a GlobalPlatform scripting language ByteString object.
The aid property represents a ReadOnly, DontDelete property. It represents the application id of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then it will contain an empty value.
7.1.5.3.2 appSpecificInstallParams
GPApplication.prototype.appSpecificInstallParams ByteString
The appSpecificInstallParams property is a GlobalPlatform scripting language ByteString object.
The appSpecificInstallParams property represents a ReadOnly, DontDelete property. It represents the install
parameters used in the install command for the application instance for the script being executed. It is populated from
the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it will be undefined.
7.1.5.3.3 card
GPApplication.prototype.card Card
The card property is a GlobalPlatform scripting language Card object.
A ReadOnly, DontDelete property. Card object used by the application.
7.1.5.3.4 crypto
GPApplication.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the application.
7.1.5.3.5 data[]
GPApplication.prototype.data[] Object[]
7.1.5.3.6 key[]
GPApplication.prototype.key[] Key[]
The key property is an array of GlobalPlatform scripting language Key objects.
The GPApplication object will be created with an array of Key objects which contains the deserialized keys for an
Application Profile. Each key will be deseralized according to its name as its index. Refer to Section 4.4.3 for more
information and examples.
This is a ReadOnly, DontDelete property. This property is an array of Keys defined in the Application Profile. There is
one element per Key Tag of the application. The index value is the value of the Name attribute of a Key Tag.Note: a Key
can also be retrieved by name using the . (dot) notation.
7.1.5.3.7 lifecycle.name
GPApplicationProfile.prototype.lifecycle.name ByteString
The lifecycle.name property is a GlobalPlatform scripting language ByteString object.
The lifecycle.name property represents a ReadOnly, DontDelete property. It represents the name of the lifecycle of
the application instance for the script being executed. It is populated from the ApplicationInstance subelement of
the Card Profile whose ProfileID matches the UniqueID of the current application profile. If it is not available or
applicable, then it will contain an empty value.
7.1.5.3.8 lifecycle.value
GPApplicationProfile.prototype.lifecycle.value Number
The lifecycle.value property is a GlobalPlatform scripting language ByteString object.
The lifecycle.value property represents a ReadOnly, DontDelete property. It represents the value of the lifecycle
value of the application instance for the script being executed. It is populated from the Value property of the
ApplicationInfo.LifeCycle subelement of the Application Profile that matches the lifecycle.name property. If it
is not available or applicable, then it will contain an empty value.
GPApplication.prototype.nonVolatileDataSpaceLimit Number
The nonVolatileDataSpaceLimit property is a ECMAScript Number object.
The nonVolatileDataSpaceLimit property represents a ReadOnly, DontDelete property. It represents the amount
of non-volatile data space specified in the install operation for the application instance for the script being executed. It is
populated from the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it
will be undefined.
7.1.5.3.10 order
GPApplicationProfile.prototype.order Number
The order property is an ECMAScript Number object.
The order property represents a ReadOnly, DontDelete property. It represents the order on the card of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then it will be undefined.
7.1.5.3.11 privilege
GPApplication.prototype.privilege Number
The privilege property is a GlobalPlatform scripting language Number object.
The privilege property represents a ReadOnly, DontDelete property. It represents the application privileges of the
application instance for the script being executed. Its value will be a hexadecimal encoding of the Privilege child
element of the respective ApplicationInstance element in the Card Profile. Each attribute in the Privilege
element represents a particular byte representation of the privilege property corresponding to the application privileges
coding set forth in the GP Card Specification Version 2.1. Multiple attributes will correspond to the property taking the
value of the logical OR of the specific byte representations associated with each privilege. If there is no Privilege child
element available for the respective ApplicationInstance element, then this property will contain an empty value.
7.1.5.3.12 profile
GPApplication.prototype.profile Object
The profile property is a tree of GlobalPlatform scripting language ByteString and ECMAScript Boolean and
Number objects.
The GPApplication object will be created with a series of objects which replicate, except for Key,
KeyDeclaration, Declaration, and DataElement elements, the GlobalPlatform XML formatted Application
Profile for the application deserialized into a tree of objects. The root XML element of the Application Profile will form the
contents of this root GPApplication.profile object. Refer to Section 4.4.1 for more information and examples.
The data type of the attribute determines the object type to create. The object type is a ByteString or a native
ECMAScript object. Specifically,
GP Systems Profiles Specification GP Scripting Language
XML Attribute Data Type Scripting Object Created
String (or String based Data Type) ByteString
Boolean Boolean
Integer Number
Elements in the XML which can have multiple occurences are created as arrays, which can be indexed by the name of
the first attribute of the element.
For elements which are specified as String data types in the Profiles specification, a ByteString object with the
encoding specified in the Encoding column in the Profiles specification will be created. For those attributes which are
enumerated lists of string, then they will be created as ByteString objects with ASCII encoding.
GPApplication.prototype.securityDomain GPSecurityDomain
The securityDomain property is a GlobalPlatform scripting language GPSecurityDomain object.
A ReadOnly, DontDelete property. Object that represents the security domain application for which the specified
application was installed under (information retrieved from the CardProfile).
7.1.5.3.14 volatileDataSpaceLimit
GPApplication.prototype.volatileDataSpaceLimit Number
The volatileDataSpaceLimit property is a ECMAScript Number object.
The volatileDataSpaceLimit property represents a ReadOnly, DontDelete property. It represents the amount of
volatile data space specified in the install operation for the application instance for the script being executed. It is
populated from the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it
will be undefined.
7.1.5.4 Methods
7.1.5.4.1 Constructor
GPApplication.prototype.constructor()
new GPApplication()
new GPApplication(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.5.4.2 getData()
GPApplication.prototype.getData()
ByteString getData(Number tag)
ByteString getData(Number tag, Number[] sw)
Send a GP GET DATA APDU through the secure channel.
If the application uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
This refers to both the GlobalPlatform GET DATA command.
Any exception thrown by the script provided in the Security Domain’s Wrap element is forwarded.
Example
this.getData(myTagValue);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.5.4.3 getStatus()
GPApplication.prototype.getStatus()
ByteString getStatus(Number type, ByteString criteria, Boolean next)
ByteString getStatus(Number type, ByteString criteria, Boolean next,
Number[] sw)
Send a GP GET STATUS APDU through the secure channel.
If the application uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
This refers to the GlobalPlatform GET STATUS command.
Any exception thrown by the script provided in the Security Domain’s Wrap element is forwarded.
Example
this.getStatus(APPS_ONLY, searchQualifier, false);
Parameter Type Description
type Number p1 is the reference control parameter as specified in the Card
Specification:
CM_ONLY Card Manager Only
APPS_ONLY Applications Only
LF_ONLY Load File Only
LFE_ONLY Load Files and All Executable Files
criteria ByteString AID of the criteria. Could be a partial AID.
next Boolean Whether the next occurrence should be returned. Default is false.
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.5.4.4 putKey()
GPApplication.prototype.putKey()
Example
dataToEncrypt = new ByteString("0000000000000000", HEX);
keyCheckValue = this.crypto.encrypt(this.key.sampleKey, Crypto.DES_ECB, dataToEncrypt);
keyInfo1 = [0x81, this.key.sampleKey, keyCheckValue];
keyInfo = [keyInfo1];
this.putKey(0, 1, 1, keyInfo);
newVersion Number Value of the new key set version (see GP Card specification)
index Number Value of the key index as specified in the Control parameter P2 (see
GP Card specification)
more Boolean A Boolean value, to indicate if it’s the last or only putKey call. The
default value is false. That value will implicitly change the P1
control parameter of the APDU (for more details see GP card
specification).
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.5.4.5 select()
GPApplication.prototype.select()
ByteString select()
ByteString select(Boolean next)
ByteString select(Boolean next, Boolean noData)
ByteString select(Boolean next, Number[] sw)
ByteString select(Boolean next, Boolean noData, Number[] sw)
Send a GP Select APDU (0x00 0xA4 0x04 …) with the AID of the application (AID value is retrieved from the Card
Profile). The select() method should implicitly reset the application’s secure channel security level. If select()
method invocation is used, then the next parameter is assumed to be false.
The select() method is used for selecting an application. This refers to the [IS7816-4] SELECT command.
Example
this.select(true);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.5.4.6 sendApdu()
GPApplication.prototype.sendApdu()
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)
Send an APDU to the card. If the application doesn’t use a secure channel the APDU is sent to the card directly (i.e.
same as Application.card.sendApdu()). If the application uses a secure channel, this method should call
implicitly the Wrap script fragment defined in the Security Domain or equivalent Application Profile unless Card
Specification defined secure channels and implementation options are used. The APDU field Lc is not specified in the
sendApdu() method, but must be calculated by the method implicitly (see [IS7816-4]).
Any exception thrown by the script provided in the Security Domain’s Wrap element is forwarded.
Example
responseAPDU = this.sendApdu(sampleCLA, sampleINS, sampleP1, sampleP2);
// A sendApdu() method sends a command APDU message to the smart card
returnSW = this.card.SW;
// Retrieve the status word returned from the command APDU
ins Number ins refers to the instruction byte (INS) of the command message.
p1 Number P1 parameter.
p2 Number P2 parameter.
data ByteString Optional data field to use with an APDU. This will be a ByteString
object. If a Case 2 command is being constructed, this must be
provided as null.
7.1.5.4.7 setStatus()
GPApplication.prototype.setStatus()
setStatus(Number status)
setStatus(Number status, Number[] sw)
Send a GP SET STATUS APDU through the secure channel. The method should implicitly create the correct APDU for
the P1 parameter (Card Manager or Application) and the Data field (AID of the instance).
If the application uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
Security Domain or equivalent Application Profile.
This refers to the GlobalPlatform SET STATUS command.
Any exception thrown by the script provided in the Security Domain’s Wrap element is forwarded.
Example
// Assume that 0x01 is a valid lifecycle state as defined in the
// Application Profile
this.setStatus(0x01);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
returns None
GPApplication.prototype.storeData()
storeData(ByteString data)
storeData(ByteString data, Boolean last)
storeData(ByteString data, Boolean last, Number[] sw)
Send a GP STORE DATA APDU through the secure channel. This method should be implemented in any case, even if
the targeted card is not a GlobalPlatform 2.1 card.
The storeData() method is used to transfer data to an application, and if a secure channel is available, through the
secure channel. This refers to the GlobalPlatform STORE DATA command.
If the application uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
Any exception thrown by the script provided in the Security Domain’s Wrap element is forwarded.
Example
this.storeData(MORE_BLOCKS, x11, dataToStore);
last Boolean A Boolean value, to indicate if it’s the last or only storeData call.
The default value is false. That value will implicitly change the P1
control parameter of the APDU (for more details see GP card
specification 2.1).
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
returns None
7.1.6 GPSecurityDomain
GPSecurityDomain is a native object used to represent the application for the script being run
when the application is a GlobalPlatform security domain or a card manager. For scripts written
for an application which is a security domain or card manager, the GPSecurityDomain is
accessed using the this object.
As defined in the ECMAScript specification, native objects are present at the start of the
execution of an ECMAScript program.
A GPSecurityDomain object should be created if in the Application Profile the Type and
SubType attributes of the ApplicationInfo element have values of “GP” and “CM” or “SD”,
respectively:
<ApplicationInfo Type=“GP” SubType=”CM” />
or
The GPSecurityDomain object implements methods which support the APDUs in the
GlobalPlatform Card Specification and also supplies several additional functions, helping simplify
repetitive or common operations involving these GlobalPlatform APDUs. The
GPSecurityDomain object inherits the properties and methods of the Application object,
and adds several APDU functions as defined in the GlobalPlatform Card Specification for load
and install operations. If a secure channel exists, APDU commands are sent through the secure
channel.
The methods and associated properties which represent the commands found in the APDU
Command Reference of the GlobalPlatform Card Specification are not extensively elaborated in
this document as to the values to use for properties and which CLA byte to use. It is expected
that the reader understand in which context the method is being used, and format and supply the
properties as required by the GlobalPlatform Card Specification.
Furthermore, it is expected that an implementation of an GlobalPlatform scripting interpreter will
make decisions based on what is required by the GlobalPlatform Card Specification. These
decisions would include which CLA byte to use, where appropriate, whether the supplied property
values are valid, and which additional fields must be populated and or calculated in order for the
command to properly function.
7.1.6.1 Summary
GPSecurityDomain.prototype.aid
GPSecurityDomain.prototype.appSpecificInstallParams
GPSecurityDomain.prototype.card
GPSecurityDomain.prototype.crypto
GPSecurityDomain.prototype.data[]
GPSecurityDomain.prototype.key[]
GPSecurityDomain.prototype.lifeCycle.name
GPSecurityDomain.prototype.lifeCycle.value
GPSecurityDomain.prototype.nonVolatileDataSpaceLimit
GPSecurityDomain.prototype.order
GPSecurityDomain.prototype.privilege
GPSecurityDomain.prototype.profile
GPSecurityDomain.prototype.secureChannel
GPSecurityDomain.prototype.securityDomain
GPSecurityDomain.prototype.volatileDataSpaceLimit
GPSecurityDomain.prototype.deleteAID()
GPSecurityDomain.prototype.getData()
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 93
GPSecurityDomain.prototype.getStatus()
GPSecurityDomain.prototype.installForExtradition()
GPSecurityDomain.prototype.installForInstall()
GPSecurityDomain.prototype.installForInstallAndSelectable()
GPSecurityDomain.prototype.installForLoad()
GPSecurityDomain.prototype.installForPersonalization()
GPSecurityDomain.prototype.load()
GPSecurityDomain.prototype.loadByName()
GPSecurityDomain.prototype.loadWithProfileID()
GPSecurityDomain.prototype.openSecureChannel()
GPSecurityDomain.prototype.putKey()
GPSecurityDomain.prototype.select()
GPSecurityDomain.prototype.sendApdu()
GPSecurityDomain.prototype.setStatus()
GPSecurityDomain.prototype.storeData()
7.1.6.2 Constants
There are no constants for the GPSecurityDomain object.
7.1.6.3 Properties
7.1.6.3.1 aid
GPSecurityDomain.prototype.aid ByteString
The aid property is a GlobalPlatform scripting language ByteString object.
The aid property represents a ReadOnly, DontDelete property. It represents the application id of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then it will contain an empty value.
7.1.6.3.2 appSpecificInstallParams
GPSecurityDomain.prototype.appSpecificInstallParams ByteString
The appSpecificInstallParams property is a GlobalPlatform scripting language ByteString object.
The appSpecificInstallParams property represents a ReadOnly, DontDelete property. It represents the install
parameters used in the install command for the application instance for the script being executed. It is populated from
the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it will be undefined.
7.1.6.3.3 card
GPSecurityDomain.prototype.card Card
The card property is a GlobalPlatform scripting language Card object.
The card object represents a ReadOnly, DontDelete property. Card object used by the security domain.
7.1.6.3.4 crypto
GPApplication.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the application.
7.1.6.3.5 data[]
GPSecurityDomain.prototype.data[] Object[]
7.1.6.3.6 key[]
GPSecurityDomain.prototype.key[] Key[]
The key property is an array of GlobalPlatform scripting language Key objects.
The GPSecurityDomain object will be created with an array of Key objects which contains the deserialized keys for an
Application Profile. Each key will be deseralized according to its name as its index. Refer to Section 4.4.3 for more
information and examples.
This is a ReadOnly, DontDelete property. This property is an array of Keys defined in the Application Profile. There is
one element per Key Tag of the application. The index value is the value of the Name attribute of a Key Tag.Note: a
Key can also be retrieved by using the . (dot) notation.
7.1.6.3.7 lifecycle.name
GPSecurityDomain.prototype.lifecycle.name ByteString
The lifecycle.name property is a GlobalPlatform scripting language ByteString object.
The lifecycle.name property represents a ReadOnly, DontDelete property. It represents the name of the lifecycle of
the application instance for the script being executed. It is populated from the ApplicationInstance subelement of
the Card Profile whose ProfileID matches the UniqueID of the current application profile. If it is not available or
applicable, then it will contain an empty value.
7.1.6.3.8 lifecycle.value
GPSecurityDomain.prototype.lifecycle.value Number
The lifecycle.value property is a GlobalPlatform scripting language ByteString object.
The lifecycle.value property represents a ReadOnly, DontDelete property. It represents the value of the lifecycle
value of the application instance for the script being executed. It is populated from the Value property of the
ApplicationInfo.LifeCycle subelement of the Application Profile that matches the lifecycle.name property. If it
is not available or applicable, then it will contain an empty value.
GPSecurityDomain.prototype.nonVolatileDataSpaceLimit Number
The nonVolatileDataSpaceLimit property is a ECMAScript Number object.
The nonVolatileDataSpaceLimit property represents a ReadOnly, DontDelete property. It represents the amount
of non-volatile data space specified in the install operation for the application instance for the script being executed. It is
populated from the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it
will be undefined.
7.1.6.3.10 order
GPSecurityDomain.prototype.order Number
The order property is an ECMAScript Number object.
The order property represents a ReadOnly, DontDelete property. It represents the order on the card of the application
instance for the script being executed. It is populated from the ApplicationInstance subelement of the Card Profile.
If it is not available or applicable, then it will be undefined.
7.1.6.3.11 privilege
GPSecurityDomain.prototype.privilege Number
The privilege property is a GlobalPlatform scripting language Number object.
The privilege property represents a ReadOnly, DontDelete property. It represents the application privileges of the
application instance for the script being executed. Its value will be a hexadecimal encoding of the Privilege child
element of the respective ApplicationInstance element in the Card Profile. Each attribute in the Privilege
element represents a particular byte representation of the privilege property corresponding to the application privileges
coding set forth in the GP Card Specification Version 2.1. Multiple attributes will correspond to the property taking the
value of the logical OR of the specific byte representations associated with each privilege. If there is no Privilege child
element available for the respective ApplicationInstance element, then this property will contain an empty value.
7.1.6.3.12 profile
GPSecurityDomain.prototype.profile Object
The profile property is a tree of GlobalPlatform scripting language ByteString and ECMAScript Boolean and
Number objects.
The GPSecurityDomain object will be created with a series of objects which replicate, except for Key,
KeyDeclaration, Declaration, and DataElement elements, the GlobalPlatform XML formatted Application
Profile for the application deserialized into a tree of objects. The root XML element of the Application Profile will form the
contents of this root GPSecurityDomain.profile object. Refer to Section 4.4.1 for more information and examples.
The data type of the attribute determines the object type to create. The object type is a ByteString or a native
ECMAScript object. Specifically,
GP Systems Profiles Specification GP Scripting Language
XML Attribute Data Type Scripting Object Created
String (or String based Data Type) ByteString
Boolean Boolean
Integer Number
Elements in the XML which can have multiple occurences are created as arrays, which can be indexed by the name of
the first attribute of the element.
For elements which are specified as String data types in the Profiles specification, a ByteString object with the
encoding specified in the Encoding column in the Profiles specification will be created. For those attributes which are
enumerated lists of string, then they will be created as ByteString objects with ASCII encoding.
7.1.6.3.14 securityDomain
GPSecurityDomain.prototype.securityDomain GPSecurityDomain
The securityDomain property is a GlobalPlatform scripting language GPSecurityDomain object.
A ReadOnly, DontDelete property. Object that represents the current Security Domain application (information retrieved
from the Card Profile). If the GPSecurityDomain represents the issuer security domain (card manager), then this
property will point to this GPSecurityDomain object.
7.1.6.3.15 volatileDataSpaceLimit
GPSecurityDomain.prototype.volatileDataSpaceLimit Number
The volatileDataSpaceLimit property is a ECMAScript Number object.
The volatileDataSpaceLimit property represents a ReadOnly, DontDelete property. It represents the amount of
volatile data space specified in the install operation for the application instance for the script being executed. It is
populated from the ApplicationInstance subelement of the Card Profile. If it is not available or applicable, then it
will be undefined.
7.1.6.4 Methods
7.1.6.4.1 Constructor
GPSecurityDomain.prototype.constructor()
new GPSecurityDomain()
new GPSecurityDomain(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.6.4.2 deleteAID()
GPSecurityDomain.prototype.deleteAID()
ByteString deleteAID(ByteString aid)
ByteString deleteAID(ByteString aid, Number[] sw)
Example
this.deleteAID(myAID);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.3 getData()
GPSecurityDomain.prototype.getData()
ByteString getData(Number tag)
ByteString getData(Number tag, Number[] sw)
Send a GP GET DATA APDU through the secure channel.
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
This refers to both the GlobalPlatform GET DATA command.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
this.getData(myTagValue);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.4 getStatus()
GPSecurityDomain.prototype.getStatus()
Example
this.getStatus(APPS_ONLY, searchQualifier, false);
Parameter Type Description
type Number p1 is the reference control parameter as specified in the Card
Specification:
CM_ONLY Card Manager Only
APPS_ONLY Applications Only
LF_ONLY Load File Only
LFE_ONLY Load Files and All Executable Files
next Boolean Whether the next occurrence should be returned. Default is false.
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.5 installForExtradition()
GPSecurityDomain.prototype.installForExtradition()
ByteString installForExtradition(ByteString secDomAID, ByteString appAID,
ByteString token)
ByteString installForExtradition(ByteString secDomAID, ByteString appAID,
ByteString token, Number[] SW)
Send a GP INSTALL APDU through the secure channel with P1 set to FOR_EXTRADITION (see GP Card specification
for more details).
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
this.installForExtradition(mySDAID, myLFAID, myToken);
sw Number[] Array of expected valid SW for the APDU. If not present, the
7.1.6.4.6 installForInstall()
GPSecurityDomain.prototype.installForInstall()
ByteString installForInstall(ByteString execLFAID,
ByteString execModAID,
ByteString appInsAID,
ByteString privileges,
ByteString installParam,
ByteString installToken)
ByteString installForInstall(ByteString execLFAID,
ByteString execModAID,
ByteString appInsAID,
ByteString privileges,
ByteString installParam,
ByteString installToken,
Number [] sw)
Send a GP INSTALL APDU through the secure channel with P1 set to FOR_INSTALL.
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
this.installForInstall(myLFAID, myModAID, myInsAID, myPrivileges, myParam, myToken);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.7 installForInstallAndSelectable()
GPSecurityDomain.prototype.installForInstallAndSelectable()
Example
this.installForInstallAndSelectable(myLFAID, myModAID, myInsAID, myPrivileges, myParam,
myToken);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.8 installForLoad()
GPSecurityDomain.prototype.installForLoad()
ByteString installForLoad(ByteString loadFileAID, ByteString secDomAID,
ByteString loadDBHash, ByteString loadParam,
ByteString loadToken)
ByteString installForLoad(ByteString loadFileAID, ByteString secDomAID,
ByteString loadDBHash, ByteString loadParam,
ByteString loadToken, Number[] SW)
Example
this.installForLoad(myLFAID, mySecDomAID, myLoadHash, myLoadParam, myLoadToken);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.9 installForPersonalization()
GPSecurityDomain.prototype.installForPersonalization()
installForPersonalization(ByteString appAID)
installForPersonalization(ByteString appAID, Number[] sw)
Send a GP INSTALL APDU through the secure channel with P1 set to FOR_PERSONALIZATION.
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
this.installForPersonalization(myAID);
Parameter Type Description
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.10 load()
GPSecurityDomain.prototype.load()
Example
// myFileContents will contain a CAP file represented as a hexadecimal
// encoded ByteString. load() will load the file onto the smart card.
myFileContents = new ByteString(“504B03040A000000000007008C2C0…”, HEX);
this.load(myFileContents);
[[aid, dap]] [[ ByteString, Each element [ aid, dap ] represents a “DAP block”, where:
ByteString ]]
· aid is a ByteString for the Security Domain AID value
· dap is a ByteString for the Load File Data Block Signature
value
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.11 loadByName()
GPSecurityDomain.prototype.loadByName()
ByteString loadByName(ByteString filename)
ByteString loadByName(ByteString filename, [ ByteString[] [aid, dap]])
Example
// Load a file named sampleApplication.cap onto the smart card
loadFileName = new ByteString(“sampleApplication.cap”, ASCII);
this.loadByName(loadFileName);
[[aid, dap]] [[ ByteString, Each element [ aid, dap ] represents a “DAP block”, where:
ByteString ]]
· aid is a ByteString for the Security Domain AID value
· dap is a ByteString for the Load File Data Block Signature
value
returns ByteString Response APDU (excluding status word)
7.1.6.4.12 loadWithProfile()
GPSecurityDomain.prototype.loadWithProfile()
ByteString loadWithProfile(ByteString loadFileProfileID)
ByteString loadWithProfile(ByteString loadFileProfileID, Number[] sw)
ByteString loadWithProfile(ByteString loadFileProfileID, [ ByteString[] [aid, dap]])
ByteString loadWithProfile(ByteString loadFileProfileID, [ ByteString[] [aid, dap]],
Number[] sw)
Example
// myFileContents will contain a CAP file represented as a hexadecimal
// encoded ByteString. loadWithProfile() will load the file onto the smart card.
myFileContents = new ByteString(“504B03040A000000000007008C2C0…”, HEX);
this.loadWithProfile(myFileContents);
[[aid, dap]] [[ ByteString, Each element [ aid, dap ] represents a “DAP block”, where:
ByteString ]]
· aid is a ByteString for the Security Domain AID value
· dap is a ByteString for the Load File Data Block Signature
value
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.13 openSecureChannel()
GPSecurityDomain.prototype.openSecureChannel()
Number openSecureChannel(Number level)
Number openSecureChannel(Number level, Number version)
Number openSecureChannel(Number level, Number version, Number index)
Open a secure channel with the Issuer Security Domain. This method should call implicitly the OpenSecureChannel
script fragment defined in the Issuer Security Domain Application Profile. Once the secure channel is opened, all
APDU’s are sent through the secure channel. It is the responsibility of Issuer Security Domain script fragment to set all
keys needed to manage the secure channel and sessions (Encryption, MACing, KEK).
Once the secure channel is opened, all APDU’s are sent through the secure channel using the Wrap script specified in
the Application Profile, if a Wrap script is provided. For cases where the secure channel is represented by a GPScp01
or GPScp02, and a Wrap script is provided, then the Wrap script takes precedence over the implicit processing of a
GPScp01 or GPScp02 secure channel.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
// Opens a secure channel with level of zero.
mySC = this.openSecureChannel(0);
returns Number If success, return the Level of security selected for the secure
channel. If the security level requested is invalid or to low, the
Security Domain script fragment could choose to raise an exception
or change itself the value to a valid security level.
7.1.6.4.14 putKey()
GPSecurityDomain.prototype.putKey()
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number type, Key key, ByteString kcv] ])
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number type, Key key, ByteString kcv] ], Number[] sw)
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number type, Key key, ByteString kcv] ],
Boolean more)
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number type, Key key, ByteString kcv] ],
Boolean more, Number[] sw)
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number keyType, Key key, Number componentCte] ])
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number keyType, Key key, Number componentCte] ], Number[] sw)
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number keyType, Key key, Number componentCte] ],
Boolean more)
ByteString putKey(Number version, Number newVersion, Number index,
[ [Number keyType, Key key, Number componentCte] ],
Boolean more, Number[] sw)
Send a GP PUT KEY APDU through the secure channel. This method should implicitly encrypt key(s) with the card
KEK
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
dataToEncrypt = new ByteString("0000000000000000", HEX);
keyCheckValue = this.crypto.encrypt(this.key.sampleKey, Crypto.DES_ECB, dataToEncrypt);
keyInfo1 = [0x81, this.key.sampleKey, keyCheckValue];
keyInfo = [keyInfo1];
this.putKey(0, 1, 1, keyInfo);
newVersion Number Value of the new key set version (see GP Card specification)
more Boolean A Boolean value, to indicate if it’s the last or only putKey call. The
default value is false. That value will implicitly change the P1 control
parameter of the APDU (for more details see GP card specification).
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.15 select()
GPSecurityDomain.prototype.select()
ByteString select()
ByteString select(Boolean next)
ByteString select(Boolean next, Boolean noData)
ByteString select(Boolean next, Number[] sw)
ByteString select(Boolean next, Boolean noData, Number[] sw)
Send a GP Select APDU (0x00 0xA4 0x04 …) with the AID of the application (AID value is retrieved from the Card
Profile). The select() method should implicitly reset the application’s secure channel security level.
The select() method is used for selecting an application. This refers to the [IS7816-4] SELECT command.
Example
this.select(true);
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
7.1.6.4.16 sendApdu()
GPSecurityDomain.prototype.sendApdu()
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)
Send an APDU to the card. If the security domain doesn’t use a secure channel the APDU is sent to the card directly
(i.e. same as Application.card.sendApdu()). If the security domain uses a secure channel, this method should
call implicitly the Wrap script fragment defined in the Security Domain or equivalent Application Profile unless Card
Specification defined secure channels and implementation options are used. The APDU field Lc is not specified in the
sendApdu method, but must be calculated by the method implicitly (see [IS7816-4]).
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
responseAPDU = this.sendApdu(sampleCLA, sampleINS, sampleP1, sampleP2);
// A sendApdu() method sends a command APDU message to the smart card
returnSW = this.card.SW;
// Retrieve the status word returned from the command APDU
p1 Number P1 parameter.
p2 Number P2 parameter.
data ByteString Optional data field to use with an APDU. This will be a ByteString
object. If a Case 2 command is being constructed, this must be
provided as null.
7.1.6.4.17 setStatus()
GPSecurityDomain.prototype.setStatus()
setStatus(ByteString aid, Number status)
setStatus(ByteString aid, Number status, Number[] sw)
Send a GP SET STATUS APDU through the secure channel. The method should implicitly create the correct APDU for
the P1 parameter (Card Manager or Application).
If the security domain uses a secure channel, this method should call implicitly the Wrap script fragment defined in the
appropriate Application Profile for a Security Domain.
This refers to the GlobalPlatform SET STATUS command.
Any exception thrown by the script provided in a Wrap element is forwarded.
Example
// This will set the status of the application to GP state PERSONALIZED
this.setStatus(myPaymentApplicationAID, 0x7F);
status Number A Life Cycle Status Coding value (as defined in the GP Card
specification). Valid values should be retrieved from the Application
Profile in the LifeCycles element.
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
returns None
7.1.6.4.18 storeData()
GPSecurityDomain.prototype.storeData()
Example
this.storeData(MORE_BLOCKS, x11, dataToStore);
more Boolean A Boolean value, to indicate if it’s the last or only storeData call.
The default value is false. That value will implicitly change the P1
control parameter of the APDU (for more details see GP card
specification 2.1).
sw Number[] Array of expected valid SW for the APDU. If not present, the
expected valid value is 0x9000.
returns None
7.1.7 SecureChannel
A SecureChannel object is a native object. A SecureChannel object is used to perform
transformation (like MACing, Encryption) on an APDU based on a security level, specifically for
those instances where the secure channel is not a standard GlobalPlatform secure channel or
one which is not supported by another scripting language object (i.e., GPScp01 and GPScp02 as
per GlobalPlatform Card Specification 2.1). The transformation of the APDU must be done only
when the APDU is sent by an Application object. Sending an APDU using the card property
of one of those objects, will never perform any transformation on the APDU (execpt the
calculation of the Lc field). Refer to Appendix C for more detail.
For this object to be successfully created, the SecureChannel element of the Application
Profile must be fully populated. That is, there needs to be OpenSecureChannel,
CloseSecureChannel and Wrap elements contain the requisite scripts present. This is in
order to facilitate the correct operation of the secure channel related methods in the respective
Application or GPApplication object.
7.1.7.1 Summary
SecureChannel.prototype.crypto
SecureChannel.prototype.state
7.1.7.2 Constants
There are no constants for the SecureChannel object.
7.1.7.3 Properties
7.1.7.3.1 crypto
SecureChannel.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the secure channel.
7.1.7.3.2 state
SecureChannel.prototype.state Number
The state property is an ECMAScript Number object.
This is a Number. ReadOnly, DontDelete property. Current state of the secure channel, as specified using one of the
following global constants:
· SC_CLOSE
· SC_OPEN
7.1.8 GPScp01
A GPScp01 object is a native object. The GPScp01 object is an implementation of the Secure
Channel Protocol 01 described in the GP Card Specification.
A GPScp01 object is used to perform transformation (like MACing, Encryption) on an APDU
based on a security level as specified in the GlobalPlatform Card Specification. The
transformation of the APDU must be done only when the APDU is sent by an GPApplication
or GPSecurityDomain object. Sending an APDU using the card property of one of those
objects, will never perform any transformation on the APDU (execpt the calculation of the Lc
field). Refer to Appendix C for more detail.
The KEK key used is known by the secure channel.
7.1.8.1 Summary
GPScp01.prototype.cardChallenge
GPScp01.prototype.cardCryptogram
GPScp01.prototype.crypto
GPScp01.prototype.diversificationData
GPScp01.prototype.hostChallenge
GPScp01.prototype.keyIndex
GPScp01.prototype.keyVersion
GPScp01.prototype.mac
GPScp01.prototype.option
GPScp01.prototype.securityLevel
GPScp01.prototype.state
GPScp01.prototype.decryptEncryptKek()
GPScp01.prototype.encryptKek()
GPScp01.prototype.externalAuthenticate()
GPScp01.prototype.getDekKey()
GPScp01.prototype.initializeUpdate()
GPScp01.prototype.setDekKey()
GPScp01.prototype.setEncKey()
GPScp01.prototype.setMacKey()
GPScp01.prototype.unwrapWrapKek()
7.1.8.2 Constants
There are no constants for the GPScp01 object.
7.1.8.3 Properties
7.1.8.3.1 cardChallenge
GPScp01.prototype.cardChallenge ByteString
The cardChallenge property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Card challenge value for the secure channel.
7.1.8.3.2 cardCryptogram
GPScp01.prototype.cardCryptogram ByteString
The cardCryptogram property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Card cryptogram returned by the InitializeUpdate APDU.
GPScp01.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the secure channel.
7.1.8.3.4 diversificationData
GPScp01.prototype.diversificationData ByteString
The diversificationData property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Diversification data returned by the InitializeUpdate APDU.
7.1.8.3.5 hostChallenge
GPScp01.prototype.hostChallenge ByteString
The hostChallenge property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Host challenge used for the InitializeUpdate APDU.
7.1.8.3.6 keyIndex
GPScp01.prototype.keyIndex Number
The keyIndex property is an ECMAScript Number object.
ReadOnly, DontDelete property. Key index returned by the InitializeUpdate APDU or the value of the keyIndex
parameter in the constructor.
7.1.8.3.7 keyVersion
GPScp01.prototype.keyVersion Number
The keyVersion property is an ECMAScript Number object.
ReadOnly, DontDelete property. Key version returned by the InitializeUpdate APDU or the value of the keyVersion
parameter in the constructor.
7.1.8.3.8 mac
GPScp01.prototype.mac ByteString
The mac property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Current value of the MAC in a session
7.1.8.3.9 option
GPScp01.prototype.option Number
The option property is an ECMAScript Number object.
ReadOnly, DontDelete property. Implementation option for the secure channel.
GPScp01.prototype.securityLevel Number
The securityLevel property is an ECMAScript Number object.
ReadOnly, DontDelete property. Current security level of the secure channel as defined in the Card Specification.
7.1.8.3.11 state
GPScp01.prototype.state Number
The state property is an ECMAScript Number object.
ReadOnly, DontDelete property. Current state of the secure channel, as specified using one of the following global
constants:
· SC_CLOSE
· SC_INITIALIZE (InitializeUpdate APDU sucessfully executed)
· SC_OPEN
7.1.8.4 Methods
7.1.8.4.1 Constructor
GPSCp01.prototype.constructor()
new GPSCp01()
new GPSCp01(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.8.4.2 decryptEncryptKek()
GPScp01.prototype.decryptEncryptKek()
ByteString decryptEncryptKek(Key decryptKey, Number decryptMech, ByteString data)
ByteString decryptEncryptKek(Key decryptKey, Number decryptMech, ByteString data,
ByteString decryptIV)
Performs a decryption operation using the key specified by the decryptKey parameter, the algorithm specified by the
decryptMech parameter, followed immediately by an encrypt operation using the KEK key and the parameters
specified by the secure channel. The mechanism, and keys for the encrypt operation are known by the secure
channel.
For GlobalPlatform 2.0.1 cards, the only valid algorithm to use is DES in ECB mode (Crypto.DES_ECB).
If the algorithm specified by the decryptMech property requires an initial value parameter, such as Crypto.DES_CBC
or Crypto.DES_CBC_PAD, the initial parameter is used as specified in decryptInitial, otherwise it is ignored.
If the secure channel is not open, then a GPError exception with value GPError.SECURE_CHANNEL_WRONG_STATE is
generated.
Example
decryptIV ByteString Initial vector to use for the decrypt operation if provided and
depending if required by the algorithm specified by the
decryptMech parameter.
returns ByteString A new ByteString containing the result of the decrypt and
encrypt operations on data.
7.1.8.4.3 encryptKek()
GPScp01.prototype.encryptKek()
ByteString encryptKek(ByteString data)
Performs an encryption operation using the KEK key, using the parameters specified by the secure channel object. The
mechanism, padding, and keys are known by the secure channel.
Note that for GlobalPlatform 2.1 cards, the algorithm information required for this encryption operation can be retrieved.
However, for GlobalPlatform 2.0.1 cards, the only valid algorithm to use is DES in ECB mode.
If the secure channel is not open, then a GPError exception with value GPError.SECURE_CHANNEL_WRONG_STATE is
generated.
Example
mySecureChannel.encryptKek(dataToEncrypt);
7.1.8.4.4 externalAuthenticate()
GPScp01.prototype.externalAuthenticate()
externalAuthenticate(Number level)
Send a GP ExternalAuthenticate APDU and update the properties affected. This method should internally generate a
Host cryptogram and calculate the MAC before sending the APDU.
If the host cryptogram or MAC generation fails during execution of this command, then a GPError object with a value of
GPError.CRYPTO_FAILED is generated.
Example
myGPScp01.externalAuthenticate(1);
returns None
7.1.8.4.5 getDekKey()
GPScp01.prototype.getDekKey()
getDekKey(Key dekKey)
Get the Data Encryption key (DEK).
Example
myGPScp01.getDekKey(myDekKey);
returns None
exception None
7.1.8.4.6 initializeUpdate()
GPScp01.prototype.initializeUpdate()
ByteString initializeUpdate(Number keyVersion, Number keyIndex)
Send a GP InitializeUpdate APDU and update the properties affected.
Example
myGPScp01.initializeUpdate (myKeyVersion, myKeyIndex);
7.1.8.4.7 setDekKey()
GPScp01.prototype.setDekKey()
setDekKey(Key dekKey)
Assign the Data Encryption key (DEK)
Example
returns None
7.1.8.4.8 setEncKey()
GPScp01.prototype.setEncKey()
setEncKey(Key encKey)
Assign the Secure Channel Encryption key
Example
myGPScp01.setEncKey(myEncryptionKey);
returns None
7.1.8.4.9 setMacKey()
GPScp01.prototype.setMacKey()
setMacKey(Key macKey)
Assign the Secure Channel MAC verification key.
Example
myGPScp01.setMacKey(myMACKey);
returns None
7.1.8.4.10 unwrapWrapKek()
GPScp01.prototype.unwrapWrapKek()
unwrapWrapKek( Key keyToUW, Key keyResult)
Performs an unwrapWrap crypto operation using the session key as the wrap key. The unwrap key to use in defined in
the Key object keyToWU, and is accessible using the getWrapKey() method on this object. The wrap key to use is the
secure session KEK.
The Key Management System and/or scripting host environment will know the algorithm necessariy in order to unwrap
the key. For GlobalPlatform 2.0.1 cards, the only valid algorithm to use is DES in ECB mode.
Example
myGPScp01.unwrapWrapKek(myKey, myKeyResult);
keyResult Key The final result of the unwrapWrap operation on the keyToWU.
returns None
7.1.9 GPScp02
A GPScp02 object is a native object. The GPScp02 object is an implemetation of the Secure
Channel Protocol 02 described in the GlobalPlatform Card specification v2.1.
A GPScp02 object is used to perform transformation (like MACing, Encryption) on an APDU
based on a security level as specified in the GlobalPlatform Card Specification. The
transformation of the APDU must be done only when the APDU is sent by an GPApplication
or GPSecurityDomain object. Sending an APDU using the card property of one of those
objects, will never perform any transformation on the APDU (execpt the calculation of the Lc
field).
The KEK key used is known by the secure channel.
7.1.9.1 Summary
GPScp02.prototype.cardChallenge
GPScp02.prototype.cardCryptogram
GPScp02.prototype.crypto
GPScp02.prototype.diversificationData
GPScp02.prototype.hostChallenge
GPScp02.prototype.keyVersion
GPScp02.prototype.option
GPScp02.prototype.rmac
GPScp02.prototype.securityLevel
GPScp02.prototype.sequenceCounter
GPScp02.prototype.smac
GPScp02.prototype.state
GPScp02.prototype.beginRMac()
GPScp02.prototype.decryptEncryptDek()
GPScp02.prototype.encryptDek()
GPScp02.prototype.endRMac()
GPScp02.prototype.externalAuthenticate()
GPScp02.prototype.getDekKey()
GPScp02.prototype.initializeUpdate()
GPScp02.prototype.setBaseKey()
GPScp02.prototype.setDekKey()
GPScp02.prototype.setEncKey(()
GPScp02.prototype.setMacKey()
GPScp02.prototype.unwrapWrapDek()
7.1.9.2 Constants
There are no constants for the GPScp02 object.
7.1.9.3 Properties
7.1.9.3.1 cardChallenge
GPScp02.prototype.cardChallenge ByteString
The cardChallenge property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Card challenge value for the secure channel.
7.1.9.3.2 cardCryptogram
GPScp02.prototype.cardCryptogram ByteString
7.1.9.3.3 crypto
GPScp02.prototype.crypto Crypto
The crypto property is a GlobalPlatform scripting language Crypto object.
A ReadOnly, DontDelete property. Crypto object used by the secure channel.
7.1.9.3.4 diversificationData
GPScp02.prototype.diversificationData ByteString
The diversificationData property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Diversification data returned by the InitializeUpdate APDU.
7.1.9.3.5 hostChallenge
GPScp02.prototype.hostChallenge ByteString
The hostChallenge property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Host challenge used for the InitializeUpdate APDU.
7.1.9.3.6 keyVersion
GPScp02.prototype.keyVersion Number
The keyVersion property is an ECMAScript Number object.
ReadOnly, DontDelete property. Key version returned by the InitializeUpdate APDU or the value of the keyVersion
parameter in the constructor.
7.1.9.3.7 option
GPScp02.prototype.option Number
The option property is an ECMAScript Number object.
ReadOnly, DontDelete property. Implementation option for the secure channel.
7.1.9.3.8 rmac
GPScp02.prototype.rmac ByteString
The rmac property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Current R-MAC value.
7.1.9.3.9 securityLevel
GPScp02.prototype.securityLevel Number
The securityLevel property is an ECMAScript Number object.
ReadOnly, DontDelete property. Current security level of the secure channel as defined in the Card Specification.
GPScp02.prototype.sequenceCounter Number
The sequenceCounter property is an ECMAScript Number object.
ReadOnly, DontDelete property. Sequence Counter returned by the InitializeUpdate APDU
7.1.9.3.11 smac
GPScp02.prototype.smac ByteString
The smac property is a GlobalPlatform scripting language ByteString object.
ReadOnly, DontDelete property. Current S-MAC value.
7.1.9.3.12 state
GPScp02.prototype.state Number
The state property is an ECMAScript Number object.
ReadOnly, DontDelete property. Current state of the secure channel, as specified using one of the following global
constants:
· SC_CLOSE
· SC_INITIALIZE (InitializeUpdate APDU successfully executed)
· SC_OPEN
· SC_RMAC
7.1.9.4 Methods
7.1.9.4.1 Constructor
GPScp02.prototype.constructor()
new GPScp02()
new GPScp02(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.9.4.2 beginRMac()
GPScp02.prototype.beginRMac()
beginRMac(Number level)
beginRMac(Number level, ByteString data)
Send a GP BeginRMac APDU.
Example
myGPScp02.beginRMac(levelRequested);
returns None
7.1.9.4.3 decryptEncryptDek()
GPScp02.prototype.decryptEncryptDek()
ByteString decryptEncryptDek(Key decryptKey, Number decryptMech, ByteString data)
ByteString decryptEncryptDek(Key decryptKey, Number decryptMech, ByteString data,
ByteString decryptIV)
Performs a decryption operation using the key specified by the decryptKey parameter, the algorithm specified by the
decryptMech parameter, followed immediately by an encrypt operation using the KEK key and the parameters
specified by the secure channel. The mechanism, and keys for the encrypt operation are known by the secure
channel.
Note that for GlobalPlatform 2.1 cards, the algorithm information required for the encryption operation can be retrieved.
If the algorithm specified by the decryptMech property requires an initial value parameter, such as Crypto.DES_CBC
or Crypto.DES_CBC_PAD, the initial parameter is used as specified in decryptInitial, otherwise it is ignored.
Example
mySecureChannel.decryptEncryptDek(myDecryptKey, this.crypto.DES_ECB,
myData);
decryptIV ByteString Initial vector to use for the decrypt operation if provided and
depending if required by the algorithm specified by the
decryptMech parameter.
returns ByteString A new ByteString containing the result of the decrypt and
encrypt operations on data.
7.1.9.4.4 encryptDek()
GPScp02.prototype.encryptDek()
ByteString encryptDek(ByteString data)
Performs an encryption operation using the KEK key, using the parameters specified by the secure channel object. The
mechanism, padding, and keys are known by the secure channel.
Note that for GlobalPlatform 2.1 cards, the algorithm information required for this encryption operation can be retrieved.
Example
myGPScp02.encryptDek(dataToEncrypt);
7.1.9.4.5 endRMac()
GPScp02.prototype.endRMac()
ByteString endRMac()
Send a GP EndRMac. This method should implictly calculate the C-MAC if needed.
Example
myGPScp02.endRMac();
7.1.9.4.6 externalAuthenticate()
GPScp02.prototype.externalAuthenticate()
externalAuthenticate(Number level)
Send a GP ExternalAuthenticate APDU and update the properties affected. This method should internaly generate a
Host cryptogram and calculate the MAC before sending the APDU.
If the host cryptogram or MAC generation fails during execution of this command, then a GPError object with a value of
GPError.CRYPTO_FAILED is generated.
Example
myGPScp02.externalAuthenticate(1);
returns None
GPScp02.prototype.getDekKey()
getDekKey(Key dekKey)
Get the Data Encryption key (DEK).
Example
myGPScp02.getDekKey(myDekKey);
returns None
exception None
7.1.9.4.8 initializeUpdate()
GPScp02.prototype.initializeUpdate()
ByteString initializeUpdate(Number keyVersion, Number keyIndex)
Send a GP InitializeUpdate APDU and updates the affected properties
Example
myGPScp02.initializeUpdate (myKeyVersion, myKeyIndex);
7.1.9.4.9 setBaseKey()
GPScp02.prototype.setBaseKey()
setBaseKey(Key baseKey)
Assign the Secure Channel Base key
Example
myGPScp02.setBaseKey(myEncryptionKey);
returns None
7.1.9.4.10 setDekKey()
GPScp02.prototype.setDekKey()
setDekKey(Key dekKey)
Assign the Data Encryption key (DEK)
Example
myGPScp02.setDekKey(myDEKKey);
returns None
7.1.9.4.11 setEncKey()
GPScp02.prototype.setEncKey()
setEncKey(Key encKey)
Assign the Secure Channel Encryption key
Example
myGPScp02.setEncKey(myEncryptionKey);
returns None
7.1.9.4.12 setMacKey()
GPScp02.prototype.setMacKey()
setMacKey(Key macKey)
Assign the Secure Channel MAC verification key.
Example
myGPScp02.setMacKey(myMACKey);
returns None
7.1.9.4.13 unwrapWrapDek()
GPScp02.prototype.unwrapWrapDek()
unwrapWrapDek(Key keyToUW, Key keyResult)
Performs an unwrapWrap crypto operation using the session key as the wrap key. The unwrap key to use in defined in
the Key object keyToWU, and is accessible using the getWrapKey() method on this object. The wrap key to use is the
secure session KEK.
The Key Management System and/or scripting host environment will know the algorithm necessariy in order to unwrap
the key. Note that for GlobalPlatform 2.1 cards, the algorithm information required for this encryption operation can be
retrieved.
Example
myGPScp02.unwrapWrapDek(myKey, myKeyResult);
keyResult Key The final result of the unwrapWrap operation on the keyToWU.
returns None
7.1.10 Card
Card is a native object used to represent the target smart card for the current personalization
script.
The response, SW, SW1 and SW2 properties will return information about the response APDU
regardless of from which method the APDU was sent.
7.1.10.1 Summary
Card.OTHER
Card.PICCA
Card.PICCB
Card.RESET_COLD
Card.RESET_WARM
Card.T0
Card.T1
Card.T14
Card.prototype.profile
Card.prototype.response
Card.prototype.SW
Card.prototype.SW1
Card.prototype.SW2
Card.prototype.baudRate()
Card.prototype.clock()
Card.prototype.powerDown()
Card.prototype.pps()
Card.prototype.reset()
Card.prototype.sendApdu()
Card.prototype.vcc()
7.1.10.2 Constants
Each of these constants must be assigned an unique value within the Card object.
Constant Usage
7.1.10.3 Properties
7.1.10.3.1 profile
Card.prototype.profile Object
Elements in the XML which can have multiple occurences are created as arrays, which can be indexed by the name of
the first attribute of the element.
For elements which are specified as String data types in the Profiles specification, a ByteString object with the
encoding specified in the Encoding column in the Profiles specification will be created. For those attributes which are
enumerated lists of string, then they will be created as ByteString objects with ASCII encoding.
7.1.10.3.2 response
Card.prototype.response ByteString
The response property is a GlobalPlatform scripting language ByteString object.
This contains in a ByteString object the response value of the most recent command APDU sent to the smart card.
The command APDU could have been sent using the methods from an object other than the Card object.
Specifically, this is the response APDU data less the status word.
If no card was previously reset, or no status word was received since the card was reset, its value is a null value.
This is a ReadOnly property.
7.1.10.3.3 SW
Card.prototype.SW Number
The SW property is an ECMAScript Number object.
Contains the status word of the command APDU most recently sent to the smart card. The command APDU could have
been sent using the methods from an object other than the Card object.
Specifically, this is the two status word bytes of the most recently executed command APDU as a Number.
If no card was previously reset, or no status word was received since the card was reset, its value is a null value.
This is a ReadOnly property.
7.1.10.3.4 SW1
Card.prototype.SW1 Number
The SW1 property is an ECMAScript Number object.
Contains the first byte of the status word of the command APDU most recently sent to the smart card. The command
APDU could have been sent using the methods from an object other than the Card object.
st
Specifically, this is the 1 status word byte of the most recently executed command APDU as a Number.
If no card was previously reset, or no status word was received since the card was reset, its value is a null value.
This is a ReadOnly property.
Card.prototype.SW2 Number
The SW2 property is an ECMAScript Number object.
Contains the second status word byte of the command APDU most recently sent to the smart card. The command
APDU could have been sent using the methods from an object other than the Card object.
nd
Specifically, this is the 2 status word byte of the most recently executed command APDU as a Number.
If no card was previously reset, or no status word was received since the card was reset, its value is a null value.
This is a ReadOnly property.
7.1.10.4 Methods
7.1.10.4.1 Constructor
Card.prototype.constructor()
new Card()
new Card(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.10.4.2 baudRate()
card.prototype.baudRate()
Boolean baudRate (Number value)
Set the baud rate in bps for the card object.
Example
this.card.baudRate(9600);
7.1.10.4.3 clock()
card.prototype.clock()
Example
this.card.clock(3571000); // set the clock speed to 3.571x MHz
7.1.10.4.4 powerDown()
card.prototype.powerDown()
Boolean powerDown()
Power down and logically eject the card, which may or may not imply physical ejection of the card. Unless the card is
physically removed and reinserted into the device, any subsequent method on this card object will fail upon execution.
Example
myCard.powerDown(); // logically eject the card
Parameter Type Description
None
exception None
7.1.10.4.5 pps()
card.prototype.pps()
Boolean pps(Number protocol)
Boolean pps(Number protocol, Number f, Number d)
Set the physical protocol for the card. The GP scripting language provides support for contact smart cards through
ISO7816. Other proprietary protocols can be supported, but depend on support by the environment implementing the
GP scripting language.
If the method executes successfully, then a true Boolean value is returned. Otherwise, if the parameters are valid,
but the environment cannot execute the method for the smart card represented by card, then a false value is
returned.
If invalid values (i.e., values not specified in this specification or values not supported by the environment) for any of the
parameters protocol, f, or d are provided, then a GPError object is generated with GPError.INVALID_DATA value.
Example
// On a card with a contact interface
this.card.pps(Card.T1, myFrequency, myDivisor);
// returns false value if the card doesn’t support T=1 protocol
7.1.10.4.6 reset()
card.prototype.reset()
Atr reset(Number resetMode)
Send a reset to the card.
If the reset attempt fails, a GPError object with a value of GPError.CARD_COMM_ERROR will be generated.
Example
sampleAtr = this.card.reset(Card.RESET_WARM); // perform a warm reset
7.1.10.4.7 sendApdu()
card.prototype.sendApdu()
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)
Send an APDU to the target smart card. The APDU is sent directly to the smart card regardless of whether a secure
channel exists or not.
Example
this.card.sendApdu(sampleCLA, sampleINS, sampleP1, sampleP2);
responseAPDU = this.card.response;
// A sendApdu() method sends a command APDU message to the smart card
returnSW = this.card.SW;
// Retrieve the status word returned from the command APDU
ins Number ins refers to the instruction byte (INS) of the command message.
p1 Number P1 parameter.
p2 Number P2 parameter.
data ByteString Optional data field to use with an APDU. This will be a ByteString
object. If a Case 2 command is being constructed, this must be
provided as null.
7.1.10.4.8 vcc()
card.prototype.vcc()
Boolean vcc(Number value)
Set the Vcc in mV for the card object. An exception will be thrown if the parameter value is invalid.
Example
this.card.vcc(5000);
// set the vcc to 5.0 V
7.1.11 Key
Key is a native object used to represent the keys defined in the Application Profile. Key objects
are created using information from the Key Profile and are named according to the name
specified in the Key XML element in the Application Profile.
Only the values not defined when the key is created can be modified by the set methods. Values
which are provided in the key or Key Profile cannot be modified using the set method. Note that
the set methods do not necessarily alter the contents of the Key Profile XML document; they
only alter contents of the Key object in the script execution context. However, a GP Scripting
Language implementation may decide or even require updates to the Key Profile based on
modifications to a key within a script.
7.1.11.1 Summary
Key.CRT_DP1
Key.CRT_DQ1
Key.CRT_P
Key.CRT_PQ
Key.CRT_Q
Key.DES
Key.EIGHTZEROS
Key.EXPONENT
Key.EXPORTABLE
Key.DECRYPT
Key.DECRYPT_ENCRYPT
Key.DERIVE
Key.ENCRYPT
Key.IMPORTABLE
Key.MODULUS
Key.PRIVATE
Key.PUBLIC
Key.SECRET
Key.SENSITIVE
Key.SIGN
Key.UNWRAP
Key.UNWRAP_WRAP
Key.VERIFY
Key.WRAP
Key.prototype.getAttribute()
Key.prototype.getComponent()
Key.prototype.getEnd()
Key.prototype.getKcv()
Key.prototype.getOwner()
Key.prototype.getProfileID()
Key.prototype.getSize()
Key.prototype.getStart()
Key.prototype.getType()
Key.prototype.getUsage()
Key.prototype.getVersion
Key.prototype.getWrapKey()
Key.prototype.setAttribute()
Key.prototype.setComponent()
Key.prototype.setEnd()
Key.prototype.setOwner()
Key.prototype.setSize()
Key.prototype.setStart()
Key.prototype.setType()
Key.prototype.setUsage()
Key.prototype.setVersion()
7.1.11.2 Constants
Each of these constants must be assigned an unique value within the Key object.
For the constants used for the setUsage() and getUsage() methods, these must be unique
values which are combinable with the logical OR function in order to produce another unique
value which enables the developer to confirm an individual usage is present or not present in the
Usage attribute. This is necessary in order to support Key objects with more then one usage
specified in the Usage attribute.
Constant Usage
Key.CRT_DP1 getComponent() and setComponent()
Key.CRT_DQ1 getComponent() and setComponent()
Key.CRT_P getComponent() and setComponent()
Key.CRT_PQ getComponent() and setComponent()
Key.CRT_Q getComponent() and setComponent()
Key.DECRYPT setUsage() and getUsage() methods
Key.DECRYPT_ENCRYPT setUsage() and getUsage() methods
Key.DERIVE setUsage() and getUsage() methods
Key.DES getComponent() and setComponent()
Key.EIGHTZEROS getKcv() method
Key.ENCRYPT setUsage() and getUsage() methods
Key.EXPONENT getComponent() and setComponent()
Key.EXPORTABLE getAttribute() and setAttribute()
Key.IMPORTABLE getAttribute() and setAttribute()
Key.MODULUS getComponent() and setComponent()
Key.PRIVATE type methods
Key.PUBLIC type methods
Key.SECRET type methods
Key.SENSITIVE getAttribute() and setAttribute()
Key.SIGN setUsage() and getUsage() methods
Key.UNWRAP setUsage() and getUsage() methods
Key.UNWRAP_WRAP setUsage() and getUsage() methods
Key.VERIFY setUsage() and getUsage() methods
Key.WRAP setUsage() and getUsage() methods
7.1.11.3 Properties
There are no properties for the Key object.
7.1.11.4 Methods
7.1.11.4.1 Constructor
Key.prototype.constructor()
new Key()
new Key(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.11.4.2 getAttribute()
Key.prototype.getAttribute()
Number getAttribute()
Retrieve the attribute value for the Key. In the XML, this is the Attribute subelement of the KeyProfile element.
Example
// If the sampleKey has the attributes set to indicate that the key is both exportable
// and importable, then the resultant keyAttribute below will contain a logical OR of
// the Key.EXPORTABLE and Key.IMPORTABLE constants.
keyAttribute = sampleKey.getAttribute();
7.1.11.4.3 getComponent()
Key.prototype.getComponent()
ByteString getComponent(Number type)
Retrieve a component, as specified by the type parameter, for the Key. This value is populated either upon creation of
the Key object in the script environment or is determined at time of method invocation.
Example
// Assume my sampleKey is a public key
myPublicExponent = sampleKey.getComponent(Key.EXPONENT);
7.1.11.4.4 getEnd()
Key.prototype.getEnd()
ByteString getEnd()
Retrieve the End Date value for the Key. In the XML, this can be found in the KeyInfo subelement of the KeyProfile
element.
Example
myDate = sampleKey.getEnd();
returns ByteString A new ByteString containing the date in the format YYYYMMDD
in ASCII.
exception None
7.1.11.4.5 getKcv()
Key.prototype.getKcv()
ByteString getKcv(Number kcvAlgo)
Retrieve the key check value value for the Key. This value is populated either upon creation of the Key object in the
script environment or is determined at time of method invocation.
Example
myKcv = sampleKey.getKcv();
7.1.11.4.6 getOwner()
Key.prototype.getOwner()
ByteString getOwner()
Retrieve the Owner attribute value for the Key. In the XML, this can be found in the KeyInfo subelement of the
KeyProfile element.
Example
returns ByteString A new ByteString containing the Owner attribute value from the
Key Profile for the key.
exception None
7.1.11.4.7 getProfileID()
Key.prototype.getProfileID()
ByteString getProfileID()
Retrieve the ProfileID value for the Key. In the XML, this can be found in the UniqueID attribute of the
KeyProfile element or the ProfileID attribute of the Key element.
Example
myProfileID = sampleKey.getProfileID();
exception None
7.1.11.4.8 getSize()
Key.prototype.getSize()
Number getSize()
Retrieve the size value for the Key. In the XML, this can be found as the Size attribute in the KeyInfo subelement of
the KeyProfile element.
Example
// For the DES key sampleDESKey which has the Size attribute set to 64
// bits in the Key Profile
myDESSize = sampleDESKey.getSize();
// myDESSize will contain the number 64
// For the RSA key sampleRSAKey which has the Size attribute set to 1024
// bits in the Key Profile
myRSASize = sampleRSAKey.getSize();
// myRSASize will contain the number 1024
returns Number For DES keys, a Number containing the size value in bits including
the parity bits.
For RSA keys, a Number containing the size of the modulus in bits.
exception None
Key.prototype.getStart()
ByteString getStart()
Retrieve the Start Date value for the Key. In the XML, this can be found in the KeyInfo subelement of the
KeyProfile element.
Example
myDate = sampleKey.getStart();
returns ByteString A new ByteString containing the date in the format YYYYMMDD
in ASCII.
exception None
7.1.11.4.10 getType()
Key.prototype.getType()
Number getType()
Retrieve the Type value for the Key. In the XML, this can be found as the Type attribute in the KeyInfo subelement
of the KeyProfile element.
Example
myType = sampleKey.getType();
Key.SECRET
Key.PRIVATE
Key.PUBLIC
exception None
7.1.11.4.11 getUsage()
Key.prototype.getUsage()
Number getUsage()
Retrieve the Usage values for the Key. In the XML, this can be found as the attributes in the Usage subelement of the
KeyProfile element.
If more then one usage value is specified, it should be extractable from the returned value by comparing against a logical
OR of the desired usages to check for.
Example
// Assume that the Usage subelement for the key sampleKey has usage
// set to Key.DECRYPT. This code will only execute decrypt if sampleKey
// has this usage feature set.
sampleKey = this.key[“keyA”];
dataToDecrypt = new ByteString(“00010203”, HEX);
initialVector = new ByteString(“00000000”, HEX);
myUsage = sampleKey.getUsage();
returns Number A Number containing one of or, for the case of multiple usages, a
logical OR combination of the usage values:
Key.ENCRYPT
Key.DECRYPT
Key.DECRYPT_ENCRYPT
Key.DERIVE
Key.SIGN
Key.VERIFY
Key.WRAP
Key.UNWRAP
Key.UNWRAP_WRAP
exception None
7.1.11.4.12 getVersion()
Key.prototype.getVersion()
Number getVersion()
Retrieve the Version value for the Key. In the XML, this can be found in the Key element or in the KeyInfo
subelement of the KeyProfile element.
Example
myVersion = sampleKey.getVersion();
exception None
7.1.11.4.13 getWrapKey()
Key.prototype.getWrapKey()
getWrapKey(Key wrapKey)
Retrieve the key that is used to wrap (encrypt) the key.
Example
sampleKey.getWrapKey(theWrapKey);
returns None
7.1.11.4.14 setAttribute()
Key.prototype.setAttribute()
setAttribute(Number value)
Attempt to set the Attribute attribute value for a key. If the attribute has already been populated based on information
from the Key Profile, then an exception is thrown.
Example
sampleKey.setAttribute(Key.SENSITIVE);
returns None
7.1.11.4.15 setComponent()
Key.prototype.setComponent()
setComponent(Number type, ByteString value)
Set a component, as specified by the type parameter, for the Key. If the component’s value is populated upon creation
of the Key object in the script environment, this method shall throw an exception.
Example
// Assume sampleKey is a public key and
// myExponent contains an exponent value
sampleKey.setComponent( Key.EXPONENT, myExponent);
value ByteString A HEX encoded ByteString containing the value for the Key
component specified by type.
returns None
7.1.11.4.16 setEnd()
Key.prototype.setEnd()
setEnd(ByteString value)
Sets the End Date value for the Key. If the attribute value has already been populated based on information from the
Key Profile, then an exception is thrown.
Example
sampleKey.setEnd(myDate);
returns None
7.1.11.4.17 setOwner()
Key.prototype.setOwner()
setOwner(ByteString value)
Sets the Owner attribute value for the Key. If the attribute value has already been populated based on information
from the Key Profile, then an exception is thrown.
Example
sampleKey.setOwner(myOwner);
returns None
7.1.11.4.18 setSize()
Key.prototype.setSize()
setSize(Number value)
Sets the Size attribute value for the Key. If the attribute value has already been populated based on information from
the Key Profile, then an exception is thrown.
Example
// For the DES key sampleDESKey which doesn’t have the Size attribute
// specified in the Key Profile, the following will set the size to 64
// bits
sampleDESKey.setSize(64);
// For the RSA key sampleRSAKey which doesn’t have the Size attribute
// specified in the Key Profile, the following will set the size to 1024
// bits
sampleRSAKey.setSize(1024)
returns None
7.1.11.4.19 setStart()
Key.prototype.setStart()
setStart(ByteString value)
Sets the Start Date value for the Key. If the attribute value has already been populated based on information from the
Key Profile, then an exception is thrown.
Example
sampleKey.setStart(myDate);
returns None
7.1.11.4.20 setType()
Key.prototype.setType()
setType(Number value)
Sets the Type attribute value for the Key.
Example
sampleKey.setType(myType);
If the Type attribute has already been defined in the Key Profile,
then a GPError will be generated with a value of
GPError.ACCESS_DENIED.
returns None
7.1.11.4.21 setUsage()
Key.prototype.setUsage()
setUsage(Number value)
Set the Usage subelement attribute values for the Key. If any of the element’s attribute values has already been
populated with true values, based on information from the Key Profile, then an exception is thrown.
If more then one usage value is specified, it can be combined using a logical OR with the other desired usages to arrive
at the usage value to specify for this method.
Example
// Assuming that sampleKey’s usages have not been defined in the Key
// Profile, the following code will set the usage of the key to allow it
// to be used for both decryption and encryption operations.
sampleKey.setUsage(Key.ENCRYPT || Key.DECRYPT);
If the Usage attribute has already been specified in the Key Profile,
then a GPError will be generated with a value of
GPError.ACCESS_DENIED.
returns None
7.1.11.4.22 setVersion()
Key.prototype.setVersion()
setVersion(Number value)
Sets the Version attribute value for the Key. If the Attribute value has already been populated based on information
from the Key Profile, then an exception is thrown.
Example
sampleKey.setVersion(myVersion);
returns None
7.1.12 Atr
The Atr object provides methods to return the value of the sequence of bytes sent by the card to
the interface device as the answer to a reset as defined in [IS7816-3].
Atr objects are created when the reset() method of the card object is executed. It is not
possible to use the Atr object as a constructor with the new operator as no constructor method is
provided.
7.1.12.1 Summary
Atr.prototype.formatByte
Atr.prototype.historicalBytes
Atr.prototype.interfaceBytes
Atr.prototype.tckByte
Atr.prototype.toByteString()
7.1.12.2 Constants
There are no constants for the Atr object.
7.1.12.3 Properties
7.1.12.3.1 formatByte
Atr.prototype.formatByte Number
The formatByte property is an ECMAScript Number object.
Contains the format byte value to the most recent answer to reset operation as specified in [IS7816-3].
7.1.12.3.2 historicalBytes
Atr.prototype.historicalBytes ByteString
The historicalBytes property is a GlobalPlatform scripting language ByteString object.
For smart cards with contact interfaces, contains the historical bytes value to the most recent answer to reset operation
as specified in [IS7816-3].
7.1.12.3.3 interfaceBytes
Atr.prototype.interfaceBytes ByteString
The interfaceBytes property is a GlobalPlatform scripting language ByteString object.
Contains the interface bytes value to the most recent answer to reset operation as specified in [IS7816-3].
7.1.12.3.4 tckByte
Atr.prototype.tckByte Number
The tckByte property is an ECMAScript Number object.
Contains the check byte tck value to the most recent answer to reset operation as specified in [IS7816-3].
7.1.12.4 Methods
7.1.12.4.1 Constructor
Atr.prototype.constructor()
new Atr()
new Atr(arguments)
There is no constructor function for this object.
Example
None
returns None
7.1.12.4.2 toByteString()
Atr.prototype.toByteString()
ByteString toByteString()
Returns in a ByteString representation the Atr object.
Example
SampleATR = this.card.reset();
myByteString = SampleATR.toByteString();
exception None
7.1.13
ByteBuffer
A ByteBuffer object is a mutable object that can be used to manipulate a sequence of bytes.
The ByteBuffer object is instantiable. There is a constructor method which can be used to
create ByteBuffer objects.
Unlike the ByteString object, all ByteBuffer methods return a reference to the same object.
Table 7.1 summarizes the different types of encoding a ByteBuffer may have. A single
ByteBuffer object may contain segments of bytes which are encoding using different types of
encoding, because there are a variety of append methods which can be utilized to append bytes
which may not correspond to encoding used by the data already in the ByteBuffer object.
Encoding Description
Each byte is encoded as two hexadecimal digits with optional whitespace. When a string
is decoded whitespace is accepted, when a string is encoded it is up to the environment
whether whitespace is inserted or not. Alphabetic characters may be uppercase or
HEX lowercase.
The value { 0xab, 0x34, 0x56 } may be encoded as follows:
ab3456
AB 34 56
Ab34 56
ab 3456
The byte sequence is interpreted as UTF-8. A character may be encoded as one, two or
three bytes depending on the Unicode character value.
For example, the following string “± € 6” translates to:
UTF8 Plus-Minus Sign (0xB1 or 0b10 110001)
Euro Sign (0x20AC or 0b10 000010 101100)
Digit Six (0x36 or 0b110110)
which is represented in UTF-8 as the following value:
{ 0xC2, 0xB1, 0xE2, 0x82, 0xAC, 0x36 }
Each byte is encoded as a single Extended ASCII character. No conversions are to occur
ASCII (eg no new-line to CRLF conversion).
The value { 0x47, 0x70, 0x21 }:
Gp!
Bytes are encoded using RFC 521 Base64 encoding. The encoded string may contain
BASE64
non-Base64 characters (eg newlines) which are to be ignored when decoding.
Support for the Compact Numeric magnetic stripe format in [IS7811-6]. Each byte is
encoded as two characters using the character table described in Table 7 of the ISO
specification (excluding the parity bits). When decoding a string with an odd number of
CN characters, an addition end-sentinel is added as the least significant nibble of the last byte.
The value { 0xB1, 0x2D, 0x3F } is encoded as:
;12=3?
The encoding “;2345” has the following value:
{ 0xB2, 0x34, 0x5F }
7.1.13.1 Summary
ByteBuffer.prototype.length
ByteBuffer.prototype.constructor()
ByteBuffer.prototype.append()
ByteBuffer.prototype.byteAt()
ByteBuffer.prototype.clear()
7.1.13.3.1 length
ByteBuffer.prototype.length Number
The length property is an ECMAScript Number object.
The current length of the contents of this ByteBuffer.
7.1.13.4 Methods
7.1.13.4.1 Constructor
ByteBuffer.prototype.constructor()
ByteBuffer new ByteBuffer()
ByteBuffer new ByteBuffer(String stringValue, Number encoding)
ByteBuffer new ByteBuffer(ByteString source)
Constructs a new ByteBuffer with empty contents, supplied hexValue or supplied stringValue.
When no parameters are supplied, return a new ByteBuffer object containing no data.
When stringValue and encodingValue is supplied, return a new ByteBuffer object with a value specified by the
supplied string and according to the encoding method specified by encoding to encode the value in stringValue.
Example
myByteBuffer = new ByteBuffer();
7.1.13.4.2 append()
ByteBuffer.prototype.append()
Example
MyByteBuffer = new ByteBuffer(“Hello World!”, ASCII);
7.1.13.4.3 byteAt()
ByteBuffer.prototype.byteAt()
Number byteAt(Number offset)
Returns the byte at the given offset of this buffer’s contents.
Example
MyByteBuffer.byteAt(sampleNumber);
returns Number The unsigned value of the byte at the given offset in the buffer
ByteBuffer.prototype.clear()
ByteBuffer clear()
ByteBuffer clear(Number offset)
ByteBuffer clear(Number offset, Number count)
Deletes contents from the buffer. If no offset is given, all contents of the buffer will be deleted.
Example
MyByteBuffer.clear();
count Number The number of bytes to delete. If no count is given all bytes after the
given offset will be deleted.
If the number of bytes specified is negative or the sum of offset
and count exceeds the length of the buffer, then a GPError will be
generated with a value of GPError.INVALID_LENGTH.
7.1.13.4.5 copy()
ByteBuffer.prototype.copy()
ByteBuffer copy(Number at, ByteBuffer source)
ByteBuffer copy(Number at, ByteString source)
ByteBuffer copy(Number at, String source)
Replaces current contents of the ByteBuffer with contents of the given source object specified, whether a
ByteBuffer, ByteString or String. The copy() method does not insert the value, as this operation is handled by
the insert() method.
Example
// Assume MyByteBuffer contains the ASCII text “Hello There” and the
// sampleByteString contains the ASCII text “World!”. The following
// method call will result in MyByteBuffer containing “Hello World”.
MyByteBuffer.copy(6, sampleByteString);
source ByteBuffer The ByteBuffer, ByteString or String from which bytes will be
ByteString appended.
String
If the sum of the offset specified in at and the length of this source
parameter exceeds the length of the current buffer, then a GPError
returns ByteBuffer The same reference to this ByteBuffer. This allows convenient
concatenation without creating numerous instances.
7.1.13.4.6 find()
ByteBuffer.prototype.find()
Number find(ByteString value)
Number find(ByteString value, Number offset)
Finds the zero based index into the ByteBuffer of the first occurrence of value specified.
Example
sampleByteString = new ByteBuffer (“01020103010401”, HEX);
findThis = new ByteString (“01”, HEX);
sampleByteString.find(findThis);
// will return 0
sampleByteString.find(findThis, 1);
// will return 2
offset Number Zero based offset to start the search for value. Negative offset
should be treated as zero. If the offset exceeds the length of the
buffer, the method should report that the value was not found.
returns Number Absolute zero based offset into the ByteBuffer. –1 returned if
value is not found
7.1.13.4.7 insert()
ByteBuffer.prototype.insert()
ByteBuffer insert(Number at, ByteBuffer source)
ByteBuffer insert(Number at, ByteString source)
ByteBuffer insert(Number at, String source)
Inserts the contents of the object specified, whether a ByteBuffer, ByteString or String, at the given position in
this ByteBuffer. The length of the contents will increase with the number of bytes inserted. The source bytes will be
inserted before the given at position and the bytes already present from that position will be moved to after the inserted
bytes. If at equals the length of the buffer, the source bytes are appended to the end of the buffer.
Example
MyByteBuffer.insert(sampleNumber, sampleByteString);
source ByteBuffer The ByteBuffer, ByteString or String from which bytes will be
ByteString appended.
String
returns ByteBuffer The same reference to this ByteBuffer. This allows convenient
concatenation without creating numerous instances.
7.1.13.4.8 toByteString()
ByteBuffer.prototype.toByteString()
ByteString toByteString()
ByteString toByteString(Number offset)
ByteString toByteString(Number offset, Number count)
Returns this buffer’s contents as a new immutable ByteString.
Example
MyByteBuffer.toByteString();
7.1.13.4.9 toString()
ByteBuffer.prototype.toString()
String toString()
String toString(Number encoding)
Returns a ECMAScript String representation of the ByteBuffer object.
Example
MyByteBuffer.toString(HEX);
7.1.14 ByteString
The ByteString object describes an ordered series of bytes which cannot be modified once
created. The ByteString object is instantiable. There is a constructor method which can be
used to create ByteString objects. Also, ByteString objects are created by several other
objects in the scripting objects.
ByteString objects are immutable, that is object instances cannot be changed.
Table 7.2 describes the different types of encoding a ByteString may have.
Encoding Description
Each byte is encoded as two hexadecimal digits with optional whitespace. When a string
is decoded whitespace is accepted, when a string is encoded it is up to the environment
whether whitespace is inserted or not. Alphabetic characters may be uppercase or
HEX lowercase.
The value { 0xab, 0x34, 0x56 } may be encoded as follows:
ab3456
AB 34 56
Ab34 56
ab 3456
The byte sequence is interpreted as UTF-8. A character may be encoded as one, two or
three bytes depending on the Unicode character value.
For example, the following string “± € 6” translates to:
UTF8 Plus-Minus Sign (0xB1 or 0b10 110001)
Euro Sign (0x20AC or 0b10 000010 101100)
Digit Six (0x36 or 0b110110)
which is represented in UTF-8 as the following value:
{ 0xC2, 0xB1, 0xE2, 0x82, 0xAC, 0x36 }
Each byte is encoded as a single Extended ASCII character. No conversions are to occur
ASCII (eg no new-line to CRLF conversion).
The value { 0x47, 0x70, 0x21 }:
Gp!
Bytes are encoded using RFC 521 Base64 encoding. The encoded string may contain
BASE64
non-Base64 characters (eg newlines) which are to be ignored when decoding.
Support for the Compact Numeric magnetic stripe format in [IS7811-6]. Each byte is
encoded as two characters using the character table described in Table 7 of the ISO
specification (excluding the parity bits). When decoding a string with an odd number of
CN characters, an addition end-sentinel is added as the least significant nibble of the last byte.
The value { 0xB1, 0x2D, 0x3F } is encoded as:
;12=3?
The encoding “;2345” has the following value:
{ 0xB2, 0x34, 0x5F }
7.1.14.1 Summary
ByteString.XOR
ByteString.prototype.length
ByteString.prototype.constructor()
ByteString.prototype.and()
ByteString.prototype.byteAt()
Constant Usage
ByteString.XOR crc() method
7.1.14.3 Properties
7.1.14.3.1 length
ByteString.prototype.length Number
The length property is an ECMAScript Number object.
The current length of the contents of this ByteString.
7.1.14.4 Methods
7.1.14.4.1 Constructor
ByteString.prototype.constructor()
ByteString new ByteString(String stringValue, Number encoding)
When stringValue is supplied, return a ByteString object containing the value specified by the supplied string
using the encoding method described by encodingValue.
Example
myByteString = new ByteString("AbcD", HEX);
//returns a bytefield containing the two bytes 0xab, 0xcd.
7.1.14.4.2 and()
ByteString.prototype.and()
ByteString and(ByteString value)
The bitwise AND of the two ByteString objects of the same length.
Returns a ByteString object containing the bitwise AND of the two objects.
If the two ByteString objects are of different lengths, then a GPError object is generated with a value of
GPError.INVALID_LENGTH.
Example
// Assume that sampleByteString contains “0x11”
// and otherByteString contains “0x00”
// newByteSting will contain 0x00
newByteString = sampleByteString.and(otherByteString);
returns ByteString The bitwise AND of the two objects as a new ByteString object.
7.1.14.4.3 byteAt()
ByteString.prototype.byteAt()
Number byteAt(Number offset)
Returns the byte at the given offset of this ByteString object’s contents.
Example
MyByteString.byteAt(sampleNumber);
returns Number The unsigned value of the byte at the given offset in the buffer
ByteString.prototype.bytes()
ByteString bytes(Number offsetByte)
ByteString bytes(Number offsetByte, Number countBytes)
Return a ByteString containing part of the ByteString from which the method is invoked.
Example
// assume that sampleByteString contains the value “0x0102”
newByteString = sampleByteString.bytes(0x01, 0x01); // will return x02
countBytes Number Optional parameter, which if not present, is the remaining bytes from
the offsetByte. Otherwise represents the maximum number of
bytes to put into the returned ByteString.
If the countBytes value is negative, then a GPError object is
generated with a value of GPError.INVALID_LENGTH.
exception GPError.ARGUMENTS_MISSING
GPError.INVALID_ARGUMENTS
GPError.INVALID_INDEX
GPError.INVALID_LENGTH
7.1.14.4.5 concat()
ByteString.prototype.concat()
ByteString concat(ByteString value)
The concatenation of this object followed by another ByteString object.
Example
// Assume that sampleByteString is a ByteString object which
// contains the binary value “0x0101” and otherByteString
// contains the binary value “0x0202”
newByteString = sampleByteString.concat(otherByteString);
// will create a new ByteString object containing the value 0x01010202
7.1.14.4.6 crc()
ByteString.prototype.crc()
Example
// Assume that sampleByteString is a ByteString object which
// contains the binary value “0x0101”
sampleByteStringCRC = sampleByteString.crc(ByteString.XOR);
// will create the CRC with XOR of sampleByteString
returns ByteString A new ByteString representing the results of the CRC operation.
7.1.14.4.7 equals()
ByteString.prototype.equals()
Boolean equals(ByteString value)
Determines whether the objects have identical contents.
Returns true if the objects are the same length and each byte is identical, false otherwise.
Example
// Assume that the ByteStrings sampleByteString contains
// “0x0101” and otherByteString contains “0x0201”
sampleByteString.equals(otherByteString);
// will return false
returns Boolean Boolean result whether the objects have identical contents.
7.1.14.4.8 find()
ByteString.prototype.find()
Number find(ByteString value)
Number find(ByteString value, Number offset)
Finds the zero based index into the ByteString of the first occurrence of value specified.
Example
sampleByteString = new ByteString (“01020103010401”, HEX);
findThis = new ByteString (“01”, HEX);
sampleByteString.find(findThis);
offset Number Zero based offset to start the search for value. Negative offset
should be treated as zero.
returns Number Absolute zero based offset into the ByteString. –1 returned if
value is not found
7.1.14.4.9 getL()
ByteString.prototype.getL()
ByteString getL(Number encoding)
A length field in a new ByteString object for the value of the ByteString object from which the method is invoked.
Returns a ByteString object containing L field appropriate to the encoding method specified by encoding.
Example
// Assume that sampleByteString is a ByteString object
// containing a 128 byte length value
myEMVlength = sampleByteString.getL(TLV.EMV);
myDGIlength = sampleByteString.getL(TLV.DGI);
// myEMVlength will contain the value 0x8180
// myDGIlength will contain the value 0x80
7.1.14.4.10 getLV()
ByteString.prototype.getLV()
ByteString getLV(Number encoding)
A LV field-pair for the object based on the encoding method specified by encoding.
Returns a ByteString object containing a L field appropriate to the length of the object, followed by the object itself.
For a ByteString b, the method call b.getLV() will return a ByteString with the same contents as the ByteString
returned by b.getL().concat(b).
Example
// Assume that sampleByteString is a ByteString object
// containing the binary value “0x0101”
otherByteString = sampleByteString.getLV(TLV.EMV);
// will return 0x020101
7.1.14.4.11 left()
ByteString.prototype.left()
ByteString left(Number value)
Return in a new ByteString object the leftmost number of bytes indicated by value. If the value is greater than the
length, return the maximum number of values.
This is equivalent to the method bytes(0, value).
Example
OtherByteString = myByteString.left(10);
7.1.14.4.12 neg()
ByteString.prototype.neg()
ByteString neg()
ByteString neg(Number size)
The twos complement (negative) of the object.
Returns a ByteString object containing the twos complement of the object.
There is no limitation on the size of the object.
Example
// Assuming that sampleByteString is a ByteString object
// with the binary value “0x0101”;
otherByteString = sampleByteString.neg();
// will populate otherByteString with “0xFEFF”
returns ByteString The twos complement of the object as a new ByteString object.
7.1.14.4.13 not()
ByteString.prototype.not()
ByteString not()
The ones complement (bitwise inverse) of the object.
Returns a ByteString object containing the ones complement of the object.
There is no limitation on the size of the object.
Example
// Assuming that the ByteString object sampleByteString
// contains the binary value “0x0101”
otherByteString = sampleByteString.not();
// will return “0x1010” in a new ByteString object otherByteString
returns ByteString The ones complement of the object as a new ByteString object.
exception None
7.1.14.4.14 or()
ByteString.prototype.or()
ByteString or(ByteString value)
The bitwise OR of the two objects.
Returns a ByteString object containing the bitwise OR of the two objects.
If the two ByteString objects are of different lengths, then a GPError object is generated with a value of
GPError.INVALID_LENGTH.
Example
// Assuming that the ByteString object sampleByteString
// contains the value “0x0100” and otherBytesString contains “0x0000”,
// the following operation will return 0x0100 in the new ByteString
// object newByteString
newByteString = sampleByteString.or(otherByteString);
ByteString
returns ByteString The bitwise OR of the two objects as a new ByteString object.
7.1.14.4.15 pad()
ByteString.prototype.pad()
Example
paddedByteString = myByteString.pad(ISO9797_METHOD_1);
7.1.14.4.16 right()
ByteString.prototype.right()
ByteString right(Number value)
Return in a new ByteString object the rightmost number of bytes indicated by value. If the value is greater than the
length, return the maximum number of values.
This is equivalent to the method call:
sampleByteString.bytes(sampleByteString.length - value, value).
Example
// If myByteString contains 0x1234567879101112131, otherByteString will
// contain 0x112131
otherByteString = myByteString.right(3);
7.1.14.4.17 startsWith()
ByteString.prototype.startsWith()
Number startsWith(ByteString value)
Example
// Assume that sampleByteString contains the value “0x0101” and
// otherByteString the value “0x0102”
similarByteCount = sampleByteString.startsWith(otherByteString);
// will return a number of 1
7.1.14.4.18 toBase64()
ByteString.prototype.toBase64()
ByteString toBase64()
ByteString toBase64(Boolean lineBreak)
Converts a ByteString object in binary representation to the equivalent Base64 representation.
The returned ByteString will contain the value passed to the method expressed as a Base64 representation rather
than as a binary representation.
Example
// Assuming sampleByteString object exists and contains
// the binary value 0x656667.
// newByteString will contain a base64 representation of 0x656667.
newByteString = sampleByteString.toBase64();
7.1.14.4.19 toBcd()
ByteString.prototype.toBcd
ByteString toBcd()
ByteString toBcd(Number countBytes)
Example
// Assume that sampleByteString contains the value “0x0101”;
newByteString = sampleByteString.toBcd(2); // will return x0257
7.1.14.4.20 toHex()
ByteString.prototype.toHex()
ByteString toHex()
ByteString toHex(Number countBytes)
Transposes a ByteString object in binary representation to the equivalent ASCII string.
The returned ByteString will contain the value passed to the method expressed as an ASCII string rather than as a
binary representation. So, for example, if the ByteString value contains 0x65666768, the equivalent ASCII
representation returned is “65666768”.
If countBytes is too small to hold the number, only the least significant digits will be expressed in the result. If
countBytes is too large, the result will be padded with zeroes on the left.
Example
// Assuming sampleByteString object exists and contains
// the binary value 0x65666768.
newByteString = sampleByteString.toHex();
// will return a ByteString object with the equivalent
// ASCII string “65666768”.
7.1.14.4.21 toSigned()
ByteString.prototype.toSigned()
Number toSigned()
Number toSigned(Boolean littleEndian)
The signed numeric value of the object.
The returned value will be negative if the most significant bit of the object is a one-bit, and non-negative otherwise. If the
length of the object is zero, zero will be returned. An exception will be thrown if the value cannot be expressed within a
signed 32-bit integer.
If the result of the method invocation does not fit within a 32 bit representation, then a GPError object is generated with
a value of GPError.DATA_TOO_LARGE.
Example
// Assume that the ByteString object sampleByteString
// contains the binary value “0x0101”
sampleInteger = sampleByteString.toSigned();
7.1.14.4.22 toString()
ByteString.prototype.toString()
String toString()
String toString(Number encoding)
Returns a ECMAScript String representation of the ByteString object.
Example
// Assume that SampleBytefield contains “0x0101” and is two bytes long,
// sampleString will contain the string “0101”
sampleString = SampleBytefield.toString(HEX);
exception None
ByteString.prototype.toUnsigned()
Number toUnsigned()
Number toUnsigned(Boolean littleEndian)
The unsigned numeric value of the object.
If the length of the object is zero, zero will be returned. An exception will be thrown if the value cannot be expressed
within a signed (not unsigned) 32-bit integer.
If the result of the method invocation does not fit within a 32 bit representation, then a GPError object is generated with
a value of GPError.DATA_TOO_LARGE.
Example
// Assume that sampleByteString contains “0x0101”
// the following operation will return the unsigned value in myInteger
myInteger = sampleByteString.toUnsigned();
returns Number The unsigned numeric value of the object, within a Number object.
7.1.14.4.24 xor()
ByteString.prototype.xor()
ByteString xor(ByteString value)
The bitwise XOR of the two objects.
Returns a ByteString object containing the bitwise XOR of the two objects. If this method is called repeatedly with the
same argument, it may not necessarily return the same object each time.
If the two ByteString objects are of different lengths, then a GPError object is generated with a value of
GPError.INVALID_LENGTH.
Example
// Assume that sampleByteString contains the value “0x0101”
otherByteString = sampleByteString.xor(“0x0001); // will return 0x0100
returns ByteString The bitwise XOR of the two objects as a new ByteString object.
7.1.15 TLV
The TLV object describes a single Tag Length Value (TLV) object.
The TLV objects are immutable, that is the object instances cannot have their values changed.
TLV objects are created using the constructor method supplied or upon the invocation of certain
methods of a TLVList object.
7.1.15.1 Summary
TLV.DGI
TLV.EMV
TLV.L16
TLV.prototype.encodingMode
TLV.prototype.size
TLV.prototype.constructor()
TLV.prototype.getL()
TLV.prototype.getLV()
TLV.prototype.getTag()
TLV.prototype.getTLV()
TLV.prototype.getTV()
TLV.prototype.getValue()
7.1.15.2 Constants
Each of these constants must be assigned an unique value within the TLV object.
Constant Usage
TLV.DGI encoding mode
TLV.EMV encoding mode
TLV.L16 encoding mode
7.1.15.3 Properties
7.1.15.3.1 encodingMode
TLV.prototype.encodingMode Number
The encodingMode property is an ECMAScript Number object.
Read only property that is set when the object is constructed. The property encodingMode can be checked by the
script to confirm what mode was used for the encoding of a TLV object.
The following modes will be mandatory:
TLV.EMV EMV encoding of TLV
TLV.DGI DGI encoding of TLV
TLV.L16 Encoding of TLV with a two byte tag and length
For TLV.EMV tag encoding requirements, refer to the August 2000 version of EMV.
For TLV.DGI tag encoding requirements, refer to Appendix B.
7.1.15.3.2 size
TLV.prototype.size Number
The size property is an ECMAScript Number object.
Read only property that represents the combined size of the concatenation of (Tag | Length | Value), where Tag and
Length values are determined by encodingMode, as it would be returned from the getTLV method.
7.1.15.4 Methods
7.1.15.4.1 Constructor
TLV.prototype.constructor()
TLV new (Number tag, ByteString value, number encoding)
Returns a new TLV object that will be initialized with Tag, Length, and Value contained within the input parameter Value
ByteString.
If the encoding parameter is incompatible with the tag presented in tag, then a GPError object is generated with a
value of GPError.INVALID_TAG.
If the value parameter contains a value which is too large for a specified encoding method, then a GPError object is
generated with a value of GPError.DATA_TOO_LARGE.
Finally, if the value cannot be decoded using the specified encoding method, then a GPError object is generated
with a value of GPError.INVALID_DATA.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newTLV = new TLV(SampleTag, SampleValue, TLV.EMV);
value ByteString The Value data that will be assigned to the TLV.
encoding Number Value representing the Encoding Method that will be assigned to the
TLV. See encodingMode property for valid values.
If the encoding parameter is not supported, then a GPError object
is generated with a value of GPError.INVALID_ENCODING.
7.1.15.4.2 getL()
TLV.prototype.getL()
ByteString getL()
Retrieve the L value of the TLV object. The length component will be encoded in the format given to the TLV object in
construction, and specified in the property encodingMode.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
myTLVLength = sampleTLV.getL();
exception None
TLV.prototype.getLV()
ByteString getLV()
Retrieve the LV value of the TLV object. The length component will be encoded in the format given to the TLV object in
construction, and specified in the property encodingMode.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newByteString = sampleTLV.getLV();
exception None
7.1.15.4.4 getTag()
TLV.prototype.getTag()
Number getTag()
Returns a Number containing Tag associated with the object, the Tag will be encoded in the format that was given in the
construction of the object, and specified in the property encodingMode.
Example
sampleTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newByteString = sampleTLV.getTag();
exception None
7.1.15.4.5 getTLV()
TLV.prototype.getTLV()
ByteString getTLV()
Retrieve the concatenated tag, length, and value components of the TLV object, the Tag and Length component will be
encoded in the format given to the TLV object in construction, and specified in the property encodingMode.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newByteString = sampleTLV.getTLV();
returns ByteString The TLV in the form of a single stream of the TLV, suitably encoded.
exception None
TLV.prototype.getTV()
ByteString getTV()
Retrieve the concatenated tag and value components of the TLV object, the Tag component will be encoded in the
format given to the TLV object in construction, and specified in the property encodingMode.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newByteString = sampleTLV.getTV();
returns ByteString The TV in the form of a single stream of the TV, suitably encoded.
exception None
7.1.15.4.7 getValue()
TLV.prototype.getValue()
ByteString getValue()
Retrieve the value compoennt of the TLV object.
Example
newTLV = new TLV(0x5A, new ByteString(“0123456789”, HEX), TLV.EMV);
newByteString = sampleTLV.getValue();
exception None
7.1.16 TLVList
The TLVList object holds a collection of TLVs as they are created into the TLVList object.
The object is mutable, that is the object instances can have TLVs added or removed.
7.1.16.1 Summary
TLVList.prototype.encodingMode
TLVList.prototype.length
TLVList.prototype.constructor()
TLVList.prototype.append()
TLVList.prototype.appendValue()
TLVList.prototype.appendValueIndex()
TLVList.prototype.deleteByIndex()
TLVList.prototype.deleteByTag()
TLVList.prototype.find()
TLVList.prototype.findIndex()
TLVList.prototype.index()
TLVList.prototype.toByteString()
TLVList.prototype.updateValue()
TLVList.prototype.updateValueIndex()
7.1.16.2 Constants
There are no constants for the TLVList object.
7.1.16.3 Properties
7.1.16.3.1 encodingMode
TLVList.prototype.encodingMode Number
The encodingMode property is an ECMAScript Number object.
Read only property that is set when the object is constructed. The property can be checked by the script to confirm
what mode was used.
The following modes will be mandatory:
TLV.EMV EMV encoding of TLVList
TLV.DGI DGI encoding of TLVList
TLV.L16 Encoding with a two byte tag and length of TLVList
For TLV.EMV tag encoding requirements, refer to the August 2000 version of EMV.
For TLV.DGI tag encoding requirements, refer to Appendix B.
7.1.16.3.2 length
TLVList.prototype.length Number
The length property is an ECMAScript Number object.
Read only property that contains the number of entries in the list.
7.1.16.4 Methods
7.1.16.4.1 Constructor
TLVList.prototype.constructor()
TLVList new (ByteString tlvStream, Number encoding)
Parses tlvStream, breaking it down into individual TLVs. These TLVs will be held internally in the TLVList object and
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
newTL = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
encoding Number Value representing the encoding method that will be assigned to the
TLVs within the TLVList. Valid encoding methods are:
TLV.EMV EMV encoding
TLV.DGI DGI encoding
TLV.L16 Encoding with a two byte tag and length
If the encoding parameter is not supported, then a GPError object
is generated with a value of GPError.INVALID_ENCODING.
returns TLVList The created object with contain all the TLV data.
7.1.16.4.2 append()
TLVList.prototype.append()
append(ByteString tlvStream)
append(TLV tlvToAppend)
append(Number tag, ByteString value)
Appends the specified TLV data to the end of the existing list of TLVs.
The supplied input can either be a TLV stream of bytes, or a separately specified Tag and Value parameter.
The individual TLVs will not break apart TLVs with constructed tags.
If the encoding parameter is incompatible with the tags presented in tlvStream, then a GPError object is generated
with a value of GPError.INVALID_TAG.
If the tlvStream parameter contains a value which is too large for a specified encoding method, then a GPError
object is generated with a value of GPError.DATA_TOO_LARGE.
If the tlvStream cannot be decoded using the specified encoding method, then a GPError object is generated with
a value of GPError.INVALID_DATA.
Finally, if the tlvStream contains TLV(s) with the same tag value or a reoccurance of an existing tag in the TLVList
object, then a GPError object is generated with a value of GPError.TAG_ALREADY_EXISTS.
Example
returns None
7.1.16.4.3 appendValue()
TLVList.prototype.appendValue()
appendValue(Number tag, ByteString data)
Appends the data to the existing data for the specified tag.
Example
// Appends to existing tag 4F’s data 0x0102A003
sampleTL.appendValue(0x4F, new ByteString(“0102A003”,HEX));
returns None
7.1.16.4.4 appendValueIndex()
TLVList.prototype.appendValueIndex()
appendValueIndex(Number index, ByteString data)
Appends the data to the existing data for the specified zero-based index into the TLVStream.
The zero-based index identifies the TLV to be modified within the TLVList, by its sequence order in the list.
Example
sampleTL = new TLVList(new ByteString(“1F01112F01223F0133”, HEX), TLV.EMV);
// sampleTL is:
// Tag 1F value 11
// Tag 2F value 22
// Tag 3F value 33
data ByteString Data to be added to the existing tag at the location in the TLVStream
indicated by index.
If the data parameter contains a value which, when appended to
the existing value for the tag at the specified index, is too large for a
specified encoding method, then a GPError object is generated
with a value of GPError.DATA_TOO_LARGE.
returns None
7.1.16.4.5 deleteByIndex()
TLVList.prototype.deleteByIndex()
deleteByIndex (Number index)
Delete the specified TLV from the list using a zero based index.
The zero-based index identifies the TLV to be deleted within the TLVList, by its sequence order in the list.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
// Delete the TLV from the list
// The TLVList object will look like
// Tag 4F Value A003
sampleTList.deleteByIndex(1);
returns None
7.1.16.4.6 deleteByTag()
TLVList.prototype.deleteByTag()
deleteByTag (Number tag)
Delete the specified TLV from the list by tag value.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVLlist(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
// Delete TLV with Tag 0x4F from TLVList
// TLV List will look like
// Tag 5F24 Value 020301
sampleTList.deleteByTag(0x4F);
Parameter Type Description
tag Number Value represents the Tag that will be deleted from the list.
returns None
7.1.16.4.7 find()
TLVList.prototype.find()
TLV find(Number tag)
Searches the list for a specified tag, and returns a TLV object.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
// Returns a TLV object in sampleTLV with
// Tag 4F Value A003
sampleTLV = sampleTList.find(0x4F);
returns TLV A TLV object which contains the data stored for that Tag. Note any
changes to the returned TLV object will not be made to the TLVList
item.
Returns a null if TLV not found.
7.1.16.4.8 findIndex()
TLVList.prototype.findIndex()
Number FindIndex (Number tag)
Searches the list for a specified tag, and returns a zero based index for that TLV.
The zero-based index identifies the TLV found within the TLVList, by its sequence order in the list.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
// This returns a value of 1 in sampleTLVIndex
sampleTLVIndex = sampleTLVList.findIndex(0x5F24);
returns Number Index that indicates the location of the TLV within TLV list. A
negative index value of –1 returned indicates that the TLV was not
found. Note this index may only be valid as long as no Add or Delete
methods are executed.
The index represents the rank of the TLV in the TLVList rather than
the position of the Tag in a ByteString representation.
7.1.16.4.9 index()
TLVList.prototype.index()
TLV index (number index)
Returns a TLV object which represents the TLV stored within the TLVList at the given index.
The zero-based index identifies the TLV to be returned within the TLVList, by its sequence order in the list.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX),
TLV.EMV);
// Returns a TLV object with
// Tag 5F24 Value 020301
sampleTLV = sampleTLVList.index(1);
returns TLV A TLV object which contains the data stored at that index. Note any
changes to the returned TLV object will not be made to the TLVList
item.
7.1.16.4.10 toByteString()
TLVList.prototype.toByteString()
ByteString toByteString()
Returns the contents of the entire list, including T, L and V values in a TLV format as a ByteString object.
Example
// Creates a TLVList with
// Tag 4F Value A003
// Tag 5F24 Value 020301
sampleTList = new TLVList(new ByteString(“4F02A0035F2403020301”, HEX), TLV.EMV);
// sampleByteString will be a ByteString object with the value
// 0x4F02A0035F2403020301
sampleByteString = sampleTLVList.toByteString(TLV.EMV);
exception None
7.1.16.4.11 updateValue()
TLVList.prototype.updateValue()
updateValue(Number tag, ByteString updateValue)
Replaces the value of an already existing tag represented by tag with the value provided in updateValue, and then
recalculate and update the length value for this tag.
Example
// Updates existing tag 4F’s data to 0x0102A003
sampleTL.updateValue(0x4F, new ByteString(“0102A003”,HEX));
updateValue ByteString Data to replace existing value of TLV specified by tag with.
If the updateValue parameter contains a value which, when
replacing the existing value for the tag, is too large for a specified
encoding method, then a GPError object is generated with a value
of GPError.DATA_TOO_LARGE.
returns None
TLVList.prototype.updateValueIndex()
updateValueIndex(Number index, ByteString updateValue)
Replaces the value of an already existing tag represented by tag with the value provided in updateValue, and then
recalculate and update the length value for this tag.
Example
// Updates the second tag’s data to 0x0102A003
sampleTL.updateValueIndex(1, new ByteString(“0102A003”,HEX));
updateValue ByteString Data to replace existing value of TLV specified by tag with.
If the updateValue parameter contains a value which, when
replacing the existing value for the tag, is too large for a specified
encoding method, then a GPError object is generated with a value
of GPError.DATA_TOO_LARGE.
returns None
A. Sample Scripts
A.1 Example Scripts for Data Preparation
Application Profile
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 1 1} -->
<gp:ApplicationProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.ApplicationProfile.xsd" UniqueID="2A864886FC6B640101"
ProfileVersion="1.1.0" ErrataVersion="0">
<gp:Description>Application Profile Test</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2003-04-30" Time="00:00:00" By="Thales e-Security"
Digest="0000"/>
</gp:Revisions>
<gp:ConflictRules arrayElement="ConflictRule" arrayIndex="#"/>
<gp:ApplicationInfo Type="GP" Subtype="APP" Version="1.0.0" Owner="GlobalPlatform"
Developer="Thales e-Security" Provider="GlobalPlatform" Domain="" VolatileDataSpaceMax="1000"
VolatileDataSpaceMin="0" NonVolatileDataSpaceMax="1000" NonVolatileDataSpaceMin="0">
<gp:Privileges/>
<gp:LifeCycles arrayElement="LifeCycle" arrayIndex="Name">
<gp:LifeCycle Name="SampleLifeCycle01" Value="01"/>
<gp:LifeCycle Name="SampleLifeCycle02" Value="02"/>
<gp:LifeCycle Name="SampleLifeCycle03" Value="03"/>
</gp:LifeCycles>
<gp:Codes arrayElement="Code" arrayIndex="ModuleID"/>
</gp:ApplicationInfo>
<gp:Key Name="MasterKey_AC" ProfileID="2A864886FC6B640301" External="true"/>
<gp:Key Name="MasterKey_MAC" ProfileID="2A864886FC6B640302" External="true"/>
<gp:Key Name="DerivedKey_AC" ProfileID="2A864886FC6B640303" External="true"/>
<gp:Key Name="DerivedKey_MAC" ProfileID="2A864886FC6B640304" External="true"/>
<gp:Key Name="IssuerPrivateKey" ProfileID="2A864886FC6B640305" External="true"/>
<gp:Key Name="GeneratedPrivateKey" ProfileID="2A864886FC6B640306" External="true"/>
<gp:Key Name="GeneratedPublicKey" ProfileID="2A864886FC6B640308" External="true"/>
<gp:Key Name="WrappedPrivateKey" ProfileID="2A864886FC6B640308" External="true"/>
<gp:Key Name="ZMK" ProfileID="2A864886FC6B640309" External="true"/>
<gp:Key Name="WrappedDerivedKey_AC" ProfileID="2A864886FC6B64030A" External="true"/>
<gp:Key Name="WrappedDerivedKey_MAC" ProfileID="2A864886FC6B64030B" External="true"/>
<gp:DataElement Name="PAN" External="true" Type="ByteString" Encoding="HEX"
FixedLength="true" Length="4" Value="" Tag="" ReadWrite="false" Update="false" Optional="false"
MandatoryAudit="false"/>
<gp:DataElement Name="PSN" External="true" Type="ByteString" Encoding="HEX"
FixedLength="true" Length="4" Value="" Tag="" ReadWrite="false" Update="false" Optional="false"
MandatoryAudit="false"/>
<gp:DataElement Name="CardHolderInput" External="true" Type="ByteString" Encoding="HEX"
FixedLength="false" Length="1024" Value="" Tag="" ReadWrite="false" Update="false"
Optional="false" MandatoryAudit="false"/>
<gp:DataElement Name="authenticateTag1" External="true" Type="ByteString" Encoding="HEX"
FixedLength="false" Length="4" Value="" Tag="" ReadWrite="false" Update="false" Optional="false"
MandatoryAudit="false"/>
// ///////////////////////////////////////////////////////////////////////
// padByteString
//
// Returns the data passed in padded to the length specifed in padLength
// with the string specified in padData. Note if padData contains
// something other than a single byte ByteString then whatever it contains
// will be appended each time.
// ///////////////////////////////////////////////////////////////////////
function padByteString(data, padLength, padData)
{
var paddedData = data;
for (var i = data.length; i < padLength; i++)
paddedData = paddedData.concat(padData);
// ///////////////////////////////////////////////////////////////////////
// generateDerivationData
//
// This function generates the derivation data which consists of
// PAN + PSN.
// ///////////////////////////////////////////////////////////////////////
function generateDerivationData(pan, psn)
{
// Create the derivation Data, alter as to what you want the derivation
// data to be.
var derivationData = pan.concat(psn);
return derivationData;
}
// ///////////////////////////////////////////////////////////////////////
// addToOutput
//
// Takes the output data element and the TLV to add and updates the
// output data with the new TLV. If the tag already exists it is
// replaced, othewise it is appended to the end of the data.
// ///////////////////////////////////////////////////////////////////////
function addToOutput(output, tlv)
{
// Search for tag
// If not present add to end
var index = output.findIndex(tlv.getTag());
if (-1 == index)
output.append(tlv.getTLV());
else
{
// Already present so update data and length
// We need to delete the old empty tag and add a new one
output.deleteByIndex(index);
output.append(tlv.getTLV());
}
}
// ///////////////////////////////////////////////////////////////////////
// STEP 1:
// ///////////////////////////////////////////////////////////////////////
// STEP 2:
// Derive some keys by generating some derivation data from the PAN and PSN
// and then generating the derived keys.
// ///////////////////////////////////////////////////////////////////////
var derivationData = generateDerivationData(data.PAN, data.PSN);
// ///////////////////////////////////////////////////////////////////////
// STEP 3:
// Sign some data that requires authentication. This data could come from
// an INI/Parameter file.
// ///////////////////////////////////////////////////////////////////////
var authenticateTLV1 = totalInput.find(data.authenticateTag1.toSigned());
var authenticateTLV2 = totalInput.find(data.authenticateTag2.toSigned());
// ///////////////////////////////////////////////////////////////////////
// STEP 4:
// Generate an RSA keyset from which we export the private key and
// create a certificate using the public key.
// ///////////////////////////////////////////////////////////////////////
this.crypto.generateKeyPair(Crypto.RSA_KEY_PAIR_GEN, key.GeneratedPublicKey,
key.GeneratedPrivateKey);
// ///////////////////////////////////////////////////////////////////////
// STEP 5:
// Generate a certificate
// ///////////////////////////////////////////////////////////////////////
// Whatever goes into your certificate.
var cert = new ByteString("6A" +
"03" +
"01" +
key.GeneratedPublicKey.getComponent(Key.MODULUS) +
"BC",
HEX);
// Add to output
var certTLV = new TLV(0x4B, paddedCert, TLV.EMV);
var signedCertTLV = new TLV(0x5B, signedCertificate, TLV.EMV);
totalOutput.append(certTLV.getTLV());
totalOutput.append(signedCertTLV.getTLV());
// ///////////////////////////////////////////////////////////////////////
// STEP 6:
// Output the data.
// ///////////////////////////////////////////////////////////////////////
// Write to output
data.Output = totalOutput.toByteString();
]]></gp:Script>
</gp:ScriptFragment>
</gp:ApplicationProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 1} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640301" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="SECRET" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="true"/>
<gp:Value Format="DES" arrayElement="Component" arrayIndex="#">
<gp:Component/>
</gp:Value>
</gp:KeyProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 2} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640302" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="SECRET" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 3} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640303" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="SECRET" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="true"/>
<gp:Value Format="DES" arrayElement="Component" arrayIndex="#">
<gp:Component/>
</gp:Value>
</gp:KeyProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 4} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640304" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="SECRET" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 5} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640305" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="PRIVATE" SubType="RSA" Size="128" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="true" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="false"/>
<gp:Value Format="CRT" arrayElement="Component" arrayIndex="#">
<gp:Component/>
<gp:Component/>
</gp:Value>
</gp:KeyProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 6} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640306" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="PRIVATE" SubType="RSACRT" Size="128" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 7} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640307" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="PUBLIC" SubType="RSA" Size="128" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="false"/>
</gp:KeyProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 8} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640308" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="PRIVATE" SubType="RSACRT" Size="128" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="false"/>
</gp:KeyProfile>
<?xml version="1.0"?>
Copyright 2003 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by
GlobalPlatform. Use of this information is governed by the GlobalPlatform license agreement and any use
inconsistent with that agreement is strictly prohibited
9/24/2003 GlobalPlatform Systems Scripting Language Specification v1.1.0 189
<!-- UniqueID corresponds to OID {globalplatform 100 3 9} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B640309" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="PRIVATE" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="true" UnwrapWrap="false" Derive="false"/>
<gp:Value Format="CRT" arrayElement="Component" arrayIndex="#">
<gp:Component/>
<gp:Component/>
</gp:Value>
</gp:KeyProfile>
<?xml version="1.0"?>
<!-- UniqueID corresponds to OID {globalplatform 100 3 10} -->
<gp:KeyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gp="http://namespaces.globalplatform.org/systems-profiles/1.1.0"
xsi:schemaLocation="http://namespaces.globalplatform.org/systems-profiles/1.1.0
GP.systems.profiles.1.1.0.KeyProfile.xsd" UniqueID="2A864886FC6B64030A" ProfileVersion="1.1.0"
ErrataVersion="0">
<gp:Description>This is an example key profile</gp:Description>
<gp:Revisions arrayElement="Revision" arrayIndex="#">
<gp:Revision Version="1.0.0" Date="2002-01-01" Time="00:00:00" By="Thales e-Security"
Digest="0A0B0C0D"/>
</gp:Revisions>
<gp:KeyInfo Type="SECRET" SubType="DES" Size="16" Owner="10" Version="1"
StartDate="2001-12-01" EndDate="2003-12-01">
<gp:KeyPart/>
<gp:TransportKey/>
</gp:KeyInfo>
<gp:Attribute Sensitive="true" Importable="true" Exportable="true"/>
<gp:Usage Encrypt="false" Decrypt="false" DecryptEncrypt="false" Sign="false" Verify="false"
Wrap="false" Unwrap="false" UnwrapWrap="false" Derive="false"/>
<gp:Value Format="DES" arrayElement="Component" arrayIndex="#">
<gp:Component/>
<gp:Component/>
</gp:Value>
</gp:KeyProfile>
]]></gp:Script>
</gp:OpenSecureChannel>
</gp:SecureChannel>
// External parameters other than cardManagerAID which are required and depend on the
application specification and issuer choice:
// loadFileAID - the application identifier for the load file (can extract from the Load File
Profile)
// loadFileName - name of the load file (can extract from the Load File Profile)
// loadFileStructure - load file structure (can extract from the load file)
// loadFileDBHash - load file data block hash
// loadParamField - any specific load parameters for the load file
// loadToken - load token
// loadMethod - a boolean parameter which specifies whether to load by filename (true)
or load using load file structure (false)
// - loadMethod could be specified by the card issuer
if (this.data.loadMethod == 74727565) {
// Load the load file using the filename of the load file
GPSystem.trace("Attempt to load using the filename "+this.data["loadFileName"]);
GPSystem.trace(" this.loadByName("+this.data["loadFileName"].toString()+");");
this.loadByName(this.data["loadFileName"]);
GPSystem.trace("Load is successful.");
}
else {
// Load using the Load File structure specified in the Card Specification
GPSystem.trace("Attempt to load using the load file structure
"+this.data["loadFileStructure"]);
GPSystem.trace(" this.load(this.data["+this.data["loadFileName"]+"]);");
this.load(this.data["loadFileStructure"]);
GPSystem.trace("Load is successful.");
}
]]></gp:Script>
</gp:ScriptFragment>
// External parameters which are required and depend on the application specification
and issuer choice:
// loadFileAID - the application identifier for the load file (can extract from Load File
Profile)
// moduleAID - application identifier of the desired application module in the load file
(can extract from Load File Profile)
// applicationAID - application identifier to assign to the newly created application
instance (specified by card issuer)
// privileges - privileges for the new application instance (can extract from Application
Profile for application)
// installParamField - application specific installation parameters (valid options should
be documented by application developer in specification)
// installToken - install token
]]></gp:Script>
</gp:ScriptFragment>
GPSystem.trace("before dgi0101");
// Create DGI 0101 Contents
myDGI = new ByteBuffer();
myDGI.append(myObject.isid);
myDGI.append(myObject.cardExp);
myObject.dgi0101 = myDGI.toByteString();
GPSystem.trace("before dgi0102");
// Create DGI 0102 Contents
myDGI.clear();
myDGI.append(myObject.fName);
myDGI.append(myObject.mName);
myDGI.append(myObject.lName);
myDGI.append(myObject.DoB);
myObject.dgi0102 = myDGI.toByteString();
GPSystem.trace("before dgi0103");
// Create DGI 0103 Contents
myDGI.clear();
myDGI.append(myObject.streetAdd);
myDGI.append(myObject.cityAdd);
myDGI.append(myObject.zipAdd);
GPSystem.trace("before dgi8101");
// Create DGI 8101 Contents
myDGI.clear();
myDGI.append(myObject.ssn);
myDGI.append(myObject.cityOB);
myDGI.append(myObject.countryOB);
GPSystem.trace("before dgi9101");
// Compute aksKey check value Create DGI 9101 Contents
ToEnc = new ByteString("0000000000000000", HEX);
myEncValue = crypto.encrypt(myKey.aksKey, Crypto.DES_ECB, ToEnc, null);
myCheckValue = (myEncValue.bytes(0,3));
GPSystem.trace("before dgi9102");
// Create DGI 9102 Contents
myDGI.clear();
// Tag for FCI Template
myDGI.append("6F", HEX);
// Length of FCI Template
//tempvar = new ByteString("51", HEX);
myDGI.append("51", HEX);
// Tag for DF Name
myDGI.append("84", HEX);
// Length of DF Name
myDGI.append(myObject.dfName.getLV());
// Tag for FCI Proprietary template
myDGI.append("A5", HEX);
// Length of FCI Proprietary template
myDGI.append("3D", HEX);
// Tag for Application Label
myDGI.append("50", HEX);
// Length of Application Label
myDGI.append(myObject.applicationLabel.getLV());
// Tag for Application Priority Indicator
myDGI.append("87", HEX);
// Length of Application Priority Indicator
myDGI.append(myObject.applicationPriority.getLV());
// Tag for Language Preference
myDGI.append("5F2D", HEX);
// Length of Language Preference
myDGI.append(myObject.languagePreference.getLV());
GPSystem.trace("before dgi1101");
// Create DGI 1101 Contents
myDGI.clear();
myDGI.append(myObject.pinBlock);
myObject.dgi1101 = crypto.encrypt(myKey.transportPINKey, Crypto.DES_ECB,
myDGI.toByteString(), null);
GPSystem.trace("before dgi1102");
// Create DGI 1102 Contents
myDGI.clear();
myDGI.append(myObject.pinCount);
myDGI.append(myObject.pinLimit);
myObject.dgi1102 = myDGI.toByteString();
GPSystem.trace("before dgi7FFF");
// Create DGI 7FFF Contents
myDGI.clear();
myDGI.append(myCheckValue);
myObject.dgi7FFF = myDGI.toByteString();
]]></gp:Script>
this.card.reset(Card.RESET_WARM);
GPSystem.trace("debut this.select;");
GPSystem.trace("aid is: "+this.card.profile.ApplicationInstances.ApplicationInstance[0].AID);
// Selecting the application for secure update
// this.select(1 ,[0x6F00]);
this.select();
GPSystem.trace("debut openSecureChannel;");
// Open a secure channel for update
this.securityDomain.openSecureChannel(MACONLY);
GPSystem.trace("before dgi0101");
// Send DGI0101 to card
myStoreData = new ByteBuffer("0101", HEX);
GPSystem.trace("myStoreData = "+myStoreData);
GPSystem.trace("myObject.dgi0101 = "+myObject.dgi0101);
myStoreData.append(myObject.dgi0101.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, P1, 0x00,
myStoreData.toByteString());
GPSystem.trace("before dgi0102");
// Send DGI0102 to card
myStoreData.clear();
myStoreData = new ByteBuffer("0102", HEX);
myStoreData.append(myObject.dgi0102.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, P1, 0x01,
myStoreData.toByteString());
GPSystem.trace("before dgi0103");
// Send DGI0103 to card
myStoreData.clear();
myStoreData = new ByteBuffer("0103", HEX);
myStoreData.append(myObject.dgi0103.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, P1, 0x02,
myStoreData.toByteString());
GPSystem.trace("before dgi8101");
// Send DGI8101 to card
// Translate PIN Block key from transport key to kek
myEncDgi = this.securityDomain.secureChannel.decryptEncryptKek(myKey.transportKeyKey,
Crypto.DES_ECB, myObject.dgi8101,null);
GPSystem.trace("after decyptEncryptKek");
myStoreData.clear();
myStoreData = new ByteBuffer("8101", HEX);
myStoreData.append(myEncDgi.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, 0x60, 0x03,
myStoreData.toByteString());
GPSystem.trace("before dgi9101");
myKey.aksKey.setWrapKey(myKey.transportKeyKey);
myKey.wrappedAksKey.setComponent(Key.DES, myObject.dgi9101);
this.securityDomain.secureChannel.unwrapWrapKek(crypto.DES_ECB,
myKey.wrappedAksKey, myKey.unwrappedWrappedAksKey);
myEncDgi = myKey.unwrappedWrappedAksKey.getComponent(Key.DES);
myStoreData.clear();
myStoreData = new ByteBuffer("9101", HEX);
myStoreData.append(myEncDgi.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, 0x60, 0x04,
myStoreData.toByteString());
GPSystem.trace("before dgi9102");
// Send DGI9102 to card
myStoreData.clear();
myStoreData = new ByteBuffer("9101", HEX);
myStoreData.append(myObject.dgi9102.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, P1, 0x05,
myStoreData.toByteString());
GPSystem.trace("before dgi1102");
// Send DGI1102 to card
myStoreData.clear();
myStoreData = new ByteBuffer("1102", HEX);
myStoreData.append(myObject.dgi1102.getLV(TLV.EMV));
GPSystem.trace("before dgi1101");
// Send DGI1101 to card
// Translate PIN Block key from transport key to kek
myEncDgi = this.securityDomain.secureChannel.decryptEncryptKek(myKey.transportPINKey,
Crypto.DES_ECB, myObject.dgi1101,null);
myStoreData.clear();
myStoreData = new ByteBuffer(0x1101);
myStoreData.append(myEncDgi.getLV(TLV.EMV));
this.securityDomain.sendApdu(CLASEC, STOREDATA, 0x60, 0x07,
myStoreData.toByteString());
GPSystem.trace("before dgi7FFF");
// Send END PERSONALIZATION command to the card
EndPersoTime = GPSystem.dateTimeBytestring();
TerminalID = GPSystem.getSystemID();
myStoreData.clear();
myStoreData.append("09", HEX);
myStoreData.append(EndPersoTime.bytes(0,5));
myStoreData.append(TerminalID.bytes(0,4));
myStoreData.append(myObject.dgi7FFF);
this.securityDomain.sendApdu(CLASEC, ENDPERSO, P1, P2, myStoreData.toByteString());
]]></gp:Script>
</gp:ScriptFragment>
</gp:ApplicationProfile>
1
Parameters changed as required