5 Verifying CAP and Export Files

This chapter describes off-card verification as a means for evaluating CAP and export files in a desktop environment.

When applied to the set of CAP files that reside on a Java Card technology compliant secure element and the set of export files used to construct those CAP files, the Java Card technology-enabled off-card verifier provides the means to assert that the content of the secure element has been verified.

Oracle’s Off-Card Verifier supports incremental verification and resolution of the set of CAP files that are installed on a Java Card technology-compliant device in a desktop environment. The unit of verification is a single CAP file. The context in which a CAP file can be executed is provided through the Application Programming Interface (API) of referenced packages as defined in their export files. Resolution is validated off-card by examining the export files of referenced packages.

Oracle’s Off-Card Verifier uses a bottom-up approach to verify the CAP files. In a nutshell, once a CAP file and its corresponding export file, if any, have been verified, it is not examined the succeeding times it is referenced. This is analogous to the process performed by an optimized Java virtual machine where, once the java.lang package has been loaded, verified, resolved, and initialized, it is not examined the succeeding times it is referenced. The same is true for a Java Card technology-compliant device.

A Java Card technology-enabled device is a secure environment. Additional security measures, such as the firewall, prevent a library from being corrupted. Once a verified CAP file has been installed on a Java Card technology-compliant device its state cannot be changed. This includes both its internal state and its context.

Off-Card verification provides a complete solution for Java Card technology-based applications when additional security constructs are applied. For more information on security measures and other details on working of the Off-Card Verifier, refer to the Off-card Verifier White paper.

This chapter contains the following sections:

Overview of Verifying CAP and Export Files

The off-card verifier is a combination of three tools, verifycap, verifyexp, and verifyrev. The following sections describe how to use each tool.

Verifying CAP Files

The verifycap tool is used to verify a CAP file within the context of packages’ export files (if any) and the export files of imported packages. This verification confirms whether a CAP file is internally consistent, as defined in the Java Card Platform Virtual Machine Specification, Classic Edition, Version 3.2, and consistent with a context in which it can reside in a Java Card technology-enabled device.

To ensure the integrity of the CAP file to be downloaded on a card, the verifier computes and outputs hash values for each of the required CAP file components. To output the hash values in a text file, specify the command line parameter -outfile hash-file-path. If the -outfile parameter is not specified, the verifier outputs the hash values on the console. A CAP file loader should compute the hash values for each of the required CAP components and verify them against the hash values produced by the verifier to assert the integrity of the CAP file being loaded on the card.

Each individual export file is verified as a single unit. The scenario is shown in Verifying a CAP File. In the figure, the package p2 CAP file is being verified. Package p2 has a dependency on package p1, so the export file from package p1 is also input. The p2.exp file is only required if p2.cap exports any of its elements.

Figure 5-1 Verifying a CAP File

Description of the illustration verifying-cap-file.png

Running verifycap

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

To run verifycap:

  1. Enter the following command (verifycap Command Line Arguments describes the available options):

    verifycap.[sh|bat] [options] export-files CAP-file

Table 5-1 verifycap Command Line Arguments

Argument Description

export-files

A list of export files of the packages that this CAP file uses could be either one of the following:

  • Export files corresponding to the package version available on the target platform.
  • Export files corresponding to the version of imported packages. In this case, you also need to check that these export files are binary compatible with export files corresponding to the packages available on the target platform.

Note that, when using this option in conjunction with the -target command line argument, any export file in this list corresponding to a Java Card platform package will automatically be overridden by the verifier to use an internal copy of the export file matching the specified target version.

For more information, see the -target command line argument in Converter Command Line Arguments.

CAP-files

Name of the CAP file to be verified.

-digest digest-algorithm-name

Specifies the digest algorithm to use for computing hash values for required CAP components. If this option is not specified or an invalid algorithm name is specified, the verifier uses SHA-256 as the default algorithm.

-outfile hash-output-file-path

Specifies the path to the text file that the verifier uses to output the computed hash values for the required CAP components. If this option is not specified, hash values are output to the system console.

Command Line Options for Off-Card Verifier Tools describes additional verifycap options.

