One-way SSL authentication on tomcat using OpenSSL
One-way SSL authentication:
Openssl is used for creating private keys and certificates.
Create a self-signed certificate for the server.
1. Create a private key
openssl genrsa -out serverprivatekey.pem 2048
2. Create an openSSL self-signed certificate for the server using the above private key
openssl req -new -x509 -key serverprivatekey.pem -out servercert.pem -days 1095
This prompts you to enter a few pieces of information, use “.” to leave the field blank. When prompted for 'Common Name' specify the hostname of the machine the tomcat runs on.
3. Tomcat currently operates only on JKS format keystore. So generate a keystore in JKS format from above certificate
openssl pkcs12 -export -out serverkeystore.pkcs12 -in servercert.pem -inkey serverprivatekey.pem
It asks for the export password, and it is recommended to provide a password.
4. Now convert serverkeystore.pkcs12 file to JKS format keystore using Java's keytool
keytool -importkeystore -srckeystore serverkeystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS
Keytool asks you for a new password(keystore password) for the JKS keystore twice, and it will also ask you for the password you set for the PKCS12 keystore created earlier.
5. Configure tomcat to use this keystore and enable HTTPS. Edit CATALINA_HOME/conf/server.xml, where CATALINA_HOME is the base directory of Tomcat. By default, the HTTPS Connector configuration is commented out. Uncomment it and change the keystorefile and keystore password(password given while creating JKS keystroe in previous step)
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="path/to/jks_keystore_file" keystorePass ="geebox"/>
References:
1. http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html
2. http://marc.info/?l=tomcat-user&m=106293430225790&w=2
3. http://yimingsun.wordpress.com/2012/03/12/step-by-step-instructions-on-self-signed-certificate-and-tomcat-over-ssl/
4. http://publib.boulder.ibm.com/infocenter/tivihelp/v5r1/index.jsp?topic=%2Fcom.ibm.itim.infocenter.doc%2Ftsk%2Ftsk_ic_security_genproc_1wayca.html
5.http://blog1.vorburger.ch/2006/08/setting-up-two-way-mutual-ssl-with.html
6. http://virgo47.wordpress.com/2010/08/23/tomcat-web-application-with-ssl-client-certificates/
Comments
Post a Comment