JavaTM Cryptography Extension (JCE)

API Specification & Reference

for IBM's Java SDK, v 6.0.1

Last modified: 11 October 2011


Copyright information

Note : Before using this information and the product it supports, be sure to read the general information under Notices.

(c) Copyright Sun Microsystems, Inc. 1998, 2005, 901 San Antonio Rd., Palo Alto, CA 94303 USA. All rights reserved.

(c) Copyright International Business Machines Corporation, 1998, 2011. All rights reserved.

U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.


Introduction

Cryptographic Concepts
Encryption and Decryption
Password-Based Encryption
Cipher
Key Agreement
Message Authentication Code

Core Classes
The Cipher Class
The Cipher Stream Classes
The CipherInputStream Class
The CipherOutputStream Class
The KeyGenerator Class
The SecretKeyFactory Class
The SealedObject Class
The KeyAgreement Class
The Mac Class

Application Exportability

How to Make Applications "Exempt" from Cryptographic Restrictions

Installing Providers for JCE

JCE Keystore

Code Examples
Using Encryption
Using Password-Based Encryption
Using Key Agreement


Appendix A: Standard Names

Appendix B: JCE Jurisdiction Policy Files

Appendix C: Maximum Key Sizes Allowed by "Strong" Jurisdiction Policy Files

Appendix D: IBMJCE Keysize Restrictions

Appendix E: Sample Programs
Diffie-Hellman Key Exchange between 2 Parties
Diffie-Hellman Key Exchange between 3 Parties
Blowfish Example
HMAC-MD5 Example
Other Examples

Appendix F: Hardware Cryptography, IBMJCECCA specifics

Appendix G: SAF (RACF) Digital certificate support for z/OS specifics

Notices


Introduction

This document is intended as a companion to the Java Cryptography Architecture (JCA) API Specification & Reference. References to chapters not present in this document are to chapters in the JCA Specification.

The Java Cryptography Extension (JCE) provides a framework and implementations for encryption, key generation and key agreement, and Message Authentication Code (MAC) algorithms. Support for encryption includes symmetric, asymmetric, block, and stream ciphers. The software also supports secure streams and sealed objects.

JCE has a provider-based architecture. Providers signed by a trusted entity can be plugged into the JCE framework, and new algorithms can be added seamlessly.

JCE supplemented the Java 2 SDK, Standard Edition, v 1.2 (J2SDK), formerly known as JDKTM version 1.2, which already included interfaces and implementations of message digests and digital signatures. As of the 1.4.2 SDK, JCE is now included as part of the SDK.

JCE is based on the same design principles found elsewhere in the JCA: implementation independence and, whenever possible, algorithm independence. It uses the same "provider" architecture.

The JCE API covers:

The JCE IBM provider, named "IBMJCE", supplies the following cryptographic services:

A Note on Terminology

The JCE release includes two software components:

  • the framework that defines and supports cryptographic services that providers can supply implementations for. This framework includes everything in the javax.crypto package.

  • a provider named "IBMJCE"
Throughout this document, the term "JCE" refers to the JCE framework. If the full release is mentioned, it will be referred to as "the JCE release."

Cryptographic Concepts

This section provides a high-level description of the concepts implemented by the API, and the exact meaning of the technical terms used in the API specification.

Encryption and Decryption

Encryption is the process of taking data (called cleartext) and a short string (a key), and producing data (ciphertext) meaningless to a third-party who does not know the key. Decryption is the inverse process: that of taking ciphertext and a short key string, and producing cleartext.

Password-Based Encryption

Password-Based Encryption (PBE) derives an encryption key from a password. In order to make the task of getting from password to key very time-consuming for an attacker, most PBE implementations will mix in a random number, known as a salt, to create the key.

Cipher

Encryption and decryption are done using a cipher. A cipher is an object capable of carrying out encryption and decryption according to an encryption scheme (algorithm).

Key Agreement

Key agreement is a protocol by which 2 or more parties can establish the same cryptographic keys, without having to exchange any secret information.

Message Authentication Code

A Message Authentication Code (MAC) provides a way to check the integrity of information transmitted over or stored in an unreliable medium, based on a secret key. Typically, message authentication codes are used between two parties that share a secret key in order to validate information transmitted between these parties.

A MAC mechanism that is based on cryptographic hash functions is referred to as HMAC. HMAC can be used with any cryptographic hash function, such as MD5, SHA-1, SHA-256, SHA-384, or SHA-512, in combination with a secret shared key. HMAC is specified in RFC 2104.


Core Classes


Application Exportability

Prior to JCE 1.2.1, the JCE framework for encryption services was not exportable. Only people in the U.S. and Canada were allowed to use it. Export control restrictions by the U.S. Commerce Department prohibit such a framework from being exported outside the U.S. or Canada, unless appropriate mechanisms have been implemented to ensure that only qualified providers can be plugged into the framework. (Qualified providers include those approved for export and those certified for domestic use only. Qualified providers are signed by a trusted entity.)

The JCE 1.2.1 (and later) framework contains such mechanisms and is thus now exportable. It is transparent to application developers how providers are authenticated, and only qualified providers can be plugged into the JCE framework.

The JCE framework also enforces restrictions regarding the cryptographic algorithms and maximum cryptographic strength available to applets/applications in different jurisdiction contexts (locations). This makes the JCE framework worldwide exportable and worldwide importable.

Implications for Applications

Applications that do not require any cryptography stronger than the default strength (as defined by the applicable jurisdiction policy files described in the next section) will not require any modifications by their vendors. Existing unmodified applications will run unrestricted, exactly as before in the domestic market (the United States and Canada). Such applications can now also be exported. When such an application is run outside the domestic market, the maximum cryptographic strength that can be utilized by any Cipher it creates is determined by the default policy.

New applications that are unsigned or that are signed but not by an entity trusted by JCE will also have the maximum cryptographic strength determined by the default policy.

Applications that need stronger cryptography will need to be signed by a "trusted signer" and have an associated permission policy file also signed and bundled with the application in a JAR file, as described in How to Make Applications "Exempt" from Cryptographic Restrictions.

Permission Model and Policy Files

JCE takes advantage of the security model introduced in J2SE. In particular, privileges related to the use of strong(er) cryptography are expressed as permission classes whose definitions are bundled with the JCE framework.

JCE comes with two JAR files:

These JAR files are signed by the same entity and they contain "jurisdiction policy files" that specify the allowable cryptography algorithms, key strengths, and algorithm parameter values for default and exempt applications (see below).

JCE represents its jurisdiction policy files as J2SE-style policy files with corresponding permission statements. As described in Default Policy Implementation and Policy File Syntax, a J2SE policy file specifies what permissions are allowed for code from specified code sources. A permission represents access to a system resource. In the case of JCE, the "resources" are cryptography algorithms, and code sources do not need to be specified, because the cryptographic restrictions apply to all code.

Downloaded Jurisdiction Policy Files

The exact contents of the downloaded JAR files depends on the jurisdiction (location) of the person downloading them. Domestic (U.S. and Canada) users receive one set of these JAR files, while everyone from other countries receives a different set.

Jurisdiction Policy Files for Domestic Market

Domestic (U.S. and Canadian) people receive JAR files that each contain a single policy file:

US_export_policy.jar:
default_domestic_US_export.policy
local_policy.jar:
default_domestic_local.policy
These files for domestic users currently specify that all applications are unrestricted, that is, the applications can utilize any available cryptographic strengths they need.

Jurisdiction Policy Files for Global Market

People outside the U.S. and Canada receive JAR files that each contain up to two policy files:

US_export_policy.jar:
default_global_US_export.policy
local_policy.jar:
default_global_local.policy
exempt_global_local.policy

As you can see, there are both "default" and "exempt" jurisdiction policy files.

The default files represent the default cryptographic strengths allowed for applications that are unsigned or that are signed but not by parties trusted by JCE. When JCE is running such applications, for each cryptography algorithm utilized, JCE determines and enforces the weaker of the cryptographic strengths specified in the two default files downloaded by the user.

If a default file for a given domain (US_export or local) specifies that applications are unrestricted, no corresponding exempt file is needed or supplied for that domain. (When applications are unrestricted the JAR files for domestic users do not currently contain any exempt policy files, and there is no exempt_global_US_export.policy.)

Otherwise, an exempt file is required. The exempt file specifies the conditions under which "exempt applications" can have reduced cryptographic restrictions. Exempt policy files are consulted when an application is determined at runtime to be potentially exempt from some or all cryptographic restrictions.

In order for an application to be recognized as "exempt" at runtime, it must have a policy file bundled with it in a JAR file. The policy file specifies what cryptography-related permissions of the application, and the conditions (if any) for those permissions. See How to Make Applications "Exempt " from Cryptographic Restrictions for further information.

Jurisdiction Policy File Format

A jurisdiction policy file consists of a very basic "grant entry" containing one or more "permission entries."

grant {
<permission entries>;
};

The format of a permission entry in a jurisdiction policy file is:

permission <crypto permission class name>[ <alg_name>
[[, <exemption mechanism name>][, <maxKeySize>
[, <AlgorithmParameterSpec class name>,
<parameters for constructing an
AlgorithmParameterSpec object>]]]];

A sample jurisdiction policy file that includes restricting the "DES" algorithm to maximum key sizes of 64 bits is:

grant {
permission javax.crypto.CryptoPermission "DES", 64;
. . .;
};

A permission entry must begin with the word permission. The <crypto permission class name> in the template above would actually be a specific permission class name, such as javax.crypto.CryptoPermission. A crypto permission class reflects the ability of an application/applet to use certain algorithms with certain key sizes in certain environments. There are two crypto permission classes: CryptoPermission and CryptoAllPermission. The special CryptoAllPermission class implies all cryptography-related permissions, that is, it specifies that there are no cryptography-related restrictions.

The <alg_name>, when utilized, is a string in quotation marks specifying the standard name of a cryptography algorithm, such as "DES" or "RSA".

The <exemption mechanism name>, when specified, is a string in quotation marks indicating an exemption mechanism which, if enforced, enables a reduction in cryptographic restrictions. The exemption mechanism names that can be used are "KeyRecovery" "KeyEscrow", and "KeyWeakening".

<maxKeySize> is an integer specifying the maximum key size (in bits) allowed for the specified algorithm.

For some algorithms it might not be sufficient to specify the algorithm strength in terms of just a key size. For example, in the case of the "RC5" algorithm, the number of rounds must also be considered. For algorithms whose strength needs to be expressed as more than a key size, the permission entry should also specify an AlgorithmParameterSpec class name (such as javax.crypto.spec.RC5ParameterSpec) and a list of parameters for constructing the specified AlgorithmParameterSpec object.

Items that appear in a permission entry must appear in the specified order. An entry is terminated with a semicolon.

Case is unimportant for the identifiers (grant, permission) but is significant for the <crypto permission class name> or for any string that is passed in as a value.

Note: An "*" can be used as a wildcard for any permission entry option. For example, an "*" (without the quotation) for an <alg_name> option means "all algorithms."


How to Make Applications "Exempt" from Cryptographic Restrictions

[Note 1: This section is applicable developers. It is only for people whose applications can be exported to countries other than the U.S. and Canada, and whose applications need to have fewer cryptographic restrictions than the default policies allow for.]

[Note 2: Throughout this section, the term "application" is meant to encompass both applications and applets.]

An application can become exempt from some or all cryptographic restrictions, after receiving U.S. government approval, under two circumstances:

  1. It is a special type of application (such as a financial or health care application) whose algorithms are deemed to be exempt from all cryptographic restrictions.

  2. It is an application that utilizes an "exemption mechanism," such as key recovery.

In order for an application to be recognized as "exempt" at runtime, it must meet the following conditions:

The steps required in order to make an application exempt from some or all cryptographic restrictions are the following:


Step 1: Write and Compile Your Application Code

The first step is to write and compile your application code basically the same as you normally would. However, if your application is going to become exempt by use of an exemption mechanism, there are some additional requirements.

Special Code Requirements for Applications that Use Exemption Mechanisms

When an application has a permission policy file associated with it (in the same JAR file) and that permission policy file specifies an exemption mechanism, then when the Cipher getInstance method is called to instantiate a Cipher, the JCE code searches the installed providers for one that implements the specified exemption mechanism. If it finds such a provider, JCE instantiates an ExemptionMechanism API object associated with the provider's implementation, and then associates the ExemptionMechanism object with the Cipher returned by getInstance.

After instantiating a Cipher, and prior to initializing it (using a call to the Cipher init method), your code must call the following Cipher method:

 public ExemptionMechanism getExemptionMechanism()

This call returns the ExemptionMechanism object associated with the Cipher. You must then initialize the exemption mechanism implementation by calling the following method on the returned ExemptionMechanism:

 public final void init(Key key)

The arguments you supply should be the same as the arguments of the same types that you will subsequently supply to a Cipher init method.

After you have initialized the ExemptionMechanism, you can proceed as usual to initialize and use the Cipher.

Step 2: Create a Permission Policy File Granting Appropriate Cryptographic Permissions

In order for an application to be recognized at runtime as being "exempt" from some or all cryptographic restrictions, it must have a permission policy file bundled with it in a JAR file. The permission policy file specifies the cryptography-related permissions of the application, and the conditions (if any) of those permissions.

Note: The permission policy file bundled with an application must be named cryptoPerms.

The format of a permission entry in a permission policy file that accompanies an exempt application is the same as the format for a jurisdiction policy file downloaded with JCE, which is:

permission <crypto permission class name>[ <alg_name>
[[, <exemption mechanism name>][, <maxKeySize>
[, <AlgorithmParameterSpec class name>,
<parameters for constructing an AlgorithmParameterSpec object>]]]];

Permission Policy Files for Exempt Applications

Some applications (such as financial and health care applications) can be completely unrestricted, just like applications that are run in the domestic market. Thus, the permission policy file that accompanies such an application usually just needs to contain the following:

grant {
// There are no restrictions to any algorithms.
permission javax.crypto.CryptoAllPermission;
};

If an application just uses a single algorithm (or several specific algorithms), then the permission policy file could simply mention that algorithm (or algorithms) explicitly, rather than granting CryptoAllPermission. For example, if an application just uses the Blowfish algorithm, the permission policy file doesn't have to grant CryptoAllPermission to all algorithms. It could just specify that there is no cryptographic restriction if the Blowfish algorithm is used. In order to make this specification, the permission policy file would look like the following:

grant {
permission javax.crypto.CryptoPermission "Blowfish";
};

Permission Policy Files for Applications Exempt Due to Exemption Mechanisms

If an application is considered "exempt" when an exemption mechanism is enforced, then the permission policy file that accompanies the application must specify one or more exemption mechanisms. At runtime, the application will be considered exempt if any of those exemption mechanisms is enforced. Each exemption mechanism must be specified in a permission entry that looks like the following:

 // No algorithm restrictions if specified
// exemption mechanism is enforced.
permission javax.crypto.CryptoPermission *,
"<ExemptionMechanismName>";

where <ExemptionMechanismName> specifies the name of an exemption mechanism. The exemption mechanism names that can be used are:

  • KeyRecovery

  • KeyEscrow

  • KeyWeakening
As an example, suppose your application is exempt if either key recovery or key escrow is enforced. Then your permission policy file should contain the following:
grant {
// No algorithm restrictions if KeyRecovery is enforced.
permission javax.crypto.CryptoPermission *,
"KeyRecovery";
// No algorithm restrictions if KeyEscrow is enforced.
permission javax.crypto.CryptoPermission *,
"KeyEscrow";
};

Note: Permission entries that specify exemption mechanisms should not also specify maximum key sizes. The allowed key sizes are actually determined from the exempt jurisdiction policy files downloaded with JCE, as described in the next section.

How Bundled Permission Policy Files Affect Cryptographic Permissions