Verifying Export Files

The verifyexp tool is used to verify an export file as a single unit. This verification is “shallow”, examining only the content of a single export file, not including export files of packages referenced by the package of the export file. The verification determines whether an export file is internally consistent and viable as defined in the Java Card Platform Virtual Machine Specification, Classic Edition, Version 3.2.

Figure 5-2 Verifying an Export File

Description of the illustration tools-62.png

Running verifyexp

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

To run verifyexp:

  1. Enter the following command (verifyexp Command Line Argument describes the available options):

    verifyexp.[sh|bat] [options] export-file

Table 5-2 verifyexp Command Line Argument

Argument Description

<export file>

Fully qualified path and name of the export file.

Command Line Options for Off-Card Verifier Tools describes additional verifyexp options.

Verifying Binary Compatibility

The verifyrev tool checks for binary compatibility between two revisions of the same package by comparing the respective export files. This scenario is illustrated in Verifying Binary Compatibility of Export Files. The export files from version 1.0 and 1.1 of package p1 are input to verifyrev. The verification examines whether the Java Card platform version rules, including those imposed for binary compatibility as defined in the Java Card Platform Virtual Machine Specification, Classic Edition, Version 3.2, have been followed.

Figure 5-3 Verifying Binary Compatibility of Export Files

Description of the illustration 63.png

Running verifyrev

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

To run verifyrev:

  1. Enter the following command:

    verifyrev.[sh|bat] [options] old-export-file new-export-file

    The new-export-file argument on the command line represents the fully qualified path to the new export file version of the package to be compared, while old-export-file represents the fully qualified path to the old export file version of the package to be compared to. The comparison and binary compatibility checks are done based on the order and version of the export files (the version can be identical). Both export files must have the same name, for example (for Unix/Linux OS replace \ with / ):

    verifyrev.bat d:\testing\old\crypto.exp d:\testing\new\crypto.exp

Command Line Options for Off-Card Verifier Tools describes additional command-line options for the off-card verifier tools.

Command Line Options for Off-Card Verifier Tools

The verifycap, verifyexp, and verifyrev, off-card verifier tools share many of the same command line options. The only exceptions are the -package, -outfile, -digest, and -target options that are available for verifycap only.

These options exhibit the same behavior regardless of the tool that calls them.

Table 5-3 verifycap, verifyexp, verifyrev Command Line Options

Option Description

-help

Prints help message.

-nobanner

Suppresses banner message.

-nowarn

Suppresses warning messages.

-package <package name>

(Available for verifycap only) Sets the name of the package to be verified.

-outfile

(Available for verifycap only) Specifies the name of the output file to store the digest (default: no output file created).

-digest

(Available for verifycap only) Specifies the digest to use (default: SHA-256)

-target

(Available for verifycap only) Specifies the target platform (3.0.4, 3.0.5, 3.1.0 or 3.2.0).

When a target is specified, the verifier automatically uses an internal copy of the export files corresponding to the specified version and ignores the export files for platform packages provided on the command line. This ensures that the correct version of export files is used and allows the verifier to detect some binary incompatibility issues when extending some of the platform classes or interfaces on versions 3.0.4 and 3.0.5 of the platform.

Note that using this option to specify the target still requires that you provide the export files for all other packages used by the CAP file. If no target is specified, the export files for all the packages used by the CAP file must be provided on the command line.

-verbose

Enables verbose mode.

-version

Prints version number and exits.

-C command-options-file

or

-commandoptionsfile command-options-file

Optional. Specifies a file containing command-line options.

-enable-preview [final|all] Enables verification against a target platform that implements Java Card preview features. The following variants are supported:
  • -enable-preview final enables only the features that have reached their final state and will be included permanently in the next specification version.
  • -enable-preview [all] (default) enables both evolving and finalized preview features.
When -enable-preview is specified, the verifier only supports targeting the latest Java Card platform version. Any other value provided for the -target option in combination with -enable-preview is rejected. If neither -enable-preview nor -target is specified, export files for all packages used by the CAP file must be provided on the command line. Note: This option is available with verifycap only.