Here are the steps to install SSL in tomcat.
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
1. Create a key pair
keytool -keysize 2048 -genkey -alias <pick a name> -keyalg RSA -keystore tomcat.keystore
default password, if not changed, is changeit
- First and last name - type your website url, for example, www.company.com
- Organizational unit - for example, engineering, production etc.
- Organization - full name of your company
- City/Locality - name of the city
- State/Province - name of state
- Country code - two letter country code. refer to this site
- type yes to confirm and press ENTER
when asked for a password for private key, select same password as the keystore otherwise you will run into this bug #38217 at the time of installation
2. Generate a certificate request (CSR)
keytool -certreq -keyalg RSA -alias <your alias> -file <your company name>.csr -keystore tomcat.keystore
3. Copy/paste the entire content of .csr and follow the steps described by your certificate provider, for example godaddy etc, to submit the csr.
4. Download the issued certificate and install it in your keystore. For example, download a zip file from godaddy, and follow these steps;
keytool -import -alias root -trustcacerts -file gd_bundle.crt
keytool -import -alias cross -trustcacerts -file gd_cross_intermediate.crt
keytool -import -alias intermed -trustcacerts -file gd_intermediate.crt
keytool -import -alias <your alias> -trustcacerts -file YourDomain.crt
keytool -import -alias cross -trustcacerts -file gd_cross_intermediate.crt
keytool -import -alias intermed -trustcacerts -file gd_intermediate.crt
keytool -import -alias <your alias> -trustcacerts -file YourDomain.crt
5. Enable SSL in tomcat. Uncomment following connector in /conf/server.xml and add keystore details.
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="<path to keystore>/tomcat.keystore" keystorePass="<keystore password>" keyAlias="<your alias>" />
6. Append following snippet in WEB-INF/web.xml of your web application.
<security-constraint>
<display-name>ssl redirect</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/*</url-pattern>
<!-- If you list http methods, only those methods are protected -->
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
7. Make sure redirect port of the http connector is pointing to correct ssl port
<connector port="80" protocol="HTTP/1.1" font="" connectionTimeout="20000" redirectPort="443" />
8. stop and start tomcat
9. try http://<your-domain> and it should automatically redirect you to https://<your-domain>
Comments