Mon 2 Apr 2007
Here is a short step-by-step for enabling ssl in tomcat + enforcing user certificates from CERN.
First you have to create a host certificate. See https://ca.cern.ch/ca/HostCertificates/ManageHostCertificates.aspx for this.
Download the Base64 files. You should now have: privkey.pem (your private key) and newcert.cer (CERN signed).
Download the CERN CA files and convert them to PEM format:
$ wget --no-check-certificate https://ca.cern.ch/ca/CRL/CERN%20Root%20CA.crt -O CERN_ROOT_CA.der
$ openssl x509 -in CERN_ROOT_CA.der -inform DER -outform PEM -out CERN_ROOT_CA.pem
$ wget --no-check-certificate https://ca.cern.ch/ca/CRL/CERN%20Trusted%20Certification%20Authority.crt -O CERN_Trusted_Certification_Authority.der
$ openssl x509 -in CERN_Trusted_Certification_Authority.der -inform DER -outform PEM -out CERN_Trusted_Certification_Authority.pem
If you want to accept old CERN certificates take the PEM file from http://service-grid-ca.web.cern.ch/service-grid-ca/crt/root_crt.html.
Concatenate the PEM files in a single chain:
$ cat newcert.cer CERN_Trusted_Certification_Authority.pem CERN_ROOT_CA.pem >hostcertchain.pem
Download this tool to convert to Sun JKS format:
$ wget http://juliusdavies.ca/commons-ssl/not-yet-commons-ssl-0.3.11.jar
And do the actual conversion:
$ java -cp not-yet-commons-ssl-0.3.11.jar org.apache.commons.ssl.KeyStoreBuilder 'password' privkey.pem hostcertchain.pem
Now you have a file named hostname.cern.ch.jks. This is your server certificate. This is enough for enabling SSL in the server. The only thing left is to configure tomcat. In server.xml you have to add something like:
<Connector port="8443"
maxThreads="20" minSpareThreads="2" maxSpareThreads="5"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" debug="0" scheme="https" secure="true"
sslProtocol="TLS"
keystoreFile="/home/user/tomcat/hostname.cern.ch.jks"
keystorePass="password"
keystoreType="JKS"
/>
Now, if you want to force the clients to have a certificate signed by CERN authority you have to create another JKS file with the following commands:
$ keytool -importcert -keystore trusted_authorities.jsk -alias CERN_ROOT_CA -file CERN_ROOT_CA.pem
$ keytool -importcert -keystore trusted_authorities.jsk -alias CERN_Trusted_Certification_Authority -file CERN_Trusted_Certification_Authority.pem
and optionally
$ keytool -importcert -keystore trusted_authorities.jsk -alias OLD_CERN_ROOT_CA -file OLD_CERN_ROOT_CA.pem
Then add to the Connector above these lines:
clientAuth="true"
truststoreFile="/home/user/tomcat/trusted_authorities.jsk"
truststorePass="password"
truststoreType="JKS"
Now, an interesting feature is the automatic redirection from http to https when the security constraint requires SSL. On the http Connector you have to specify the correct port for SSL in this parameter:
redirectPort="8443"
This will be used when you put the following options in the security-constraint section of each zones’ web.xml:
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
Special thanks to Adi for his patience in guiding me through the SSL maze! All the commands are belong to him
2 Responses to “Enabling SSL in Tomcat”
Leave a Reply
You must be logged in to post a comment.
April 2nd, 2007 at 20:41
Just to add that the above procedure works for Tomcat 5 and above. For older versions this is also possible but the Connector setup is a little bit different.
May 12th, 2010 at 13:32
To upgrade from Tomcat 5.0 or 5.5 to Tomcat 6.0 or later and still have SSL support you need either to:
1. Add to server.xml Server section at least this line from the Tomcat 6.0 default configuration file:
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /></code>2. Install APR on the base system
sudo apt-get install libtcnative-1
3. Convert all keys to APR / OpenSSL format
OR
1. disable APR (SSLEngine="off" for the Listener above) and in the SSL Connector add protocol="org.apache.coyote.http11.Http11Protocol"
and here you find more information about the new configuration options http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
Otherwise SSL doesn't work at all even though Tomcat listens on that port. And one symptom is this error in Firefox:
SSL received a record that exceeded the maximum permissible length.(Error code: ssl_error_rx_record_too_long)
By the way, Tomcat 6.0.26 needed libtcnative-1 version 1.1.17+, and Ubuntu 9.10 has just the wrong one (1.1.16). But Ubuntu 10.04 provides libtcnative-1 version 1.1.19 so you just have to run the latest and greatest of everything