SSL Installation: Jetty Java HTTPS Servlet Web Server

March 25, 2019 in WebServer

SSL Installation: Jetty Java HTTPS Servlet Web Server

  • The following instructions will guide you through the SSL installation process on Jetty Jave HTTP Servlet Web Server.
  • If you have more than one server or device, you will need to install the certificate on each server or device you need to secure.
  1. Make sure you have all the following files saved before proceeding:

    • Your Server Certificate - This is the certificate you received from the CA for your domain. You may have been sent this via email. If not, you can download it by visiting your Account Dashboard and clicking on your order.

    • Intermediate Certificates - These files allow the devices connecting to your server to identify the issuing CA. There may be more than one of these certificates. If you got your certificate in a ZIP folder, it should also contain the Intermediate certificate(s), which is sometimes referred to as a CA Bundle.

    • Your Private Key - This file should be on your server, or in your possession if you generated your CSR from a free generator tool. On certain platforms, such as Microsoft IIS, the private key is not immediately visible to you but the server is keeping track of it.

  2. Convert your certificate files from PEM (.cer or .crt) to PKCS#7 (.p7b) Format, find instructions here: Converting a PFX file to PEM, SPC, and PVK files

    • Select PEM as your Current type.

    • Select P7B as your Change for.

    • Upload Your Server Certificate.

    • Upload Root CA Certificate.

      Note: This file is usually pre-installed on your server or device. You can always install it again to ensure the correct certificate chain is built.

    • Upload Your Intermediate Certificates.

      Note: If you have two intermediate files, upload the second file as the Root CA Certificate. This will allow you to still build the correct certificate chain since the Root should be pre-installed on your server or device.

    • Click Convert and Save on your server or device.

  3. Add the certificates to your keystore by running the following command:

    keytool -import -alias [enter_alias_name] -trustcacerts -file [enter_certificate_filename].p7b -keystore [enter_keystore_name]
    Note 1: Enter the same alias name and keystore name that was used when generating of the private key and Certificate Signing Request (CSR).

    Note 2: If you receive Error Message: "java.lang.Exception: Input not an X.509 certificate", double-check the alias/keystore name entered and the format of the certificate. You may still be using the PEM (.cer or .crt) format and not the correct PKCS#7 (.p7b) format.

    • Alternative Installation Instructions if keytool Error Message "certificatessxception: Input not an X.509 certificate" occurs:

      1. Using the PEM (.cer or .crt) formatted certificate, import the Intermediate Certificate into your keystore by running the following command:

        keytool -import -alias intermediate -trustcacerts -file intermediate_file_name -keystore [enter_keystore_name]

      2. Using the PEM (.cer or .crt) formatted certificate, import Your Server Certificate into your keystore by running the following command:

        keytool -import -alias [enter_alias_name] -trustcacerts -file server_certificate_file_name -keystore [enter_keystore_name]

  4. Verify the Contents of the keystore by running the following command:

    keytool -list -v -keystore your_keystore_filename >output_filename.txt

  5. Enter your keystore password.

  6. View the Output File.


    Note: Your Server Certificate will be imported into the alias by the "Entry Type" of the specified "PrivateKeyEntry".

  7. Edit the Jetty Connector to point to the keystore and password:

    <Call name="addConnector">
    <Arg>
    <New class="org.mortbay.jetty.security.SslSocketConnector">
    <Set name="Port">8443</Set>
    <Set name="maxIdleTime">30000</Set>
    <Set name="keystore"><SystemProperty name="jetty.home" default="." />/etc/keystore</Set>
    <Set name="password">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
    <Set name="keyPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
    <Set name="truststore"><SystemProperty name="jetty.home" default="." />/etc/keystore</Set>
    <Set name="trustPassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
    </New>
    </Arg>
    </Call>

    Note 1: Reference Jetty Configuring Setting for a correct configuration. This Jetty Configuration documentation will also address how to set your SSL/HTTPS Ports and redirect HTTP to HTTPS.

Congratulations! You've successfully installed your SSL certificate! To check your work, visit the website in your browser at https://yourdomain.tld and view the certificate/site information to see if HTTPS/SSL is working properly. Remember, you may need to restart your server for changes to take effect.