At runtime, when an application being run outside the U.S. and Canada instantiates a Cipher (through a call to its getInstance method) and that application has an associated permission policy file, JCE checks to see whether the permission policy file has an entry that applies to the algorithm specified in the getInstance call. If it does, and the entry grants CryptoAllPermission or does not specify that an exemption mechanism must be enforced, it means there is no cryptographic restriction for this particular algorithm.

If the permission policy file has an entry that applies to the algorithm specified in the getInstance call and the entry does specify that an exemption mechanism must be enforced, then the exempt jurisdiction policy files are examined. If the exempt permissions include an entry for the relevant algorithm and exemption mechanism, and that entry is implied by the permissions in the permission policy file bundled with the application, and if there is an implementation of the specified exemption mechanism available from one of the registered providers, then the maximum key size and algorithm parameter values for the Cipher are determined from the exempt permission entry.

If there is no exempt permission entry implied by the relevant entry in the permission policy file bundled with the application, or if there is no implementation of the specified exemption mechanism available from any of the registered providers, then the application is allowed only the standard default cryptographic permissions.

Step 3: Prepare for Testing

Step 3a: Get a Code-Signing Certificate for Testing

Request a code-signing certificate for testing only. This certificate has a limited validity period (30 days). It is provided for testing only. You should not use it to sign your product in the production environment.

Below are the steps you should use to get a code-signing certificate for testing. For more information on the keytool tool, see keytool (for Solaris) (for Microsoft Windows).

  1. Use keytool to generate a DSA keypair.
     keytool -genkeypair -alias <alias> -keyalg DSA -keysize 1024
    -dname "cn=<Company Name>,ou=Java Software Code Signing,
    o=Sun Microsystems Inc"
    -keystore <keystore file name>
    -storepass <keystore password>

    (Note: This command must be typed as a single line. Multiple lines and indentation are used in the examples just for legibility purposes.)

    This command will generate a DSA keypair (a public key and an associated private key) and store it in an entry in the specified keystore. The public key is stored in a self-signed certificate. The keystore entry can subsequently be accessed using the specified alias.

    The option values in angle brackets ("<" and ">") represent the actual values that must be supplied. For example, <alias> must be replaced with whatever alias name you want to be used to refer to the newly generated keystore entry in the future, and <keystore file name> must be replaced with the name of the keystore to be used. Note: Do not surround actual values with angle brackets. For example, if you want your alias to be myTestAlias, specify the -alias option as follows:

     -alias myTestAlias

    If you specify a keystore that doesn't yet exist, it will be created.

    Note: If the commands lines you type are not allowed to be as long as the keytool -genkeypair command you want to execute (for example, if you are typing to a Microsoft Windows DOS prompt), you can create and execute a plain-text batch file containing the command. That is, create a new text file that contains nothing but the full keytool -genkeypair command. (Remember to type it all on one line.) Save the file with a .bat extension. Then in your DOS window, type the file name (with its path, if necessary). This will cause the command in the batch file to be executed.

  2. Use keytool to generate a certificate signing request.
    keytool -certreq -alias <alias> -sigalg DSA 
    -file <csr file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    Here, <alias> is the alias for the DSA keypair entry created in the previous step. This command generates a Certificate Signing Request (CSR), using the PKCS#10 format. It stores the CSR in the file whose name is specified in <csr file name>.

  3. Send the CSR and contact information to the JCE Code Signing Certification Authority.

    Send, using email, the CSR and contact information to javasec@us.ibm.com. Put the following in the Subject line of your email message:

     Request a Certificate for Signing a JCE Application (Testing)
    
                

    Put the contact information in the body of the message and send the CSR file as a plain-text attachment to the message. If your mail tool has an option for specifying the encoding format to be used for attachments, select the "MIME" option. Note: The CSR file is just a plain text file, in Base 64 encoding. Only the first and last lines are human-readable.

    Include the following contact information in the body of your message:

    Company Name
    Street Address (Not a post office box)
    City
    State/Province
    Country
    Company Telephone Number
    Company Fax Number
    Company Home Page URL
    Requester Name
    Requester Telephone Number
    Requester Email Address
    Brief description of your company (size,
    line of business, etc.)

    All of the above information is required, except for the home page URL.

    The JCE Code Signing Certification Authority will authenticate you, the requester. Then it will create and sign a code-signing certificate for testing, valid for 30 days. It will send you an e-mail message containing two plain-text file attachments: one file containing this code-signing certificate for testing and another file containing its own CA certificate, which authenticates its public key.

  4. Use keytool to import the certificates received from the CA.

    After you have received the two certificates from the JCE Code Signing Certification Authority, you can use keytool to import them into your keystore.

    First import the CA certificate as a "trusted certificate":

    keytool -import -alias <alias for the CA cert> 
    -file <CA cert file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    Then import the code-signing certificate:
    keytool -import -alias <alias> 
    -file <code-signing cert file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    Here, <alias> is the same alias as the one that you created in step 1 where you generated a DSA keypair. This command replaces the self-signed certificate in the keystore entry specified by <alias> with the one signed by the JCE Code Signing Certification Authority.

Now that you have in your keystore a certificate from an entity trusted by JCE (the JCE Code Signing Certification Authority), you can place your application code and permission policy file in a JAR file (Step 3b) and then use that certificate to sign the JAR file (Step 3c).

Step 3b: Bundle the Application and Permission Policy File into a JAR File

In order to prepare for testing, your application and permission policy file (created in Step 2) must be bundled together into a JAR file, which will be signed in the next step.

For example, to create a JAR file named myApp.jar containing the myApp.class and cryptoPerms files, you could type the following in your command window:

jar cvf myApp.jar myApp.class cryptoPerms
For more information on the jar tool, see jar (for Solaris) (for Microsoft Windows).

Step 3c: Sign the JAR File for Testing

Sign the JAR file created in the previous step with the code-signing certificate obtained in Step 3a. For more information on the jarsigner tool, see jarsigner (for Solaris) (for Microsoft Windows).

jarsigner -keystore <keystore file name> 
-storepass <keystore password>
<JAR file name> <alias>

Here, <alias> is the alias into the keystore for the entry containing the code-signing certificate received from the JCE Code Signing Certification Authority (the same alias as that specified in the commands in Step 3a).

You can test verification of the signature using the following command:

jarsigner -verify <JAR file name> 

The text "jar verified" will be displayed if the verification was successful.

Step 3d: Set Up Your Environment Like That of a Global User

In order to ensure that your application can be run with the reduced cryptographic restrictions that your exemption allows, you will need to set up your environment to be like that of users running your application in markets other than the U.S. and Canada (because programs run in the U.S. and Canada have no cryptographic restrictions).

Anyone in the world (including those in the U.S. and Canada) can download and install the global JCE distribution. Download and install this distribution and use it for your testing in Step 4.

Step 3e: (Only for apps using exemption mechanisms) Install a Provider Implementing the Exemption Mechanism Specified in the Permission Policy File

In order for an application to be exempt from cryptographic restrictions due to enforcement of an exemption mechanism, a provider that implements the exemption mechanism must be installed. Therefore, you need to install such a provider in order to test your application, and the client of your application will also need to install such a provider. The method of installing providers is described in Installing Providers for JCE.

Note: The "IBMJCE" provider does not implement any exemption mechanisms, so you will need to obtain code from a provider that has an appropriate implementation.

Step 4: Test Your Application

Now that your JCE environment is set up the same as it would be for global users, you can test your application as though you were running it from a country other than the U.S. or Canada.

You could start off directly testing your application itself. Or you could initially write and run a shorter test program that creates a Cipher that attempts to do encryption using the algorithms and cryptographic strengths your application should be allowed to use if your request for exempt status is accepted. Of course, any test program you utilize must be bundled with a copy of the permission policy file and signed using the certificate for testing, as described in Step 3b and Step 3c.

One way to test whether or not you are able to utilize keys of a particular size is to generate a key of that size and then instantiate and attempt to initialize a Cipher using that key and one of the algorithms that your application will utilize. (You can generate a key of a particular size by, for example, using a javax.crypto.KeyGenerator and calling its init method with a keysize parameter, or by using a java.security.KeyPairGenerator and calling its initialize method with a keysize parameter.) If the keysize is greater than the maximum allowable keysize given the environment in which the program is run -- determined by the jurisdiction policy files and the permission policy file bundled with the application, if any -- then the Cipher init method throws a SecurityException. The exception should not occur if you are utilizing a keysize that should be accepted for your exempt application. If a SecurityException is thrown, review the previous steps carefully and ensure you have followed them all.

After you have a short test program working, test your complete application.

Step 5: Prepare for Production

Step 5a: Apply for Government Approval

Apply to the Bureau of Export Administration in the U.S. Department of Commerce for exemption from cryptographic restrictions. Specify why your application qualifies for exemption. Is it a special type of application, such as a health care or financial application, whose algorithms the government considers exempt from cryptographic restrictions? Is it an application that utilizes an "exemption mechanism" such as key recovery? Consult your export attorney for more information.

Include a copy of the permission policy file that you created in Step 2 and that you intend to bundle with your application code in the JAR file for your application.

Here are a couple URLs that might be of use to you:

Step 5b: Get a Code-Signing Certificate for Production

Below are the steps you should use to get a code-signing certificate for production. Note that they are basically the same as the steps used to get a code-signing certificate for testing (Step 3a), except that the certificate you receive for production will last a lot longer than the temporary certificate you received for testing, and you will need to show proof of exemption from cryptographic restrictions before you will be issued a code-signing certificate for production.

  1. Use keytool to generate a DSA keypair.
     keytool -genkeypair -alias <prAlias> -keyalg DSA -keysize 1024
    -dname "cn=<Company Name>,ou=Java Software Code Signing,
    o=Sun Microsystems Inc"
    -keystore <keystore file name>
    -storepass <keystore password>

    (Note: This must be typed as a single line. Multiple lines and indentation are used in the examples just for legibility purposes.)

    This command will generate a DSA keypair (a public key and an associated private key) and store it in an entry in the specified keystore. The public key is stored in a self-signed certificate. The keystore entry can subsequently be accessed using the alias specified in <prAlias>.

    As mentioned in the corresponding step for obtaining a code-signing certificate for testing (Step 3a), the option values in angle brackets ("<" and ">") represent the actual values that must be supplied. (Do not surround actual values with angle brackets.) Also, if the commands that you type are not allowed to be as long as the keytool -genkeypair command you want to execute, you can create and execute a plain-text batch file containing the command.

  2. Use keytool to generate a certificate signing request.
    keytool -certreq -alias <prAlias> -sigalg DSA 
    -file <csr file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    Here, <prAlias> is the alias for the DSA keypair entry created in the previous step. This command generates a Certificate Signing Request (CSR), using the PKCS#10 format. It stores the CSR in the file whose name is specified in <csr file name>.

  3. Send the CSR, contact information, and proof of exemption to the JCE Code Signing Certification Authority.

    Send, using e-mail, the CSR and contact information to javasec@us.ibm.com.

    Put the following in the Subject line of your email message:

    Request a Certificate for Signing a JCE Application (Production)
                

    Put the contact information in the body of the message and send the CSR file as a plain text attachment to the message. If your mail tool has an option for specifying the encoding format to be used for attachments, select the "MIME" option. Note: The CSR file is just a plain text file, in Base 64 encoding. Only the first and last lines are human-readable.

    Include the following contact information in the body of your message:

    Company Name
    Street Address (Not a post office box)
    City
    State/Province
    Country
    Company Telephone Number
    Company Fax Number
    Company Home Page URL
    Requester Name
    Requester Telephone Number
    Requester Email Address
    Brief description of your company (size,
    line of business, etc.)

    After the JCE Code Signing Certification Authority has received your e-mail message, it will send you a request number, also using e-mail. After receiving this request number, mail a copy of your proof of exemption from cryptographic restrictions received from the U.S. government in Step 5a. Include in your mailing a note indicating the request number so that your hardcopy mailing can be matched to your email message containing the CSR and contact information. The exemption proof and request number should be mailed to

    Corporate Export
    Attn: Encryption export
    901 San Antonio Road, UPAL01-541
    Palo Alto, CA 94303

    After the JCE Code Signing Certification Authority has received your email message and the proof of exemption from cryptographic restrictions, it will authenticate you, the requester. Then it will create and sign a code-signing certificate for production, valid for 5 years. It will send you an email message containing two plain-text file attachments: one file containing this code-signing certificate for testing and another file containing its own CA certificate, which authenticates its public key.

  4. Use keytool to import the certificates received from the CA.

    After you have received the two certificates from the JCE Code Signing Certification Authority, you can use keytool to import them into your keystore.

    If you are using the same keystore as that used for testing, you will already have imported the CA certificate as a "trusted certificate" in the fourth substep of Step 3a: Get a Code-Signing Certificate for Testing, so you don't need to do that again.

    If you are using a different keystore, you need to import the CA certificate into your keystore as a "trusted certificate":

    keytool -import -alias <alias for the CA cert> 
    -file <CA cert file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    In any case, then you should import the code-signing certificate:
    keytool -import -alias <prAlias> 
    -file <code-signing cert file name>
    -keystore <keystore file name>
    -storepass <keystore password>
    Here, <prAlias> is the same alias as the one that you created in step 1 where you generated a DSA keypair. This command replaces the self-signed certificate in the keystore entry specified by <prAlias> with the one signed by the JCE Code Signing Certification Authority.

Now that you have in your keystore a code-signing certificate for production from an entity trusted by JCE (the JCE Code Signing Certification Authority), you can place your application code and permission policy file in a JAR file (Step 5c) and then use that certificate to sign the JAR file (Step 5d)

Step 5c: Bundle the Application and Permission Policy File into a New JAR File

Create a new JAR file containing the application and permission policy file, to be signed in the next step using the official code-signing certificate.

jar cvf <JAR file name> <space-separated list of classes>

        cryptoPerms

This command creates a JAR file with the specified name containing the specified classes and the permission policy file (which must always be named cryptoPerms).

For performance reasons, it is best to create this new JAR file rather than simply adding the official production signature to the JAR file created in Step 3b that was signed using the testing certificate obtained in Step 3a. If the JAR file used in production still contains signatures generated by the test certificate, the JCE framework might waste time trying to verify those signatures.

Step 5d: Sign the JAR File for Production

Sign the JAR file created in the previous step with the code-signing certificate obtained in Step 5b.

jarsigner -keystore <keystore file name> 
-storepass <keystore password>
<JAR file name> <prAlias>

Here, <prAlias> is the alias into the keystore for the entry containing the code-signing certificate for production received from the JCE Code Signing Certification Authority (the same alias as that specified in the commands in Step 5b).

You can test verification of the signature using the following:

jarsigner -verify <JAR file name> 

The text "jar verified" will be displayed if the verification was successful.

Step 6: Run Your Test Programs Again

Your application should have been thoroughly tested in Step 4. However, at this point run your test programs again to make sure that everything still works correctly because what you tested in Step 4 is signed by a different certificate.

Step 7: Deploy Your Application

Now that your application has been officially made exempt and has been tested, the final step is to make your application available to your customers. If your application is exempt only if an exemption mechanism is enforced, also either supply your customers with one or more providers that implement appropriate exemption mechanisms or suggest where you customers can obtain such providers.


Installing Providers for JCE

Cryptographic providers for JCE are installed and configured in much the same way as cryptographic providers for the Java 2 platform. More information about installing and configuring providers can be found in the Installing Providers section of the Java Cryptography Architecture API Specification & Reference document.

There are two parts to installing a provider: installing the provider package classes, and configuring the provider.

Installing the Provider Classes

The first thing you must do is make the provider classes available so that they can be found when requested. Provider classes are shipped as a JAR (Java ARchive) file.

There are a couple possible ways of installing other provider classes:

For more information on "installed" extensions, see Installed Extensions.

For more information on "bundled" extensions, see Bundled Extensions.

Configuring the Provider

The next step is to add the provider to your list of approved providers. This step is done statically by editing the following security properties file

