1

My SSL server uses the following certificate setup: leaf -> intermediate -> root (trusted ca). I have verified using openssl that it's returning both leaf and intermediate certificate (at least I think it does):

$ openssl s_client -showcerts -connect <SSL server endpoint>

depth=2 CN = root-cn - 1537386011
verify return:1
depth=1 OU = intermediate-ou, CN = intermediate-cn
verify return:1
depth=0 OU = leaf-ou, CN = leaf-cn
verify return:1
CONNECTED(00000003)
---
Certificate chain
 0 s:/OU=leaf-ou/CN=leaf-cn
   i:/OU=intermediate-ou/CN=intermediate-cn
-----BEGIN CERTIFICATE-----
<leaf certificate>
-----END CERTIFICATE-----
 1 s:/OU=intermediate-ou/CN=intermediate-cn
   i:/CN=root-cn - 1537386011
-----BEGIN CERTIFICATE-----
<intermediate certificate>
-----END CERTIFICATE-----
---
Server certificate
subject=/OU=leaf-ou/CN=leaf-cn
issuer=/OU=intermediate-ou/CN=intermediate-cn
---
Acceptable client certificate CA names
..
/CN=root-cn - 1537386011
..
---
SSL handshake has read 17882 bytes and written 427 bytes
---

But, when I attempt to use curl specifying only root certificate as cacert with a client certificate issued by intermediate issuer, SSL handshake fails with the error SSL peer had some unspecified issue with the certificate it received/SSL_ERROR_CERTIFICATE_UNKNOWN_ALERT.

(I'm running the curl command on the same host the server, hence the CN name in the client certificate matches with that of server).

$ curl -k -v --cacert <root-ca> --cert <client cert> --key <client cert key> <endpoint>

*   CAfile: <cafile>
* skipping SSL peer certificate verification
* NSS: client certificate from file
*   subject: CN=leaf-cn,OU=leaf-ou
*   common name: leaf-cn
*   issuer: CN=intermediate-cn,OU=intermediate-ou
* NSS error -12224 (SSL_ERROR_CERTIFICATE_UNKNOWN_ALERT)
* SSL peer had some unspecified issue with the certificate it received.

It works if I add intermediate certs along with root as trusted (--cacert flag) when invoking the curl command. But after going through several StackExchange posts here, it seems if the server is returning intermediate certificates, then the client shouldn't need to add them as trusted.

Any idea what am I missing here? Would appreciate any pointers.

1
  • Actually, I realized that my client certificate's is issued by an intermediate which has same CN as server side but a different OU. So, they are totally different certificates. I think that's why it doesn't work. Although, both client and server side intermediates are issued by the same root ca. Jan 14, 2022 at 0:41

1 Answer 1

2

... it seems if the server is returning intermediate certificates, then the client shouldn't need to add them as trusted.

Your problem is not that the client does not trust the server certificate. In fact, the latter verification was explicitly disabled by you with -k. This also shows in the debug message "skipping SSL peer certificate verification".

SSL peer had some unspecified issue with the certificate it received.

The problem is instead the server (i.e. the SSL peer from the perspective of the client) is complaining about the client certificate it received, not the client about the server certificate. This is probably because the client sends only the leaf certificate but not the intermediate CA too. Assuming that the server will only trust the root CA, it will not be able to build the trust chain just from leaf certificate and root CA. It does not matter if the server knows about the intermediate certificate in the context of its own certificate, it needs to know about it in the context of client certificate validation.

It works if I add intermediate certs along with root as trusted (--cacert flag) when invoking the curl command.

This answer and this post on the curl mailing list suggest that with some backends (NSS?) curl will use the --cafile option also to figure out which intermediate certificates it might send together with the client certificate to the server. This means in this case the server will get both leaf and intermediate from the client and can thus successfully verify the client certificates.

1
  • Thank you! Those two linked questions helped. My curl version was really old, and even though I was appending client's intermediate certificate in --cert file, it didn't work. Upgrading curl to the latest version works just fine now. Jan 14, 2022 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .