-
Notifications
You must be signed in to change notification settings - Fork 169
SSL Configuration In Tomcat
First you will need to obtain and install a certificate. Here are steps to achieve this:
- Generate a keystore using the
keytool
utility included with the Java JDK
keytool -genkey -alias webapi -keyalg RSA -keystore C:\path\to\my\keystore.jks -keysize 2048
- Generate CSR (Certificate Signing Request)
keytool -certreq -alias webapi -keystore C:\path\to\my\keystore.jks -file C:\path\to\csr\webapi.csr
-
Now you need to follow instructions of CA (Certification Authority) of your choice to submit your CSR (for example VeriSign) to obtain the SSL certificate. Alternatively, you may opt to use OpenSSL to create a local CA for non-production use.
-
When you obtained certificate from CA, you need to import the CA’s root and intermediate certificates into a Java keystore file before you import the actual SSL certificate. The steps below outline this process for a Windows machine.
- Take your SSL certificate with a .cer extension. and double click on it.
- At the certificate popup click on Certification Path.
- Double click on the top certificate Root in order to bring up its information.
You will perform the same steps as above in step 1 but with the middle certificate (Intermediate).
- Go back to your SSL certificate under the Certification Path tab and double click on the Middle Certificate Intermediate in the tier.
You should now have three files:
- Your Root Certificate.
- Your Intermediate Certificate.
- Your SSL certificate where both the Root, and Intermediate are derived from.
Import the Root Certificate first. You will specify your own alias for this import Example: Root.
keytool -import -alias root -trustcacerts -file C:\path\to\root.cer -keystore C:\path\to\my\keystore.jks
Import the Intermediate CA certificate second. You will specify your own alias for this import. Example: Intermediate.
keytool -import -alias intermediate -trustcacerts -file C:\path\to\intermediate.cer -keystore C:\path\to\my\keystore.jks
Lastly, import the actual SSL certificate into the keystore.
keytool -importcert -trustcacerts -alias webapi -file C:\path\to\cert\webapi.p7b -keystore C:\path\to\my\keystore.jks
Now you can add SSL connector in Tomcat's server.xml
file
<Connector
port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="200"
scheme="https"
secure="true"
SSLEnabled="true"
keyAlias="webapi"
keystoreFile="C:\path\to\my\keystore.jks"
keystorePass="{Your keystore password}"
clientAuth="false"
sslProtocol="TLS"/>
Apache Tomcat contains more details on SSL Setup here.