Installing SSL Certificate on Apache Tomcat using Keytool


When deploying a web application using Apache Tomcat, it is important to ensure that communication is secure to protect sensitive data from prying eyes. One way to achieve this is by installing an SSL certificate on your server. In this article, we will walk you through the step-by-step process of creating a .jks file and installing an SSL certificate on Apache Tomcat using Keytool.

Step 1: Obtain SSL Certificate

Assuming you have already generated a Certificate Signing Request (CSR), you should have received the SSL certificate from the Certificate Authority (CA) in the following files:

DigiCertCA.crt
star_company_com.crt
TrustedRoot.crt
company.com.key

Step 2: Merge the SSL Certificates

Open a terminal window and concatenate the SSL certificate files into a single file called 'company.crt' using the following command:

cat star_company_com.crt DigiCertCA.crt TrustedRoot.crt > company.crt

Step 3: Create a .jks File

Use the following command to create a new .jks file called 'company.jks':

keytool -genkey -alias tomcat -keyalg RSA -keystore company.jks

Step 4: Import the SSL Certificate into .jks File

Use the following command to import the SSL certificate into the 'company.jks' file:

keytool -import -alias tomcat -keystore company.jks -file company.crt

Step 5: Configure Apache Tomcat

Open the Tomcat configuration file called 'server.xml' located at '/usr/local/tomcat/conf/server.xml' using a text editor and add the following lines to enable SSL:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="/path/to/company.jks" keystorePass="password"/>

Replace '/path/to/company.jks' with the actual path to the 'company.jks' file and 'password' with the password you set during the creation of the .jks file.

Step 6: Restart Apache Tomcat

Save the 'server.xml' file and restart Apache Tomcat to apply the changes.

Conclusion

By following the above steps, you can successfully install an SSL certificate on Apache Tomcat using Keytool. This will ensure that all communication between the server and clients is secure and encrypted, providing peace of mind for both the website owners and visitors.

Alternative Solution

In case you have access to OpenSSL, you can use the following command to create a .p12 file:

openssl pkcs12 -export -in star_company_com.crt -inkey company.com.key -out company.p12

Then, use the following command to convert

keytool -importkeystore -srckeystore company.p12  -srcstoretype PKCS12 -destkeystore company.jks -deststoretype JKS

No comments:

Post a Comment