Faq Tomcat Soap SSL
Faq Tomcat Soap SSL
Faq Tomcat Soap SSL
Setting up Apache Tomcat and a Simple Apache SOAP Client for SSL
Communication.
By Peter Glynn and Darrell Drake, with minor updates by Jonathan Chawke, April 2001.
Introduction
This document gives steps involved in setting up Apache Tomcat and a simple Apache SOAP client for
SSL communication.
The aim of this document is to allow a person with minimum Java security to be able to set up SSL
connection in a Apache SOAP/Tomcat Application. The steps you will carry out are:
1. Install the Java Secure Socket Extensions (JSSE) package (available from Sun).
2. Generate Client and Server Certificates for SSL communication.
a. Generate a Server Key and Certificate
b. Export the Server Certificate
c. Generate a Client Key and Certificate
d. Export the Client Certificate
e. Import the Certificates into the Keystores
3. Set up Tomcat for SSL Communication
4. Modify the SOAP Client to use SSL
Assumptions
It is assumed that you have installed Apache SOAP and Apache Tomcat, and that the sample SOAP
applications are working.
z Before you do anything, read the installation instructions for JSSE! (they are available online at:
http://java.sun.com/products/jsse/install.html).
z Add the JSSE jars to your classpath. This should hopefully add it to the classpath of your Tomcat
server. If not, add it to the classpath of the Tomcat server or just copy the JSSE jar files to the lib
directory of Tomcat (e.g. C:\jakarta-tomcat-3.2.1\lib). This will automatically load on start-
up of Tomcat.
The JSSE 1.0.2 jars that you need in your classpath are:
{ jsse.jar
{ jcert.jar
{ jnet.jar
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 2 of 9
It is necessary to generate a Certificate for the client and the server. These Certificates are then imported
into a keystore, to which the client and server connect.
The keystore acts as a database for security certificates.
You are going to use the keytool utility in the JDK to do these tasks (see Sun's documentation for more
information on this tool).
Launch keytool from a shell (or command prompt) to generate your public and private key.
Note that the Certificate and keystore files will be generated in the directory you run keytool from.
For example, to generate a keystore (in file server.keystore) for server soapsvr.test.tcd.ie using
password changeit (for both the keystore and the certificate) in the Computer Engineering group at
Trinity College Dublin, Ireland, one would type the following: keytool -genkey -alias tomcat-sv
-dname "CN=soapsvr.test.tcd.ie, OU=ComputerEngineering, O=Trinity College Dublin,
L=Dublin, S=Dublin, C=IE" -keyalg RSA -keypass changeit -storepass changeit -
keystore server.keystore
Note that
>From command prompt run this command to export your certificate from the keystore into an external
file (we do this so we can import the certificate into the client's keystore as a trusted certificate).
keytool -export -alias tomcat-sv -storepass changeit -file server.cer -keystore server.keystor
If everything works, you should now have a file called server.cer which contains your server's
certificate.
This step is very similar to the generation of the server key and certificate - it uses the same keytool
tool with different parameters.
Note that the keystore file name has changed (it is now client.keystore). Use keytool as follows:
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 3 of 9
client.keystore
This step is very similar to the export of the server certificate - it uses the same keytool tool with
different parameters:
keytool -export -alias tomcat-cl -storepass changeit -file client.cer -keystore client.keystor
If everything works, you should now have a file called client.cer which contains your client's
certificate.
We want the client certificate to be added to the server's keystore, and the server's certificate to be added
to the client's keystore.
Doing this will mean that the client and server trust one another.
Import the server certificate into the client's keystore:
keytool -import -v -trustcacerts -alias tomcat -file server.cer -keystore
client.keystore -keypass changeit -storepass changeit
Import the client certificate into the server's keystore: keytool -import -v -trustcacerts -alias
tomcat -file client.cer -keystore server.keystore -keypass changeit -storepass
changeit
You need to amend server.xml (located in the conf directory of Apache Tomcat). Add the following
lines to the xml file:
<Connector className ="org.apache.tomcat.service.PoolTcpConnector">
</Connector>
Note that the value used for the keystore parameter (shown in bold above) may be different on your
machine; it should contain the full path and filename of the server keystore file (server.keystore)
generated in Step 2a above. Note also that the port number we chose to use for SSL in the above
configuration is 8443. The port normally used for HTTPS is 443, but for testing we are using 8443.
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 4 of 9
At this point, you should restart your Tomcat server. It will probably take a bit longer to start up. You
can now use a web browser to test that it is working.
Test the SSL installation by opening your browser and typing in the following URL:
https://servername:8443/index.html
Note that servername should be replaced with the name of the server on which you are running Tomcat.
If SSL is working then you should see the default home page for your Tomcat installation.
Your browser may generate a warning about un-trusted certificates or unrecognised authorities (just
click OK).
You need to set up properties before you call the URL in the SOAP client. Here is an example SOAP
client that calls a SOAP service using HTTPS on a Tomcat server:
// classes for ssl
import javax.net.ssl.SSLSocketFactory;
import java.security.Security;
...
//
//
// specify the location of where to find key material for the default TrustManager (th
System.setProperty("javax.net.ssl.trustStore","C:\\jdk1.3\\bin\\client.keystore");
// use Sun's reference implementation of a URL handler for the "https" URL protocol ty
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// note that the url is using https protocol and not http
//
//
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 5 of 9
call.setTargetObjectURI( urn );
call.setMethodName( "getFlightInfo" );
...
Response resp;
try
catch (SOAPException e)
e.printStackTrace();
return;
Once again the bold directory path is a pointer to the client keystore. This may have to be changed
depending on where you generated it. Also note that the url is https and not http. It's an easy mistake to
make!
If your client needs to use a proxy server in order to access the SOAP service, then add the following
lines to your code:
System.setProperty("https.proxyHost", "proxy"); // set name of proxy server that supp
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 6 of 9
If you are using Socks proxy then set these (system) properties:
System.setProperty("socksProxyHost", "hostname"); // set name of socks server
By Darrell Drake
Overview
This instruction set covers creating mutual trust between two entities using a certificate chains (my
certificate with an attached lineage of public certificates), which is more practical in a production
environment than the minimal security approach. In this case a principal is trusted if any of the
certificates in its chain are trusted. Additional tool needed: IBM KeyMan, which can read and issue
certificates from keystores in the JKS and PKCS12 formats. Other formats (e.g. IBM CMS Key
Database) don't work well, at least in my experience.
Downloading KeyMan
z From the initial window, click on the "create new" icon on the left
OR
from an already-open KeyMan window, under the File menu choose New.
z Specify the type of keystore (pkcs 7, 12 and JKS are options)
z Immediately the template is created
z Under the Actions menu choose generate key
z Select the desired key algorithm and length, click OK
z WAIT
z From the initial window, click on the "open" icon on the right
OR
from an already-open KeyMan window, under the File menu choose Open
z Select "local resource", click next
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 7 of 9
z Make sure the new key pair (and just the key pair) is selected
z Under the Actions menu, choose Create Certificate
z Choose Self-Signed Certificate, click next
z Fill in the principal information as requested, click next
z Select the period of validity for the new certificate, click next
If you leave the "-file certreq_file" part out, the pkcs10 request will be printed to your standard
output, which you can highlight and copy to the system clipboard, transfer to a file or directly into
KeyMan (see next step "issuing certificate"). The principal information in the request will be what you
entered when using the "-genkey" command earlier.
z Make sure the new key pair (and just the key pair) is selected
z Under the Actions menu, choose Request Certificate
z Choose "Generate a PKCS#10 Request", click next
OR
If you want to get a commercial certificate for your server, choose "Go online to a CA" (I don't
know the remaining steps for doing that)
z Fill in the principal information as requested, click next
z Enter the filename where you want to save the request,
OR
Choose to copy the request to the system clipboard, click next
z The request is now stored in the location that you specified.
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 8 of 9
NOTE: If the server gets a certificate chain from a higher CA entity, the client could import that higher
entity's certificate as a trusted CA certificate (it may already have that certificate by default), and it
would thus trust the server certificate.
Troubleshooting
One extremely useful tip for troubleshooting SSL is to use the built-in SSL debugging features:
java -djavax.net.debug=help YourClassname
(this will give you a help message for SSL debugging features)
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003
Page 9 of 9
Keytool Error
Further Information
SOAP
SSL
file://C:\DOCUME~2\Owner\LOCALS~1\Temp\U1EEM74T.htm 20/02/2003