4 Working With CAP Files

This chapter describes how you can generate a CAP file from a given Java Card Assembly file using the capgen tool, and how you can produce an ASCII representation of a CAP file using the capdump tool.

One of the files generated by the Converter is the CAP file. The CAP file utilizes the JAR file format and contains a set of components that describe a Java language package. In addition to the components, the CAP file also contains the manifest file META-INF/MANIFEST.MF, which you can use to improve distribution.

This chapter contains the following sections:

Compact CAP File and Manifest File Syntax

A CAP file utilizes the JAR file format, and contains a set of components that describe a Java language package. In addition to the components, the CAP file also contains the manifest file META-INF/MANIFEST.MF. The manifest file provides additional human-readable information regarding the contents of the CAP file and the package that it represents. You can use this information to facilitate the distribution and processing of the CAP file.

The following information applies to the version 2.3 compact CAP files and versions 2.2 or 2.1 CAP files generated with the Converter.

The information in the manifest file is presented in name:value pairs. These name:value pairs are described in Table 4-1.

Table 4-1 Name:Value Pairs in the MANIFEST.MF File

Name Value

Java-Card-CAP-Creation-Time

Creation time of CAP file. For example:

Tue Feb 13 09:56:03 CET 2024

The format of the time stamp is operating system-dependent.

Java-Card-Converter-Version

The version of the converter tool. Default: 3.2.0.

Java-Card-Converter-Provider

Provider of the converter tool. For example:

Oracle Corporation

Java-Card-CAP-File-Version

CAP file major.minor version. Possible values are: 2.1, 2.2, or 2.3.

Java-Card-Package-Version

The major.minor version of package. For example: 1.0

Java-Card-Package-AID

AID for the package. For example:

0xa0:0x00:0x00:0x00:0x62:0x03:0x01:0x0c:0x07

Java-Card-Package-Name

The fully-qualified package name in dot (.) format. For example: javacard.framework

Java-Card-Applet-<n>-AID

The AID for applet n. For example: 0xa0:0x00:0x00:0x00:0x62:0x03:0x01:0x0c:0x07:0x05

Java-Card-Applet-<n>-Name

Simple class name for applet n. For example: MyApplet

Java-Card-Imported-Package-<n>-AID

The AID for imported package n. For example: 0xa0:0x00:0x00:0x00:0x62:0x00:0x01

Java-Card-Import-Package-<n>-Version

The major.minor version of imported package n. For example: 1.0

Java-Card-Integer-Support-Required

Can be TRUE or FALSE. The value is TRUE if the package requires integer support.

The properties in the manifest file include:

Sample Manifest File

The following code sample illustrates the manifest file that the Converter generates when it converts package jcard.applications. This package contains two applets, MyClass1 and MyClass2.

Manifest-Version: 1.0
Created-By: 17.0.9 (Oracle Corporation)
[...]
Java-Card-CAP-Creation-Time: Tue Feb 13 09:56:03 CET 2024
Java-Card-Converter-Version:  [v3.2.0]
Java-Card-Converter-Provider: Oracle Corporation
Java-Card-CAP-File-Version: 2.3
Java-Card-Package-Version: 1.0
Java-Card-Package-Name: jcard.applications
Java-Card-Package-AID: 0xa0:0x00:0x00:0x00:0x62:0x03:0x01:0x0c:0x07
Java-Card-Applet-1-Name: MyClass1
Java-Card-Applet-1-AID: 0xa0:0x00:0x00:0x00:0x62:0x03:0x01:0x0c:0x07:0x05
Java-Card-Applet-2-Name: MyClass2
Java-Card-Applet-2-AID: 0xa0:0x00:0x00:0x00:0x62:0x03:0x01:0x0c:0x07:0x06
Java-Card-Imported-Package-1-AID: 0xa0:0x00:0x00:0x00:0x62:0x00:0x01
Java-Card-Imported-Package-1-Version: 1.0
Java-Card-Imported-Package-2-AID: 0xa0:0x00:0x00:0x00:0x62:0x01:0x01
Java-Card-Imported-Package-2-Version: 1.1
Java-Card-Integer-Support-Required: TRUE

Extended CAP File Manifest File Syntax

An extended CAP file utilizes the JAR file format, and has the same properties as a compact CAP file. However, there are some differences in the way the information that is specific to the extended CAP file is represented in the META-INF/MANIFEST.MF file.

