Javascript required
Skip to content Skip to sidebar Skip to footer

How to Install Ssl Certificate in Tomcat 9

This section describes how to install a downloaded certificate on a Tomcat server. After a certificate is installed, the communication security of your web server is ensured using SSL.

If an error occurs during certificate installation, click Consult Now in the One-to-One Consultation area on the right of the certificate download page.

Prerequisites

  • The certificate is in the Issued state.
  • You have downloaded the SSL certificate. For details, see Downloading a Certificate.
  • You have installed the OpenSSL tool.

    Download the latest OpenSSL installation package from https://www.openssl.org/source/. The OpenSSL must be 1.0.1g or later.

  • You have installed Keytool.

    Keytool is typically included in the Java Development Kit (JDK) tool package.

Constraints

  • Before installing the certificate, enable port 443 on the server where the SSL certificate is installed and add port 443 to the security group. Otherwise, HTTPS cannot be enabled after the installation.
  • If a domain name maps to multiple servers, deploy the certificate on each server.
  • The domain name to be run on the target server must be the same as the one associated with the certificate. Otherwise, the web browser will display a message indicating that the domain name is insecure.

Procedure

To install an SSL certificate on a Tomcat server, perform the following steps:

Step 1: Obtaining Files → Step 2: Creating a Directory → Step 3: Modifying Configuration Files → Step 4: Restarting the Tomcat → Verifying the Result

Step 1: Obtaining Files

Before installing a certificate, obtain the certificate file and password file. Perform the following operations based on the value selected for CSR when applying for a certificate:

  • If you select System generated CSR for CSR when applying for a certificate, perform the operations according to the instructions in System generated CSR.
  • If you select Upload a CSR for CSR when applying for a certificate, perform the operations according to the instructions in Upload a CSR.

Detailed operations are as follows:

  • System generated CSR
    1. Decompress the downloaded certificate file on your local PC.

      The downloaded file contains the Apache, IIS, Nginx, and Tomcat folders as well as the domain.csr file.

      Figure 1 Decompressing an SSL certificate package on a local computer

    2. Obtain Certificate ID_Domain name bound to the certificate_server.jks and Certificate ID_Domain name bound to the certificate_keystorePass.txt from Certificate ID_Domain name bound to the certificate_Tomcat .

      The password file keystorePass.txt contains the initial random password generated by the service. To ensure system security, you are advised to change the password. You can change the password when converting the certificate format. For more details, see What Are Mainstream Formats of Digital Certificates?

  • Upload a CSR
    1. Decompress the downloaded certificate package to obtain the Certificate ID_Domain name bound to the certificate_server.pem file.

      The Certificate ID_Domain name bound to the certificate_server.pem file contains two segments of certificate codes -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----, which are the server certificate and intermediate CA certificate respectively.

    2. Use OpenSSL to convert the PEM certificate into a PFX certificate and obtain the server.pfx file.
      1. Save the PEM certificate and the private key server.key generated during CSR generation to the bin directory in the OpenSSL installation directory.
      2. In the bin directory of the OpenSSL installation directory, run the following command to convert the PEM certificate into a PFX certificate and press Enter:

        openssl pkcs12 -export -out server.pfx -inkey server.key -in Certificate ID_Domain name bound to the certificate_server.pem

        The command output is as follows:

        Enter Export Password:
      3. Enter the password of the PFX certificate and press Enter.

        The password is user-defined. Set it as required.

        The command output is as follows:

        Verifying - Enter Export Password:

        Record the password of the PFX certificate. The password of the JKS certificate must be the same as that of the PFX certificate. Otherwise, the Tomcat service may fail to start.

        To improve password security, set the password based on the following rules:

        • Consists of 8 to 32 characters.
        • Must contain at least three types of the following characters: uppercase letters, lowercase letters, digits, and special characters ~`!@#$%^&*()_+|{}:"<>?-=\[];',./
      4. Re-enter the password of the PFX certificate and press Enter.

        If no error information is displayed, the server.pfx file has been generated in the OpenSSL installation directory.

    3. Use Keytool to convert the PFX certificate into a JKS certificate and obtain the server.jks file.
      1. Copy the server.pfx file generated in 2 to the %JAVA_HOME%/jdk/bin directory.
      2. In the %JAVA_HOME%/jdk/bin directory, run the following command and press Enter:

        keytool -importkeystore -srckeystore server.pfx -destkeystore server.jks -srcstoretype PKCS12 -deststoretype JKS

        The following message is displayed.

        Enter the destination keystore password:
      3. Enter the password of the JKS certificate and press Enter.

        Set the password of the JKS certificate to the same as that of the PFX certificate. Otherwise, Tomcat may fail to start.

        The command output is as follows:

        Re-enter the new password:
      4. Re-enter the password of the JKS certificate and press Enter.

        The command output is as follows:

        Enter the source keystore password:
      5. Enter the password of the PFX certificate set in 2.c and press Enter.

        If information similar to the following is displayed, the conversion is successful and the server.jks file has been generated in the OpenSSL installation directory.

        Entry for alias                        1                        imported successfully. Import command completed: 1 entry successfully imported, 0 entries failed or canceled
      6. Create a keystorePass.txt file in the %JAVA_HOME%/jdk/bin directory and save the password of the JKS certificate in the file.
    4. Place the converted certificate file server.jks and the new password file keystorePass.txt in the same directory.

Step 2: Creating a Directory

Create a cert directory in the Tomcat installation directory, and copy the server.jks and keystorePass.txt files to the cert directory.

Step 3: Modifying Configuration Files

Tomcat7

Tomcat8.5 or Tomcat9

Detailed operations are as follows:

  • Tomcat7
    1. Find the following parameters in the server.xml file in the Tomcat installation directory:
                          <!--                    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"                clientAuth="false" sslProtocol="TLS" />                    -->                  
    2. Find the preceding parameters and delete the comment characters <!- - and - ->.
    3. Add the following parameters. Change the values of the parameters according to Table 1.
      keystoreFile="cert/server.jks" keystorePass="Certificate key"

      The complete configuration is as follows. Modify other parameters based on your needs.

      <Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"                    keystoreFile="cert/server.jks"                    keystorePass="Certificate key"       clientAuth="false" sslProtocol="TLS" />

      Do not directly copy all configuration. Only parameters keystoreFile and keystorePass need to be added. Set other parameters based on site requirements.

      Table 1 Parameter description (1)

      Parameter

      Description

      port

      Port number to be used on the server. You are advised to set the value to 443.

      protocol

      HTTP protocol. Retain the default value.

      keystoreFile

      Path for storing the server.jks file. The value can be an absolute path or a relative path. Example: cert/server.jks

      keystorePass

      Password of server.jks. Set this parameter to the password provided in the keystorePass.txt file.

      NOTICE:

      If the password contains &, replace it with &amp; to avoid configuration failure.

      An example command is provided as follows:

      If the password is keystorePass="Ix6 & APWgcHf72DMu", change it to keystorePass="Ix6 &amp; APWgcHf72DMu".

      clientAuth

      Whether to require all customers to show the security certificate and authenticate their identity. Retain the default value.

    4. Find the following parameters in the server.xml file in the Tomcat installation directory:
      <Host name="localhost"  appBase="webapps"       unpackWARs="true" autoDeploy="true">
    5. Change the value of Host name to the domain name bound to the certificate.

      The complete configuration is as follows (www.domain.com is used as an example):

      <Host name="www.domain.com"  appBase="webapps"       unpackWARs="true" autoDeploy="true">
    6. Save the configuration file.
  • Tomcat8.5/9
    1. Find the following parameters in the server.xml file in the Tomcat installation directory:
                          <!--                    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"            maxThreads="150" SSLEnabled="true">     <SSLHostConfig>         <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"                      type="RSA" />     </SSLHostConfig> </Connector>                    -->                  
    2. Find the preceding parameters and delete the comment characters <!- - and - ->.
    3. Configure the certificate parameters. Change the values of the parameters according to Table 2.

      Modify the following parameter settings:

      certificateKeystoreFile="conf/localhost-rsa.jks"

      Add the following parameter:

      certificateKeystorePassword="Certificate key"

      The complete configuration is as follows. Modify other parameters based on your needs.

      <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"            maxThreads="150" SSLEnabled="true">     <SSLHostConfig>         <Certificate                    certificateKeystoreFile="cert/server.jks"                    certificateKeystorePassword="Certificate key"                      type="RSA" />     </SSLHostConfig> </Connector>

      Do not directly copy all configuration. Only parameter certificateKeystoreFile needs to be modified and certificateKeystorePassword needs to be added. Set other parameters based on site requirements.

      Table 2 Parameter description (2)

      Parameter

      Description

      port

      Port number to be used on the server. You are advised to set the value to 443.

      protocol

      HTTP protocol. Retain the default value.

      certificateKeystoreFile

      Path for storing the server.jks file. The value can be an absolute path or a relative path. Example: cert/server.jks

      certificateKeystorePassword

      Password of server.jks. Set this parameter to the password provided in the keystorePass.txt file.

      NOTICE:

      If the password contains &, replace it with &amp; to avoid configuration failure.

      An example command is provided as follows:

      If the password is certificateKeystorePassword="Ix6 & APWgcHf72DMu", change it to certificateKeystorePassword="Ix6 &amp; APWgcHf72DMu".

    4. Find the following parameters in the server.xml file in the Tomcat installation directory:
      <Host name="localhost"  appBase="webapps"       unpackWARs="true" autoDeploy="true">
    5. Change the value of Host name to the domain name bound to the certificate.

      The complete configuration is as follows (www.domain.com is used as an example):

      <Host name="www.domain.com"  appBase="webapps"       unpackWARs="true" autoDeploy="true">
    6. Save the configuration file.

Step 4: Restarting the Tomcat

Run the ./shutdown.sh command in the bin directory of Tomcat to stop the Tomcat service.

After 10 seconds, run the ./startup.sh command to start the Tomcat service. If the process is automatically started by the daemon process, you do not need to manually start the process.

How to Install Ssl Certificate in Tomcat 9

Source: https://support.huaweicloud.com/intl/en-us/usermanual-scm/scm_01_0081.html