Ssl On Tomcat 8.5

Posted onby admin
Ssl On Tomcat 8.5

Re: SSL connection Tomcat 8.5 Hello k, After a bit of setup and some testing internally I was able to get the SteamSensorConsole example from the.NET SDK to work correctly. Hello Apache Tomcat 8.5.23 Centos 7.4 (3.10.0-514.16.1.el7.x8664) Java 1.8.0152 (with jce) Running in Docker Container I'm upgrading our applications from Apache.

Seems a bit different as this is only occurring with SSL; Server version: Apache Tomcat/8.5.9 Server built: Dec 5 2016 20:18:12 UTC Server number: OS Name: Windows Server 2012 R2 OS Version: 6.3 Architecture: amd64 JVM Version: 1.8.0112-b15.

Apache Tomcat 8.5.23
Centos 7.4 (3.10.0-514.16.1.el7.x86_64)
Java 1.8.0_152 (with jce)
Running in Docker Container
I'm upgrading our applications from Apache Tomcat 8.0.47 to 8.5.23,
but when trying to get TLS/SSL working on a connector I get the
following error:
22-Nov-2017 11:52:46.098 SEVERE [main]
org.apache.coyote.AbstractProtocol.init Failed to initialize end point
associated with ProtocolHandler ['https-jsse-nio2-18443']
java.lang.IllegalArgumentException: the trustAnchors
parameter must be non-empty
at org.apache.coyote.AbstractProtocol.init(
at org.apache.coyote.http11.AbstractHttp11Protocol.init(
at org.apache.catalina.connector.Connector.initInternal(
at org.apache.catalina.util.LifecycleBase.init(
at org.apache.catalina.core.StandardService.initInternal(
at org.apache.catalina.util.LifecycleBase.init(
at org.apache.catalina.core.StandardServer.initInternal(
at org.apache.catalina.util.LifecycleBase.init(
at org.apache.catalina.startup.Catalina.load(
at org.apache.catalina.startup.Catalina.load(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.catalina.startup.Bootstrap.load(
at org.apache.catalina.startup.Bootstrap.main(
Caused by: the
trustAnchors parameter must be non-empty
... 20 more
I've changed the connector configuration to use
SSLHostConfig/Certificate, but our certificate generation process
(self signed certificates) has remained the same. I did a quick
internet search, and saw that other people had similar, but not exact
issues, and going back to 8.5.4 'solved' the issue. So I did this as a
quick test, so at least I could see that our configuration changes
where correct, and yes the application ran ok with Tomcat 8.5.4. The
connector configuration is:
<Connector port='${servers.port}'
maxThreads='150' SSLEnabled='true' scheme='https'
secure='true' server='Apache' maxPostSize='100000'>
<SSLHostConfig certificateVerification='none'
sslProtocol='TLSv1.2' protocols='TLSv1.2'
truststorePassword='${truststore.pass}' honorCipherOrder='true'
<Certificate certificateKeystoreFile='/usr/local/tomcat/ssl/server-keystore.p12'
Setting in CATALINA_OPTS and viewing the resultant
logging, seems to indicate that the certificate is being loaded, but
not the trust store, with the only truststore loaded coming from:
Best Regards
This email is sent on behalf of Northgate Public Services (UK) Limited and
its associated companies including Rave Technologies (India) Pvt Limited
(together 'Northgate Public Services') and is strictly confidential and
intended solely for the addressee(s).
If you are not the intended recipient of this email you must: (i) not
disclose, copy or distribute its contents to any other person nor use its
contents in any way or you may be acting unlawfully; (ii) contact
Northgate Public Services immediately on +44(0)1442 768445 quoting the name
of the sender and the addressee then delete it from your system.
Northgate Public Services has taken reasonable precautions to ensure that
no viruses are contained in this email, but does not accept any
responsibility once this email has been transmitted. You should scan
attachments (if any) for viruses.
Northgate Public Services (UK) Limited, registered in England and Wales
under number 00968498 with a registered address of Peoplebuilding 2,
Peoplebuilding Estate, Maylands Avenue, Hemel Hempstead, Hertfordshire, HP2
4NW. Rave Technologies (India) Pvt Limited, registered in India under
number 117068 with a registered address of 2nd Floor, Ballard House, Adi
Marzban Marg, Ballard Estate, Mumbai, Maharashtra, India, 400001.
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

SSL/TLS Configuration HOW-TO

Table of Contents

  • Configuration
  • Installing a Certificate from a Certificate Authority

Quick Start

The 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.

To install and configure SSL/TLS support on Tomcat, you need to followthese simple steps. For more information, read the rest of this HOW-TO.

  1. Create a keystore file to store the server's private key andself-signed certificate by executing the following command:



    and specify a password value of 'changeit'.

  2. Uncomment the 'SSL HTTP/1.1 Connector' entry in $CATALINA_BASE/conf/server.xml and modify as described in the Configuration section below.

Introduction to SSL/TLS

Transport Layer Security (TLS) and its predecessor, Secure Sockets Layer(SSL), are technologies which allow web browsers and web servers to communicateover a secured connection. This means that the data being sent is encrypted byone side, transmitted, then decrypted by the other side before processing.This is a two-way process, meaning that both the server AND the browser encryptall traffic before sending out data.

Another important aspect of the SSL/TLS protocol is Authentication. This meansthat during your initial attempt to communicate with a web server over a secureconnection, that server will present your web browser with a set ofcredentials, in the form of a 'Certificate', as proof the site is who and whatit claims to be. In certain cases, the server may also request a Certificatefrom your web browser, asking for proof that you are who you claimto be. This is known as 'Client Authentication,' although in practice this isused more for business-to-business (B2B) transactions than with individualusers. Most SSL-enabled web servers do not request Client Authentication.

SSL/TLS and Tomcat

Tomcat 8 windows 64

It is important to note that configuring Tomcat to take advantage ofsecure sockets is usually only necessary when running it as a stand-aloneweb server. Details can be found in theSecurity Considerations Document.When running Tomcat primarily as a Servlet/JSP container behindanother web server, such as Apache or Microsoft IIS, it is usually necessaryto configure the primary web server to handle the SSL connections from users.Typically, this server will negotiate all SSL-related functionality, thenpass on any requests destined for the Tomcat container only after decryptingthose requests. Likewise, Tomcat will return cleartext responses, that willbe encrypted before being returned to the user's browser. In this environment,Tomcat knows that communications between the primary web server and theclient are taking place over a secure connection (because your applicationneeds to be able to ask about this), but it does not participate in theencryption or decryption itself.


In order to implement SSL, a web server must have an associated Certificatefor each external interface (IP address) that accepts secure connections.The theory behind this design is that a server should provide some kind ofreasonable assurance that its owner is who you think it is, particularlybefore receiving any sensitive information. While a broader explanation ofCertificates is beyond the scope of this document, think of a Certificateas a 'digital driver's license' for an Internet address. It states whatcompany the site is associated with, along with some basic contactinformation about the site owner or administrator.

This 'driver's license' is cryptographically signed by its owner, and istherefore extremely difficult for anyone else to forge. For sites involvedin e-commerce, or any other business transaction in which authentication ofidentity is important, a Certificate is typically purchased from a well-knownCertificate Authority (CA) such as VeriSign or Thawte. Suchcertificates can be electronically verified -- in effect, the CertificateAuthority will vouch for the authenticity of the certificates that it grants,so you can believe that the Certificate is valid if you trust the CertificateAuthority that granted it.

In many cases, however, authentication is not really a concern. Anadministrator may simply want to ensure that the data being transmitted andreceived by the server is private and cannot be snooped by anyone who may beeavesdropping on the connection. Fortunately, Java provides a relativelysimple command-line tool, called keytool, which can easily createa 'self-signed' Certificate. Self-signed Certificates are simply usergenerated Certificates which have not been officially registered with anywell-known CA, and are therefore not really guaranteed to be authentic at all.Again, this may or may not even be important, depending on your needs.

General Tips on Running SSL

The first time a user attempts to access a secured page on your site,he or she is typically presented with a dialog containing the details ofthe certificate (such as the company and contact name), and asked if he or shewishes to accept the Certificate as valid and continue with the transaction.Some browsers will provide an option for permanently accepting a givenCertificate as valid, in which case the user will not be bothered with aprompt each time they visit your site. Other browsers do not provide thisoption. Once approved by the user, a Certificate will be considered validfor at least the entire browser session.

Also, while the SSL protocol was designed to be as efficient as securelypossible, encryption/decryption is a computationally expensive process froma performance standpoint. It is not strictly necessary to run an entireweb application over SSL, and indeed a developer can pick and choose whichpages require a secure connection and which do not. For a reasonably busysite, it is customary to only run certain pages under SSL, namely thosepages where sensitive information could possibly be exchanged. This wouldinclude things like login pages, personal information pages, and shoppingcart checkouts, where credit card information could possibly be transmitted.Any page within an application can be requested over a secure socket bysimply prefixing the address with https: instead ofhttp:. Any pages which absolutely requirea secure connection should check the protocol type associated with thepage request and take the appropriate action if https is notspecified.

Finally, using name-based virtual hosts on a secured connection can beproblematic. This is a design limitation of the SSL protocol itself. The SSLhandshake, where the client browser accepts the server certificate, must occurbefore the HTTP request is accessed. As a result, the request informationcontaining the virtual host name cannot be determined prior to authentication,and it is therefore not possible to assign multiple certificates to a singleIP address. If all virtual hosts on a single IP address need to authenticateagainst the same certificate, the addition of multiple virtual hosts should notinterfere with normal SSL operations on the server. Be aware, however, thatmost client browsers will compare the server's domain name against the domainname listed in the certificate, if any (applicable primarily to official,CA-signed certificates). If the domain names do not match, these browsers willdisplay a warning to the client user. In general, only address-based virtualhosts are commonly used with SSL in a production environment.


Prepare the Certificate Keystore


Tomcat currently operates only on JKS, PKCS11 orPKCS12 format keystores. The JKS formatis Java's standard 'Java KeyStore' format, and is the format created by thekeytool command-line utility. This tool is included in the JDK.The PKCS12 format is an internet standard, and can be manipulatedvia (among other things) OpenSSL and Microsoft's Key-Manager.

Each entry in a keystore is identified by an alias string. Whilst manykeystore implementations treat aliases in a case insensitive manner, casesensitive implementations are available. The PKCS11 specification,for example, requires that aliases are case sensitive. To avoid issues relatedto the case sensitivity of aliases, it is not recommended to use aliases thatdiffer only in case.

To import an existing certificate into a JKS keystore, please read thedocumentation (in your JDK documentation package) about keytool.Note that OpenSSL often adds readable comments before the key, butkeytool does not support that. So if your certificate hascomments before the key data, remove them before importing the certificate withkeytool.

To import an existing certificate signed by your own CA into a PKCS12keystore using OpenSSL you would execute a command like:

For more advanced cases, consult theOpenSSL documentation.

To create a new JKS keystore from scratch, containing a singleself-signed Certificate, execute the following from a terminal command line:



(The RSA algorithm should be preferred as a secure algorithm, and thisalso ensures general compatibility with other servers and components.)

This command will create a new file, in the home directory of the userunder which you run it, named '.keystore'. To specify adifferent location or filename, add the -keystore parameter,followed by the complete pathname to your keystore file,to the keytool command shown above. You will also need toreflect this new location in the server.xml configuration file,as described later. For example:



After executing this command, you will first be prompted for the keystorepassword. The default password used by Tomcat is 'changeit'(all lower case), although you can specify a custom password if you like.You will also need to specify the custom password in theserver.xml configuration file, as described later.

Next, you will be prompted for general information about this Certificate,such as company, contact name, and so on. This information will be displayedto users who attempt to access a secure page in your application, so makesure that the information provided here matches what they will expect.

Finally, you will be prompted for the key password, which is thepassword specifically for this Certificate (as opposed to any otherCertificates stored in the same keystore file). The keytool promptwill tell you that pressing the ENTER key automatically uses the same passwordfor the key as the keystore. You are free to use the same password or to selecta custom one. If you select a different password to the keystore password, youwill also need to specify the custom password in the server.xmlconfiguration file.

If everything was successful, you now have a keystore file with aCertificate that can be used by your server.

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.If you configured Connector by specifying genericprotocol='HTTP/1.1' then the implementation used by Tomcat ischosen automatically. 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 JavaJSSE implementation.

As configuration attributes for SSL support significantly differ betweenAPR vs. JSSE implementations, it is recommended toavoid auto-selection of implementation. It is done by specifying a classnamein the protocol attribute of the Connector.

To define a Java (JSSE) connector, regardless of whether the APR library isloaded or not, use one of the following:

Alternatively, to specify an APR connector (the APR library must be available) use:

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

The default value is

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.

SSLRandomSeed allows to specify a source of entropy. Productive system needs a reliable source of entropybut entropy may need a lot of time to be collected therefore test systems could use no blocking entropysources 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 theTomcat instance. An example <Connector> elementfor an SSL connector is included in the default server.xmlfile installed with Tomcat. To configure an SSL connector that uses JSSE, youwill need to remove the comments and edit it so it looks something likethis:

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 attributesare mandatory, are documented in the SSL Support section of theHTTP connector configurationreference. Make sure that you use the correct attributes for the connector youare using. The BIO, NIO and NIO2 connectors use JSSE whereas the APR/native connectoruses APR.

The port attribute is the TCP/IPport number on which Tomcat will listen for secure connections. You canchange this to any port number you wish (such as to the default port forhttps communications, which is 443). However, special setup(outside the scope of this document) is necessary to run Tomcat on portnumbers 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 asyou normally do, and you should be in business. You should be able to accessany web application supported by Tomcat via SSL. For example, try:

and you should see the usual Tomcat splash page (unless you have modifiedthe ROOT web application). If this does not work, the following sectioncontains some troubleshooting tips.

Installing a Certificate from a Certificate Authority

To obtain and install a Certificate from a Certificate Authority (like, thawte.comor, 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 choiceyou have to create a so called Certificate Signing Request (CSR). That CSR will be usedby the Certificate Authority to create a Certificate that will identify your websiteas 'secure'. To create a CSR follow these steps:

  • Create a local self-signed Certificate (as described in the previous section): Note: In some cases you will have to enter the domain of your website (i.e. in the field 'first- and lastname' in order to create a working Certificate.
  • The CSR is then created with:

Now you have a file called certreq.csr that you can submit to the Certificate Authority (look at thedocumentation of the Certificate Authority website on how to do this). In return you get a Certificate.

Ssl On Tomcat 8.5

Importing the Certificate

Now 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.

  • Download a Chain Certificate from the Certificate Authority you obtained the Certificate from.
    For commercial certificates go to:
    For trial certificates go to:
    For go to:
    For go to:
  • Import the Chain Certificate into your keystore
  • And finally import your new Certificate


Here is a list of common problems that you may encounter when setting upSSL communications, and what to do about them.

  • When Tomcat starts up, I get an exception like ' {some-directory}/{some-file} not found'.

    A likely explanation is that Tomcat cannot find the keystore file where it is looking. By default, Tomcat expects the keystore file to be named .keystore in the user home directory under which Tomcat is running (which may or may not be the same as yours :-). If the keystore file is anywhere else, you will need to add a keystoreFile attribute to the <Connector> element in the Tomcat configuration file.

  • When Tomcat starts up, I get an exception like ' Keystore was tampered with, or password was incorrect'.

    Assuming that someone has not actually tampered with your keystore file, the most likely cause is that Tomcat is using a different password than the one you used when you created the keystore file. To fix this, you can either go back and recreate the keystore file, or you can add or update the keystorePass attribute on the <Connector> element in the Tomcat configuration file. REMINDER - Passwords are case sensitive!

  • When Tomcat starts up, I get an exception like ' SSL handshake error No available certificate or key corresponds to the SSL cipher suites which are enabled.'

    A likely explanation is that Tomcat cannot find the alias for the server key within the specified keystore. Check that the correct keystoreFile and keyAlias are specified in the <Connector> element in the Tomcat configuration file. REMINDER - keyAlias values may be case sensitive!

  • My Java-based client aborts handshakes with exceptions such as 'java.lang.RuntimeException: Could not generate DH keypair' and ' Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)'

    If you are using the APR/native connector, starting with version 1.1.34 it will determine the strength of ephemeral DH keys from the key size of your RSA certificate. For example a 2048 bit RSA key will result in using a 2048 bit prime for the DH keys. Unfortunately Java 6 only supports 768 bit and Java 7 only supports 1024 bit. So if your certificate has a stronger key, old Java clients might produce such handshake failures. As a mitigation you can either try to force them to use another cipher by configuring an appropriate SSLCipherSuite and activate SSLHonorCipherOrder, or embed weak DH params in your certificate file. The latter approach is not recommended because it weakens the SSL security (logjam attack).

If you are still having problems, a good source of information is theTOMCAT-USER mailing list. You can find pointers to archivesof previous messages on this list, as well as subscription and unsubscriptioninformation, at

Ssl On Tomcat 8.5 Software

Using the SSL for session tracking in your application

This 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:

  • Tomcat must have a connector with the attribute isSecure set to true.
  • If SSL connections are managed by a proxy or a hardware accelerator they must populate the SSL request headers (see the SSLValve) so that the SSL session ID is visible to Tomcat.
  • If Tomcat terminates the SSL connection, it will not be possible to use session replication as the SSL session IDs will be different on each node.

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 BIO, NIO and NIO2 connectors. It is not yet implemented for the APR connector.

Miscellaneous Tips and Bits

To access the SSL session ID from the request, use:

For additional discussion on this area, please seeBugzilla.

Download Tomcat 8.5

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 BIO, NIO and NIO2 connectors, not the APR/native connector.

Ssl On Tomcat 8.5 Download

Notice: This comments section collects your suggestions on improving documentation for Apache Tomcat.
If you have trouble and need help, read Find Help page and ask your question on the tomcat-users mailing list. Do not ask such questions here. This is not a Q&A section.
The Apache Comments System is explained here. Comments may be removed by our moderators if they are either implemented or considered invalid/off-topic.