FreeKB - Tomcat Encrypt outbound requests (SSL / TLS / truststore)
Tomcat - Encrypt outbound requests (SSL / TLS / truststore)

First and foremost, it's important to recongize that an application running on Tomcat will have both inbound and outbound requests. Typically, an inbound request is when a remote system makes a request for some resource from an app deployed to Tomcat. Typically, and outbound request is when an app deployed to Tomcat needs to go out, such as when making a query to a remote SQL database. This article only deals with securing outbound requests. Refer to this article to secure inbound requests.


Inbound requests use a keystore to secure the requests. Outbound requests use a truststore to trust the connection between the app running on Tomcat and the remote system. So, when you see keystore, think "inbound" and when you see truststore think "outbound".


As an example, let's say your app running on Tomcat needs to download the foo.txt file from over a secured HTTPS connection. If the Tomcat app is NOT configured to trust, the Tomat catalina.out logs should contain something like this. PKIX path building failed: unable to find valid certification path to requested target


In this scenario, you will first need to create a trust store file, such as trust.jks or cacerts.p12 (it can be named anything you want), which can be done using the Java keytool command.

keytool -keystore trust.p12 -storetype pkcs12 -storepass itsasecret -genkey -alias placeholder -keyalg RSA -keysize 2048


Then remove the private key that was created in trust.p12.

keytool -keystore trust.p12 -storetype pkcs12 -storepass itsasecret -delete -alias placeholder


You will then obtain the public certificate for and then import the certificate into the trust store.

keytool -keystore trust.p12 -storetype pkcs12 -storepass itsasecret -import -alias -file


You will then need to configure your Tomcat application server to use the trust store file. This is often done by adding the following key value pairs to the JAVA_OPTS variable in ${tomcat_install_root}/bin/




You may want to all so the following debug parameter.



And then restart your Tomcat application server for this change to take effect.



Now, your Tomcat app should be able to download the foo.txt file from over HTTPS.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 2712c in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |