Introduction
This article is written to explain the JCRE functionality and behavior. More over this article explains some basic components of the JCRE such as the Javacard Applet, the Javacard Appplet firewall and JVCRE context switching mechanism.
The Java-card Runtime Environment
The Java Card runtime environment (JCRE) should be considered as the part of the platform that implements the component that does the Java Card Applet interpretation, and it is the most important part of the Java Card platform. JCRE is responsible for:
1. Smart Card resource management (e.g. Allocate Smart Card computing resources).
2. Network communication management (e.g. Card Acceptance Device sessions).
3. Applet manipulation (e.g. Applet execution).
4. Real-time on card security enforcement (e.g. Apply security policies).
The JCRE sits on top of the smart card hardware native system and represents the part of the Smart Card operating system that performs the executions , it is actually the core module of the operating system. The classes are responsible of managing the transactions between an off card entity and the on card entity (e.g. Update Applet data).
The Java Card application framework defines the Java Card API available to the programmer. The installer makes sure the Java Card Applet downloading happens in a secure and efficient manner. The software component called installer is what makes possible dynamic application management, without the installer Java Card Applets would not be capable of being installed dynamically, meaning after the Smart Card fabrication stage.
JCRE lifetime
The JCRE is initialized at the Smart Card initialization stage and remains active until the Smart Card is terminated. During initialization the JCRE creates all the necessary services (objects that implement the services) needed for the SC in order to be functional. After a Java Card Applet is downloaded and installed the JCRE creates Java Card instances and Java Card Applets create objects to store data. At this point it would be important to mention that a JCApplet can have a different AID than its own instance (see JCApplet Name Convention paragraph).
JCRE features
The JCRE component supports the Java Card language model, but also supports many other features unique to Java Card platform. Three of the most important features concerning both Smart Card functionality and security are:
1. Persistent and transient objects.
2. Atomic operations and transactions.
3. Applet firewall and sharing mechanism.
When the JCRE wants to make a JCApplet persistent [4], (all JCApplets are persistent by default) then stores a reference of the JCApplet instance object in a persistent memory type such as NVM. The term persistent is used to describe a JCApplet that sustains a cold reboots.
A JCApplet can create a transient object [4], (all JCApplets objects are transient by default, for security reasons) when it stores a reference of the object in a non-persistent memory such as RAM. The term transient is used to describe an object that does not sustain cold reboots; JCApplets are not allowed to carry data between CAD sessions.
By using the term Atomic operations/transactions [4] we refer to the ability of the JCRE to make transactions all or nothing, meaning that in order for a transaction to take effect has to be performed correctly until the end without errors or else the effect of this transaction won’t take place. The JCVM will ensure that each write operation to an object is atomic. A transaction can fail for many reasons (e.g. the card holder removes the card from the CAD before the transactions is performed).
Part of the SUN Java Card platform security requirements demands [1] was that the on-card linker and loader are needed to contribute in fulfilling these requirements. The JCVM firewall security mechanism performs a set of verifications to ensure that memory integrity is preserved.
The main role of the on-card Java Card firewall is to make sure that the runtime behavior of JCApplets converted applets (CAP files) happens in a secure and clear way, preventing objects from performing illegal access operations, performed mostly outside their Java Card packages. A package is a collection of JCApplets and objects associated with only a single application.
The main goal of the Java Card firewall is to strictly enforce Java Card generic security policies defined in the Java Card specification. The Java Card firewall provides the assurance that the access rules of Java Card Runtime Environment specification 2.1 are fulfilled [1].
Java Card Applets
Before describing in more detail the security properties of a JCApplet, we should recall in this section what makes Java Card applications different if compared to other ordinary applications. A JCApplet is restricted by: the limited resources of the Smart Card and the Java Card platform security requirements.
A normal JCApplet goes through many different phases:
1. Loading: The code of the application is downloaded from the off card entity into the on card entity, the SC.
2. Installation: An applet instance is created and registered during the JCApplet installation [3]. Several instances of the same applet can coexist with different AID, so as the JCRE can select them.
3. Personalization: A registered JCApplet (in order for a JCApplet to register first has to install) instance object is personalized only after receiving and initializing the proper data. An applet is personalized only once and only then can become operational or functional. Note however that there is no explicit support for each JCApplet in the system concerning personalization [3], which means that the programmer has to take into consideration programming that task.
4. Processing: When a registered, operational JCApplet is selected, it can receive several C-APDU commands and responds back with R-APDU, and afterwards it can be deselected. This can be repeated many times until the transaction is performed.
Java Card Applet Name Conventions
Each JCApplet instance is identified by a pre-selected application identifier (AID). The same thing happens for the JCApplet, actually before any JCApplet can run first has to have the corresponding package already installed.
If the JCApplet instances are registered with the default AID (meaning the JCApplet owner AID) then the register function is called without parameters. If the JCApplet instances are installed with other AID then the parameters that initialized the register method are provided from the install function and the instance becomes operational. An AID is literary speaking a byte array used as a selection identifier. Each AID that complies with the ISO 78164 consists of a RID and PIX. The RID is a 5-byte value called resource identifier and PIX is a 0 to 11-byte value, called proprietary identifier extension. The PIX value works as a company identifier and the PIX is used as an application identifier within the same company.
Java Card Applet Categories
The Java Card platform supports three different kinds of JCApplets, the ROM JCApplet, the Pre-issuance JCApplets and the Post-issuance JCApplets.
The ROM JCApplets are simply a JCApplets written into Smart Card ROM memory space, which means that it must be burned into the ROM during the Smart Card fabrication stage. Because ROM JCApplets are owned by the issuer the Java Card platform treats them as a trusted peace of software and allows this kind of JCApplets to make native calls, e.g. using the C/C++ programming languages.
Pre-issuance JCApplets are simply JCApplets written into an NVM memory, which means that the procedure takes place after the Smart Card fabrication stage. Because Pre-issuance JCApplets are also owned by the issuer the Java Card platform treats them as a semi-trusted peace of software and does not allow making native calls.
Post-issuance JCApplets are simply JCApplets written into the Smart Card NVM memory, which means that the procedure takes place after the Smart Card fabrication stage. Actually post-issuance JCApplets are installed to the smart card after the card is launched to the field. Because Post-issuance JCApplets are not owned by the issuer the Java Card platform treats them as an un-trusted peace of software and does not allow making native calls.
Java Card Applet life cycle
In order for a JCApplet to be functional or operational first has to go through a few procedures that reside inside the smart card platform. After the packages defining a JCApplet have been loaded and linked correctly, inside the SC, the JCApplet can start operating normally. A JCApplet first has to be installed, then has to register and then if selected can start performing useful tasks by using the process function to process C-APDU commands. Now because JCRE is a single threaded environment only one JCApplet can run each time, a JCApplet becomes selected only when explicitly requested by an application host. The term selected refers to a procedure performed when an off-card entity wishes to interact with a specific JCApplet that resides into the SC. A regular JCApplet goes through lots of phases during its life time and before it terminates.
The following functions that are used to manipulate JCApplets are well formed procedures defined at the Java Card platform specification:
1. JCApplet install: Is the method called by the JCRE during a JCApplet installation in order to create a JCApplet instance. The install method is similar to functionality with the Java main function, when this method is called then three things happen: a. a service object is created on behalf of the JCApplet, b. the service object is initialized to provide the specific services, c. the service object is registered with the JCRE. Service Object (SO) is the term that refers to an object created by a post-issuance or pre-issuance JCApplet in order to become operational.
2. JCApplet registration: Is the function called by the JCRE used to do two things: a. to store the JCApplet reference to the JCRE (so as the JCApplet can become selectable) and b. to assign a valid AID to the instance, the default AID is the same of the JCApplet.
3. JCApplet process: Is the function used by the JCApplet instance to process the incoming C-APDU and produce the outgoing R-APDU.
After a JCApplet is selected, it can get deselected and selected again many times until the JCRE decides to dispose the JCApplet permanently from the smart card (e.g. delete the JCApplet). A JCApplet remains in suspended state until it gets selected by the JCRE. The SELECT APDU command is the only C-APDU command standardized on the Java Card platform [4], providing that way interoperable JCApplet selection in various Java Card implementations.
Before new JCApplet gets selected by the JCRE (the JCRE is single threaded) must first deactivate the previously selected JCApplet, unless the previously selected JCApplet is the one that has to be selected now. If the JCRE receives an APDU SELECT command about a JCApplet, then if the JCApplet is installed and registered to the JCRE then it will get selected and capable of interacting with the host application through the JCRE.
JCApplet firewall
The primary goal (as already mentioned earlier) of the on-card JCApplet firewall is to execute Java Card byte-code in a secure manner, preventing objects from illegally accessing memory parts outside their Java Card packages [1]. Even though Java Card platform is multi-application platform Java Card Applications isolation is not always true! Access between two or more packages is possible and can be controlled by the firewall. At this point Java Card platform could be considered as a hybrid of multi-application platforms and multi-function platforms.
Java Card Application firewall provides the assurance that the access rules of Java Card Runtime Environment specification 2.1 are fulfilled [2,1]. The firewall can not stop ill formed Java Card Applets that behave maliciously. Actually the confidentiality of a Java Card Application will not be preserved by the firewall if such applications provide a sharable interface associated with confidential data and fail to properly manage that data (for Sharable Interface see relevant paragraph that follows), because any other application may legally obtain the data references and gain access to the data (see more about sharable on article Object Sharing paragraph).
The Java Card firewall takes into account the following aspects:
1. The currently selected JCApplet.
2. Object access rights.
3. Context switching between objects.
4. Access across different group contexts.
Any attempt to go through the firewall raises a SecuirtyException (Java Card Exceptions and Exception Handling are beyond the scope of this report) [19].
JCApplet firewall features
The single threaded JCRE uses the Java Card Application firewall to prevent objects from being illegally accessed by JCApplets that do not have the ownership. The context notion, of the context the object is contained, enforces the proper access requirements. Each CAP file loaded in the card is associated with a specific runtime context under the following rules [1]:
1. Every Java Card Application is represented by only one package.
2. One Java Card package defines only a single runtime context.
3. All JCApplets that belong to the same package use one runtime context also called group context.
4. Objects created during a specific runtime context belong to that context.
5. All methods and objects that belong to the system JCApplets (entry-points and arrays, see relevant paragraph that follows) belong to a particular context along with the JCRE context, also called system context.
7. JCRE entry points, objects and global arrays are within the JCRE package and can be accessed from any context [1].
As a consequence, Java Card Applications are securely isolated from other contexts; this is a security requirement for all multi-application platforms. One of the responsibilities the linker has is to resolve object references. A method cannot directly refer to objects if they are not objects of the system or if they are outside its package [1].
[1]St?©phanie Motr?©, Formal Model and Implementation of the Java Card Dynamic Security Policy, 2000, date retrieved: 22-06-2005
URL:http://66.102.9.104/search?q=cache:PHaFaHXJeIAJ:www-lsr.imag.fr/afadl2000/Programme/Articles/motre.doc
+java-card+CAP+verification+attacks+&hl=en&start=31&ie=UTF-8&client=firefox-a
[2]Sun Microsystems, Inc, Java Card(TM) Specification, Version 2.2.1, October 29 2003, date retrieved: 01-07-2005
URL: http://java.sun.com/products/javacard/specs.html
[3]Renaud Marlet, Daniel Le M??etayer (Trusted Logic), Security Properties and Java Card Specificities to Be Studied In the SecSafe Project, Version 1.0, 2001/08/23, Date retrieved: 01-08-2005
[4]Zhiqun Chen, Java Card TM Technology for Smart Cards, June 2000, Sun Microsystems Inc.