The following table lists the names in the manifest file that are specific to the Java Card packages and Java Card Applets. These fields are changed to consider the extended CAP file context:

The information in the manifest file is presented in name:value pairs. These name:value pairs are described in Sample Extended CAP Manifest File .

Table 4-2 Extended CAP File Manifest File Name Syntax

Name Changed To: Change Description

Java-Card-Package-AID

Java-Card-Package-<n>-AID

An extended CAP file can have multiple packages. Therefore, an index is added for each package name.

Java-Card-Package-Version

Java-Card-Package-<n>-Version

An extended CAP file can have multiple packages. Therefore, an index is added for each package version.

If the package is not exported (private or applet package with no shareable interfaces), the value of this field is set to private.

Java-Card-Applet-<n>-AID

Java-Card-Package-<m>-Java-Card-Applet-<n>-AID

An extended CAP file can have multiple packages. Therefore, the package that contains the applet is added for each applet AID.

Java-Card-Applet-<n>-Name

Java-Card-Package-<m>-Java-Card-Applet-<n>-Name

An extended CAP file can have multiple packages. Therefore, the package that contains the applet is added for each applet name.

Some new name:value pairs are added in the extended CAP manifest file. These name value pairs have extended CAP file-specific information. The following table lists and describes the new name value pairs.

Table 4-3 Name:Value Pairs in the extended CAP MANIFEST.MF File

Name Value

Java-Card-CAP-Name

The extended CAP file name as defined in the CAP_name field from the JSON input configuration file.

Java-Card-CAP-AID

The extended CAP file AID as present in the header component of the CAP file.

Java-Card-CAP-Version

The extended CAP file version as present in the header component of the CAP file.

Sample Extended CAP Manifest File

The following code sample illustrates the sample extended CAP MANIFEST.MF file.

Manifest-Version: 1.0
Created-By: 1.7.0_60 (Oracle Corporation)
Name: BigApplet007
Java-Card-Integer-Support-Required: FALSE
Java-Card-Imported-Package-1-AID: 0xa0:0x00:0x00:0x00:0x62:0x00:0x01
Java-Card-Package-1-Name: com.oracle.lib
Java-Card-CAP-Version: 1.0
Java-Card-Package-3-Java-Card-Applet-1-AID: 0x01:0x02:0x03:0x04:0x05:0x06:0x01
Java-Card-Imported-Package-1-Version: 1.0
Java-Card-Package-3-Java-Card-Applet-1-Name: BigApplet001
Java-Card-Package-4-AID: private
Java-Card-CAP-Creation-Time: Tue Feb 13 09:56:03 CET 2024
Java-Card-Converter-Provider: Oracle Corporation
Java-Card-Package-4-Version: private
Java-Card-Package-2-Name: com.oracle.ext
Java-Card-Package-1-AID: 0x01:0x02:0x03:0x04:0x05:0x09
Java-Card-Package-4-Java-Card-Applet-2-Name: BigApplet001
Java-Card-Package-3-Name: com.oracle.bigapp
Java-Card-Package-3-Version: private
Java-Card-CAP-Name: BigApplet007
Java-Card-Package-2-Version: 1.0
Java-Card-Converter-Version:  [v3.1.0]
Java-Card-Package-4-Java-Card-Applet-1-Name: BigApplet002
Java-Card-Imported-Package-2-AID: 0xa0:0x00:0x00:0x00:0x62:0x01:0x01
Java-Card-Package-2-AID: 0x01:0x02:0x03:0x04:0x05:0x0b
Java-Card-Package-4-Java-Card-Applet-1-AID: 0x01:0x02:0x03:0x04:0x05:0x07:0x01
Java-Card-Package-4-Java-Card-Applet-2-AID: 0x01:0x02:0x03:0x04:0x05:0x08:0x01
Java-Card-CAP-AID: 0x01:0x02:0x03:0x04:0x05:0x06:0x0a
Java-Card-Package-4-Name: com.oracle.bigapp02
Java-Card-CAP-File-Version: 2.3
Java-Card-Package-3-AID: private
Java-Card-Imported-Package-2-Version: 1.7
Java-Card-Package-1-Version: 1.0

Generating CAP Files From Java Card Assembly Files

Use the capgen tool to generate a compact CAP file from a given Java Card Assembly file or an extended CAP file from one or more Java Card Assembly files. The CAP file that is generated has the same contents as a CAP file produced by the Converter. The capgen tool is a backend to the Converter.

Running capgen

