0

I don't have to fix something that doesn't work, but I try to understand why something works, because I think it should not work.

I'm using OpenJDK11 / Ubuntu 16.04. I make an HTTPS call. The SSL handshake succeeds.

The cert chain contains 3 certs:

  • API certificate of course. Issued by an intermediate CA (issuer = CN = DigiCert TLS RSA SHA256 2020 CA1,O = DigiCert Inc,C = US)
  • Intermediate CA certificate. Issued by a root CA (issuer = CN = DigiCert Global Root CA,OU = www.digicert.com,O = DigiCert Inc,C = US)
  • Root certificate

The second certificate is not available in the cacert keystore in use (default keystore under lib/security folder). This sounds quite normal as the cert was issued in April 2021, while the JRE was released on January 2021 (openjdk version "11.0.10" 2021-01-19)

Why can this handshake succeed? In my mind, as Java doesn't know the second certificate, it can not validate the API certificate.

  • 3
    IIRC (but my TLS/SSL is a bit rusty, so I might be wrong), your API sends the entire certificate chain, so as that includes the intermediate certificate, Java can verify it. As an aside, the latest OpenJDK is 11.0.12, you might want to upgrade. – Mark Rotteveel Oct 01 '21 at 12:43
  • I think what Mark is right: It's up to the server presenting the certificate to also provide necessary intermediate certificates. The best bet is to always send all known chains going to all known root certificates. This way if the client knows any of the root certificates, it's fine. – Joachim Sauer Oct 01 '21 at 12:45
  • To be exact, TLS (and SSL) specifications require the server to send the full chain except it may omit the root (and if the root _is_ sent that copy is not used, only the one in the client's truststore); you can use `keytool -printcert -sslserver host[:port]` to see exactly what your server sends. In addition certs from most public CAs for over a decade include the AIA (AuthorityInfoAccess) extension with a caIssuer field, which can be used to dynamically fetch intermediate cert(s); browsers often do this automatically, while Java/JCE doesn't by default but can be configured to. – dave_thompson_085 Oct 02 '21 at 18:31
  • Thanks a lot. Effectively, i wrote a little java program to see what certificates are sended by the server, and the intermediate cert is sended. I thought, but it was an error, that the jvm had to get the intermediate cert into the trusttore in order to read his public key and validate the site cert. It was a mistake. – Damien Tacheron Oct 04 '21 at 07:19

1 Answers1

-1

In order to validate the server certificate during the ssl handhshake phase, the http client needs the certificate which was used to sign the server certificate (the intermediate certificate), and the certificate which was used to sign the intermediate certificate (root certificate).

All these certificates constitute what is known as "the chain of certification". There is usually one intermediate certificate, sometimes there is no intermediate certificate (server cert signed directly by the root certificate), or you could have many intermediate certificates.

JCE/JSE needs all these certificates for validating the server identity. If one certificate is missing (generaly the root certificate), or perempted, or invalid, or under some circumstances due to network failures or bad server setup, java throws a SSLHandshakeException.

Java looks for the root certificate in his trusted store (according to the JRE setup : there are defaults, they can be overrided by differents ways) The server certificate is sended by the server.

I thought that the intermediate certificate has to be present also in the java trusted store. This was a mistake. In fact, the intermediate certificate is sended by the server also.

i hadn't a SSLHandhakeException while the intermediate certificate was not present in the java trust store, so i didn't understood. After speaking here, and writing some lines of java to read what is sended by the server, i understand now that the intermediate certificate is sended by the server.

So, you don't need to have the intermediate(s) certificate(s) in java trust store for the ssl handhsake to succeed.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 06 '21 at 14:07
  • done. more details added – Damien Tacheron Dec 12 '21 at 11:30