How to generate a CSR in Tomcat with Keytool
Create a New Keystore
You will need to create a new Keystore, this is done by this command:
1 |
keytool -genkey -alias domainname.prefix -keyalg RSA -keysize 2048 -keystore /path/domainname.prefix.jks |
When the commands ask for the firstname and lastname, please type domainname.prefix instead of you name, else the certificate will issues to you name, instead of the domain name.
Generate a CSR from Your New Keystore
- Next, you need to generate a CSR file, this is done by this command
1keytool -certreq -alias domainname.prefix -file certreq.cer -keystore /path/domainname.prefix.jks - Type the keystore password that you chose earlier and hit Enter.
- Please upload the certreq.cer, to you standard certificate supplier.
Installing the SSL Certificates to the Keystore
- You will then get a certificate, save it as signcert.cer
- Download aswell the correct intermediate certificate, aswell as the correct root certificate.
- Import them with this command:
123keytool -import -trustcacerts -alias root -file root.cer -keystore /path/domainname.prefix.jkskeytool -import -trustcacerts -alias intermediate -file intermediate.cer -keystore /path/domainname.prefix.jks
- Import the signed certificate
1keytool -import -trustcacerts -alias domainanme.prefix -file signcert.cer -keystore /path/domainname.prefix.jks
Configuring your SSL Connector
Before Tomcat can accept secure connections, you need to configure an SSL Connector.
- In a text editor, open the Tomcat server.xml file.
The server.xml file is usually located in the conf folder of your Tomcat’s home directory.
- Locate the connector that you want to use the new keystore to secure.
Usually, a connector with port 443 or 8443 is used, as shown in step 4.
- If necessary, uncomment the connector.
To uncomment a connector, remove the comment tags (<!– and –>).
- Specify the correct keystore filename and password in your connector configuration.
When you are done, your connector should look something like this:
1 |
<Connector port="443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" SSLEnabled="true"clientAuth="false" sslProtocol="TLS" keyAlias="server" keystoreFile="/path/domainname.prefix.jks " keystorePass="your_keystore_password" /> |
Note: If you are using a version of Tomcat prior to Tomcat 7, you need to change “keystorePass” to “keypass”.
- Save your changes to the server.xml file.
- Restart Tomcat.