| C H A P T E R 6 |
|
Java Card Platform Libraries |
The Java SE platform and the Java Platform, Enterprise Edition (Java EE) provide a very rich set of libraries for the development of applications for desktop computers and server machines. Unfortunately, these libraries require multiple megabytes of memory to run, and are therefore unsuitable for small devices with limited resources.
A general goal for designing the libraries for the Java Card platform is to provide a minimum useful set of libraries for practical application development for the various market segments for smart card devices. As explained in Section 2.1, Goals, the Java Card platform is a “lowest common denominator” standard that includes only the minimal Java platform features and APIs for a wide range of smart card devices. Given the strict memory constraints and differing features of smart card devices, it is virtually impossible to create a set of libraries that would be ideal for everyone. No matter where the bar for feature inclusion is set, the bar is inevitably going to be too low for some smart card devices and users, and possibly too high for others.
To ensure upward compatibility with larger editions of the Java platform, the majority of the libraries included in the Java Card platform are a subset of the Java SE platform, the Java EE platform, and Java Platform, Micro Edition (Java ME platform). While upward compatibility is a very desirable goal, Java SE and Java EE class libraries have strong internal dependencies that make subsetting them difficult in important areas such as security, input-output, networking, and storage. These dependencies are a natural consequence of the design evolution and reuse that has taken place over time during the development of Java libraries. Unfortunately, these dependencies make it difficult to take just one part of the libraries without including several others. For this reason, some Java ME class libraries, especially in the area of networking are included.
The Java Card platform libraries defined by the Virtual Machine Specification, Java Card Platform, v3.0.1, Connected Edition can be divided into the following two categories:
Classes belonging to the former category are located in packages java.lang.*, java.util, java.io, and java.security. A detailed list of these classes is presented in Section 6.2, Classes Derived from Java SE Platform.
Classes belonging to the latter category are located in package javax.microedition.io, and javax.microedition.pki. These classes are discussed in Section 6.3, Classes Derived from Java ME Platform.
The Java Card platform supports a number of classes that have been derived from the Java SE 6 platform. Each class that has the same name and package name as a Java SE class is identical to or a subset of the corresponding Java SE class. The semantics of the classes and their included methods in the subset are not changed. The classes do not include any public or protected methods or fields that are not available in the corresponding Java SE classes.
For a definitive reference on the classes listed in this section, refer to the Application Programming Interface Specification, Java Card Platform, Version 3.0.1, Connected Edition for all the Java Card platform and framework libraries in Javadoc
tool format.
Java SE class libraries include several classes that are intimately coupled with the Java virtual machine. Similarly, several standard Java technology tools assume the presence of certain classes in the system. For instance, the standard Java technology compiler (javac) generates code that requires that certain functions of classes String and StringBuffer and StringBuilder be available. The system classes included in the Virtual Machine Specification, Java Card Platform, v3.0.1, Connected Edition are provided in the following list. Each of these classes is a subset of the corresponding class in the Java SE platform.
java.lang.Object java.lang.Class<T> java.lang.Enum java.lang.Runtime java.lang.System java.lang.Thread java.lang.Runnable (interface) java.lang.String java.lang.StringBuffer java.lang.StringBuilder java.lang.Throwable java.lang.Iterable<T> (interface) java.lang.annotation.Annotation java.lang.annotation.AnnotationFormatError java.lang.annotation.Documented java.lang.annotation.ElementType java.lang.annotation.Inherited java.lang.annotation.Retention java.lang.annotation.RetentionPolicy java.lang.annotation.Target java.lang.Override java.lang.SuppressWarnings
The following basic data type classes from package java.lang are supported. Each of these classes is a subset of the corresponding class in the Java SE platform.
java.lang.Boolean java.lang.Byte java.lang.Short java.lang.Integer java.lang.Long java.lang.Character java.lang.Void
The following collection classes from package java.util are supported.
java.util.Vector<E> java.util.Stack<E> java.util.Hashtable<K,V> java.util.Enumeration<E> (interface)
The following classes from package java.io are supported.
java.io.InputStream java.io.OutputStream java.io.ByteArrayInputStream java.io.ByteArrayOutputStream java.io.DataInput (interface) java.io.DataOutput (interface) java.io.DataInputStream java.io.DataOutputStream java.io.Reader java.io.BufferedReader java.io.BufferedWriter java.io.Writer java.io.PrintWriter java.io.InputStreamReader java.io.OutputStreamWriter java.io.PrintStream
The Java Card platform includes a small subset of the standard Java SE classes java.util.Calendar, java.util.Date, and java.util.TimeZone. To conserve space, the Virtual Machine Specification, Java Card Platform, v3.0.1, Connected Edition requires only one time zone to be supported. By default, this time zone is GMT. Additional time zones may be provided by manufacturer-specific implementations of the Java Card platform, as long as the time zones are compatible with those provided by the Java SE platform.
java.util.Calendar java.util.Date java.util.TimeZone
Two additional utility classes are provided. Class java.util.Random provides a simple pseudo-random number generator that is useful for implementing security applications. Class java.lang.Math provides methods min, max and abs that are frequently used by other Java library classes. The java.util.EventObject class and the java.util.EventListener class provide the basic event functionality required for web applications.
java.util.Random java.lang.Math java.util.EventObject java.util.EventListener
The Java Card platform includes a small subset of Java SE platform security classes which support Access Control security functions.
java.security.AccessController java.security.Permission java.security.BasicPermission
The Java Card platform also includes a small subset of Java SE platform internationalization framework to enable internationalization and localization functionality.
java.util.Locale java.util.ResourceBundle java.util.ListResourceBundle
Since the libraries included in the Java Card platform are generally intended to be highly compatible with Java SE class libraries, the library classes included in the Java Card platform MUST throw precisely the same exceptions as regular Java SE classes. Consequently, a fairly comprehensive set of exception classes has been included.
In contrast, as explained in Section 4.3, Exception and Error Handling Limitations, the error handling capabilities of the Java Card platform are limited. By default, a virtual machine conforming to the Java Card platform is required to support only the error classes listed below in Section 6.2.9.2, Error Classes.
java.lang.Exception java.lang.ArithmeticException java.lang.ArrayIndexOutOfBoundsException java.lang.ArrayStoreException java.lang.AssertionError java.lang.ClassCastException java.lang.ClassNotFoundException java.lang.IllegalAccessException java.lang.IllegalArgumentException java.lang.IllegalStateException java.lang.IllegalMonitorStateException java.lang.IllegalThreadStateException java.lang.IndexOutOfBoundsException java.lang.InstantiationException java.lang.InterruptedException java.lang.NegativeArraySizeException java.lang.NoSuchFieldError java.lang.NullPointerException java.lang.NumberFormatException java.lang.RuntimeException java.lang.SecurityException java.lang.StringIndexOutOfBoundsException java.util.EmptyStackException java.util.NoSuchElementException java.util.MissingResourceException java.security.AccessControlException java.io.EOFException java.io.InterruptedIOException java.io.IOException java.io.UnsupportedEncodingException java.io.UTFDataFormatException
java.lang.Error java.lang.NoClassDefFoundError java.lang.OutOfMemoryError java.lang.VirtualMachineError
Character sets and character case conversion support - A Java Card platform implementation is required to support Unicode characters. Character information is based on the Unicode Standard, version 3.0. However, since the full character tables required for Unicode support can be excessively large for devices with tight memory budgets, by default the character property and case conversion facilities in the Java Card platform assume the presence of ISO Latin-1 range of characters only. More specifically, implementations must provide support for character properties and case conversions for characters in the “Basic Latin” and “Latin-1 Supplement” blocks of Unicode 3.0. Other Unicode character blocks may be supported as necessary.
Character encodings - The Java Card platform includes limited support for the translation of Unicode characters to and from a sequence of bytes. In the Java SE platform, this is done using objects called Readers and Writers, and this same mechanism is utilized in the Java Card platform using the InputStreamReader and OutputStreamWriter classes with identical constructors.
new InputStreamReader(InputStream is); new InputStreamReader(InputStream is, String enc); new OutputStreamWriter(OutputStream os); new OutputStreamWriter(OutputStream os, String enc);
If the enc parameter is present, it is the name of the encoding to be used. Where it is not, a default encoding (defined by the system property javacard.encoding) is used.
A virtual machine conforming to Virtual Machine Specification, Java Card Platform, v3.0.1, Connected Edition must support the following character encodings:
Additional converters may be provided by particular implementations. If a converter for a certain encoding is not available, an UnsupportedEncodingException will be thrown. For official information on character encodings in the Java SE platform, refer to
http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
Localization support - The Java Card platform includes limited support for localization based on a small subset of Java SE platform internationalization framework, see Section 6.2.8, Basic Internationalization and Localization Classes.
A virtual machine conforming to Virtual Machine Specification, Java Card Platform, v3.0.1, Connected Edition does not include the java.util.Properties class from the Java SE platform. In the Java SE platform, that class is used for storing system properties such as the name of the host operating system, version number of the virtual machine and so on.
In the Java Card platform, the set of platform properties described in TABLE 6-2 is available. These properties and other manufacturer specific extensions can be accessed by calling the method System.getProperty(String key).
Property javacard.encoding describes the default character encoding name. This information is used by the system to find the correct class for the default character encoding in supporting internationalization.
Property line.separator describes the default line separator. This is used by some of the I/O classes to terminate output lines written to an output stream.
Note that the properties defined above can be extended by smart card device manufacturers.
Manufacturer-specific property definitions should be prefixed with the same package name that the manufacturer-specific classes use (e.g., com.companyname.propertyname). The microedition namespace, as well as the java, javax, javacard and javacardx namespaces are reserved, and may only be extended by the Java Card platform specifications.
The Java Card platform supports a number of classes that have been derived from the Java ME platform. Each class that has the same name and package name as a Java ME class is identical to the corresponding Java ME class. The semantics of the classes and their included methods are not changed. The classes do not include any public or protected methods or fields that are not available in the corresponding Java ME classes.
For a definitive reference on the classes listed in this section, refer to the Application Programming Interface Specification, Java Card Platform, Version 3.0.1, Connected Edition for all the Java Card platform and framework libraries in Javadoc tool format.
The Generic Connection framework classes are a generalization of the Java SE technology-network and I/O classes. The goal for this generalized design is to be a functional subset of Java SE classes, which can easily map to common low-level hardware or to any Java SE technology implementation, but with better extensibility, flexibility and coherence in supporting new devices and protocols.
Instead of using a collection of different kinds of abstractions for different forms of communication, a set of related abstractions are used at the application programming level.
The following code line is the generic form used to request a network connection. An implementation specific instance implementing the specified protocol interface is returned.
Connector.open("<protocol>:<address>;<parameters>");
The syntax of the Connector.open parameter strings should generally follow the Uniform Resource Identifier (URI) syntax as defined in the IETF standard RFC3986 (http://www.ietf.org/rfc/rfc3986.txt).
The Generic Connection Framework includes the following base classes:
javax.microedition.io.Connector javax.microedition.io.Connection(interface) javax.microedition.io.InputConnection(interface) javax.microedition.io.OutputConnection(interface) javax.microedition.io.StreamConnection(interface) javax.microedition.io.ContentConnection(interface) javax.microedition.io.StreamConnectionNotifier(interface) javax.microedition.io.DatagramConnection(interface)
Additional Generic Connection Framework classes provide network protocol specific extensions to the base classes:
javax.microedition.io.Datagram(interface) javax.microedition.io.UDPDatagramConnection(interface) javax.microedition.io.HttpConnection(interface) javax.microedition.io.HttpsConnection(interface) javax.microedition.io.SocketConnection(interface) javax.microedition.io.SecureConnection(interface) javax.microedition.io.SecurityInfo javax.microedition.io.ServerSocketConnection(interface)
The general purpose Generic Connection Framework exception class is also included:
javax.microedition.io.ConnectionNotFoundException
In order to read and write data to and from Generic Connections, a number of input and output stream classes are needed. The stream classes supported by the Java Card platform are listed in Section 6.2.4, Input-Output Classes.
A minimal set of classes to support certificate objects is included for supporting public key infrastructure cryptography.
javax.microedition.pki.Certificate(interface) javax.microedition.pki.CertificateException
Copyright © 2009 Sun Microsystems, Inc. All rights reserved.