Friday, May 17, 2013

Setup SSL in Tomcat

Setup SSL in Tomcat

1. Create certificate file(Key store)
We can create keystore file using java "keytool" command utility
C:\Program Files\Java\jdk1.6.0_21\bin>keytool -genkey -alias yash -keypass yash123 -keystore mycertificate.cer -storepass yash123
what is your first and last name? yash jadhav
what is the name of your organizational unit? SHRI RAM
what is the name of your organization? SHRI RAM
what is the name of your city or locality? Hyderabad
what is the name of your state or Province? Andhra Pradesh
what is the two-letter country code for this unit? IN
yes

2. Copy the myCertification.cer file into tomcat/conf

3. Modify the Server.xml file in conf folder
 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" keystoreFile="conf/myCertificate.cer" keystorePass="yash123"/>
             
4. Test tomcat(start tomcat)
    https://localhost:8443/


Sometimes you may get below exception:keytool error: java.io.FileNotFoundException: mycertificate.cer <Access Denied>

Solution:
This could happen if you are not running the command prompt in administrator mode. If you are using windows7, go to START -> ALL PROGRAMS -> ACCESSORIES -> right click on command prompt and say run as administrator


Follow all the above steps(1-4).

No comments:

Post a Comment