<java-home>\lib\security\java.security [Windows]
<java-home> /lib/security/java.security [UNIX]
Here <java-home> refers to the directory where the JRE was installed. For example, if you have J2SDK v 1.4 installed on Linux in a directory named jdk1.4, you need to edit the following file:
jdk1.4/jre/lib/security/java.security
Similarly, if you have Java 2 Runtime Environment, Standard Edition, v 1.4 (J2RE) installed on Linux in a directory named jre1.4, you need to edit this file:
jre1.4/lib/security/java.security

For each provider, this file should have a statement of the following form:

 security.provider.n=masterClassName

      

This statement declares a provider, and specifies its preference order n. The preference order is the order in which providers are searched for requested algorithms when no specific provider is requested. The order is 1-based; 1 is the most preferred, followed by 2, and so on.

masterClassName must specify the fully qualified name of the provider's "master class". The provider vendor should supply you this name.

J2SE comes standard with a number of providers, which are automatically configured as static providers in the java.security properties file, as follows:

 security.provider.1=com.ibm.jsse.IBMJSSEProvider
security.provider.2= com.ibm.crypto.provider.IBMJCE
security.provider.3=com.ibm.security.jgss. IBMJGSSProvider
security.provider.4=com.ibm.security.cert.IBMCertPath
(The "JCE" provider's master class is the IBMJCE class in the com.ibm.crypto.provider package.)

In order to statically add a new provider to your list of providers, you need to edit the security properties file to contain a line of the format shown above. For example, suppose that a provider's master class is the CryptoX class in the com.cryptox.provider package, and that you would like to make this provider the fifth preferred provider. To do so, add the following line to the java.security file below the line for the "IBMCertPath" provider:

 security.provider.5=com.cryptox.provider.CryptoX

Providers can also be registered dynamically. To do so, a program can call either the addProvider or insertProviderAt method in the Security class. This type of registration is not persistent and can be done only by "trusted" programs. See the Security class section of the Java Cryptography Architecture API Specification and Reference.

An example of dynamic registration of the "CryptoX" provider is the following:

 Provider cx = new com.cryptox.provider.CryptoX();
Security.addProvider (cx);

JCE Keystore

The "IBMJCE" provider supplies its own implementation of the java.security.KeyStore class in Java 2 SDK, v 1.4. Its implementation employs a much stronger protection of private keys (using password-based encryption with Triple DES) than the keystore implementation supplied by the "SUN" provider prior to Java 2 SDK, v 1.4. (Note that because Java 2 SDK, v 1.4 is distributed world-wide in binary and source format, it cannot employ any strong encryption mechanisms.)

In order to take advantage of the keystore implementation of the "IBMJCE" provider, you specify "JCEKS" as the keystore type.

You can upgrade your keystore of type "JKS" - this is the name of the keystore type implemented by the "SUN" provider in J2SDK - to a JCE keystore of type "JCEKS" by changing the password of a private-key entry in your keystore. Note that once you have upgraded your keystore, your keystore can be accessed only by a JVM using JCE.

To apply the cryptographically strong key protection supplied by "IBMJCE" to a private key named "signkey" in your default keystore, use the following command, which will prompt you for the old and new key passwords:

 keytool -keypasswd -alias signkey -storetype jceks

You might want to change the password back to its old value, using the same command.

See the Security Tools for more information about keystores and how they are managed.


Code Examples

This section is a short tutorial on how to use some of the major features of the JCE APIs. Complete sample programs using these APIs can be found in Appendix E of this document.

Using Encryption

This section describes the process of generating a key, creating and initializing a cipher object, encrypting a file, and then decrypting it. The Data Encryption Standard (DES) is used throughout this example.

Generating a Key

To create a DES key, we have to instantiate a KeyGenerator for DES. We do not specify a provider, because we do not care about a particular DES key generation implementation. Because we do not initialize the KeyGenerator, a system-provided source of randomness will be used to create the DES key:

 KeyGenerator keygen = KeyGenerator.getInstance("DES");
SecretKey desKey = keygen.generateKey();

After the key has been generated, the same KeyGenerator object can be re-used to create further keys.

Creating a Cipher

The next step is to create a Cipher instance. To do this, we use one of the getInstance factory methods of the Cipher class. We must specify the name of the requested transformation, which includes the following components, separated by slashes (/):

  • the algorithm name
  • the mode (optional)
  • the padding scheme (optional)

In this example, we create a DES (Data Encryption Standard) cipher in Electronic Codebook mode, with PKCS#5-style padding. We do not specify a provider, because we do not care about a particular implementation of the requested transformation.

The standard algorithm name for DES is "DES", the standard name for the Electronic Codebook mode is "ECB", and the standard name for PKCS#5-style padding is "PKCS5Padding":

 Cipher desCipher;

// Create the cipher
desCipher = Cipher. getInstance("DES/ECB/PKCS5Padding");

We use the generated desKey from above to initialize the Cipher object for encryption:

 // Initialize the cipher for encryption
desCipher.init(Cipher.ENCRYPT_MODE, desKey);

// Our cleartext
byte[] cleartext = "This is just an example".getBytes();

// Encrypt the cleartext
byte[] ciphertext = desCipher.doFinal(cleartext);

// Initialize the same cipher for decryption
desCipher.init(Cipher.DECRYPT_MODE, desKey);

// Decrypt the ciphertext
byte[] cleartext1 = desCipher.doFinal(ciphertext);

cleartext and cleartext1 are identical.

Using Password-Based Encryption

In this example, we prompt the user for a password from which we derive an encryption key.

It would seem logical to collect and store the password in an object of type java.lang.String. However, here's the caveat: Objects of type String are immutable, that is, there are no methods defined that allow you to change (overwrite) or zero out the contents of a String after usage. This feature makes String objects unsuitable for storing security sensitive information such as user passwords. You should always collect and store security sensitive information in a char array instead.

For that reason, the javax.crypto.spec.PBEKeySpec class takes (and returns) a password as a char array.

The following method is an example of how to collect a user password as a char array:

 /**
* Reads user password from given input stream.
*/
public char[] readPasswd(InputStream in) throws IOException {
char[] lineBuffer;
char[] buf;
int i;

buf = lineBuffer = new char[128];

int room = buf.length;
int offset = 0;
int c;

loop: while (true) {
switch (c = in.read()) {
case -1:
case '\n':
break loop;

case '\r':
int c2 = in.read();
if ((c2 != '\n') && (c2 != -1)) {
if (!(in instanceof PushbackInputStream)) {
in = new PushbackInputStream(in);
}
((PushbackInputStream)in).unread(c2);
} else
break loop;

default:
if (--room < 0) {
buf = new char[offset + 128];
room = buf.length - offset - 1;
System.arraycopy(lineBuffer, 0, buf, 0, offset);
Arrays.fill(lineBuffer, ' ' );
lineBuffer = buf;
}
buf[offset++] = (char) c;
break;
}
}

if (offset == 0) {
return null;
}

char[] ret = new char[offset];
System.arraycopy(buf, 0, ret, 0, offset);
Arrays.fill(buf, ' ');

return ret;
}

In order to use Password-Based Encryption (PBE) as defined in PKCS#5, we have to specify a salt and an iteration count. The same salt and iteration count that are used for encryption must be used for decryption:

 PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;

// Salt
byte[] salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, ( byte)0xee, (byte)0x99
};

// Iteration count
int count = 20;

// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);

// Prompt user for encryption password.
// Collect user password as char array (using the
// "readPasswd" method from above), and convert
// it into a SecretKey object, using a PBE key
// factory.
System.out.print("Enter encryption password: ");
System.out.flush();
pbeKeySpec = new PBEKeySpec(readPasswd(System.in));
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES ");

// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

// Our cleartext
byte[] cleartext = "This is another example".getBytes();

// Encrypt the cleartext
byte[] ciphertext = pbeCipher.doFinal(cleartext);

Using Key Agreement

Refer to Appendix D for sample programs that use the Diffie-Hellman key exchange between 2 and 3 parties, respectively.


Appendix A: Standard Names

The JCE API requires and utilizes a set of standard names for algorithms, algorithm modes, and padding schemes. This specification establishes the following names as standard names. It supplements the list of standard names defined in Appendix A in the Java Cryptography Architecture API Specification & Reference. Note that algorithm names are treated as case-insensitive.

A list of all valid JCE algorithm names can be obtained using the Java appliction JCEAlgorithms.java

Cipher

Algorithm

