![]() ![]() ![]() ![]() |
Java Card platform Remote Method Invocation (“Java Card RMI”) is a subset of the Java Remote Method Invocation (RMI) system. It provides a mechanism for a client application running on the CAD platform to invoke a method on a remote object on the card. The on-card transport layer for Java Card RMI is provided in the package javacard.framework.service
by the class RMIService
. It is designed as a service requested by the Java Card RMI-based applet when it is the currently selected applet.
The Java Card RMI message is encapsulated within the APDU object passed into the RMIService
methods.
This section defines the subset of the RMI system that is supported by Java Card RMI.
A remote object is one whose remote methods can be invoked remotely from the CAD client. A remote object is described by one or more remote interfaces. A remote interface is an interface which extends, directly or indirectly, the interface java.rmi.Remote
. The methods of a remote interface are referred to as remote methods. A remote method declaration includes the exception java.rmi.RemoteException
(or one of its superclasses such as java.io.IOException
or java.lang.Exception
) in its throws
clause. Additionally, in the remote method declaration, a remote object declared as the return value must be declared as the remote interface, not the implementation class of that interface.
Java Card RMI imposes additional constraints on the definition of remote methods. These constraints are a result of the Java Card platform language subset and other feature limitations.
The parameters of a remote method must only include parameters of the following types:
The return value of a remote method must only be one of the following types:
All parameters including array parameters are always transmitted by value during the remote method invocation. The return values from a remote method are transmitted by value for primitive types and arrays; return values that are remote object references are transmitted by reference using a remote object reference descriptor.
Java Card RMI uses the following simplified model for returning exceptions thrown by remote methods:
The definition of the supported subset of Java Card RMI for Java Card platform version 2.2.1 implies functional limitations during the execution of Java Card API remote methods:
The Java Card RMI message protocol consists of two commands that are used to:
To ensure that the protocol is compatible with all applications, the SELECT FILE command is used for getting the initial reference. The response to the SELECT FILE command allows the remote method invocation command itself to be customized by the applet.
The selection command used to retrieve the initial reference is the ISO7816-4 Select File command, with the following options in the header:
In addition, an alternate RFU variant of the Return FCI option is required to configure the RMIService
for an alternate Java Card RMI protocol format. (For more details see Section 8.4.1 "SELECT FILE Command.”)
The answer to this command is a constructed TLV(tag-length-value) data structure (ISO 7816-6) that includes the following information:
In order to request a method invocation, the CAD client provides the following information:
The response to the invocation request may include one of the following items:
This section describes the formats used to encapsulate the following:
This section uses a C-like structure notation similar to that used in the Virtual Machine Specification for the Java Card™ Platform, Version 2.2.1.
A remote object identifier is a 16-bit unsigned number which uniquely identifies a remote object on the card.
The remote object reference descriptor includes the remote object identifier, as well as information to instantiate the proxy class on the CAD client. The remote object reference descriptor uses one of two alternate formats. The representation based on the name of the class uses the remote_ref_with_class
format. The representation based on the names of the implemented remote interfaces uses the remote_ref_with_interfaces
format.
A remote object reference descriptor is therefore defined as follows:
remote_ref_descriptor { union { ref_null remote_ref_null remote_ref_with_class remote_ref_c remote_ref_with_interfaces remote_ref_i } }
The items in the remote_ref_descriptor
structure are:
ref_null
is the representation of a null reference using the following format:
The remote_ref_id
item must be the reserved value 0xFFFF
.
remote_ref_with_class
is the definition of a remote object reference using the class name and uses the following format:
remote_ref_with_class { u2 remote_ref_id != 0xFFFF u1 hash_modifier_length u1 hash_modifier[ hash_modifier_length ] u1 pkg_name_length u1 package_name[ pkg_name_length ] u1 class_name_length u1 class_name[ class_name_length ] }
The remote_ref_id
item represents the remote reference identifier. The value of this field must not be 0xFFFF
which denotes the null
reference.
The hash_modifier
item is an UTF-8 string of length specified in the hash_modifier
_length item and is used to ensure that method identifier hash codes are unique.
The pkg_name_length
item is the number of bytes in the package_name
item to represent the name of the package in UTF-8 string notation. The value of this item must be non-zero.
The package_name
item is the variable length representation of the fully qualified name of the package which contains the remote class in UTF-8 string notation. The fully qualified name of the package represented here uses the internal form wherein the ASCII periods (‘.
’) that normally separate the indentifiers that make up the fully qualified name are replaced by ASCII forward slashes (‘/
’). For example, the internal form of the normally fully qualified package name of the package java.rmi
is java/rmi
.
The class_name_length
item is the number of bytes in the class_name
item to represent the name of the remote class in UTF-8 string notation. The value of this item must be non-zero.
The class_name
item is the variable length representation of the name of the implementation class of the remote object in UTF-8 string notation.
remote_ref_with_interfaces
item is the definition of a remote object reference using the names of the interfaces and uses the following format:
remote_ref_with_interfaces { u2 remote_ref_id != 0xFFFF u1 hash_modifier_length u1 hash_modifier[ hash_modifier_length ] u1 remote_interface_count rem_interface_def remote_interfaces[remote_interface_count] }
The definition of the remote_ref_id
, the hash_modifier_length
and the hash_modifier
item are the same as that described earlier in the remote_ref_with_class
structure.
The remote_interface_count
item indicates the number of rem_interface_def
format entries in the remote_interfaces item. This number must be less than 16.
The remote_interfaces
item comprises a sufficient list of rem_interface_def
format entries containing the names of remote interfaces implemented. This list is such that when combined with their remote superinterfaces, the complete set of remote interfaces implemented by the remote object can be enumerated. The rem_interface_def
item uses the following format:
rem_interface_def { u1 pkg_name_length u1 package_name[ pkg_name_length ] u1 interface_name_length u1 interface_name[ interface_name_length ] }
The items in the rem_interface_def
structure are as follows:
The pkg_name_length
item is the number of bytes used in the package_name
item to represent the name of the package in UTF-8 string notation. If the value of this item is 0, it indicates that the package name of the previous remote_interfaces
item must be used instead. The value of this item in remote_interfaces[0]
must not be 0
.
The package_name
item is the pkg_name_length
byte length representation of the fully qualified name of the package which contains the remote interface in UTF-8 string notation. The fully qualified name of the package represented here uses the internal form wherein the ASCII periods (‘.
’) that normally separate the indentifiers that make up the fully qualified name are replaced by ASCII forward slashes (‘/
’). For example, the internal form of the normally fully qualified package name of the package java.rmi
is java/rmi
.
The interface_name_length
item is the number of bytes in the interface_name
item to represent the name of the remote interface in UTF-8 string notation.
The interface_name
item is the variable length representation of the name of the remote interface implemented by the remote object in UTF-8 string notation.
A method identifier will always be used in association with a remote object reference. A method identifier is defined as follows:
The method_id
is a unique 16-bit hashcode identifier of the remote method within the remote class. This 16-bit hashcode consists of the first two bytes of the SHA-1 message digest function performed on a class specific hash modifier string followed the name of the method followed by the method descriptor representation in UTF-8 format. Representation of a method descriptor is the same as that described in The Java Virtual Machine Specification (Section 4.3.3)
Every parameter will have the following generic format:
Primitive data types void
, boolean
, byte
, short
and int
will respectively be encoded as follows:
void_param { } boolean_param { u1 boolean_value } byte_param { s1 byte_value } short_param { s2 short_value } int_param { s4 int_value }
The boolean_value
field may only take the values 0
(for false
) and 1 (for true
). All the other fields can take any value in their range.
The representation of the null array parameter and arrays of the boolean
, byte
, short
and int
component types include the length information and will respectively be encoded as follows:
null_array_param {
u1 length = 0xFF
}
boolean_array_param {
u1 length != 0xFF
u1 boolean_value[length]
}
byte_array_param {
u1 length != 0xFF
s1 byte_value[length]
}
short_array_param {
u1 length != 0xFF
s2 short_value[length]
}
int_array_param {
u1 length != 0xFF
s4 int_value[length]
}
length
field in each of the array data structure defined above represents the number of elements of the array, and not its size in bytes.
A return value may be any of the parameter types described in the previous section encapsulated within a normal response format. In addition, the return value may represent a remote object reference type, a null
return type, various exceptions and the error type.
The generic structure of a return value is as follows:
The return value using the return_response
encoding is always followed by a good completion status code of 0x9000
in the response APDU.
A normal response encapsulates primitive return types, arrays of primitive data types using the same format for the param
item as described in Section 8.3.4 "Parameter Encoding” using the following format:
The null_array_param
format described in the Parameter Encoding Section 8.3.4 is not used to represent a null
array reference. Instead, a null object reference as well as a null array reference share the following common format:
In addition, a remote object reference descriptor type is also encapsulated using the normal response format as follows:
The following is the encoding when an API defined exception is thrown by the remote method. It may be returned during any remote method invocation. The reason
item is the Java Card platform exception reason code, or 0
for a java.lang,
java.rmi
or java.io
exceptions:
The values for the exception_type
item are shown below:
java.lang.Throwable = 0x00
java.lang.ArithmeticException = 0x01
java.lang.ArrayIndexOutOfBoundsException = 0x02
java.lang.ArrayStoreException = 0x03
java.lang.ClassCastException = 0x04
java.lang.Exception = 0x05
java.lang.IndexOutOfBoundsException = 0x06
java.lang.NegativeArraySizeException = 0x07
java.lang.NullPointerException = 0x08
java.lang.RuntimeException = 0x09
java.lang.SecurityException = 0x0A
java.io.IOException = 0x0B
java.rmi.RemoteException = 0x0C
javacard.framework.APDUException = 0x20
javacard.framework.CardException = 0x21
javacard.framework.CardRuntimeException = 0x22
javacard.framework.ISOException = 0x23
javacard.framework.PINException = 0x24
javacard.framework.SystemException = 0x25
javacard.framework.TransactionException = 0x26
javacard.framework.UserException = 0x27
javacard.security.CryptoException = 0x30
javacard.framework.service.ServiceException = 0x40
The following is the encoding when a user defined exception is thrown by the remote method. The exception_type
item represents the closest API defined exception type. It may be returned during any remote method invocation. The reason
item is the Java Card platform exception reason code, or 0
for the subclasses of java.lang
, java.rmi
or java.io
exceptions:
The following encoding represents an error condition on the card. The error may occur due to marshalling, unmarshalling or resource related problems.
The values of the error_detail
item are enumerated below:
= 0x0001
= 0x0002
The
Remote Method signature did not match the parameter format = 0x0003
0x0004
0x0005
0x0006
0xFFFF
Section 8.3 "Data Formats” described the various elements included in the data portion of the Java Card RMI messages. This section describes the complete format of the APDU commands - the header as well as the data portion containing the message elements described earlier.
The Select command for an RMI based applet must have the following format:
Field
|
Value
|
Description
|
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CLA
|
%b000000xx
|
The bits (b2,b1*) are used for logical channels
|
||||||||||||
INS
|
0xA4
|
SELECT FILE
|
||||||||||||
P1
|
0x04
|
Select by AID
|
||||||||||||
P2
|
%b000x00xx
|
Return FCI information
|
||||||||||||
The bits (b2,b1*) are used for partial selection if supported. If bit b5* is 1, the remote reference descriptor uses the remote_ref_with_interfaces
format, otherwise it uses the alternate remote_ref_with_class
format.
Field
|
Value
|
Description
|
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Lc
|
xx
|
Length of the AID
|
||||||||||||
Data
|
AID
|
AID of the applet to be selected (between 5 and 16 bytes)
|
||||||||||||
The format of the response is defined as shown below. Note that the applet may extend the format to include additional information, if necessary before sending the response back to the CAD. The additional information must retain the TLV format and must not introduce any additional information under the jc_rmi_data_tag
.
select_response { u1 fci_tag = 0x6F u1 fci_length u1 application_data_tag = 0x6E u1 application_data_length u1 jc_rmi_data_tag = 0x5E u1 jc_rmi_data_length u2 version = 0x0202 u1 invoke_ins union { normal_ref_response normal_initial_ref normal_null_response null_initial_ref error_response initial_ref_error } initial_ref }
The jc_rmi_data_length
item above is the combined length in bytes of the version
item, invoke_ins
item and the initial_ref
item. The application_data_length
item is jc_rmi_data_length + 2
. The fci_length
item is application_data_length + 2
.
The response data includes invoke_ins
, the instruction byte to use in the method invocation command. It also includes initial_ref
, the initial remote object reference descriptor. The initial_ref
item corresponds to the remote object designated as the initial reference to the RMIService
instance during construction. The initial_ref
item can be a normal_ref_response item described in Section 8.3.5.1 or a null
representation using a normal_null_response
item described in Section 8.3.5.1, if the initial remote reference object is not enabled for remote access. Also, note that if an error occurs during the marshalling of the initial remote reference descriptor, an error response is returned in initial_ref
instead using the error_response item format described in Section 8.3.5.3 .
select_response
structure shown above uses the C-like “union” notation, the lengths of the alternate representations within the union do not use any padding to normalize their lengths.
The format of the remote_ref_descriptor
to be used in this response as well as all subsequent responses - remote_ref_with_class
or remote_ref_with_interfaces
- is determined by the value of the P2 byte of the SELECT FILE command.
RMIService
instance which processes the SELECT FILE command sets (or changes) the format of the remote object reference descriptor based on the value of the P2 byte. Once set or changed, the RMIService
instance uses only that format in all Java Card RMI responses it generates.
The Invoke command for a remote method invocation request must have the following format:
The data part of the request command is structured as:
The object_id
is the remote object identifier of the object whose remote method is to be invoked. The method to be invoked is specified by the method_id
item, and each parameter
is specified by a param
structure.
The response format uses the return_response structure as described in Section 8.3.5 "Return Value Encoding” above.
The RMIService
class implements the Java Card RMI protocol and processes the RMI access commands described earlier: SELECT FILE and INVOKE. It performs the function of the transport layer for Java Card RMI commands on the card.
The RMIService
object maintains a list of remote objects which have been returned during the current applet selection session. It enforces the following rules for the lifetime of the remote object references:
RMIService
instance which returned the reference.
In addition, a remote object reference descriptor of an object must only be returned from the card if it is exported (See the class javacard.framework.service.CardRemoteObject
.) Otherwise, an exception is thrown (See the class javacard.framework.service.RMIService
.)
This method sets the value of invoke_ins described in Section 8.4.1, which is returned in the response to the SELECT FILE command. The change in the Java Card RMI protocol only goes into effect the next time this RMIService
instance processes the SELECT FILE command. If this method is not called, the default instruction byte value (DEFAULT_RMI_INVOKE_INSTRUCTION
) is used.
The processCommand
method of the RMIService
class is invoked by the applet to process an incoming RMI message. RMIService
collaborates with other services by using the common service format (CSF) in the APDU buffer. It processes only the incoming Java Card RMI APDU commands and produces output as described in the previous sections.
When called with a SELECT FILE command with format described in Section 8.4.1, this method builds a response APDU as described in that section.
When called with an INVOKE command with the format described in Section 8.4.2, this method must call the specified remote method of the identified remote object with the specified parameters. It must catch all exceptions thrown by the remote method. When an exception is caught or the remote method returns, this method must build a response APDU in the format described in Section 8.4.2.
Prior to invoking the remote method the following errors must be detected and must result in an error response in the format described in Section 8.3.5.3:
In addition, upon return from the remote method, the following errors must be detected and must result in an error response in the format described in Section 8.3.5.3:
In addition to the above, the object access firewall rules must be enforced in a manner similar to that of the invokevirtual
instruction (Section 6.2.8.4) by this method when a remote method is invoked. Only methods of a remote object owned by the context of the currently selected applet may be invoked.
Since array parameters to remote methods are transmitted by value, array objects need to be allocated on the card when a remote method with array arguments is invoked via the INVOKE command. Global array objects (Section 6.2.2) must be used for incoming remote method arguments. Global arrays have the following properties:
The implementation may choose to maintain the data portion of these global array objects used for remote method parameters in the APDU buffer itself.
![]() ![]() ![]() ![]() |
Runtime Environment Specification for the Java Card Platform Specification, 2.2.1 |
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.