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

Jason Schultz jetson23 at
Fri Mar 20 15:21:50 UTC 2020

I apologize for bringing this old subject back up, but I'm running into something I wanted to poll the list on.

Based on Victor's email below, I am doing the following in my application to set up my server to send a certificate chain *excluding* the root certificate during a handshake.

status = SSL_CTX_set_mode(ctx, SSL_MODE_NO_AUTO_CHAIN);
status = SSL_CTX_build_cert_chain(ctx, SSL_BUILD_CHAIN_FLAG_NO_ROOT);

When I configure a certificate chain, the server sends the chain, excluding the root. The call to SSL_CTX_build_cert_chain() accomplishes this, with the "no root" flag. This works as expected.

The interesting part comes in when I am configuring a self-signed certificate as the server cert.

** NOTE **: I know this isn't recommended, this is ONLY for test purposes, and our users will configure servers in this way, also ONLY for test purposes. This is why I'm testing the operation of this configuration.

As Victor indicated, my EE certificate is also the entire chain; of 1 self-signed certificate. Setting the SSL_MODE_AUTO_CHAIN flag allowed me to configure a self-signed certificate on the server, the two calls above succeed, and my server sends that single, self-signed cert in the handshake. This is true for version 3 self-signed certificates, with the CA bit set.

If I have a version 1 *RSA* certificate, with the CA bit NOT set(so CA:FALSE), the call to SSL_CTX_build_cert_chain() errors. I think this is the expected behavior. Does everyone agree with that? Since OpenSSL 1.1.1 is more strict regarding the CA bit, the building of the "chain" will fail because a self-signed cert MUST have CA:TRUE.

The incorrect behavior I think I'm seeing is when configuring a self-signed ECDSA certificate. I'll paste the certificate below, but I would think this version 1 certificate that does NOT have CA:TRUE would error in the same was the similar RSA certificate did above. Does anyone know what could be the result of the (seemingly) different behavior? Are there any other tests I could try to lead me to an answer?



TEST:/etc/ssl # openssl x509 -text -noout -in certs/ecdsacert.pem
        Version: 1 (0x0)
        Serial Number:
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C=US, ST=State, L=City, O=Company, OU=Networking, CN=COMMON-NAME/emailAddress=john.doe at
            Not Before: Mar 17 18:23:09 2020 GMT
            Not After : Mar 17 18:23:09 2021 GMT
        Subject: C=US, ST=State, L=City, O=Company, OU=Networking, CN=COMMON-NAME/emailAddress=john.doe at
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
    Signature Algorithm: ecdsa-with-SHA256

From: openssl-users <openssl-users-bounces at> on behalf of Viktor Dukhovni <openssl-users at>
Sent: Friday, May 31, 2019 9:44 PM
To: openssl-users at <openssl-users at>
Subject: Re: OpenSSL server sending certificate chain(inc. root cert) during handshake

> On May 31, 2019, at 3:20 PM, Jason Schultz <jetson23 at> 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

[ 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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the openssl-users mailing list