The following names can be specified as the algorithm component in a transformation when requesting an instance of Cipher:

  • AES: Advanced Encryption Standard as specified by NIST in FIPS 197. Based on the Rijndael algorithm by Joan Daemen and Vincent Rijmen, AES is a 128-bit block cipher supporting keys of 128, 192, and 256 bits.

  • Blowfish: The block cipher designed by Bruce Schneier. More information can be found on CounterPane's web site.

  • DES: The Digital Encryption Standard as described in FIPS 46-3.

  • DESede: Triple DES Encryption (DES-EDE).

  • MARS: A shared-key (symmetric) block cipher, supporting 128-bit blocks and variable key size created by IBM. More information can be found at IBM Research.

  • PBEWith<digest>And<encryption>: The password-based encryption algorithm (PKCS #5), using the specified message digest (<digest>) and encryption algorithm (<encryption>).

    <digest> may be one of; MD2, MD5, SHA, SHA1, SHA-1

    <encryption> may be; DES, RC2, TripleDES, 128BitRC2, 128BitRC4, 2KeyTripleDES or 3KeyTripleDES

    NB: Not all combinations are valid.

  • RC2 and RC4: Variable-key-size encryption algorithms developed by Ron Rivest for RSA Data Security, Inc.

  • RSA: The RSA encryption algorithm as defined in PKCS #1.

  • Seal: A software-efficient stream cipher by Phil Rogaway, IBM.

Mode

The following names can be specified as the mode component in a transformation when requesting an instance of Cipher:

  • ECB: Electronic Codebook Mode, as defined in: The National Institute of Standards and Technology (NIST) Federal Information Processing Standard (FIPS) PUB 81, "DES Modes of Operation,"U.S. Department of Commerce, Dec 1980.

  • CBC: Cipher Block Chaining Mode, as defined in FIPS PUB 81.
  • CFB: Cipher Feedback Mode, as defined in FIPS PUB 81.
  • CTR: Counter Mode, as defined in NIST SP 800-38A.
  • OFB: Output Feedback Mode, as defined in FIPS PUB 81.
  • PCBC: Plaintext Cipher Block Chaining, as defined by Kerberos.

Padding

The following names can be specified as the padding component in a transformation when requesting an instance of Cipher:

  • NoPadding: No padding.

  • PKCS5Padding: The padding scheme described in: RSA Laboratories, "PKCS #5: Password-Based Encryption Standard," version 1.5, November 1993.

  • SSL3Padding: The padding scheme defined in the SSL Protocol Version 3.0, November 18, 1996, section 5.2.3.2 (CBC block cipher):
     block-ciphered struct {
    opaque content[SSLCompressed.length];
    opaque MAC[CipherSpec.hash_size];
    uint8 padding[GenericBlockCipher.padding_length];
    uint8 padding_length;
    } GenericBlockCipher;

    The size of an instance of a GenericBlockCipher must be a multiple of the block cipher's block length.

    The padding length, which is always present, contributes to the padding, which implies that if:

     sizeof(content) + sizeof(MAC) % block_length = 0,
    padding has to be (block_length - 1) bytes long, because of the existence of padding_length.

    This makes the padding scheme similar (but not an exact match) to PKCS5Padding, where the padding length is encoded in the padding (and ranges from 1 to block_length). With the SSL scheme, the sizeof(padding) is encoded in the always present padding_length and therefore ranges from 0 to block_length-1.

    Note that this padding mechanism is not supported by the "IBMJCE" provider.

KeyAgreement

The following algorithm names can be specified when you request an instance of KeyAgreement:

  • DiffieHellman: Diffie-Hellman Key Agreement as defined in PKCS #3: Diffie-Hellman Key-Agreement Standard, RSA Laboratories, version 1.4, November 1993.

KeyGenerator

The following algorithm names can be specified when you request an instance of KeyGenerator:

  • AES
  • Blowfish
  • DES
  • DESede
  • HmacMD2
  • HmacMD5
  • HmacSHA1
  • HmacSHA256
  • HmacSHA384
  • HmacSHA512
  • MARS
  • RC2
  • RC4
  • Seal

KeyPairGenerator

The following algorithm names can be specified when requesting an instance of KeyPairGenerator:

  • DSA
  • DiffieHellman
  • RSA

SecretKeyFactory

The following algorithm names can be specified when you request an instance of SecretKeyFactory:

  • AES
  • DES
  • DESede
  • PBEWith<digest>And<encryption>: Secret-key factory for use with PKCS #5 password-based encryption, where <digest> is a message digest and <encryption> is an encryption algorithm.
    • <digest> can be one of; MD2, MD5, SHA, SHA1 or SHA-1
    • <encryption> can be; DES, RC2, TripleDES, 128BitRC2 or 12BitRC4

    NB: Not all combinations are valid.

  • PBKDF1
  • PBKDF2
  • PKCS5Key
  • RC2
  • RC4
  • Seal

KeyFactory

The following algorithm names can be specified when you request an instance of KeyFactory:

  • DSA
  • DiffieHellman
  • RSA

AlgorithmParameterGenerator

The following algorithm names can be specified when you request an instance of AlgorithmParameterGenerator:

  • DSA
  • DiffieHellman

AlgorithmParameters

The following algorithm names can be specified when you request an instance of AlgorithmParameters:

  • AES
  • DES
  • DESede
  • DSA
  • DiffieHellman
  • PBE
  • RC2

MAC

The following algorithm names can be specified when you request an instance of Mac:

  • HmacMD2
  • HmacMD5: The HMAC-MD5 keyed-hashing algorithm as defined in RFC 2104.
  • HmacSHA1: The HMAC-SHA1 keyed-hashing algorithm as defined in RFC 2104.
  • HmacSHA256: The HMAC-SHA256 keyed-hashing algorithm as defined in RFC 2104.
  • HmacSHA384: The HMAC-SHA384 keyed-hashing algorithm as defined in RFC 2104.
  • HmacSHA512: The HMAC-SHA512 keyed-hashing algorithm as defined in RFC 2104.

Keystore Types

The following types can be specified when you request an instance of KeyStore:


Appendix B: JCE Jurisdiction Policy Files

The JCE jurisdiction policy files contain the maximum allowable cryptography strength defined by laws (such as the U.S. export regulations).

You can obtain the jurisdiction policy files for the U.S. and Canada when downloading the JCE software bundle for users within the U.S. and Canada. There is no restriction to the maximum allowable cryptography strength in the jurisdiction policy files for users within the U.S. and Canada.

You can obtain the jurisdiction policy files for global users when downloading the JCE software bundle for global users. There are restrictions to the maximum allowable cryptography strength in the jurisdiction policy files for global users. Currently, 512 bits is the maximum allowable keysize for RSA encryption; 64 bits is the maximum allowable keysize for all other encryption algorithms.

The jurisdiction policies are enforced by the JCE framework. For example, you cannot usually use a Blowfish key of 448 bits with the JCE software for global users even if there is a provider that supports this keysize for Blowfish, because the global jurisdiction policy files say that the maximum allowable keysize for Blowfish is 64. You can use a Blowfish key of 448 bits with the JCE software for users within the U.S. and Canada if there is a provider that supports this keysize for Blowfish, because there is no restriction in the jurisdiction policy files for users within the U.S. and Canada.

The only condition under which an application run in a country outside the U.S. and Canada can utilize cryptographic strengths greater than those defined in the global jurisdiction policy files is if the application is "exempt," as described in How to Make Applications "Exempt" from Cryptographic Restrictions.

For more information about application exportability and jurisdiction policy files, see Application Exportability.


Appendix C: Maximum Key Sizes Allowed by "Strong" Jurisdiction Policy Files

Due to import control restrictions, the jurisdiction policy files included with the Java 2 SDK, v 1.4 allow "strong" but limited cryptography to be used. Here are the maximum key sizes allowed by this "strong" version of the jurisdiction policy files:

Algorithm

Maximum Key Size

DES

64

DESede

*

RC2

128

RC4

128

RC5

128

RSA

2048

* (all others)

128


Appendix D: IBMJCE Keysize Restrictions

The IBMJCE provider enforces the following restrictions on the keysize passed to the initialization methods of the following classes:


Appendix E: Sample Programs

Appendix F: Hardware Cryptography, IBMJCECCA specifics

Introduction

The IBMJCECCA provider replaces the IBMJCE4758 provider from earlier releases.

The IBMJCECCA provider extends Java Cryptography Extension (JCE) and Java Cryptography Architecture (JCA) seamlessly to add the capability to use hardware cryptography using IBM Common Cryptographic Architecture (CCA) interfaces. This provider implements the existing JCE architecture, taking advantage of hardware cryptography to give Java SE programmers the significant security and performance advantages of hardware cryptography with minimal changes to existing Java applications. Because the complexities of hardware cryptography are handled within the normal JCE APIs, the advanced security and performance of hardware cryptographic devices are made easily available.

IBM CCA is a set of software elements that provide common application interfaces to secure, high-speed cryptographic services on various platforms using hardware cryptographic devices. On the z/OS platform, access to hardware cryptographic devices is controlled by the Integrated Cryptographic Service Facility (ICSF).  The ICSF component of z/OS provides IBM Common Cryptographic Architecture interfaces to hardware devices. One or more hardware cryptography features must be installed in order to use the IBMJCECCA provider.

For more information about the cryptographic features supported, refer to the zSeries machine's reference or technical guide and your service / support organization. See http://www-03.ibm.com/systems/z/os/zos/tools/java/products/j6jcecca.html#over for more information about the cryptographic services which are supported by the hardware cryptographic devices you have installed. The "Configuring and using hardware cryptographic devices on z/OS" section of this document should be consulted for configuring the correct hardware environment. In addition, the unrestricted policy files in your JVM should be installed to allow the IBMJCECCA provider to load and to function.

The IBMJCECCA provider supports the following:

  • Message Digest via the MD2, MD5, SHA-1, SHA-256, SHA-384, and SHA-512 algorithms
  • Signature and KeyFactory classes
  • the symmetric algorithms AES, DES, triple DES (also known as DESede), HMAC, PBE
  • the asymmetric algorithms RSA encryption and decryption with zero padding and PKCS 1 type 2 padding
  • digital signature creation and verification using the RSA and DSA algorithms (note that DSA is only supported on IBM eServer zSeries 800 (z800) and IBM eServer zSeries 900 (z900) hardware)
  • true random number generation
  • key generation via key factories
  • generation and management of keys and certificates using the keytool application

Like other JCE providers, the IBMJCECCA provider can be added to the JVM using the Security.insertProviderAt() and Security.addProvider() methods, and by adding it to the provider list in the lib/ext/java.security file.

Types of cryptographic hardware utilization

In the cryptography environment there are multiple ways to take advantage of cryptographic hardware. The IBMJCECCA provider supports multiple types of hardware utilization. Once an asymmetric key pair or symmetric key is generated, it is tied to the hardware type used to generate it. The type supported for asymmetric key pairs is "PKDS". The two types supported only for symmetric keys are "CKDS" and "PROTECTED". Type "CLEAR" is supported both for asymmetric key pairs and for symmetric keys. Each type is described in more detail below. The types of hardware utilization make trade offs between increased security and increased performance but, in general, any type of hardware cryptographic utilization is more secure than similar cryptographic functions provided by a provider implemented to use only software cryptography.

PKDS hardware key pairs

These keys are known to ICSF as encrypted DATA keys. In this case the encrypted DATA key is subsequently stored in the PKDS.

The hardware can be used with key pairs to provide increased security and also to take advantage of multiple hardware devices on the system. Key pairs generated using this high level of security are called PKDS key pairs. When a PKDS key pair is generated, the private key is encrypted using the system's master key, and the key pair is stored in a system key storage area. This key storage area is a RACF-protected data set. The clear text version of this key can never be viewed or retrieved. What is stored in the JCE keystore or returned to the application at key pair generation is only a reference to the private key, called a label. Because the key is stored in a data set instead of on a particular hardware device, cryptographic operations using PKDS key pairs can take advantage of multiple cryptographic hardware devices. When a cryptographic operation request is received, the private key is decrypted by the CCA software layer and the request is submitted to the next available cryptographic device.

The PKDS key type provides the highest level of security supported by the IBMJCECCA provider. Operations using PKDS key types are more secure and generally slower than similar operations using CLEAR type key pairs.

CKDS hardware symmetric keys

These keys are known to ICSF as encrypted DATA keys. In this case the encrypted DATA key is subsequently stored in the CKDS.

The hardware can be used with symmetric keys to provide increased security and also to take advantage of multiple hardware devices on the system. Symmetric keys generated using this high level of security are called CKDS keys. When a CKDS key is generated, it is encrypted using the system's master key and the resulting key token is stored in a system key storage area. This key storage area is a RACF-protected data set. The clear text version of this key can never be viewed or retrieved. What is stored in the JCE keystore or returned to the application at key generation is only a reference to the key, called a label. Because the key is stored in a data set instead of on a particular hardware device, cryptographic operations using CKDS keys can take advantage of multiple cryptographic hardware devices. When a cryptographic operation request is received, the key is decrypted by the CCA software layer and the request is submitted to the next available cryptographic device.

The system master key can only be changed using the ICSF component of z/OS. When the system master key is changed, ICSF also updates the CKDS entries so that the keys it contains will be encrypted using the new system master key. This ensures that CKDS keys remain usable even if the system master key is changed.

The CKDS key type provides the highest level of security supported by the IBMJCECCA provider for symmetric keys. Operations using CKDS key types are the most secure symmetric key operations supported by the IBMJCECCA provider.

PROTECTED hardware symmetric keys

These keys are known to ICSF as encrypted DATA keys.

The hardware can be used with symmetric keys to provide increased security and also to take advantage of multiple hardware devices on the system. Symmetric keys generated using this level of security are called PROTECTED keys. When a PROTECTED key is generated, it is encrypted using the system's master key. What is stored in the JCE keystore or returned to the application at key generation is only the encrypted key, called a key token. Because the system master key is never available outside the CCA software layer, a PROTECTED key is more secure than a CLEAR key. When a cryptographic operation request is received, the key is decrypted by the CCA software layer and the request is submitted to the next available cryptographic device.

ICSF is the z/OS component that is used to change the system master key. PROTECTED keys are encrypted using the host master key and then stored outside the CKDS, that is, outside the control of ICSF. This means that if the system master key is changed, any PROTECTED key created using the old system master key becomes unusable and data encrypted using it cannot be decrypted. For this reason, PROTECTED keys are recommended only for short-term use. They should not be used for data that will be encrypted and then decrypted at a much later date.

The PROTECTED key type has the highest level of security supported by the IBMJCECCA provider for symmetric keys. Operations using PROTECTED key types are more secure and generally slower than similar operations using CLEAR keys.

CLEAR hardware key pairs and symmetric keys

These keys are known to ICSF as clear DATA keys.

The hardware can also be used to accelerate the performance of the cryptographic operation. The lowest level of hardware security is a "CLEAR" key pair or symmetric key. When the key pair or symmetric key is generated as type CLEAR, the keypair or symmetric key is stored in a clear and unprotected representation. This clear key pair or symmetric key can be used by the application to perform cryptographic operations on any CCA-capable hardware cryptographic device the system supports. There is no overhead for retrieving the key from the PKDS or CKDS, no overhead for decrypting the key, and no requirement for the cryptographic operation to be processed by a specific hardware device.

The CLEAR key type is the fastest type supported by the IBMJCECCA provider, but it is also the least secure.

Note: Most JCE providers using software cryptography support only the key pair and symmetric key type CLEAR.

Key storage overview

All three types of hardware key pair and all three types of symmetric key supported by the IBMJCECCA provider can be used by any application. For CKDS and PKDS keys, the application will have only a label. For PROTECTED keys, the application will have only an encrypted token. For CLEAR keys, the application will have an actual clear representation of the key material. The IBMJCECCA provider accepts key labels, key tokens, and clear representations of keys interchangeably and treats all the same as actual keys. Key labels, key tokens, and clear representations of keys can be stored by the application using whatever mechanism they choose.

The IBMJCECCA provider includes a Java keystore (type JCECCAKS) that can be used to store any of these representations of keys. A JCECCAKS keystore provides an added level of security, allowing the keys stored in it to be encrypted using passwords before they are stored in the keystore file. This means that if you choose CLEAR keys or PROTECTED keys for performance reasons, they can be stored in keystore entries that are password protected. While password protection is provided for all keystore entries, regardless of the type of key stored in the entry, it is not as important for PKDS and CKDS keys. This is because, for PKDS and CKDS keys, the keystore entry contains only a key label and no sensitive key information.

Key generation and storage

Key generation can be accomplished either using the keytool application included with the IBMJCECCA provider or using JCE APIs. The keytool application included with the IBMJCECCA provider is called hwkeytool. It enables you to generate symmetric keys and key pairs then store them in a keystore file of type JCECCAKS. The JCE APIs allow you to generate symmetric keys and key pairs in an application and then, at the discretion of the application, also store them in a keystore of type JCECCAKS.

RSA Signature and Verification

The IBMJCECCA provider supports digital signature and verification with the available RSA and DSA algorithms (note that DSA is only supported on z800 and z900 hardware). This implementation moves all algorithm processing to the installed cryptographic hardware device. RSA is a relatively compute intensive algorithm, so this moves a significant portion of the CPU instructions off the main processor and onto the cryptographic hardware device. The cryptographic hardware processes this work on a secure card, making it much harder to capture and compromise the sensitive material involved. The cryptographic hardware is also much faster than software cryptographic processing.

An additional benefit provided by cryptographic hardware is the choice of two levels of security, CLEAR key pairs and PKDS based key pairs. Cryptographic hardware capabilities imcrease the base security of the operation (by having the hardware process the algorithm and data), reduce the load on general purpose CPs, potentially increase the throughput rate of the request, and (optionally) permit use of more secure key pairs.

DSA Signature and Verification

Note that the DSA algorithm is only supported on hardware cryptographic devices for z800 and z900 machines.

DSA signature and verification using hardware cryptographic devices is only available in Cryptographic Coprocessor Facility (CCF) hardware.

An additional restriction is that, due to the hardware capabilities for DSA in the CCF hardware, the only type of key pair that is available for DSA is PKDS. The CCF hardware does not support CLEAR DSA key pairs.

MD2, MD5, and SHA hashing algorithms

Hashing algorithms are not as compute intensive as the RSA and DSA algorithms, so it is not always better to use hardware devices to perform them. This is because the overhead of using the hardware device can outweigh the potential performance gains. Further, the security of performing hashing algorithms on hardware is not substantially better than performing the same operations in software, because the hash subsequently is used in a more secure RSA or DSA sign or verify operation. For these reasons many hardware cryptography devices don't support hashing algorithms and, in some cases, the CCA layer performs the hashing algorithm in software rather than hardware.

The IBMJCECCA provider calls the CCA interfaces to perform MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashing, and performs MD2 hashing via software. In some cases, the IBM CCA layer performs the MD5 hash using software instead of hardware.

Note the following regarding the SHA algorithms.

  • SHA-256 is only supported on z9 and newer zSeries processor families.
  • SHA-384 and SHA-512 are only supported on z10 and newer zSeries processor families.

Random Number generation

The IBM CCA hardware devices provide a true random number generator. This is an improvement over the java.util.Random class which provides a pseudo random number generation capability based on salting a random number operation with some value. The IBMJCECCA provider takes advantage of the true random number generation capabilities in the cryptographic hardware and makes them available to applications with the SecureRandom class.

IBMJCECCA provider package includes:

  • An implementation of the Digital Signature Algorithm (DSA), described in NIST FIPS 186 (only supported on z800 and z900 hardware)
  • An implementation of RSA, described in PKCS #1.
  • An implementation of the MD2 (RFC1319), MD5 (RFC 1321) and SHA-1 (NIST FIPS 180-1) SHA (SHA1, SHA-256, SHA-384, SHA512: NIST FIPS 180-3) message digest algorithms.

    Note the following regarding the SHA algorithms.

    • SHA-256 is supported on z9 and newer zSeries processor families
    • SHA-384 and SHA-512 are supported on z10 and newer zSeries processor families.

  • An implementation of the HmacMD2, HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, and HmacSHA512 hashing message authentication code algorithms.

    Note the following regarding the HmacSHA algorithms.

    • HmacSHA256 is supported on z9 and newer zSeries processor families.
    • HmacSHA384 and HmacSHA512 are supported on z10 and newer zSeries processor families.

  • An implementation of the AES cipher algorithm.
  • An implementation of the DES cipher algorithm.
  • An implementation of the TripleDES cipher algorithm.
  • An implementation of the following PBE algorithms:
    • PBEWithMD2AndDES
    • PBEWithMD2AndTripleDES
    • PBEWithMD5AndDES
    • PBEWithMD5AndTripleDES
    • PBEWithSHA1AndDES
    • PBEWithSHA1AndTripleDES
    • PBEWithSHAAnd2KeyTripleDES
    • PBEWithSHAAnd3KeyTripleDES
  • A DSA key pair generator for generating a pair of public and private keys suitable for the DSA algorithm (only supported on z800 and z900 hardware).
  • An RSA key pair generator for generating a pair of public and private keys suitable for the RSA algorithm.
  • An AES key generator for generating a key suitable for the AES algorithm.
  • A DES key generator for generating a key suitable for the DES algorithm.
  • A TripleDES key generator for generating a key suitable for the TripleDES algorithm.
  • An HmacMD2 key generator for generating a key suitable for the HmacMD2 algorithm.
  • An HmacMD5 key generator for generating a key suitable for the HmacMD5 algorithm.
  • A HmacSHA1 key generator for generating a key suitable for the HmacSHA1. algorithm.
  • An HmacSHA256 key generator for generating a key suitable for the HmacSHA256 algorithm.
    • Note that the HmacSHA256 algorithm is supported on z9 and newer zSeries processor families.
  • An HmacSHA384 key generator for generating a key suitable for the HmacSHA384 algorithm.
    • Note that the HmacSHA384 algorithm is supported on z10 and newer zSeries processor families.
  • An HmacSHA512 key generator for generating a key suitable for the HmacSHA512 algorithm.
    • Note that the HmacSHA512 algorithm is supported on z10 and newer zSeries processor families.
  • A DSA algorithm parameter generator (only supported on z800 and z900 hardware).
  • A DSA algorithm parameter manager (only supported on z800 and z900 hardware).
  • An AES algorithm parameter manager.
  • A DES algorithm parameter manager.
  • A TripleDES algorithm parameter manager.
  • An implementation of the proprietary "IBMSecureRandom" random number generation algorithm.
  • A "certificate factory" for X.509 certificates and Certificate Revocation Lists (CRLs).
  • Keystore implementations for the proprietary keystore type named "JCECCAKS".

Overview of differences between the software JCE implementation and the hardware JCE implementation

There are few differences between the software cryptography implementation of JCE (IBMJCE) and the hardware implementation (IBMJCECCA). For example, DES and Triple DES operations available in the IBMJCE provider are the same in the IBMJCECCA provider. One difference, discussed below, is in the required key attribute restrictions for the RSA cipher algorithm. A more important difference is in the list of supported cryptographic algorithms. The IBMJCECCA provider supports fewer algorithms than the IBMJCE provider, due to limitations in the currently available hardware. The cryptographic operations provided by the IBMJCECCA are the same as for previous versions of JCE.  Therefore, an existing application can be migrated easily from a software JCE provider, such as IBMJCE, into the hardware JCE environment, IBMJCECCA.  To migrate, it is only necessary to generate new key pairs for RSA or DSA with appropriate attributes (see below) and to change the security provider.

The security provider can be changed either by using API calls with the provider parameter or by changing the provider list to place the IBMJCECCA in a preferred position (that is, with a lower sequence number than the IBMJCE provider). If it is necessary to have a software JCE provider, such as IBMJCE, in the provider list in a position preferred to the position of the IBMJCECCA, you must specify the IBMJCECCA provider in the getInstance() API if you want to use it instead of the software provider. If the provider is not specified on an API call, the actual provider invoked at runtime will be the first one on the provider list that supports the requested algorithm and key type. This could cause a software JCE provider to be used instead of the IBMJCECCA provider.

The following section, titled "Specific Changes and Requirements", provides more details for the advanced applications developer. 

Specific Changes and Requirements

The following sections discuss the restrictions and features that differ from the basic software JCE provider (IBMJCE) to the hardware assisted JCE provider (IBMJCECCA).

The KeyFactory Class:

The key factory class is an engine class designed to provide opaque cryptographic keys (objects of type Key) and key specifications (transparent representations of the underlying key material).

AES
The IBMJCECCA provider supports a key type for AES keys that have been stored previously in the host CKDS. The keys are objects of type SecretKey. The SecretKeyFactory can be used to generate a key of this type from a KeyLabelKeySpec containing the CKDS label for the key.

Other keySpec classes supported by the AES KeyFactory include the AESKeySpec and the SecretKeySpec.

DES
The IBMJCECCA provider supports a key type for DES keys that have been stored previously in the host CKDS. The keys are objects of type SecretKey. The SecretKeyFactory can be used to generate a key of this type from a KeyLabelKeySpec containing the CKDS label for the key.

Other keySpec classes supported by the DES KeyFactory include the DESKeySpec and the SecretKeySpec.

Triple DES (aka DESede and 3DES)
The IBMJCECCA provider supports a key type for triple DES keys that have been stored previously in the host CKDS. The keys are objects of type SecretKey. The SecretKeyFactory can be used to generate a key of this type from a KeyLabelKeySpec containing the CKDS label for the key.

Other keySpec classes supported by the triple DES KeyFactory include the DESedeKeySpec and the SecretKeySpec.

DSA
The IBMJCECCA provider supports a key type for DSA private hardware keys that is similar to the DSA Private keys available in software providers. DSA private hardware keys are objects of type DSAPrivateHWKey. The corresponding DSA public keys are objects of type DSAPublicKey.

The KeyFactory class can be used to generate a DSA Private hardware key from a DSAPrivateKeyHWSpec. The KeyFactory can also be used to generate a DSA public key from a DSAPublicKeySpec or an X509EncodedKeySpec.

The KeyFactory class can also derive a DSAPrivateKeyHWSpec from a DSA Private hardware key or a DSAPublicKeySpec or X509PublicKeySpec from a DSA public key.

RSA
The IBMJCECCA provider adds a new key type for RSA private hardware keys that is similar to the RSA Private keys available in software providers. RSA private hardware keys are objects of type RSAPrivateHWKey. The corresponding RSA public keys are objects of type RSAPublicKey.

The KeyFactory class can be used to generate an RSA private hardware key from a RSAPrivateHWKeySpec, RSAPrivateCrtKeySpec, RSAPrivateKeySpec, or KeyLabelKeySpec. The KeyFactory can also be used to generate an RSA public key from an RSAPublicKeySpec , X509EncodedKeySpec,or KeyLabelKeySpec. Keys that already in the PKDS can also be created by passing a KeyLabelKeySpec to the RSA KeyFactory.

The KeyFactory class can also derive an RSAPrivateKeyHWSpec from an RSA private hardware key or an RSAPublicKeySpec or X509PublicKeySpec from an RSA public key.

Note that an RSAPrivateKeyHWSpec and a DSAPrivateKeyHWSpec are valid only on the system where the private key was originally generated. Private hardware keys can not be moved from the system on which they are generated to another system. This is true for all private hardware keys, including clear private keys, and is part of the security provided for them.

Algorithm Parameters Classes:

The CCAAlgorithmParameterSpec class:

This class (which implements the AlgorithmParameterSpec interface) specifies whether the AES, DES, or triple DES key to be generated will be a secret hardware key and whether it will be stored in the CKDS.

In the default case, an object of this class is created without specifying a key type, and this object is passed to the init() method of an AESKeyGenerator, a DESKeyGenerator, or a DESedeKeyGenerator. In this case, a subsequent call to generateKey() will return a key object containing the requested key encrypted using the host master key.

A CCAAlgorithmParameterSpec object can be used to specify the strength (size) of the key to be generated.

If the CCAAlgorithmParameterSpec object is being used to generate a key in the system CKDS, the CCAAlgorithmParameterSpec can be used to specify the CKDS label to use to identify the CKDS entry. If a label is specified, it must be unique in the CKDS and must follow the ICSF rules for CKDS entry labels. If no label is specifed for a new CKDS entry, the KeyGenerator generateKey() method will create one automatically.

A CCAAlgorithmParameterSpec object can also be used to explicitly specify the type of key to be generated:

  • CCAAlgorithmParameterSpec.CKDS can be passed to the CCAAlgorithmParameterSpec constructor, and the resulting object passed to the init() method of an AESKeyGenerator, a DESKeyGenerator, or a DESedeKeyGenerator. In this case, a subsequent call to generateKey() will return a key object containing the CKDS label for requested key encrypted using the host master key and stored in the system CKDS.


  • CCAAlgorithmParameterSpec.PROTECTED can be passed to the CCAAlgorithmParameterSpec constructor, and the resulting object passed to the init() method of an AESKeyGenerator, a DESKeyGenerator, or a DESedeKeyGenerator. In this case, a subsequent call to generateKey() will return a key object containing the requested key encrypted using the host master key. This key can also be generated using a KeyGenerator class and passing a CCAAlgorithmParameterSpec object, created without specifying a key type, to the KeyGenerator init() method.


  • CCAAlgorithmParameterSpec.CLEAR can be passed to the CCAAlgorithmParameterSpec constructor and the resulting object passed to the init() method of an AESKeyGenerator, a DESKeyGenerator, or a DESedeKeyGenerator. In this case, a subsequent call to generateKey() will return a key object containing the clear key material for requested key. This key can also be generated using a KeyGenerator class without passing any CCAAlgorithmParameterSpec object to the KeyGenerator init() method.

CCAAlgorithmParameterSpec has the following constructors:

public CCAAlgorithmParameterSpec()


public CCAAlgorithmParameterSpec(int size)


public CCAAlgorithmParameterSpec(byte hwType)


public CCAAlgorithmParameterSpec(int size,byte hwType)


public CCAAlgorithmParameterSpec(int size,byte hwType,String label)


public CCAAlgorithmParameterSpec(byte hwType,String label)


Parameters that can be passed to the constructors:


The size parameter must be valid for the specific algorithm of the KeyGenerator to which this CCAAlgorithmParameterSpec will be passed.

The hwType parameter must be one of the following constant values:
  • CCAAlgorithmParameterSpec.CLEAR
  • CCAAlgorithmParameterSpec.PROTECTED
  • CCAAlgorithmParameterSpec.CKDS

The label parameter must be valid for the ICSF component, according to the rules defined for the Key Generator Utility Program (KGUP).

CCAAlgorithmParameterSpec has the following methods:

public int getKeySize()

This method returns the key size specified to the CCAAlgorithmParameterSpec constructor. If no key size was specified, this method returns 0.

public byte getHwType()

This method returns the key type specified to the CCAAlgorithmParameterSpec constructor. The returned value will be one of the following constant values:
  • CCAAlgorithmParameterSpec.CLEAR
  • CCAAlgorithmParameterSpec.PROTECTED
  • CCAAlgorithmParameterSpec.CKDS

public String getLabel()

This method returns the CKDS label specified to the CCAAlgorithmParameterSpec constructor. If no CKDS label was specified, this method returns null.

It is not necessary to specify a CCAAlgorithmParameterSpec object in order to create a key using an AESKeyGenerator, a DESKeyGenerator, or a DESedeKeyGenerator. If no CCAAlgorithmParameterSpec object is passed to the KeyGenerator init() method before the generateKey() method is called, the key object returned will contain the clear key material for requested key.

The KeyParameterSpec class for DSA hardware (DSAHWKeyParameterSpec):

This class (which implements the AlgorithmParameterSpec interface) specifies the set of parameters to use with the DSA hardware algorithm. These are:
  • DSAKeyHWAttributes

    Due to hardware restrictions, these must be KeyHWAttributeValues.PKDS and KeyHWAttributeValues.SIGNATURE.

  • DSAParameterSpec

    These are:

    • p - the prime
    • q - the sub-prime
    • g - the base

  • KeySize

    This parameter specifies the size of the key based on prime p.

  • KeyLabel

    This parameter specifies the name that will be used as a reference to the key stored in the hardware.


See the Java API documentation for the specific methods, default values and restrictions associated with this class.

The KeyParameterSpec class for RSA hardware (RSAKeyParameterSpec):

This class (which implements the AlgorithmParameterSpec interface) specifies the set of parameters to use with the RSA hardware algorithm. These are:
  • RSAKeyHWAttributes

    This parameter includes

    • RSAKeyHWAttributes.type

      which must have one of the following values:

      • KeyHWAttributeValues.PKDS
      • KeyHWAttributeValues.CLEAR
      • KeyHWAttributeValues.RETAIN

    • RSAKeyHWAttributes.usage

      which must have one of the following values:

      • KeyHWAttributeValues.SIGNATURE
      • KeyHWAttributeValues.KEYMANAGEMENT

  • KeySize

    This parameter specifies the size of the key.

  • KeyLabel

    If the RSAKeyHWAttributes.type is not specified as KeyHWAttributeValues.CLEAR, this parameter specifies the name that will be used as a reference to the key stored in hardware.

See the Java API documentation for the specific methods, default values and restrictions associated with this class.

The Key Interface Class:

As discussed above, the clear key material for private hardware keys of type PKDS is never returned to an application and can never be transported for use on another system. For this reason, no implementation of the Key interface can be used to represent them.

A software reference to a private hardware key of type PKDS is not a key or a key specification, but instead is a label that can be specified to the IBMJCECCA provider in place of a key. The following method can be used to retrieve the representation of a hardware key pair:

public byte [] getToken() 

For a DSA key pair, getToken() returns the label that represents the key stored in the PKDS associated with the hardware.

For an RSA key pair of type CLEAR, getToken() returns an internal CCA token. For an RSA key pair of type PKDS, getToken() returns the label that represents the key stored in the PKDS associated with the hardware.

Key Specification Interfaces and Classes

The KeyLabelKeySpec Class

This class (which implements the KeySpec Interface) specifies the CKDS label for an AES, DES, or DESede key stored in the system CKDS. If a KeyLabelKeySpec is passed to the generateSecret() method of an AESKeyFactory, a DESKeyFactory, or a DESedeKeyFactory then the key object returned will represent a key already stored in the CKDS. Note that generateSecret() does not create a new CKDS entry and does not verify that such an entry currently exists in the CKDS.

It has the following methods:

public byte[] getLabel()

This method returns the CKDS label for the key.

public byte[] getLabelBytes()

This method returns the ASCII byte representation of the CKDS label for the key.

The DSAPrivateHWKeySpec Class

This class (which implements the KeySpec Interface) specifies a DSA private hardware key with its associated parameters. It has the following methods:
public byte[] getLabel()

This method returns the private key label.

public DSAKeyHWAttributes getAttributes()

This method returns the DSA algorithm parameters used to calculate the key.

public DSAParameterSpec getDSAParamSpec()

This method returns the DSA hardware attributes associated with the key.

See the Java API documentation for the specific methods, default values and restrictions associated with this class.

The RSAPrivateHWKeySpec Class

This class (which implements the KeySpec Interface) specifies an RSA private hardware key with its associated parameters. It has the following methods:
public byte[] getToken()

This method returns the private key token, which can be an internal CCA token or a key label.

public RSAKeyHWAttributes getAttributes()

This method returns the RSA hardware attributes associated with the key.

See the Java API documentation for the specific methods, default values and restrictions associated with this class.

The SecureRandom Class:

The SecureRandom class in this provider is a true random number generator that does not need seeding. Therefore, calls to setSeed(), getSeed() and generateSeed() will throw an exception.

The following illustrates using SecureRandom:

java.security.SecureRandom random = null;
random = java.security.SecureRandom.getInstance( "IBMSecureRandom");
byte[] testData = new byte[1024];
random.nextBytes(testData);

In this example, an instance of the SecureRandom class is obtained, a byte array is instantiated, and a random number of size 1024 bytes is generated.

See the Java API documentation for the specific methods, default values and restrictions associated with this class

Reading Base64-Encoded Certificates

Certificates encoded with Base64 are read in and written out in the ISO8859_1 code page, not the local code page. This is done to make them compatible with the Base64-Encoded Certificates on other platforms. For this reason an encoded certificate may not be human readable on some platforms.

The Signature Class:

The IBMJCECCA provider supports signatures of the following types:

  • SHA1 with DSA, except that DSA is only supported on z800 and z900 hardware
  • SHA1 with RSA
  • MD2 with RSA
  • MD5 with RSA
  • SHA256 with RSA (supported on z9 and newer zSeries processor families)
  • SHA384 with RSA (supported on z10 and newer zSeries processor families)
  • SHA512 with RSA (supported on z10 and newer zSeries processor families)
A Signature is created by calling the MessageDigest class that will be used when computing the signature and then calling the CCA hardware to create the actual signature from the hash and the corresponding private key. A Signature is verified by creating a hash and passing in both the public key and the previously generated signature to the hardware. (See "Specific Changes and Requirements" for specific class names.)

Data Encryption Standard (DES): Keys

The hardware JCE implementation (IBMJCECCA) extends the DES key available in the software JCE implementation (IBMJCE). In the IBMJCE implementation, the actual DES key material is stored in the key object. The IBMJCECCA implementation extends this by adding the following alternative representations:

  • A DES key previously stored in the CKDS. The key object will contain the CKDS label for the key.

    The following illustrates creating a DES key object for a key already stored in the CKDS with the label "MYENCRYPTEDDESKEY" and then (for purposes of illustration) deleting the CKDS entry.

    // create a key object for an existing CKDS entry
    // (No checking is done to verify that the entry exists, or
    // that the key it contains is actually a DES key.)
    //
    SecretKeyFactory desKeyFactory =
            SecretKeyFactory.getInstance("DES", "IBMJCECCA");
    KeyLabelKeySpec spec =
            new KeyLabelKeySpec("MYENCRYPTEDDESKEY");
    SecretKey key = desKeyFactory.generateSecret(spec);
    
    // delete the entry from the CKDS
    // (An exception is thrown if the CKDS entry does not exist.)
    //
    key.deleteCKDSEntry();
    
    //
    // Note that, in this example, the Java key object still
    // exists, but the CKDS entry it represents has been deleted.
    // Any attempt to use the object "key" will cause an exception
    // containing a hardware return code and reason code.
    //
                            

    On z800 and z900 machines, a key object containing the CKDS label for an encrypted DES key can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    On the z890 and z990 and newer zSeries processors, a key object containing the CKDS label for a clear DES key can be used for CBC mode, CFB mode, or ECB mode encryption and decryption with the IBMJCECCA provider. This environment also supports using a key object containing the CKDS label for an encrypted DES key for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object containing the CKDS label for an encrypted DES key can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a DES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a DES hardware token. Unwrapping to a key object containing a DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping DES keys, see RSA

  • A DES key generated by an IBMJCECCA call to the underlying hardware. The key object will contain a hardware token. This token contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating a DES key object containing a hardware key token

    // create a new key token and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec();
    KeyGenerator keyGen =
            KeyGenerator.getInstance( "DES", "IBMJCECCA" );
    keyGen.init( ccaAlgParmSpec, null );
    Key desKey = keyGen.generateKey();
                            

    A key object containing a DES hardware token can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object containing a DES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a DES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a DES hardware token. Unwrapping to a key object containing a DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping DES keys, see RSA

  • A DES key generated by an IBMJCECCA call to the underlying hardware and then stored in the CKDS. The key object will contain the label for the new CKDS entry. The CKDS entry holds a token that contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating a protected DES key token, storing it in a new CKDS entry with an automatically generated label, and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS);
    KeyGenerator keyGen = KeyGenerator.getInstance("DES", "IBMJCECCA");
    keyGen.init( ccaAlgParmSpec, null );
    Key thisKey = keyGen.generateKey();
                            

    The following illustrates generating a protected DES key token, storing it in a new CKDS entry with the label "ADESTOKENINCKDS", and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS,
                                          "ADESTOKENINCKDS");
    KeyGenerator keyGen = KeyGenerator.getInstance("DES", "IBMJCECCA");
    keyGen.init(ccaAlgParmSpec,null);
    Key thisKey = keyGen.generateKey();
                            

    A key object representing a DES hardware token can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object representing a DES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a DES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a DES hardware token. Unwrapping to a key object containing the label for a CKDS entry that contains a DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping DES keys, see RSA

