Friday, May 22, 2009

Create/Deploy/Test a Signed Applet

1. Package the applet into a JAR file:
The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in <applet> tag, replace the codebase attribute with the archive attribute. The value of the archive attribute is a URL of a JAR file.

   $ jar -cvf SignedApplet.jar *.class
2. Create a public/private key pair. The command for this is

$ keytool -genkey -alias signFiles
-keystore compstore
-keypass kpi135 -dname "cn=jones"
-storepass ab987c

Verify your keystore:

$ keytool -list -keystore compstore
-storepass ab987c

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

signfiles, May 21, 2009, keyEntry,
Certificate fingerprint (MD5): 20:3D:6D:A0:20:71:2D:85:7D:72:6C:23:B5:2F:16:D7
$
keytool is another SDK utility. It will prompt you for a password to your keystore and for the remaining parameters, one of which is alias, whose value is the name of the key. The keystore is a file that contains your public/private key-pairs, and the public-keys of others with whom you exchange information. See the documentation in the above link.

3. Create a certificate for the key you created in the previous step.
$ jarsigner -keystore compstore
-storepass ab987c
-keypass kpi135
-signedjar SSignedApplet.jar SignedApplet.jar signFiles
Again, keytool will prompt you for a keystore password and remaining parameters. This certificate is now self-signed by you, meaning that it has not been validated by any third party. This is suitable for demo purposes, and may be acceptable to yourself and those who know you because if there is any doubt that the certificate is really yours they can always call you up and ask you for the digest to verify that it is really you and not some impostor that created the certificate. However, if this applet were to be widely distributed, and you wanted it to be accepted by those who do not know you personally, you would certainly want to pay a modest fee to obtain a certificate that is validated by a trusted certificate authority. The procedure for this is straightforward, but beyond the scope of this simple tutorial.

4. Run jarsigner associate this certificate with the JAR file that contains your applet.
You will need to give the name of the public key of the certificate you just created. This creates a digest for each file in your JAR and signs them with your private key. These digests or hashes, the public key, and the certificate will all be included in the "WEB-INF" directory of the JAR.

Verify your signed applet jar file:

$ jar -tvf SignedApplet.jar
25 Thu May 21 14:56:42 MST 2009 META-INF/MANIFEST.MF
141 Thu Sep 25 02:11:08 MST 2008 java.policy.applet
776 Thu May 21 14:09:50 MST 2009 appletexample/Welcome.class
2005 Thu May 21 14:49:22 MST 2009 appletexample/SignedAppletDemo.class

$ jar -tvf SSignedApplet.jar
265 Thu May 21 15:00:56 MST 2009 META-INF/MANIFEST.MF
432 Thu May 21 15:00:56 MST 2009 META-INF/SIGNFILE.SF
762 Thu May 21 15:00:56 MST 2009 META-INF/SIGNFILE.DSA
141 Thu Sep 25 02:11:08 MST 2008 java.policy.applet
776 Thu May 21 14:09:50 MST 2009 appletexample/Welcome.class
2005 Thu May 21 14:49:22 MST 2009 appletexample/SignedAppletDemo.class

5. Update your html files to use the signed applet jar file:
Welcome.html: within your applet tag
code="appletexample/Welcome.class"
archive="SSignedApplet.jar"
width="500" height="400"
SignedApplet.html: within your applet tag
code="appletexample/SignedAppletDemo.class"
archive="SSignedApplet.jar"
param="" name="file" value="/"
width="400" height="400"
6. Deploy the html and jar files to Apache HTTP server:
Copy Welcome.html, SignedApplet.html, and SSignedApplet.jar (not the SignedApplet.jar) to Apache's htdocs/applet directory (I create a folder called "applet" under htdocs folder).

C:\Apache\Apache2.2\htdocs\applet>dir
Volume in drive C has no label.
Volume Serial Number is 588C-3312

Directory of C:\Apache\Apache2.2\htdocs\applet

05/22/2009 10:24 AM <DIR> .
05/22/2009 10:24 AM <DIR> ..
05/22/2009 10:21 AM 247 SignedApplet.html
05/21/2009 03:00 PM 3,794 SSignedApplet.jar
05/22/2009 10:24 AM 173 Welcome.html
3 File(s) 4,214 bytes
2 Dir(s) 25,086,658,560 bytes free

C:\Apache\Apache2.2\htdocs\applet>

