Java SSLSocket: How to send full server cert chain

2019-02-27 11:50发布

问题:

When I create an SSLServerSocket in Java 7 the server correctly uses my server certificate and key. The certificate was issued by a sub-ca of a ca. Therefore the complete chain from the root cert to the server cert has four certificates. The complete chain is present in the keystore/truststore.

However when a client connects the server always sends only the server certificate itself. This also applies to Java based web servers like Jetty.

Because most clients have only the root ca certificate installed and not the two sub-ca certificates this is a big problem.

How can I force Java to send the full certificate chain in the SSL/TLS handshake?

回答1:

A key entry in a keystore isn't just for a single certificate, but for a certificate chain (see KeyStore.setKeyEntry, which takes a Certificate[] chain parameter).

If you want a specific chain to be used, it needs to be set up as a chain in the entry where you have the certificate and its private key. Whether the intermediate certificates are also in the same keystore, in different entries doesn't really matter.

This is a very similar problem to getting a client to send the full client-certificate chain. The same keystore configuration steps should also work from a server point of view, as described in this question.