LogIn

Tomcat

Edit the Tomcat Configuration File

Tomcat can use two different implementations of SSL:

  • the JSSE implementation provided as part of the Java runtime (since 1.4)
  • the APR implementation, which uses the OpenSSL engine by default.
The exact configuration details depend on which implementation is being used. The implementation used by Tomcat is chosen automatically unless it is overriden as described below. If the installation uses APR - i.e. you have installed the Tomcat native library - then it will use the APR SSL implementation, otherwise it will use the Java JSSE implementation.

To avoid auto configuration you can define which implementation to use 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 do:

\"\"\"\"\"\"
\"\"
<-- Define a blocking Java SSL Coyote HTTP/1.1 Connector on port 8443 -->
<Connector protocol=\"org.apache.coyote.http11.Http11Protocol\"
           port=\"8443\" .../>

<-- Define a non-blocking Java SSL Coyote HTTP/1.1 Connector on port 8443 -->
<Connector protocol=\"org.apache.coyote.http11.Http11NioProtocol\"
           port=\"8443\" .../>
\"\"
\"\"\"\"\"\"
Alternatively, to specify an APR connector (the APR library must be available) use:
\"\"\"\"\"\"
\"\"
<-- Define a APR SSL Coyote HTTP/1.1 Connector on port 8443 -->
<Connector protocol=\"org.apache.coyote.http11.Http11AprProtocol\"
           port=\"8443\" .../>
\"\"
\"\"\"\"\"\"

If you are using APR, you have the option of configuring an alternative engine to OpenSSL.

\"\"\"\"\"\"
\"\"
<Listener className=\"org.apache.catalina.core.AprLifecycleListener\"
          SSLEngine=\"someengine\" SSLRandomSeed=\"somedevice\" />
\"\"
\"\"\"\"\"\"
The default value is
\"\"\"\"\"\"
\"\"
<Listener className=\"org.apache.catalina.core.AprLifecycleListener\"
          SSLEngine=\"on\" SSLRandomSeed=\"builtin\" />
\"\"
\"\"\"\"\"\"
So to use SSL under APR, make sure the SSLEngine attribute is set to something other than off. The default value is on and if you specify another value, it has to be a valid engine name.
If you haven\'t compiled in SSL support into your Tomcat Native library, then you can turn this initialization off
\"\"\"\"\"\"
\"\"
<Listener className=\"org.apache.catalina.core.AprLifecycleListener\"
          SSLEngine=\"off\" />
\"\"
\"\"\"\"\"\"
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 $CATALINA_BASE/conf/server.xml file, where $CATALINA_BASE represents the base directory for the Tomcat 6 instance. An example <Connector> element for an SSL connector is included in the default server.xml file installed with Tomcat. For JSSE, it should look something like this:

\"\"\"\"\"\"
\"\"
<-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!--
<Connector 
           port=\"8443\" maxThreads=\"200\"
           scheme=\"https\" secure=\"true\" SSLEnabled=\"true\"
           keystoreFile=\"${user.home}/.keystore\" keystorePass=\"changeit\"
           clientAuth=\"false\" sslProtocol=\"TLS\"/>
-->
\"\"
\"\"\"\"\"\"

The example above will throw an error if you have the APR and the Tomcat Native libraries in your path, as Tomcat will try to use the APR connector. The APR connector uses different attributes for SSL keys and certificates. An example of an APR configuration is:

\"\"\"\"\"\"
\"\"
<-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!--
<Connector 
           port=\"8443\" maxThreads=\"200\"
           scheme=\"https\" secure=\"true\" SSLEnabled=\"true\"
           SSLCertificateFile=\"/usr/local/ssl/server.crt\" 
           SSLCertificateKeyFile=\"/usr/local/ssl/server.pem\"
           clientAuth=\"optional\" SSLProtocol=\"TLSv1\"/>
-->
\"\"
\"\"\"\"\"\"

You will note that the example SSL connector elements are commented out by default. You can either remove the comment tags from around the the example SSL connector you wish to use or add a new Connector element of your own. In either case, you will need to configure the SSL Connector for your requirements and environment. The configuration options and information on which attributes are mandatory for the JSSE based connectors (BIO and NIO) are documented in the SSL Support section of the HTTP connector configuration reference. The configuration options and information on which attributes are mandatory for the APR connector are documented in the HTTPS section of the APR How-To.

The port attribute (default value is 8443) is the TCP/IP port number on which Tomcat will listen for secure connections. You can change this to any port number you wish (such as to the default port for https communications, which is 443). However, special setup (outside the scope of this document) is necessary to run Tomcat on port numbers lower than 1024 on many operating systems.

If you change the port number here, you should also change the value specified for the redirectPort attribute on the non-SSL connector. This allows Tomcat to automatically redirect users who attempt to access a page with a security constraint specifying that SSL is required, as required by the Servlet Specification.

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:

\"\"\"\"\"\"
\"\"
https://localhost:8443
\"\"
\"\"\"\"\"\"

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.