Use a PFX file with Tomcat

A PFX file is a PKCS#12 keystore. Tomcat can use it without conversion. Problems usually come from the alias, a missing certificate chain or an export without the private key.

Use the PFX directly

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           SSLEnabled="true" maxThreads="150">
  <SSLHostConfig protocols="TLSv1.2+TLSv1.3">
    <Certificate certificateKeystoreFile="conf/server.pfx"
                 certificateKeystoreType="PKCS12"
                 certificateKeystorePassword="password-from-export" />
  </SSLHostConfig>
</Connector>

Without certificateKeyAlias, Tomcat takes the first key in the file. That almost always works, because a PFX holds only one key.

What is in the file?

keytool -list -v -keystore server.pfx -storetype PKCS12 | grep -E "Alias|Entry type|chain length"

It is easier in the certificate converter or the Java keystore helper: drop the file in, enter the password, view the contents.

Export correctly from Windows

  1. Open certlm.msc, select the certificate under Personal → Certificates, right-click → All Tasks → Export.
  2. Choose “Yes, export the private key”. If the option is greyed out, the key was created as non-exportable. Then only a new certificate helps.
  3. Tick “Include all certificates in the certification path if possible”. That puts the intermediates in the file.
  4. Set a password. For encryption, “TripleDES-SHA1” works everywhere. “AES256-SHA256” is more modern, but very old Java 8 versions cannot read it.

Complete a missing chain

If the intermediates are missing, repackage the PFX with OpenSSL:

openssl pkcs12 -in server.pfx -nodes -out all.pem          # add -legacy if needed
openssl pkcs12 -export -in all.pem -certfile intermediate.crt \
  -name tomcat -out server-new.p12

Or without a command line: the certificate converter adds the intermediates automatically and saves a new PFX.

Typical error messages

How keystores work in Tomcat in general is in the article configure a keystore in Tomcat.

FAQ

Do I have to convert the PFX to JKS?

No. Tomcat reads PKCS#12 directly; since Java 9 it is even the default format.

Can I use the same PFX for IIS and Tomcat?

Yes, if the name in the certificate matches. Both read the same format.

OpenSSL says “unsupported” when opening the PFX.

Older Windows exports use RC2 encryption, which OpenSSL 3 only reads with -legacy. Tomcat or Java can usually open the file anyway.

Sources and documentation