|
A policy file can be defined to require a signature on all applets or applications that attempt to run with the policy file. The signature is a way to verify that the applet or applicationis from a reliable source and can be trusted to run with the permissions granted in the policy file. If a policy file requires a signature, an applet or application can get the access granted by the policy file only if it has the correct signature. If the applet or application has the wrong signature or no signature, it will not get access to the file. This section walks through an example of signing an applet, verifying the signature, and running the applet with a policy file.
Signed Applet Example
The policy file granting access can be set up to require or not
require a signature. If a signature is required, the applet has to be
bundled into a Java ARchive (JAR) file before it can be signed.
This example shows you how to sign and grant permission to an applet
so it can create
These files are used for the example. You can copy them to or create them in your working directory.
Usually an applet is bundled and signed by an intranet developer and handed off to the end user who verifies the signature and runs the applet. In this example, the intranet developer performs Steps 1 through 5 and Ray, the end user, performs Steps 6 through 8. But, to keep things simple, all steps occur in the same working directory.
Intranet Developer Susan, the intranet developer, bundles the applet executable in a JAR file, signs the JAR file, and exports the public key certificate. 1: Compile the Applet
In her working directory, Susan uses the
2: Make a JAR File
Susan then stores the compiled
3: Generate Keys A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.
Susan creates a In her working directory, Susan creates a keystore database and generates the keys: keytool -genkey -alias signFiles -keystore compstore -keypass kpi135 -dname "cn=jones" -storepass ab987c
This
The generated key pair is stored in a keystore database called compstore
(
The You can view all keytool options and parameters by typing:
4: Sign the JAR File
JAR Signer is a command line tool for signing and verifying the
signature on JAR files. In her working directory, Susan uses
jarsigner to make a signed copy of the
jarsigner -keystore compstore -storepass ab987c
-keypass kpi135
-signedjar
SSignedApplet.jar SignedApplet.jar signFiles
The 5: Export the Public Key Certificate
The public key certificate is sent with the JAR file to the end user
who will be using the applet. That person uses the certificate to
authenticate the signature on the JAR file. A certificate is sent
by exporting it from the
In her working directory, Susan uses keytool to copy the certificate from
keytool -export -keystore compstore -storepass ab987c -alias signFiles -file CompanyCer.cer As the last step, Susan posts the JAR and certificate files to a distribution directory on a web page. End User Ray, the end user, downloads the JAR file from the distribution directory, imports the certificate, creates a policy file granting the applet access, and runs the applet. 6: Import Certificate as a Trusted Certificate
Ray downloads
keytool -import -alias company -file
CompanyCer.cer -keystore
raystore -storepass abcdefgh
7: Create the Policy File
The policy file grants the
Ray creates the policy file in his home directory using either
8: Run the Applet in Applet Viewer
Applet Viewer connects to the HTML documents and resources specified in
the call to appletviewer -J-Djava.security.policy=Write.jp http://aURL.com/SignedApplet.html
Note:
Type everything on one line and put a space after
The -J-Djava.security.policy=Write.jp option tells Applet Viewer to run
the applet referenced in the SignedApplet.html file
with the Write.jp policy file.
Note:
The Policy file can be stored on a server
and specified in the
Running an Application with a Policy File
This application invocation restricts
java -Djava.security.manager
-Djava.security.policy=polfile MyProgram
Signed Applets in JDK 1.1 JDK 1.1 signed applets can access local system resources if the local system is properly set up to allow it. See the JDK 1.1 Signed Applet Example page for details. [TOP] | |||||||
|
| ||||||||||||