Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.4 for Eclipse on Windows
E37550-04
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

11 Security and MIDlet Signing

This chapter describes how to work with sign MIDlets and work with MIDlet suite security. The Oracle Java ME SDK provides tools to sign MIDlet suites, manage keys, and manage root certificates.

MIDP 2.1 (JSR 118) includes a comprehensive security model based on protection domains. MIDlet suites are installed into a protection domain that determines access to protected functions. The MIDP 2.1 specification also includes a recommended practice for using public key cryptography to verify and authenticate MIDlet suites.

The general process to create a cryptographically signed MIDlet suite is as follows:

  1. The MIDlet author, probably a software company, buys a signing key pair from a certificate authority (the CA).

  2. The author signs the MIDlet suite with the signing key pair and distributes their certificate with the MIDlet suite.

  3. When the MIDlet suite is installed on the emulator or on a device, the implementation verifies the author's certificate using its own copy of the CA's root certificate. Then it uses the author's certificate to verify the signature on the MIDlet suite.

  4. After verification, the device or emulator installs the MIDlet suite into the security domain that is associated with the CA's root certificate.

For definitive information, consult the MIDP 2.1 specification:

http://download.oracle.com/otndocs/jcp/midp-2.1-mrel-oth-JSpec

See the following topics:

11.1 Security Domains

The SDK supports the following security domains:

minimum. All permissions are denied to MIDlets in this domain.

maximum. All permissions are granted to MIDlets in this domain. Maximum is the default setting.

unidentified_third_party. Provides a high level of security for applications whose origins and authenticity cannot be determined. The user is prompted frequently when the application attempts a sensitive operation.

identified_third_party. Intended for MIDlets whose origins were determined using cryptographic certificates. Permissions are not granted automatically, but the user is prompted less often than for the unidentified_third_party domain.

operator. All permissions are denied to MIDlets in this domain.

manufacturer. Intended for MIDlet suites whose credentials originate from the manufacturer's root certificate.

11.2 Setting Security Domains

In the SDK, when you use Run Project via OTA your packaged MIDlet suite is installed directly into the emulator where it is placed in a security domain. The emulator uses public key cryptography to determine the appropriate security domain.

11.2.1 Specify the Security Domain for an Emulator

Follow these steps to specify the security domain for an emulated device.

  1. Select the device in the device selector.

  2. In the Properties Window, expand the General properties, and for the Security Domain option, select a domain from the dropdown list.

11.2.2 Specify the Security Domain for a Project

Follow these steps to set a MIDlet Suite's security domain at runtime.

  1. Right-click the package and select Run As > Run Configurations... from the context menu.

  2. Select the project's JAD file, then select the Emulation tab.

  3. Specify the device and the security domain, and click Run.

You can also sign your MIDlet or IMlet with JADtool ("Sign MIDlet Suites (jadtool).".

11.3 Signing a Project With a Key Pair

Devices use signing information to check an application's source and validity before allowing it to access protected APIs. For test purposes, you can create a signing key pair to sign an application. A key pair consists of the following:

You can create a key pair as described in "Managing Keystores and Key Pairs."

Follow these steps to sign a Java ME package in Eclipse.

  1. In the Package view right-click on a package and select Properties to open the Properties dialog.

  2. In the Java ME category, select Signing. For help with this page, view the following help topic: Java ME Development User Guide > Reference > Property Pages > Java ME.

  3. Click Enable project specific settings. Specify a keystore and a password option.

  4. Click OK.

To obfuscate code, see "Obfuscating."

11.4 Managing Keystores and Key Pairs

The Oracle Java ME SDK command line tools described in "Manage Certificates (MEKeyTool)" manage an emulator's list of root certificates.

Oracle Java ME SDK ships a default keystore named _main.ks in installdir\runtimes\cldc-hi\appdb. This keystore is automatically copied from your installation's default location to each instance of the default devices (the emulators). These instances are typically stored in:

username\javame-sdk\3.4\work\devicename

External devices have similar lists of root certificates, although you typically cannot modify them. When you deploy your application on an external device, you must use signing keys issued by a certificate authority whose root certificate is present on the device. This makes it possible for the device to verify your application.

In Eclipse you can also use MTJ utilities to manage keystores as described in "Signing a Project With a Key Pair." You can also use the -import option to import certificates from these keystores as described in "Manage Certificates (MEKeyTool)."

11.5 Command Line Samples

This section is a summary of command line samples for keystore and certificate tasks. To find information on keytool, see:

http://docs.oracle.com/javase/7/docs/technotes/tools

These samples show literal paths on a sample system. You can replace the paths and options as you see fit. These samples contain line feeds to accommodate the book format. In practice they commands should be entered on a single line.

Generate a keypair.

As mentioned in "Managing Keystores and Key Pairs," Java ME includes a default keystore used for the emulators. For test purposes you can also make your own keypair containing a new keystore and a certificate. For example:

"C:\Program Files\Java\jdk1.6.0_35\bin\keytool" -genkeypair -alias mykp 
-keyalg RSA -keysize 1024 -validity 365 -dname "cn=dlp, L=Santa Clara, S=CA"
-keypass 123456 -keystore D:/temp/mykeystore.ks -storepass 654321

List the keypair.

C:\Program Files\Java\jdk1.7.0_13\bin\keytool -list -alias mykp 
-keystore mykeystore.ks -storepass 654321

Export a certificate to a file.

C:\Program Files\Java\jdk1.7.0_13\bin\keytool -exportcert -alias mykp 
-keystore mykeystore.ks -storepass 654321 -file d:\temp\mykpcert

Print the certificate file.

C:\Program Files\Java\jdk1.7.0_13\bin\keytool -printcert -file d:\temp\mykpcert

Import the keystore (including your certificate) into the default keystore.

For a description of MEKeyTool, see "Manage Certificates (MEKeyTool)." In this example mekeytool is launched from the Oracle Java ME SDK installation bin directory.

mekeytool -import -alias mykp -keystore D:\temp\mykeystore.ks -MEkeystore D:\temp\_main.ks -storepass 654321