Data Encryption Standard (DES): Operations

The hardware JCE implementation (IBMJCECCA) of DES does not change any of the APIs that are available in software JCE implementation (IBMJCE). Therefore, an application that used the DES capabilities of the IBMJCE will not require modification to use the IBMJCECCA, except for specific references to the provider. For example, if a call to the getInstance() API specified the IBMJCE provider, it will be necessary to change the call to specify the IBMJCECCA provider instead.

Although all DES ciphers are available in the IBMJCECCA provider, they are not all available in the hardware devices. The hardware cryptographic devices only support the Cipher Block Chaining (CBC) and Electronic Code Book (ECB) versions of DES. That is, all of the DES ciphers are supported by the IBMJCECCA provider, but only CBC and ECB modes use hardware cryptography.

It is not always more efficient to use hardware cryptography instead of software cryptography. The DES algorithm is not as compute intensive as some asymmetric algorithms such as RSA. For smaller data sizes, software DES cryptography can be faster than hardware cryptography. Because of this, a software version of DES with CBC and ECB also were implemented in the IBMJCECCA provider. For small amounts of data, software DES (CBC or ECB) is sometimes faster than hardware DES (CBC or ECB) cryptography, The exact size of the data at which the performance trade off is found varies from system to system. Therefore, a "clip level" is used to specify the data size at which hardware cryptography is used. Any data length below the clip level will use software cryptography. The clip level is a system property called "ibm.DES.usehdwr.size" and has a default value of 60. Thus, by default, any DES CBC or ECB processing where the data size is 60 bytes or less will be performed using software cryptography and any data size greater than 60 bytes will be performed using hardware cryptography. For ciphers other than DES CBC and DES ECB this system property has no function.

You can adjust the clip level by changing the system property to the desired level. If you set the system property to 0, all DES CBC and DES ECB processing will be performed using hardware cryptography. If you set the system property to -1, all DES CBC and DES ECB processing will be performed using software cryptography. This system property applies to both DES and triple DES CBC and ECB processing.

Note that the data size comparison to the clip level is done when the first data is passed to the cipher for encryption or decryption. For example, consider an application that decrypts the contents of a tape by reading each record and passing it to the cipher before reading the next record. In this case, the first record passed to the cipher object will be the tape header. If the tape header is smaller than the current clip level, the decryption will be done using software, even though the subsequent records may be very large. This is a case where you might choose to set the clip level to 0 so that hardware cryptography will be used, regardless of the size of the first record processed.

The example below shows how to set the "ibm.DES.usehdwr.size" system property when a java program named programName is run.

java -Dibm.DES.usehdwr.size=80 programName

This value can also be set programatically with the Java System.setProperty() method.

Triple DES (aka DESede or 3DES): Keys

The hardware JCE implementation (IBMJCECCA) extends the triple DES key available in the software JCE implementation (IBMJCE). In the IBMJCE implementation, the actual triple DES key material is stored in the key object. The IBMJCECCA implementation extends this by adding the following alternative representations:

  • A triple DES key previously stored in the CKDS. The key object will contain the CKDS label for the key.

    The following illustrates creating a triple DES key object for a key already stored in the CKDS with the label "MYENCRYPTEDTDESKEY" and then (for purposes of illustration) deleting the CKDS entry.

    // create a key object for an existing CKDS entry
    // (No checking is done to verify that the entry exists, or
    // that the key it contains is actually a DESede key.)
    //
    SecretKeyFactory desKeyFactory =
            SecretKeyFactory.getInstance("DESede", "IBMJCECCA");
    
    KeyLabelKeySpec spec =
            new KeyLabelKeySpec("MYENCRYPTEDTDESKEY");
    SecretKey key = desKeyFactory.generateSecret(spec);
    
    // delete the entry from the CKDS
    // (An exception is thrown if the CKDS entry does not exist.)
    //
    key.deleteCKDSEntry();
    
    //
    // Note that, in this example, the Java key object still
    // exists, but the CKDS entry it represents has been deleted.
    // Any attempt to use the object "key" will cause an exception
    // containing a hardware return code and reason code.
    //
                            

    On z800 and z900 machines, a key object containing the CKDS label for an encrypted DES key can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    On z890, z990, and newer zSeries processors, a key object containing the CKDS label for a clear DES key can be used for CBC mode, CFB mode, or ECB mode encryption and decryption with the IBMJCECCA provider. This environment also supports using a key object containing the CKDS label for an encrypted DES key for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object containing the CKDS label for an encrypted triple DES key can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A triple DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear triple DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a triple DES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a triple DES hardware token. Unwrapping to a key object containing a triple DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping triple DES keys, see RSA

  • A triple DES key generated by an IBMJCECCA call to the underlying hardware. The key object will contain a hardware token. This token contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating a triple DES key object containing a hardware key token

    // create a new key token and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec();
    KeyGenerator keyGen =
            KeyGenerator.getInstance( "DESede", "IBMJCECCA" );
    keyGen.init( ccaAlgParmSpec, null );
    Key tdesKey = keyGen.generateKey();
                            

    A key object containing a triple DES hardware token can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object containing a triple DES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A triple DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear triple DES key. If the RSA Cipher object is initialized with a CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a triple DES hardware token. Unwrapping to a key object containing a triple DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping triple DES keys, see RSA

  • A triple DES key generated by an IBMJCECCA call to the underlying hardware and then stored in the CKDS. The key object will contain the label for the new CKDS entry. The CKDS entry holds a token that contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating a protected triple DES key token, storing it in a new CKDS entry with an automatically generated label, and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS);
    KeyGenerator keyGen = KeyGenerator.getInstance("DESede","IBMJCECCA");
    keyGen.init(ccaAlgParmSpec,null);
    Key thisKey = keyGen.generateKey();
                            

    The following illustrates generating a protected triple DES key token, storing it in a new CKDS entry with the label "ATRIPLEDESTOKENINCKDS", and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS,
                                          "ATRIPLEDESTOKENINCKDS");
    KeyGenerator keyGen = KeyGenerator.getInstance("DESede", "IBMJCECCA");
    keyGen.init(ccaAlgParmSpec, null);
    Key thisKey = keyGen.generateKey();
                            

    A key object representing a triple DES hardware token can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object representing a triple DES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    A triple DES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear triple DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a triple DES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a triple DES hardware token. Unwrapping to a key object containing the label for a CKDS entry that contains a triple DES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping triple DES keys, see RSA

Triple DES (aka DESede or 3DES): Operations

Although all triple DES ciphers are available in the IBMJCECCA provider, they are not all available in the hardware devices. The hardware cryptographic devices only support the Cipher Block Chaining (CBC) and Electronic Code Book (ECB) version of triple DES. That is, all of the triple DES ciphers are supported by the IBMJCECCA provider, but only CBC and ECB use hardware cryptography.

Triple DES is slightly more compute intensive than DES, but like DES is less compute intensive than asymmetric algorithms such as RSA. Therefore, for smaller data sizes, software triple DES cryptography can be faster than hardware triple DES cryptography. For this reason, triple DES with CBC or ECB is also implemented in software within the IBMJCE4758 provider. The same "clip level" (specified in a system property called "ibm.DES.usehdwr.size") is used to determine the data size at which hardware cryptography is used for triple DES. For more information about the "ibm.DES.usehdwr.size" system property, see the discussion above.

AES: Keys

The hardware JCE implementation (IBMJCECCA) extends the AES key available in the software JCE implementation (IBMJCE). In the IBMJCE implementation, the actual AES key material is stored in the key object. The IBMJCECCA implementation extends this by adding the following alternative representation:

  • An AES key previously stored in the CKDS. The key object will contain the CKDS label for the key.

    The following illustrates creating an AES key object for a key already stored in the CKDS with the label "MYENCRYPTEDAESKEY" and then (for purposes of illustration) deleting the CKDS entry.

    // create a key object for an existing CKDS entry
    // (No checking is done to verify that the entry exists, or
    // that the key it contains is actually an AES key.)
    //
    SecretKeyFactory aesKeyFactory =
            SecretKeyFactory.getInstance("AES", "IBMJCECCA");
    KeyLabelKeySpec spec =
            new KeyLabelKeySpec("MYENCRYPTEDAESKEY");
    SecretKey key = aesKeyFactory.generateSecret(spec);
    
    // delete the entry from the CKDS
    // (An exception is thrown if the CKDS entry does not exist.)
    //
    key.deleteCKDSEntry();
    
    //
    // Note that, in this example, the Java key object still
    // exists, but the CKDS entry it represents has been deleted.
    // Any attempt to use the object "key" will cause an exception
    // containing a hardware return code and reason code.
    //
                            

    A key object containing the CKDS label for a clear AES key can be used for CBC mode, CFB mode, or ECB mode encryption and decryption with the IBMJCECCA provider.

    A key object containing the CKDS label for an encrypted AES key can be used for CBC mode or ECB mode encryption and decryption with the IBMJCECCA provider.

  • A key object containing the CKDS label for an encrypted AES key can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    An AES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear AES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain an AES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains an AES hardware token. Unwrapping to a key object containing an AES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping AES keys, see RSA

  • An AES key generated by an IBMJCECCA call to the underlying hardware. The key object will contain a hardware token. This token contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating an AES key object containing a hardware key token

    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec();
    KeyGenerator keyGen =
            KeyGenerator.getInstance( "AES", "IBMJCECCA" );
    keyGen.init( ccaAlgParmSpec, null );
    Key aesKey = keyGen.generateKey();
                       

    A key object containing an AES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    An AES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear AES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain an AES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains an AES hardware token. Unwrapping to a key object containing an AES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping AES keys, see RSA

  • An AES key generated by an IBMJCECCA call to the underlying hardware and then stored in the CKDS. The key object will contain the label for the new CKDS entry. The CKDS entry holds a token that contains the key encrypted with the host master key. The key material for this type of key is never resident in system memory in clear form.

    The following illustrates generating a protected AES key token, storing it in a new CKDS entry with an automatically generated label, and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS);
    KeyGenerator keyGen = KeyGenerator.getInstance("AES", "IBMJCECCA");
    keyGen.init( ccaAlgParmSpec, null );
    Key thisKey = keyGen.generateKey();
                       

    The following illustrates generating a protected AES key token, storing it in a new CKDS entry with the label "ANAESTOKENINCKDS", and creating a key object containing the label for the CKDS entry.

    // create a new CKDS entry and a key object to represent it
    //
    CCAAlgorithmParameterSpec ccaAlgParmSpec =
            new CCAAlgorithmParameterSpec(CCAAlgorithmParameterSpec.CKDS,
                                          "ANAESTOKENINCKDS");
    KeyGenerator keyGen = KeyGenerator.getInstance("AES", "IBMJCECCA");
    keyGen.init(ccaAlgParmSpec, null);
    Key thisKey = keyGen.generateKey();
                       

    A key object representing an AES hardware token can be used for CBC mode encryption and decryption with the IBMJCECCA provider.

    A key object representing an AES hardware token can be passed to an IBMJCECCA RSA Cipher object to be wrapped for export to another host. This is not supported for AMODE(64).

    An AES key that has been wrapped by an RSA Cipher can be passed to the IBMJCECCA RSA Cipher to be unwrapped for import from another host. By default, the resulting (unwrapped) key object will contain a clear DES key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain an AES hardware token. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains an AES hardware token. Unwrapping to a key object containing the label for a CKDS entry that contains an AES hardware token is not supported for AMODE(64).

    For more information about wrapping and unwrapping AES keys, see RSA

AES: Operations

The hardware JCE implementation (IBMJCECCA) of AES does not change any of the APIs that are available in software JCE implementation (IBMJCE). Therefore, an application that used the AES capabilities of the IBMJCE will not require modification to use the IBMJCECCA, except for specific references to the provider. For example, if a call to the getInstance() API specified the IBMJCE provider, it will be necessary to change the call to specify the IBMJCECCA provider instead.

The IBMJCECCA provider hardware cryptographic devices only support the Cipher Feedback (CFB), the Cipher Block Chaining (CBC) and the Electronic Code Book (ECB) versions of AES. Software failover support, as provided for DES and DESede, is available for AES ECB ciphers and AES CBC ciphers only.

RSA

Both RSA encryption and decryption are available in the IBMJCECCA provider using hardware cryptography. Because the RSA algorithm is quite compute intensive, using hardware cryptography provides significant performance improvements over software cryptography. Using hardware to perform the RSA encryption and decryption also allows use of the more secure PKDS stored key pairs. With a PKDS stored key pair, the sensitive private key is never made available in the clear.

In software implementations of JCE providers (such as IBMJCE), RSA encryption and decryption are implemented with PKCS 1 type 2 padding. RSA encryption and decryption with PKCS 1 type 2 padding is also implemented in hardware cryptography and available with the IBMJCECCA provider.

However, there are two restrictions imposed by the hardware:

  • The type of key pair that is needed
    The hardware implementation of RSA requires that the keys used to encrypt/decrypt data be generated to have a key usage of KEYMANAGEMENT. This means that when the RSA key pair is generated the key usage must be set to KEYMANAGEMENT.
  • The maximum length of the data that can be encrypted or decrypted
    The hardware implementation of RSA limits the amount of data to be encrypted or decrypted to 245 bytes or 11 bytes smaller that the modulus size of the key, in bytes, which ever is smaller.

The IBMJCECCA provider also implements RSA encryption/decryption with "zero padding". This padding scheme is not supported by all JCE providers. The default padding scheme is PKCS 1 type 2 padding for the IBMJCECCA provider.

The following illustrates creating an instance of an RSA Cipher with "zero padding"

Cipher myCipher = Cipher.getInstance("RSA/ /ZeroPadding", "IBMJCECCA");

The following illustrate creating an instance on an RSA Cipher with "PKCS 1 type 2 padding"

Cipher myCipher = Cipher.getInstance("RSA/ /PKCS1Padding", "IBMJCECCA");
Or
Cipher myCipher = Cipher.getInstance("RSA", "IBMJCECCA"); // accept the default padding

The IBMJCECCA provider supports RSA wrapping of a symmetric key for export to another host. The following keys are supported for RSA wrapping:

  • a key object containing a clear AES,DES, or triple DES key.
  • a key object containing a CKDS label for an encrypted AES, DES or triple DES key
  • a key object containing a hardware token with an encrypted AES, DES or triple DES key.
The following keys are not supported for RSA wrapping with AMODE(64):
  • a key object containing a CKDS label for an encrypted AES, DES or triple DES key.
  • a key object containing a hardware token with an encrypted AES, DES or triple DES key.