7. Test your Signed Applet from localhost:
Your applet is now signed. The next time you or someone else downloads it in it's page the browser will present a dialog box displaying the credentials you just created for it and asking the user permission to run it. If he/she chooses not to, the applet will throw the same AccessControlException that we saw in the Java Console window the first time we tried to run it in our browser. The difference is that now the user gets to make an informed decision as to whether or not they trust your applet to not harm his/her system.



References/Links:
1. <a href="http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html">Signed Applet Tutorial by Larry Siden</a>
2. <a href="http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html">Tutorials: Chapter 10: Signed Applets from Sun Developer Network</a>

Wednesday, May 20, 2009

Tomcat 6 CGI HTTP status 404 error?

Problem:
HTTP status 404 error?

Solution:
Need to keep the *.cgi files in Tomcat6.0\webapps\ROOT\WEB-INF\cgi folder.

Tomcat 6 CGI java.lang.SecurityException?

Problem:
Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be
loaded by this web application

Solution:
In Tomcat 6, I noticed that the servlet-cgi.jar is now part of catalina.jar
Change the $CATALINA_BASE/conf/context.xml
From: <Context>
To : <Context privileged="true">

Tomcat 6 CGI: java.io.IOException: CreateProcess: perl

Problem:
java.io.IOException: CreateProcess: perl "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\cgi\test.txt" error=2

Solution:
Update the conf/web.xml to add the follings:
FROM:


<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>

<load-on-startup>5</load-on-startup>
</servlet>

TO:

<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>

<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value>
</init-param>

<load-on-startup>5</load-on-startup>
</servlet>

Restart Tomcat.

Just an FYI.... I still can't enable CGI in Tomcat 6 after fixing this issue. What the $%@#$%

Tomcat auto-configure Issue: cannot find the path specified

Problem:
httpd.exe: Syntax error on line 484 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf:
Could not open configuration file C:/Program/ Files/Apache/ Software/ Foundation/Tomcat/ 6.0/conf/jk/mod_jk.conf-auto:
The system cannot find the path specified.

Solution:
Looks like Apache doesn't like spaces in the path (i.e. "C:\Program Files\...". Reinstall Apache HTTP server and Tomcat server without spaces in the install paths.
Don't use the default install path for both Apache 2.2 and Tomcat 6.

Click the link for more information about how to install Apache 2.2 and Tomcat 6....

Tomcat auto-configure Issue: The specified module could not be found

Problem:
httpd.exe: Syntax error on line 484 of C:/Apache/Apache2.2/conf/httpd.conf:
Syntax error on line 4 of C:/Apache/Tomcat6.0/conf/jk/mod_jk.conf-auto: Cannot load
C:/Apache/Apache2.2/modules/mod_jk-apache-2.2.3.so into server:
The specified module could not be found.

Solution:
The module file I copied was mod_jk-1.2.28-httpd-2.2.3.so, I forgot to rename it.
What the #$%@...
Rename it to mod_jk-apache-2.2.3.so and it fixed the issue.

Click the link for more information about how to install Apache 2.2 and Tomcat 6....

Apache 2.2 + Tomcat 6 Installation and Configuration on Windows XP SP2

This summary is not available. Please click here to view the post.

Monday, May 18, 2009

Tomcat 6 ServiceStart returned 3 Error

Problem:
After downloading TomCat 6.0 and installing the .exe, everything was smooth and i left most of the settings as default. I'm having problems starting my tomcat 6.0 service in "Configure" on my windows XP sp2. It was unable to start the service after install. And, it gave me the following errors in the jakarta_service_20090518.log.


[2009-05-18 16:25:00] [443 javajni.c] [error]
FindClass org/apache/catalina/startup/Bootstrap failed
[2009-05-18 16:25:00] [1005 prunsrv.c] [error]
Failed loading main
org/apache/catalina/startup/Bootstrap class
C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\bootstrap.jar
[2009-05-18 16:25:00] [1269 prunsrv.c] [error]
ServiceStart returned 3


Solution:
I found that there are more than one java jre installed on my windows XP, one is located on
C:\java\jre1.5.0_16
and the other is located on
C:\Program Files\Java\jdk1.5.0_16\jre
. When re-installing Tomcat 6, I changed the default
C:\java\jre1.5.0_16
to
C:\Program Files\Java\jdk1.5.0_16\jre
, and it fixed those errrors.