I'm trying to connect to a secure webservice.
I was getting a handshake failure even though my keystore and truststore have been set correctly.
After several days of frustration, endless googling and asking everyone around I found out that the only problem was that java chose not to send the client certificate to the server during the handshake.
Specifically:
- Server requested a client certificate (CN=RootCA) - i.e. "give me a cert that is signed by the root CA"
- Java looked into the keystore and only found my client certificate which is signed by the "SubCA", which in turn is issued by the "RootCA". It didn't bother to look into the truststore...duh OK I guess
- Sadly when I tried to add the "SubCA" certificate to the keystore, that didn't help at all. I did check if the certificates get loaded into the keystore. They do, but the KeyManager ignores all certificates except the client one.
- All of the above leads to the fact that java decides it doesn't have any certificates that satisfy the server's request and sends nothing...tadaaa handshake failure :-(
My questions:
- Is it possible that I added the "SubCA" certificate to the keystore in a manner that "broke the certificate chain" or something so that the KeyManager only loads the client certificate and ignores the rest? (Chrome and openssl manage to figure that out so why can't java? - note that the "SubCA" cert is always presented separately as the trusted authority so Chrome apparently correctly packs it along with the client cert during handshake)
- Is this a formal "configuration issue" on the server side? The server is a third party. I would expect the server to request a certificate signed by the "SubCA" authority since that's what they provided us with. I suspect that the fact that this works in Chrome and openssl is because they are "less restrictive" and java just goes "by the book" and fails.
I did manage to put together a dirty workaround for this, but I'm not very happy about it so I'll be glad if anyone can clarify this one for me.
Question&Answers:os