Setting Up SSL on Tomcat
Step 1. Generating the KeyStore file
i) Go to bin directory of jdk
cd %JAVA_HOME%/bin on Windows
cd $JAVA_HOME/bin on Linuxkeytool -genkey -alias techtracer -keypass ttadmin -keystore techtracer.bin -storepass ttadmin
ii)execute following command
keytool -genkey -alias -keypass -keystore -storepass
please note that the values in angle brackets i.e. inside <> can be changed as per ur choice.
but make sure keypass and storepass passwords should be the same.
The .bin file is actually your keystore file
When you enter it will ask you some questions.Look below for a reference as to what to answer for the questions.
What is your first and last name?
[Unknown]: yogita Sananse
What is the name of your organizational unit?
[Unknown]: home
What is the name of your organization?
[Unknown]: mycert
What is the name of your City or Locality?
[Unknown]: pune
What is the name of your State or Province?
[Unknown]: maharashtra
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?
[no]: yes
The command would then conclude. It would make a .bin file with the name you had provided inside the bin directory itself.
In this case it is mycert.bin which will located in
C:\Program Files\Java\jdk1.6.0_02\bin\
Note : if you do not find it in bin directory please check c:\Documents and Settings\yogita.sananse\ folder it may be created here
iii) Put the .bin file in the webapps directory of Tomcat.
This is required to avoid the need to give an absolute path of the file in the next step.
Step 2.Configuring Tomcat for using the Keystore file
i) Modify server.xml :
Open the file server.xml which can be found at: /conf/server.xml
Now you have to modify it. Find the Connector element which has port=”8443″ and uncomment it if already not done. Add two lines.
last two lines in bellow tag are newly added ones.
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="true" disableUploadTimeout="true"
acceptCount="100″ debug=”0″ scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="../webapps/techtracer.bin"
keystorePass="ttadmin" />
Now all you have to do is start your server and check the working of SSL by pointing your browser to the URL to:
https://localhost:8443/
Note : Now that you have your tomcat running in the SSL mode you are ready to deploy an application to test its working. You must note that still your tomcat can run in normal mode too at the same time i.e on port 8080 with http. So it is but obvious that any application deployed to the server will be running on http and https at the same time. This is something that we don’t want. We want our application to run only in the secured mode.
Step 3 : Configuring your web application to work with SSL
Modify web.xml of your application which you want to make https enabled only and want to disable http access for it .
(In order to do this for our test, take any application which has already been deployed successfully in Tomcat and first access it through http and https to see if it works fine.)
If yes, then open the web.xml of that application and just add this XML fragment before web-app ends i.e
The term CONFIDENTIAL is the term which tells the server to make the application work on SSL. If you want to turn the SSL mode for this application off then just turn don’t delete the fragment. Just put the value as NONE instead ofCONFIDENTIAL. That’s it!
No comments:
Post a Comment