Re: JKS certificate for Tomcat client authentication

2018-03-17 Thread Igor Cicimov
Hi Chris,

On Tue, Feb 27, 2018 at 1:56 AM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> Igor,
>
> On 2/23/18 5:47 PM, Igor Cicimov wrote:
> > On Sat, Feb 24, 2018 at 7:52 AM, Christopher Schultz <
> > ch...@christopherschultz.net> 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:
> >>>
> >>> JAVA_OPTS="$JAVA_OPTS
> >>> -Djavax.net.ssl.keyStore=/opt/encompass/keystore/keystore.jks"
> >>> JAVA_OPTS="$JAVA_OPTS
> >>> -Djavax.net.ssl.trustStore=/opt/encompass/keystore/truststore.jks"
> >>>
> >>>
> >>>
> 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  $ keytool -import -alias client-cert -file
> >>> cert2.pem -keystore keystore.jks -storepass 
> >>>
> >>> 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:
>
> https://github.com/ChristopherSchultz/ssltest
>
> 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
> present.
>
> >> 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 

Re: JKS certificate for Tomcat client authentication

2018-02-26 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Igor,

On 2/23/18 5:47 PM, Igor Cicimov wrote:
> On Sat, Feb 24, 2018 at 7:52 AM, Christopher Schultz < 
> ch...@christopherschultz.net> 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:
>>> 
>>> JAVA_OPTS="$JAVA_OPTS 
>>> -Djavax.net.ssl.keyStore=/opt/encompass/keystore/keystore.jks" 
>>> JAVA_OPTS="$JAVA_OPTS 
>>> -Djavax.net.ssl.trustStore=/opt/encompass/keystore/truststore.jks"
>>>
>>>
>>> 
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  $ keytool -import -alias client-cert -file 
>>> cert2.pem -keystore keystore.jks -storepass 
>>> 
>>> 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:

https://github.com/ChristopherSchultz/ssltest

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

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

Re: JKS certificate for Tomcat client authentication

2018-02-23 Thread Igor Cicimov
Hi Chris,

On Sat, Feb 24, 2018 at 7:52 AM, Christopher Schultz <
ch...@christopherschultz.net> 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:
> >
> > JAVA_OPTS="$JAVA_OPTS
> > -Djavax.net.ssl.keyStore=/opt/encompass/keystore/keystore.jks"
> > JAVA_OPTS="$JAVA_OPTS
> > -Djavax.net.ssl.trustStore=/opt/encompass/keystore/truststore.jks"
> >
> > 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  $ keytool -import -alias client-cert -file
> > cert2.pem -keystore keystore.jks -storepass 
> >
> > 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.


> 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?


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


> - -chris
>

Thanks,
Igor


Re: JKS certificate for Tomcat client authentication

2018-02-23 Thread Christopher Schultz
-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:
> 
> JAVA_OPTS="$JAVA_OPTS 
> -Djavax.net.ssl.keyStore=/opt/encompass/keystore/keystore.jks" 
> JAVA_OPTS="$JAVA_OPTS 
> -Djavax.net.ssl.trustStore=/opt/encompass/keystore/truststore.jks"
> 
> 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  $ keytool -import -alias client-cert -file
> cert2.pem -keystore keystore.jks -storepass 
> 
> 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?

Does the process result in the items you expected to be in the keystore?

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.

- -chris
-BEGIN PGP SIGNATURE-
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlqQfxMACgkQHPApP6U8
pFgyEA/9E8xItsOkifnpYSqvxfiFsJzLbEQRU7TiIAqqwl3rD0uhDkulnUHtO0h7
mk9bekd7YuWFu3JSm8ht2HklyDbTkEJyRJLHcQupLXE3mj427neeTT2p1oOJxwwu
nuMJ9NQw2Nofas3TlyyvkkIfZddk/Afuq7D4JuXgnKU6DPc2I9YB0RxsMnPmVCn9
ApiGWakOnxeLapAGHdYXg+e1qDOmuYn0VLkr3hkrS07cPuzRTKjmCVBrI8locpUx
MOBYtdEF8rKmEWvTzJI0EM43FEGQaamKaYxBo4LLT0esaE1sM9D8tU/ckgsmTWWN
6pjO4JI0d/yXmeMuTtdspvdoXiLDtJz/krHFI/wPILO8ABMWToAMNSxZJI/s8c4T
CImCz6YJ+K+lLi3638Pz7cQ8V6KXgHaOsj7aaB4jqWyF/Z1heZUg+8xJYX2xo3cn
11br7rXWX5cFPJr7QeS/nZU194/SdGxe2XvpVgCnb6cXVgLd9UKPO/8htp6PmBya
t7RAEE25o/I0ew/ankjRxqz3iwcVWjRZF+r83gisaj3ZltJ+pJx9PPsc9Kd+gc0f
c/iscO/Bt9Jyb/lcJzR1lZ0EMU70RLhLrtGFPYd99Lp5ONsgnYgG3+7NdE5Jw01p
MMy5zTlN8Mm5/xQjopECn3Bfl385UH6dbtLlK/sPZaVElwhySxM=
=F4jp
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org