Table of ContentsQuick StartThe description below uses the variable name $CATALINA_BASE to refer the base directory against which most relative paths are resolved. If you have not configured Tomcat for multiple instances by setting a CATALINA_BASE directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME, the directory into which you have installed Tomcat. Show To install and configure SSL/TLS support on Tomcat, you need to follow these simple steps. For more information, read the rest of this How-To.
Introduction to SSL/TLSTransport Layer Security (TLS) and its predecessor, Secure Sockets Layer (SSL), are technologies which allow web browsers and web servers to communicate over a secured connection. This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. This is a two-way process, meaning that both the server AND the browser encrypt all traffic before sending out data. Another important aspect of the SSL/TLS protocol is Authentication. This means that during your initial attempt to communicate with a web server over a secure connection, that server will present your web browser with a set of credentials, in the form of a "Certificate", as proof the site is who and what it claims to be. In certain cases, the server may also request a Certificate from your web browser, asking for proof that you are who you claim to be. This is known as "Client Authentication," although in practice this is used more for business-to-business (B2B) transactions than with individual users. Most SSL-enabled web servers do not request Client Authentication. SSL/TLS and TomcatIt is important to note that configuring Tomcat to take advantage of secure sockets is usually only necessary when running it as a stand-alone web server. Details can be found in the Security Considerations Document. When running Tomcat primarily as a Servlet/JSP container behind another web server, such as Apache or Microsoft IIS, it is usually necessary to configure the primary web server to handle the SSL connections from users. Typically, this server will negotiate all SSL-related functionality, then pass on any requests destined for the Tomcat container only after decrypting those requests. Likewise, Tomcat will return cleartext responses, that will be encrypted before being returned to the user's browser. In this environment, Tomcat knows that communications between the primary web server and the client are taking place over a secure connection (because your application needs to be able to ask about this), but it does not participate in the encryption or decryption itself. Tomcat is able to use any of the the cryptographic protocols that are provided by the underlying environment. Java itself provides cryptographic capabilities through JCE/JCA and encrypted communications capabilities through JSSE. Any compliant cryptographic "provider" can provide cryptographic algorithms to Tomcat. The built-in provider (SunJCE) includes support for various SSL/TLS versions like SSLv3, TLSv1, TLSv1.1, and so on. Check the documentation for your version of Java for details on protocol and algorithm support. If you use the optional CertificatesIn order to implement SSL, a web server must have an associated Certificate for each external interface (IP address) that accepts secure connections. The theory behind this design is that a server should provide some kind of reasonable assurance that its owner is who you think it is, particularly before receiving any sensitive information. While a broader explanation of Certificates is beyond the scope of this document, think of a Certificate as a "digital passport" for an Internet address. It states which organisation the site is associated with, along with some basic contact information about the site owner or administrator. This certificate is cryptographically signed by its owner, and is therefore extremely difficult for anyone else to forge. For the certificate to work in the visitors browsers without warnings, it needs to be signed by a trusted third party. These are called Certificate Authorities (CAs). To obtain a signed certificate, you need to choose a CA and follow the instructions your chosen CA provides to obtain your certificate. A range of CAs is available including some that offer certificates at no cost. Java provides a relatively simple command-line tool, called General Tips on Running SSLWhen securing a website with SSL it's important to make sure that all assets that the site uses are served over SSL, so that an attacker can't bypass the security by injecting malicious content in a JavaScript file or similar. To further enhance the security of your website, you should evaluate to use the HSTS header. It allows you to communicate to the browser that your site should always be accessed over https. Using name-based virtual hosts on a secured connection requires careful configuration of the names specified in a single certificate or Tomcat 8.5 onwards where Server Name Indication (SNI) support is available. SNI allows multiple certificates with different names to be associated with a single TLS connector. ConfigurationPrepare the Certificate KeystoreTomcat currently operates
only on Each entry in a keystore is identified by an alias string. Whilst many keystore implementations treat aliases in a case insensitive manner, case
sensitive implementations are available. The To import an existing certificate into a To import an existing certificate signed by your own CA into a
For more advanced cases, consult the OpenSSL documentation. To create a new Windows:
Unix:
(The RSA algorithm should be preferred as a secure algorithm, and this also ensures general compatibility with other servers and components.) This command will create a new file, in the home directory of the user under which you run it, named " Windows:
Unix:
After executing this command, you will first be prompted for the keystore password. The default password used by Tomcat is " Next, you will be prompted for general information about this Certificate, such as company, contact name, and so on. This information will be displayed to users who attempt to access a secure page in your application, so make sure that the information provided here matches what they will expect. Finally, you will be prompted for the key password, which is the password specifically for this Certificate (as opposed to any
other Certificates stored in the same keystore file). The If everything was successful, you now have a keystore file with a Certificate that can be used by your server. Edit the Tomcat Configuration FileTomcat can use three different implementations of SSL:
The exact configuration details depend on which implementation is being used. If you configured Connector by specifying
generic Auto-selection of implementation can be avoided if needed. It is done by specifying a classname in the protocol attribute of the Connector. To define a Java (JSSE) connector, regardless of whether the APR library is loaded or not, use one of the following:
The OpenSSL JSSE implementation can also be configured explicitly if needed. If the APR library is installed (as for using the APR connector), using the sslImplementationName attribute allows enabling it. When using the OpenSSL JSSE implementation, the configuration can use either the JSSE attributes or the OpenSSL attributes (as used for the APR connector), but must not mix attributes from both types in the same SSLHostConfig or Connector element.
Alternatively, to specify an APR connector (the APR library must be available) use:
If you are using APR or JSSE OpenSSL, you have the option of configuring an alternative engine to OpenSSL.
The default value is
Also the
So to enable OpenSSL, make sure the SSLEngine attribute is set to something other than SSLRandomSeed allows to specify a source of entropy. Productive system needs a reliable source of entropy but entropy may need a lot of time to be collected therefore test systems could use no blocking entropy sources like "/dev/urandom" that will allow quicker starts of Tomcat. The final step is to configure the Connector in the
Note: If tomcat-native is installed, the configuration will use JSSE with an OpenSSL implementation, which supports either this configuration or the APR configuration example given below. The APR connector uses different attributes for many SSL settings, particularly keys and certificates. An example of an APR configuration is:
The configuration options and information on which attributes are mandatory, are documented in the SSL Support section of the HTTP connector configuration reference. Make sure that you use the correct attributes for the connector you are using. The NIO and NIO2 connectors use JSSE unless the JSSE OpenSSL implementation is installed (in which case it supports either the JSSE or OpenSSL configuration styles), whereas the APR/native connector uses APR. The If you change the port number here, you should also change the value specified for the After completing these configuration changes, you must restart Tomcat as you normally do, and you should be in business. You should be able to access any web application supported by Tomcat via SSL. For example, try: and you should see the usual Tomcat splash page (unless you have modified the ROOT web application). If this does not work, the following section contains some troubleshooting tips. To obtain and install a Certificate from a Certificate Authority (like verisign.com, thawte.com or trustcenter.de), read the previous section and then follow these instructions: Create a local Certificate Signing Request (CSR)In order to obtain a Certificate from the Certificate Authority of your choice you have to create a so called Certificate Signing Request (CSR). That CSR will be used by the Certificate Authority to create a Certificate that will identify your website as "secure". To create a CSR follow these steps:
Now you have a file called Importing the CertificateNow that you have your Certificate you can import it into you local keystore. First of all you have to import a so called Chain Certificate or Root Certificate into your keystore. After that you can proceed with importing your Certificate.
Each Certificate Authority tends to differ slightly from the others. They may require slightly different information and/or provide the certificate and associated certificate chain in different formats. Additionally, the rules that the Certificate Authorities use for issuing certificates change over time. As a result you may find that the commands given above may need to be modified. If you require assitance then help is available via the Apache Tomcat users mailing list. Using OCSP CertificatesTo use Online Certificate Status Protocol (OCSP) with Apache Tomcat, ensure you have downloaded, installed, and configured the Tomcat Native Connector. Furthermore, if you use the Windows platform, ensure you download the ocsp-enabled connector. To use OCSP, you require the following:
Generating OCSP-Enabled CertificatesApache Tomcat requires the OCSP-enabled certificate to have the OCSP responder location encoded in the certificate. The basic OCSP-related certificate authority settings in the
The settings above encode the OCSP responder address
Configuring OCSP ConnectorTo configure the OCSP connector, first verify that you are loading the Tomcat APR library. Check the
Apache Portable Runtime (APR) based Native library for Tomcat for more information about installation of APR. A basic OCSP-enabled connector definition in the
Starting OCSP ResponderApache Tomcat will query an OCSP responder server to get the certificate status. When testing, an easy way to create an OCSP responder is by executing the following:
Do note that when using OCSP, the responder encoded in the connector certificate must be running. For further information, see OCSP documentation . TroubleshootingAdditional information may be obtained about TLS handshake failures by configuring the dedicated TLS
handshake logger to log debug level messages by adding the following to
or
depending on the Connector being used. Here is a list of common problems that you may encounter when setting up SSL communications, and what to do about them.
If you are still having problems, a good source of information is the TOMCAT-USER mailing list. You can find pointers to archives of previous messages on this list, as well as subscription and unsubscription information, at https://tomcat.apache.org/lists.html. Using the SSL for session tracking in your applicationThis is a new feature in the Servlet 3.0 specification. Because it uses the SSL session ID associated with the physical client-server connection there are some limitations. They are:
To enable SSL session tracking you need to use a context listener to set the tracking mode for the context to be just SSL (if any other tracking mode is enabled, it will be used in preference). It might look something like:
Note: SSL session tracking is implemented for the NIO and NIO2 connectors. It is not yet implemented for the APR connector. Miscellaneous Tips and BitsTo access the SSL session ID from the request, use:
For additional discussion on this area, please see Bugzilla. To terminate an SSL session, use:
Note that this code is Tomcat specific due to the use of the SSLSessionManager class. This is currently only available for the NIO and NIO2 connectors, not the APR/native connector. |