tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: JKS certificate for Tomcat client authentication
Date Mon, 26 Feb 2018 14:56:42 GMT
Hash: SHA256


On 2/23/18 5:47 PM, Igor Cicimov wrote:
> On Sat, Feb 24, 2018 at 7:52 AM, Christopher Schultz < 
>> wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
>> Igor,
>> On 2/23/18 4:45 AM, Igor Cicimov wrote:
>>> Hi all,
>>> I have the following setup in the tomcat default file on 
>>> Ubunntu-14.04:
The keystore.jks holds dozen of SSL keys our app uses to
>>> authenticate to various web services. One of these
>>> certificates expired and I used openssl to create new private
>>> key (key.pem) and CSR, that the other side signed and sent back
>>> (cert.pem). Then I concatenated the certificate and the private
>>> key into single file:
>>> $ cat cert.pem key.pem > cert2.pem
>>> and imported the file into the existing keystore using
>>> keytool:
>>> $ keytool -delete -alias client-cert -keystore keystore.jks 
>>> -storepass xxxx $ keytool -import -alias client-cert -file 
>>> cert2.pem -keystore keystore.jks -storepass xxxx
>>> The signing root CA and the intermediate certificate already
>>> exist in the truststore.jks keystore.
>>> Does this procedure sound sane? Is there a better (or maybe
>>> proper) way of doing it?
>> Are you just sanity-checking your process for importing certs
>> into a JKS bundle?
> I'm just sanity-checking the process in terms of keystore
> functionality and any possible issues for the JVM using and finding
> the cert and the key in the store.
> The reason being after importing the new cert our access does not
> work any more and the issuer has a limited (as they say, *sigh*)
> troubleshooting capability on their side. Not sure how is that
> possible having in mind that they have designed and are in control
> of the authentication (ssl client certs) and authorization
> (username/password) system (Tivoli Axis2 app if that matters).
> Building something and then not being able to tell clients if their
> access is denied due to bad/missing certificate or bad/missing 
> credentials is just unbelievable. They even claim they can't even
> see our side connecting at all to their web service although in our
> logs I can see:
> Invalid Content-Type:text/html. Is this an error message instead of
> a SOAP response?
> response coming back but as html error message instead of SOAP
> response.

You could try my ssltest tool. It supports client TLS authentication.
Maybe just a sanity-check that there isn't anything wrong with your
own Java client:

Also, since you have the original (separate) key and (signed)
certificate files, definitely give this a try:

$ openssl s_client \
    -showcerts \
    -cert cert.pem \
    -key key.pem \
    -connect [endpoint]

If you can't connect using that, then either the cert or the key is
not correct. OpenSSL should tell you if the key doesn't match the
cert, or if the password is wrong.

If you remove the -cert and -key arguments and try to connect, the
service ought to tell you which certificates are acceptable. It will
probably tell you that anything signed by a particular certificate is
okay and not your particular certificate (otherwise, they'd have a
million certs they trust).

Once you can confirm that the crypto material you have (key, certs),
then you can use ssltest above to see if you have packaged those bits
into the keystore properly. You might want to use a separate keystore
for this testing purpose, just in case something else is interfering.

Theoretically, as long as your keystore contains:

1. The signing (or, more likely, the "intermediate") certificate
2. The signed certificate
3. The signed certificate's private key

You ought to be able to connect. You don't really even need a
certificate "alias", though things "seem" to work better when they are

>> Does the process result in the items you expected to be in the
>> keystore?
>> From what I can see all the bits are there. I have enabled the
>> java ssl
> debugging and can see the cert being loaded on startup and
> exchanged during SSL handshake and no errors can be seen in the
> process, like the usual PKIX error when matching cert can not be
> found etc.
> Any ideas what can be possibly wrong?

Lots of things:

1. Wrong cert in the store (unsigned versus signed, though if you are
using openssl for everything you usually don't have an unsigned
cert... only the CSR).

2. Missing intermediate certificate. This can be easy to do if you
have a keystore with lots of stuff in it. Perhaps the service has
rotated their intermediate certificate and your newly-issued
certificate was signed with a certificate newer than the one already
in your keystore.

3. Mismatched key/cert.

4. Certificate needs an "alias" for some reason? But you are providing
one, so ... probably not this.

5. Can't negotiate some other part of the TLS connection. Maybe they
only support TLSv1.2 or something? Or no cipher suites in common?
OpenSSL should tell you what's up.

>> I'd personally be very paranoid if the JKS file was the only
>> place all of those key/cert pairs were stored, because of my
>> (bad) experience using JKS keystores in the past. Thankfully,
>> Oracle is finally deprecating them and making the default
>> keystore type PKCS12 in the future. JKS (and it's surprisingly
>> extant cousin, JSEKS) never should have existed.
> Yeah I saw some warning messages with the latest Oracle jdk-1.8_161
> about JKS being deprecated in favour of PKCS12 when I use keytool
> on the servers. I never saw those before at least not for jdk-1.7
> for sure.

IIRC, PKCS12 has always been supported by the JVM. So if you'd like to
switch from one format to another, you should have no trouble. Once
you get it working /at all/, that is.

IMHO, you should try to use separate keystores for separate services
if you can manage it. So if you connect to 5 services which require
mutual TLS authentication, I'd have 5 separate keystores which only
contain the bits required to connect to that one service.

I'd do that for several reasons, but one of those reasons is that at
some point, you'll need to completely change what's in the keystore
(new key/certicicate, new intermediate cert from the issuer, etc.) and
you won't know what you can remove safely if it's an all-in-one
bundle. Over time, you'll end up with 100 certificates that you aren't
sure if you need anymore.

Anytime I have code, configuration, etc. that I'm "afraid" to touch
for fear of breaking something, it's a red flag that it's not being
maintained properly. Separate keystores are much easier to maintain.

- -chris
Comment: GPGTools -
Comment: Using GnuPG with Thunderbird -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message