The IBMJCECCA provider supports RSA unwrapping of a symmetric key for import from another host. By default, the resulting (unwrapped) key object will contain a clear key. If a CCAAlgorithmParameterSpec is created with no type specified, or with type CCAAlgorithmParameterSpec.PROTECTED, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain a hardware token. This token will contain the key encrypted with the host master key. If a CCAAlgorithmParameterSpec is created with type CAAlgorithmParameterSpec.CKDS, and the RSA Cipher is initialized with this CCAAlgorithmParameterSpec, the resulting (unwrapped) key object will contain the label for a CKDS entry that contains a hardware token. This token will contain the key encrypted with the host master key. Unwrapping to a key object containing a hardware token is not supported with AMODE(64).

The following illustrates generating a triple DES key object containing a clear key, wrapping it, then unwrapping it to a triple DES key object containing a clear key.

// Generate a clear triple DES key
//
KeyGenerator keyGen =
        KeyGenerator.getInstance("DESede", "IBMJCECCA");
Key tdesKey = keyGen.generateKey();

// Generate an RSA key pair
//
KeyPairGenerator rsaKeyPairGen =
        KeyPairGenerator.getInstance("RSA","IBMJCECCA");
rsaKeyPairGen.initialize(1024);
KeyPair rsaKeyPair = rsaKeyPairGen.generateKeyPair();
PublicKey rsaPub = rsaKeyPair.getPublic();
PrivateKey rsaPriv = rsaKeyPair.getPrivate();

// Wrap the triple DES key as for export
//
Cipher rsaCipher = Cipher.getInstance("RSA","IBMJCECCA");
rsaCipher.init(Cipher.WRAP_MODE, rsaPub,
               (AlgorithmParameters)null, null);
byte[] wrappedKey = rsaCipher.wrap(tdesKey);

// Unwrap the triple DES key as for import
// Unwrap to a clear key
//
Key unwrappedDesKey =
        rsaCipher.unwrap(wrappedKey, "DESede", Cipher.SECRET_KEY);
        

The following illustrates generating a triple DES key object containing a hardware key token, wrapping it, then unwrapping it to a triple DES key object containing a hardware key token.

// Generate a secure triple DES hardware key
//
CCAAlgorithmParameterSpec ccaAlgParmSpec =
        new CCAAlgorithmParameterSpec();
KeyGenerator keyGen =
        KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGen.init(ccaAlgParmSpec, null);
Key tdesKey = keyGen.generateKey();

// Generate an RSA key pair
//
KeyPairGenerator rsaKeyPairGen =
        KeyPairGenerator.getInstance("RSA","IBMJCECCA");
rsaKeyPairGen.initialize(1024);
KeyPair rsaKeyPair = rsaKeyPairGen.generateKeyPair();
PublicKey rsaPub = rsaKeyPair.getPublic();
PrivateKey rsaPriv = rsaKeyPair.getPrivate();

// Wrap the triple DES hardware key as for export
//
Cipher rsaCipher = Cipher.getInstance("RSA","IBMJCECCA");
rsaCipher.init(Cipher.WRAP_MODE, rsaPub,
               (AlgorithmParameters)null, null);
byte[] wrappedKey = rsaCipher.wrap(tdesKey);

// Unwrap the triple DES key as for import
// Unwrap to a secure hardware key
//
CCAAlgorithmParameterSpec ccaAlgParmSpec_forUnwrap =
        new CCAAlgorithmParameterSpec();
rsaCipher.init(Cipher.UNWRAP_MODE, rsaPriv,
               ccaAlgParmSpec_forUnwrap, null);
Key unwrappedDesKey =
        rsaCipher.unwrap(wrappedKey, "DESede", Cipher.SECRET_KEY);
        

The following illustrates deleting a RSA hardware key object for a key stored in PKDS, with the label "MYRSAKEY".

// Get the key store instance, open an input stream to the
// keystore file and load the key store.
//
KeyStore jceccaks = KeyStore.getInstance("JCECCAKS", "IBMJCECCA");
InputStream istream = new FileInputStream("keyStore.cca");
jceccaks.load(istream, "keystorePW".toCharArray());

// Given the alias for the PKDS key entry, retrieve the private
// hardware key from the key store.
//
PrivateKey privateKey = (PrivateKey) jceccaks.getKey("MYRSAKEY", "myrsakeyPW".toCharArray());

// Delete the RSA hardware PKDS key entry.
//
((RSAPrivateHWKey)privateKey).deletePKDSEntry();

// Delete the RSA key store object.
//
jceccaks.deleteEntry("MYRSAKEY");

// Write the modified key store contents to the key store file.
//
OutputStream ostream = new FileOutputStream("keyStore.cca");
jceccaks.store(ostream, "keystorePW".toCharArray());
         

NOTE: The DSAPrivateHWKey class also has a deletePKDSEntry method. The illustration above can be followed to delete DSA private hardware PKDS key entries by substituting the DSAPrivateHWKey class for the RSAPrivateHWKey class.

HMAC and PBE

The HMAC and PBE algorithms are supported in the IBMJCECCA provider using the same APIs that are supported by software JCE providers such as IBMJCE. However, the IBMJCECCA provider supports them by making use of other algorithms implemented in the cryptographic hardware.

Keystores for IBMJCECCA

The IBMJCECCA provider supports four keystores: JCECCAKS, JCE4758KS, JCECCARACFKS, and JCE4758RACFKS. The JCECCAKS uses strong encryption (triple DES) to protect the keys when stored in a file. The JCECCARACFKS keystore handles keys and certificates stored in RACF keyrings. The JCE4758KS and JCE4758RACFKS keystores are included for downward compatibility. The JCECCAKS keystore extends and replaces the JCE4758KS keystore. The JCECCARACFKS keystore extends and replaces the JCE4758RACFKS keystore.

JCECCAKS supports migration of keys from other keystores using normal keystore interfaces. The following is a list of keys that are supported by JCECCAKS for migration and for storage:

  • RSAPrivateHWKey
  • DSAPrivateHWKey
  • RSAPrivateKey
  • RSAPrivateCrtKey
  • DSAPrivateKey
  • any SecretKey
For an example of migrating keys from one keystore to another, see Migrate.java in the
$(java_home)/demo/jcecca/src
directory, where $(java_home) is the directory where the Java SDK is installed.

Default Keystore for IBMJCECCA
The default JCE keystore is named .keystore and is located in the user's home directory. The default JCECCAKS keystore is named .HWkeystore and is located in the user's home directory.

On the z/OS platform, the user with ID userid has a default home directory ("user.home") of /home/userid. For example, the user ID "U23LPTQ " would, by default, have a home directory of /home/U23LPTQ.

IBMJCECCA Runtime Exception Handler

In the event of an ICSF error, an application can retrieve error data from the ICSF API call using the runtime exception class.

The JCECCARuntimeException class:

The IBMJCECCA provider might throw an instance of this class (which extends RuntimeException) during operations with ICSF. The class includes methods to retrieve the following data from the ICSF API call:
  • The name of the ICSF API call which threw the exception
  • The exception message generated by the IBMJCECCA provider
  • The ICSF API call return code, in decimal
  • The ICSF API call reason code, in decimal
For example, an application can catch this exception and display ICSF API call data as:
catch (Exception e) {
    if (e instanceof JCECCARuntimeException) {
             JCECCARuntimeException jcre = (JCECCARuntimeException)e;
                System.err.println("API name: " + jcre.getAPIName());
                System.err.println("Message: " + jcre.getExceptionMessage());
                System.err.println("RC: " + jcre.getReturnCode());
                System.err.println("RS: " + jcre.getReasonCode());
    }
    e.printStackTrace();
                        

Configuring and using hardware cryptographic devices on z/OS

To use a hardware cryptographic device, the appropriate card must be installed and configured according to the specifications that are provided with the card. On some platforms it is also necessary for the user or application to set up the cryptographic environment and provide access control (log into the card).

z/OS specifics

On the z/OS platform, access to hardware cryptographic devices is controlled by the Integrated Cryptographic Service Facility (ICSF).  The ICSF product provides IBM Common Cryptographic Architecture (CCA) interfaces to hardware devices. ICSF must be configured and running before the hardware cryptographic device is accessed.  For more information about ICSF see the ICSF publications, including the following:
  • Integrated Cryptographic Service Facility Overview - SC23-3977
  • ICSF System Programmers Guide - SC23-3974
  • ICSF Administrator's Guide - SC23-3975
  • The hardware keytool application (hwkeytool)

    With few exceptions, the hardware keytool application (hwkeytool) uses the same syntax and commands as the software version provided with JCA (keytool). The differences between hwkeytool and keytool are as follows:
    • hwkeytool provides additional parameters to the genkeypair, genseckey, and delete commands. 
    • The default keystore is .HWkeystore, although the JCE default (.keystore) can be specified using the -keystore parameter.

    The additional parameters for genkeypair are:

    • -keylabel
      [-keylabel <keylabel>]

      If -hardwaretype PKDS is specified, this optional parameter is used to specify the label that will identify the hardware key within the hardware storage. If -hardwaretype PKDS is specified and this parameter is not specified, a random label is generated.
    • -hardwaretype
      [-hardwaretype <hardwaretype>]

      This optional parameter is used to set the type of key pair generated (CLEAR, PKDS). If this parameter is not specified when generating a DSA key pair, the generated key pair is type PKDS. If this parameter is not specified when generating an RSA key pair, the generated key pair is type CLEAR.
    • -hardwareusage
      [-hardwareusage <hardwareusage>]

      This optional parameter is used to set the usage (SIGNATURE, KEYMANAGEMENT) for a generated key pair. If this parameter is not specified, when generating a DSA key pair, the generated key pair has usage SIGNATURE. If this parameter is not specified when generating an RSA key pair, the generated key pair has usage KEYMANAGEMENT.
    • -existinglabel
      [-existinglabel <existinglabel>]

      This optional parameter is used to specify the PKDS label for an existing PKDS key entry. When using this parameter, the genkeypair request will create a key object for this PKDS key entry. The -file parameter must be specified to include the certificate file associated with the PKDS key entry. The parameters -hardwaretype, -hardwareusage, -keysize, -dname, -sigalg, -keylabel and -validity are not required and must not be specified.
    • -file
      [-file <cert_file>]

      This optional parameter is used to specify the certificate file associated with a PKDS key entry. This parameter must be specified when -existinglabel is specified.

    The additional parameters for genseckey are:

    • -hardwaretype
      [-hardwaretype <hardwaretype>]

      This optional parameter is used to set the type of secret key generated (CLEAR, PROTECTED, or CKDS). If this parameter is not specified, the generated key is type CLEAR.
    • -keylabel
      [-keylabel <keylabel>]

      If -hardwaretype CKDS is specified, this optional parameter is used to specify the label that will identify the hardware key within the hardware storage. If -hardwaretype CKDS is specified and the -keylabel parameter is specified, the request is for a new key to be generated and stored in the CKDS using the specified keylabel. If -hardwaretype CKDS is specified and neither this parameter nor the -existinglabel parameter is specified, the request is for a new key to be generated and a random CKDS label generated.
    • -existinglabel
      [-existinglabel <existingkeylabel>]

      If -hardwaretype CKDS is specified, this optional parameter is used to specify the label that identifies the hardware key within the hardware storage. If -hardwaretype CKDS is specified and the -existinglabel parameter is specified, the request is for a key object representing a key already stored in the CKDS with the specified keylabel.

    The additional parameter for delete is:

    • -hardwarekey
      [-hardwarekey]

      This optional parameter is used to specify that the key pair be deleted from both the keystore and the hardware. If this parameter is not specified, the key is only deleted from the keystore.

    The concept of -hardwareusage is introduced with the hwkeytool.  By using this parameter when creating a key pair, you can specify the authority that key pair will have in the CCA provider.  The hwkeytool interfaces support the hardwareusage values SIGNATURE and KEYMANAGEMENT.  A key pair created with hardwareusage SIGNATURE is valid for signatures (sign and verify) only.  A keypair created with hardwareusage KEYMANAGEMENT is valid for signatures and for key management functions.  The Java Cryptography Architecture also defines hardwareusage type CCA, for keys used for key management only, but this is not supported by hwkeytool because it is not useful to applications.  Key pairs with hardwareusage SIGNATURE and KEYMANAGEMENT behave similarly in JCE because both can be used for signatures.  Key pairs with hardwareusage KEYMANAGEMENT are needed for other components of Java, including the Java Secure Sockets Layer (JSSE). 

    The concept of -keylabel is introduced with the hwkeytool.  By using this parameter when creating a secret key or keypair, you can specify the label that will be used to identify the hardware key within the hardware storage.  That is, -keylabel can be specified when creating a key or key pair to set a specific label that the CCA software will use to identify the key or key pair for storage and retrieval.  This label is not used by normal JCE applications, but is made available for the advanced user who needs to control the label used by underlying CCA software to identify the key or key pair.  In other words, a normal JCE application will identify the keypair by name (alias); this label is only used by the CCA software to identify CKDS and PKDS key entries. By default, the JCE methods generate a random label to identify the key entry. 

    The concept of -existinglabel is introduced with the hwkeytool.  By using this parameter when creating a key or key pair object, you indicate that the key or key pair is already stored within the hardware storage with the label you specify as the -existinglabel value.  That is, -existinglabel can be used when creating a secret key or key pair object to specify the label that must be used to identify the secret key or key pair for retrieval.  This label is not used by normal JCE applications, but is made available for the advanced user who needs to use keys stored in the underlying CCA software to identify the key or key pair.  In other words, a normal JCE application will identify the keypair by name (alias); this label is only used by the CCA software to identify CKDS keys and PKDS key pairs.  

    The following illustrates creating and storing an RSA key pair with the name Test1 with PKDS hardware:  

    hwkeytool -genkeypair -alias Test1 -keyalg RSA -storetype JCECCAKS -dname "cn=Test one, ou=JCA, o=IBM, l=Endicott, st=NY" -keypass test123 -storepass 123test -hardwaretype PKDS  -hardwareusage SIGNATURE


    The following illustrates deleting that key entry from the keystore and also deleting the keys from hardware storage:  

    hwkeytool -delete -alias Test1 -keypass test123 -storepass 123test -hardwarekey

    Software to Hardware Key Migration Aids

    At times it might be desirable to migrate a software key into a JCECCAKS hardware keystore. To aid in this process, the class com.ibm.crypto.hdwrCCA.provider.WrapperKey has been created. An instance of this class is a wrapper that contains a software key and the hardware attributes to associate with the key when it is imported into the hardware keystore.

    The following code snippet illustrates wrapping a software key "SoftwareKey" and inserting it into keystore "okeyStore":

    
         byte storeType = KeyHWAttributeValues.RETAIN;
         byte keyUsage = KeyHWAttributeValues.KEYMANAGEMENT;
         keyAttribs = new RSAKeyHWAttributes(storeType,keyUsage);
         WrapperKey wrappedKey =
              new WrapperKey((java.security.PrivateKey)SoftwareKey,keyAttribs);
    
         okeyStore.setKeyEntry(alias, wrappedKey, istorePass, certs);
        

    Appendix G: SAF (RACF) Digital Certificate Support for z/OS Specifics

    Introduction

    The digital certificate support in the System Authorization Facility (SAF) and implementations in external security managers such as RACF provide applications with an alternative to storing certificates and/or keys in datasets or files. Previously, Java security providers on z/OS were unable to take advantage of the digital certificate support in SAF because there was no Java keystore that supported SAF. The JCECCARACFKS and JCERACFKS keystores now available in the SDK provides SAF digital certificate support, enabling the IBMJCE and IBMJCECCA providers to store and retrieve keys and certificates from SAF.

    See Key Management for more information on keystores.

    Digital certificate support is implemented as two Keystore types, JCERACFKS and JCECCARACFKS. An InputStream class called RACFInputStream, an OutputStream class called RACFOutputStream, and a URLStreamHandler class are also implemented. The URLStreamHandler class enables a RACFInputStream or RACFOutputStream to be accessed using a URL. URLStreamHandlers are also available for both the IBMJCE keytool program and the IBMJCECCA keytool program (hwkeytool) for z/OS. See the keytool users guide for more information on keytool.

    The RACF keystore classes, JCERACFKS for the IBMJCE provider and JCECCARACFKS for the IBMJCECCA provider, are only available on the z/OS platform where SAF is available.

    A keystore class, JceRACFKeyStore, is implemented in both the IBMJCE and IBMJCECCA providers. This class is available for storing and retrieving certificates and keys from a RACF key ring. The RACFInputStream and RACFOutputStream are only intended to be used with the JceRACFKeyStore. Use of the RACFInputStream or RACFOutputStream with other Key Stores may cause unexpected results.

    All of the JAVA RACF services, including the JceRACFKeyStore, RACFInputStream and RACFOutputStream, make use of the R_datalib (IRRSDL00) service to retrieve and store certificates from RACF. In order to use this service certain authorizations must be granted to the user, depending on the desired setup. Be sure to have the correct authorizations set for R_datalib before using any Java RACF classes. For more information on how to set the necessary authorizations see the following publication:

    z/OS Security Server RACF Callable Services - SA22-7691

    There are two ways to access keys and certificates stored in an SAF external security manager implementation using the RACFInputStream and RACFOutputStream. The first is using the RACFInputStream or RACFOutputStream directly by passing a newly created instance of it to the JceRACFKeyStore. The second is indirect, using URLStreamHandler to call RACFInputStream or RACFOutputStream and then passing the instance into JceRACFKeyStore. These are described in more detail below.

    The JCECCARACFKS and JCERACFKS keystores are able to store and retrieve certificates from a keyring honoring mixed case label and alias names. Users are encouraged to make use of alias or label names that contain at least one different character in their name than the rest of the alias or label names that are attached to the keyring. It is highly encouraged that users do not make use of same character alias or label names that differ only by case. A search mismatch can occur when storing or retrieving information from a JCECCARACFKS and JCERACFKS keystore when using same character label or alias names differing only by case.

    Setting up a RACF keyring from RACF

    When setting up a keyring, any certificate connected as a "PERSONAL" certificate is considered a KeyEntry and therefore can be used as an end user certificate (for example, in a SSL handshake) since the private key is available. Any certificate connected as "CERTAUTH" is considered a TrustedCertEntry and can be used, for example, as a Certificate Authority (CA) certificate in the authentication process of SSL. Any keyring that has a certificate that is not self signed and is connected as "PERSONAL" must also have the CA certificate of the "PERSONAL" certificate connected as "CERTAUTH". In the case of a self signed certificate, a "CERTAUTH" certificate is not required to be present. Certificates connected as "SITE" are not supported at this time. Below is an example setup of a RACF keyring that can be used by a JSSE client and server for both trust and key information.

                Certificate Label Name Cert Owner USAGE    DEFAULT
                ---------------------- ---------- -------- -------
                PersonalEndUserCert    ID(USERID) PERSONAL YES
                PersonalEndUserCACert  CERTAUTH   CERTAUTH NO
                

    Using a RACFInputStream to load a RACF key ring into a Java RACF KeyStore

    Creating a RACFInputStream requires these three parameters:
  • userID - a string containing the ID of the user that owns the keyring
  • ringid - a string containing the name of the RACF key ring
  • password - a character array containing the password for the keystore
  • The following is an example of using RACFInputSteam directly, passing it a user ID, a ring ID and a null password. import com.ibm.crypto.provider.RACFInputStream; String ksfname; char[] storePass = null; RACFInputStream riStream = new RACFInputStream(System.getProperty("user.name"), ksfname, storePass); KeyStore racfKeyStore = KeyStore.getInstance("JCERACFKS"); racfKeyStore.load(riStream, storePass); riStream.close();

    In the above example, the system property "user.name" is used to obtain the userid that will be passed to RACF. In an actual application, this will probably not be done.

    Using a RACFOutputStream to store a Java RACF KeyStore into a RACF key ring

    Creating a RACFOutputStream requires these three parameters:
  • userID - a string containing the ID of the user that owns the keyring
  • ringid - a string containing the name of the RACF key ring
  • password - a character array containing the password for the keystore
  • The following is an example of using RACFOutputStream directly, passing it a user ID, a ring ID and a null password. import com.ibm.crypto.provider.RACFOutputStream; String ksfname; char[] storePass = null; RACFOutputStream roStream = new RACFOutputStream(System.getProperty("user.name"), ksfname, storePass); KeyStore racfKeyStore = KeyStore.getInstance("JCERACFKS"); racfKeyStore.store(roStream, storePass); roStream.close();

    In the above example, the system property "user.name" is used to obtain the userid that will be passed to RACF. In an actual application, this will probably not be done.

    Storing keys into RACF using the RACFKeyStore

    The RACF KeyStore can be used to update an existing RACF key ring or create a new RACF key ring. If the RACF key ring specified by the userid and ring name to the RACFOutputStream does not exist, the Key Ring will be created. If the RACF Key Ring already exists, then it will be updated. In either case, all certificates and keys in the KeyStore will be added to the RACF key ring when the store method is invoked. When updating an existing RACF key ring, any existing RACF certificates and keys that are deleted, will be removed from the RACF key ring when the store method is invoked.

    Entries deleted from the RACF KeyStore will be removed from the RACF key ring, but the RACF certificate profile will not be deleted from RACF. If a certificate is added that already exists in RACF, but with a different label/alias, the certificate will be added to the RACF Key Ring with the existing label, and an IOException will be returned to indicate the certificate already exists with a different label/alias.

    If an error is detected while updating a RACF Key Ring, all additional adds or deletes of entries are processed, but only the first error will be reported as an exception.
    The following scenario demonstrates this property:

    1. A RACFInputStream is created to specify an existing input RACF Key Ring.
    2. The RACFInputStream is loaded into a RACFKeyStore using the RACFKeyStore.load() method.
    3. The input ring contains 1 key entry named Key01 and 1 trusted certificate entry named Cert01.
    4. Key01 is deleted using the RACFKeyStore.delete() method.
    5. Two new key entries named Key02 and Key03 are added to the RACFKeyStore using the RACFKeyStore.setKeyEntry() method.
    6. A RACFOutputStream is created to specify an output RACF Key Ring.
    7. The updates are written to the RACF Key Ring specified in the RACFOutputStream using the RACFKeyStore.Store() method.
      1. First, the delete entry is processed by successfully removing Key01 from the output RACF Key Ring.
      2. Next, all entries from the RACFKeyStore are added to the output RACF Key Ring.
      3. In this example, an error occurs while attempting to add Key02 to the output RACF Key Ring.
      4. Cert01 is added successfully to the output RACF Key Ring.
      5. An error occurs while attempting to add Key03 to the output RACF Key Ring.
    8. An exception is thrown with the details of the error that occured while attempting to add Key02.

    Accessing a RACFInputStream and RACFOutputStream using URLStreamHandler

    In SDK 1.2 and above, the URLStreamHandler class enables access to data using user defined classes. The system property java.protocol.handler.pkgs allows the application to define the classes that access the data. The URL "safkeyring " and associated classes access data stored in an SAF (RACF) keyring.

    The following java property must be defined to enable the URLStreamHandler class to create a RACFInputStream:

    java.protocol.handler.pkgs

    If the IBMJCE provider is being used to provide cryptographic support, the property must be set to the value com.ibm.crypto.provider. The following example illustrates setting this property on the java command line when running the Java class "myApplication":

    java -Djava.protocol.handler.pkgs=com.ibm.crypto.provider myApplication

    If the IBMJCECCA provider is being used to provide cryptographic support, the property must be set to the value com.ibm.crypto.hdwrCCA.provider. The following example illustrates setting this property programatically in a Java application:

    System.setProperty( "java.protocol.handler.pkgs", "com.ibm.crypto.hdwrCCA.provider" );

    Supported key types for storing into a RACF KeyStore

    The JCERACFKS RACF Key Store supports the following Java key types:

    • RSAPrivateKey - Software format
    • RSAPrivateCrtKey - Software CRT format
    The JCECCARACFKS RACF Key Store supports the following Java key types:
    • RSAPrivateKey - Software key format
      This key type is converted to RSAPrivateHWKey format
    • RSAPrivateCrtKey - Software CRT format
      This key type is converted to an RSAPrivateHWKey format
    • RSAPrivateHWKey - CLEAR Format with External ICSF Token
    • RSAPrivateHWKey - PKDS Format
    All other key formats are not supported.

    Passwords and the RACF KeyStore

    In file based KeyStores the password parameter is used for three primary reasons:

    • Protect the integrity of the KeyStore file
    • Protect keys in Java memory while being used in a KeyStore
    • Protect keys when at rest in the file based KeyStore
    The password parameter is used differently by the RACF KeyStore. Since keys in the RACF KeyStore are stored in the RACF Data Base rather than in a file, the password is only used to protect keys while the KeyStore is in Java memory. Digital Certificates and Keys in RACF Key Rings are protected by RACF profiles.

    All the following RACF KeyStore methods use the password parameter:

    RACFInputStream.RACFInputStream() JceRACFKeyStore.load() JceRACFKeyStore.setKeyEntry() JceRACFKeyStore.getKeyEntry() JceRACFKeyStore.store() RACFOutputStream.RACFOutputStream() The RACFInputStream.RACFInputStream() method uses the input password to protect keys loaded from RACF in Java memory.

    The JceRACFKeyStore.load() method uses the input password to validate that the input RACFInputStream is constructed with the same password.

    The JceRACFKeyStore.setKeyEntry() method uses the input password to protect the input key.

    The JceRACFKeyStore.getKeyEntry() method uses the input password to recover the protected key.

    The JceRACFKeyStore.store() method uses the input password to validate that the input RACFOutputStream is constructed with the same password.

    The RACFInputStream.RACFOutputStream() method uses the input password to recover any protected keys from Java memory before storing them to a RACF Key Ring.

    In addition to KeyStore passwords, Java APIs enable an application to specify a password to protect an individual KeyStore entry. Within an instance of using the JceRACFKeyStore, RACFInputStream and RACFOutputStream to retrieve and set keys, the same password must be used. It is recommended that all passwords are left to default.

    The password parameter defaults to "password" on all methods by passing in null.

    hwkeytool and the ICSF CSFSERV and CSFKEYS RACF classes

    If the user of hwkeytool is not authorized to create new profiles in the ICSF CSFKEYS RACF class, hwkeytool may create a key that the user is not able to access. To prevent this from happening, the user of hwkeytool should verify that they are authorized to the profiles in the ICSF CSFSERV RACF class including CSFPKG. A number of these ICSF services are used by hwkeytool. In addition, the user of hwkeytool should verify that they have authority to create new profiles in the ICSF CSFKEYS RACF class.

    Developers and users of programs that invoke the Java security class KeyPairGenerator to generate an IBMJCECCA public and private key pair should also be aware of above item relating to the ICSF CSFKEYS and CSFSERV RACF classes.

    Updates to a JCECCARACFKS KeyStore

    A KeyStore is a Java object containing a collection of keys and certificates that are referenced by unique labels or alias names. For most Java keystores, the persistent data is stored in a file. However, the persistent data for a JCECCARACFKS keystore is stored in the RACF database and connected to a RACF keyring. Due to the nature of the RACF database and keyrings, the behavior of a JCECCARACFKS keystore during update operations differs from the behavior of file based keystores.

    In the following discussion, "application" can refer to a user KeyStore application or can refer to the hwkeytool utility program.

    KeyStore load and update operations

    In order to access the contents of a keystore, an application uses the load() method to retrieve the persistent data from the keystore and create a KeyStore object. This object can be queried and updated by the application. KeyStore update methods include deleteEntry(), setEntry(), setCertificateEntry(), and setKeyEntry(). hwkeytool update commands supported for RACF keystores include -delete, -genkeypair, -importcert, and -importkeystore.

    If the application intends to modify the persistent data for the keystore, it uses the store() method. The behavior of the store() method depends on the underlying storage of the persistent data.

    File based keystores and the KeyStore store() method

    The update model for file based keystores is a replace model. When the application uses the store() method for a file based keystore, the contents of the KeyStore object in the application memory replace the current persistent data for the keystore. In other words, any KeyStore update that has been successful will be reflected in the new version of the persistent data for the keystore.

    One consequence of the replace model occurs if two applications are updating the same keystore at the same time. To illustrate, suppose application app1 and application app2 are modifying some keystore and

    1. app1 loads the keystore into a KeyStore object and makes some updates
    2. app2 loads the keystore into a KeyStore object and makes some updates
    3. app1 stores the contents of the KeyStore object into the persistent keystore data
    4. app2 stores the contents of the KeyStore object into the persistent keystore data
    In this case, because the app1 changes were not stored in persistent data before app2 loaded the keystore, and because app2 replaced the persistent data after app1, updates made by app1 are overwritten by app2.

    RACF keystores and the KeyStore store() method

    The update model for a JCECCARACFKS keystore is an update model. It was implemented in this way to avoid the effect described above. If a change is made to an existing KeyStore entry, the existing version of the entry is disconnected from the keyring, the data for the new entry is added to the RACF database, and then the new entry is connected to the keyring. Even if the update is a delete operation, whether deleteEntry() or hwkeytool -delete, the data is not removed from the RACF database, it is only disconnected from the keyring represented by the KeyStore. To delete data from the RACF database, you must use the RACF utility RACDCERT.

    Some RACF database and keyring updates that are not permitted are:

    • An entry with an expired certificate cannot be updated.
    • An entry cannot be updated with an expired certificate.
    • A certificate entry cannot be replaced with a key entry.
    • A key entry cannot be replaced with a certificate entry.
    • An entry cannot be updated unless the public key in the new version matches the public key in the existing version.
    • Although a single certificate can be connected to many keyrings, there can be only one copy of it in the RACF database and it will be stored with only one label.

    When the IBMJCECCA security provider can detect an update that will not be allowed by RACF, an exception is thrown when the KeyStore entry update is attempted. In some cases, the IBMJCECCA security provider can not predict that a RACF database update will be unsuccessful. One consequence of this is that a KeyStore update may be successful but an error or warning is reported during the store() operation.

    Some possible effects of this behavior are:

    • The previous version of the entry is disconnected from the keyring and the new version is not connected to the keyring.
    • A certificate may be connected to the keyring using a label other than the one specified in the KeyStore update.
    If there are unintended and undesired changes to a keystore, it might be necessary to reconnect or to update keyring entries using the RACF utility RACDCERT.

    Additional Information:

    For more information on inserting or updating information in the RACF External Security Manager refer to the RACDCERT command. Publications available for RACF include:

    • z/OS Security Server RACF Security Administrator's Guide - SA22-7683
    • z/OS Security Server RACF Command Language Reference - SA22-7687
    • z/OS Security Server RACF Callable Services - SA22-7691

    Notices

    This information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service.

    IBM may have patents or pending patent applications covering subject matter in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to:

    For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property Department in your country or send inquiries, in writing, to:

    The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law:

    INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you.

    This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the information. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this information at any time without notice.

    Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk.

    IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you.

    Licensees of this program who wish to have information about it for the purpose of enabling (i) the exchange of information between independently created programs and other programs (including this one) and (ii) the mutual use of the information which has been exchanged, should contact:

    Such information may be available, subject to appropriate terms and conditions, including in some cases, payment of a fee.

    The licensed program described in this document and all licensed material available for it are provided by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement or any equivalent agreement between us.

    Any performance data contained herein was determined in a controlled environment. Therefore, the results obtained in other operating environments may vary significantly. Some measurements may have been made on development-level systems and there is no guarantee that these measurements will be the same on generally available systems. Furthermore, some measurement may have been estimated through extrapolation. Actual results may vary. Users of this document should verify the applicable data for their specific environment.

    Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products.



    Trademarks

    IBM is a trademark or registered trademark of International Business Machines Corporation in the United States, or other countries, or both.

    Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

    Other company, product, or service names may be trademarks or service marks of others.