To run capgen:

  1. Enter the following on the command line (see Table 4-4 for a description of the options):

capgen.[sh|bat] [options] filename

Note:

The file to invoke capgen is a script file (capgen.[sh|bat]). It is located under [$JC_HOME_TOOLS/bin | %JC_HOME_TOOLS%\bin] and needs to be executed from there.

Table 4-4 capgen Command Line Options

Option Description

-help

Prints a help message.

-nobanner

Suppresses all banner messages.

filename

Specifies the Java Card Assembly file in case of the compact CAP file generation or a capgen JSON configuration file in case of the extended CAP file generation.

-o filename

Enables you to specify an output file. If the output file is not specified with the -o flag, output defaults to the file a.jar in the current directory.

-version

Outputs the version information.

-config

Enables capgen to run in the extended mode. In this case, the filename parameter is a JSON configuration file, similar to the one given for the Converter in the extended mode. The JCA input files are defined in the configuration file.

Using a JSON Configuration File for capgen in the Extended Mode

In the extended mode, the capgen tool generates extended CAP files, from one or multiple Java Card Assembly files.

For using the capgen tool in the extended mode, a JSON configuration file must be used with the -config option. This JSON file is similar to the one used by the Converter tool (see Using a JSON Configuration File for Converter in the Extended Mode ). The only difference is, some of the general conversion parameters that are used by the Converter tool, including the export paths, are not used by the capgen tool. This is because, this information is already present in the JCA files. For each of the package, only the path to the JCA files is provided. The information that is not present in the JCA files remain in the JSON file, similar to the extended CAP file information and static resources information.

The configuration in the JSON file is a JSON object with a single field, inputConfig. All other fields are defined inside this field at different levels of hierarchy. The description of levels follows:

Table 4-5 JSON File Options for capgen

Option Level Description
CAP_AID CAP file The AID of the CAP file available as an executable load module.
CAP_name CAP file The name of the CAP file generated by the Converter. On the disk, the name of the CAP file would look like <CAP_name>.cap and all the components inside the CAP file will be located in the <CAP_name>/javacard directory.
CAP_version CAP file The user-defined version of the CAP file as an executable load module.
debug CAP file Generates the optional debug component of a CAP file. The same rules apply to the compact mode.
outputDir CAP file Sets the root directory for output of the CAP file.
inputPackages CAP file An array of JSON objects, each representing the configuration for the Java package to be converted and added to the CAP file.
staticResources CAP file An array of JSON objects. Each representing the configuration for a static resource to be loaded on the CAP file.
jcainputfile Package

A valid path to an existent and accessible Java Card Assembly file converted for this package.

This path can be given as a relative path. Relative paths conform to the same rules as the Converter JSON configuration files. These are relative to the location of the JSON configuration file.

outputDir Package Sets the root directory for output of the JCA and EXP files generated for this package. The same rules apply for the compact mode. If this option is not set, the baseDir value is taken.
id Static Resource An integer representing the identification number for the static resource. The static resource IDs must be unique across the CAP file.
file Static Resource A valid system path to an existent and accessible file on the disk. The contents of this file is loaded as binary data in the CAP file for the static resource.

Capgen JSON Configuration File Sample

The capgen JSON configuration file sample follows (for Unix/Linux OS replace \ with /):

{
	"inputConfig": {
		"CAP_AID": "01:02:03:04:05:10",
		"CAP_name": "hellosample",
		"CAP_version": "1.0",
		"debug": true,
		"outputDir": "thecapfile",
		"inputPackages": [{
			"jcainputfile": "package1\\com\\lib\\javacard\\lib.jca"
		}, {
			"jcainputfile": "package2\\com\\mine\\javacard\\mine.jca"
		}, {
			"jcainputfile": "package3\\com\\sample\\javacard\\sample.jca"
		}],
		"staticResources":[{
			"id" : 1,
			"file" : "staticres\\static1.res"
		}, {
			"id" : 2,
			"file" : "staticres\\static2.res"
		}]
	}
}

Producing a Text Representation of a CAP File

Use the capdump tool to produce an ASCII representation of a CAP file.

Running capdump

To run capdump:

  1. Enter the following on the command line:

    capdump.[sh|bat] filename

    There are no command line options, filename is the CAP file, and output from the command is always written to standard output.

Note:

The file to invoke capdump is a script file (capdump.[sh|bat]). It is located under [$JC_HOME_TOOLS/bin | %JC_HOME_TOOLS%\bin] and needs to be executed from there.