OpenSSL server sending certificate chain(inc. root cert) during handshake

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenSSL server sending certificate chain(inc. root cert) during handshake

Jason Schultz
I believe this behavior is common among all supported versions of OpenSSL, but most of my testing has been with OpenSSL 1.0.2, the latest LTS release.

My application using OpenSSL is acting as a server. I have a server certificate configured that has been signed by a self-signed/root certificate, so the chain is only the server certificate and the root certificate. The certificates were created using OpenSSL, for non-production use only. The server application is calling SSL_CTX_use_certificate_file() to load the server cert, residing in /etc/ssl/certs. 

Depending on what's in /etc/ssl/certs, the handshake behavior will show 1 of 2 things:

  1. If only the server certificate (and NOT the self-signed root cert) is in /etc/ssl/certs/, only the server certificate will be presented in the handshake.
  2. If the server AND self-signed root certificates are in /etc/ssl/certs/, the entire chain will be presented during the handshake. 
My questions deal with #2: Why does OpenSSL include the root cert in the certificate chain? Will the root cert be included in the chain any time it's in the same directory as the server cert? Is there a way, via API call, configuration, etc, to force OpenSSL to NOT send the root certificate as part of the chain in this case? Or is there something more basic I'm missing? Googling for answers has not proved fruitful as there are a lot of results, none of which pertain to my situation...although my google fu may be lacking.

Thanks in advance.

Reply | Threaded
Open this post in threaded view
|

Re: OpenSSL server sending certificate chain(inc. root cert) during handshake

Sam Roberts
The root cert is not used for validation, so it doesn't have to be
sent. However, sending it does no harm, and it is useful for humans
who are attempting to diagnose problems, it allows them to see what
what root cert they are expected to have locally for sucessful cert
chain validation.
Reply | Threaded
Open this post in threaded view
|

Re: OpenSSL server sending certificate chain(inc. root cert) during handshake

Jason Schultz
Right, I realize it doesn't have to be sent, my questions are why is it sent and is there a way to force OpenSSL to not send it?

You may have answered the first question as to "why?". But is OpenSSL doing this just to make problems easier to diagnose? Are there other reasons?

More importantly, can I force OpenSSL to not send the root cert?

Thanks,

Jason



From: Sam Roberts <[hidden email]>
Sent: Friday, May 31, 2019 7:32 PM
To: Jason Schultz
Cc: [hidden email]
Subject: Re: OpenSSL server sending certificate chain(inc. root cert) during handshake
 
The root cert is not used for validation, so it doesn't have to be
sent. However, sending it does no harm, and it is useful for humans
who are attempting to diagnose problems, it allows them to see what
what root cert they are expected to have locally for sucessful cert
chain validation.
Reply | Threaded
Open this post in threaded view
|

Re: OpenSSL server sending certificate chain(inc. root cert) during handshake

Viktor Dukhovni
In reply to this post by Jason Schultz
> On May 31, 2019, at 3:20 PM, Jason Schultz <[hidden email]> wrote:
>
> My questions deal with #2: Why does OpenSSL include the root cert in the certificate chain?

The OpenSSL SSL_CTX_build_cert_chain(3) function constructs a complete
chain of trust for your certificate chain, based on the configured trust
stores (CAfile and/or CApath).  If you call this function, then you can
control how your certificates chain is augmented.

But if your EE certificate is the entire chain, then the internal automatic
chain construction code will assume that the chain was not built, and will
try to augment it unless you set the SSL_MODE_NO_AUTO_CHAIN flag via:

  SSL_CTX_set_mode(3), or
  SSL_set_mode(3)

[ Which really ought to also document SSL_MODE_NO_AUTO_CHAIN ]

> Will the root cert be included in the chain any time it's in the same directory
> as the server cert?

No, the chain is augmented based on the configured trust stores, and does
not directly consider the directory holding the chain file.

> Is there a way, via API call, configuration, etc, to force OpenSSL to NOT send the
> root certificate as part of the chain in this case?

You can set a CAfile/CApath that do not include the location of the root
cert, or disable automatic chain construction, and build the chain just
the way you like it via SSL_CTX_build_cert_chain(3), possibly passing the
SSL_BUILD_CHAIN_FLAG_NO_ROOT flag.

--
        Viktor.