I had the same issue, eventually I found a solution that works without splitting the file, by following Petter Ivarrson's answer
My problem was when converting .p12 certificate to .pem. I used:
openssl pkcs12 -in cert.p12 -out cert.pem
This converts and exports all certificates (CA + CLIENT) together with a private key into one file.
The problem was when I tried to verify if the hashes of certificate and key are matching by running:
// Get certificate HASH
openssl x509 -noout -modulus -in cert.pem | openssl md5
// Get private key HASH
openssl rsa -noout -modulus -in cert.pem | openssl md5
This displayed different hashes and that was the reason CURL failed.
See here: https://michaelheap.com/curl-58-unable-to-set-private-key-file-server-key-type-pem/
I guess that was because all certificates are inside a file (CA + CLIENT) and CURL takes CA certificate instead of CLIENT one. Because CA is first in the list.
So the solution was to export only CLIENT certificate together with private key:
openssl pkcs12 -in cert.p12 -out cert.pem -clcerts
``
Now when I re-run the verification:
```sh
openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in cert.pem | openssl md5
HASHES MATCHED !!!
So I was able to make a curl request by running
curl -ivk --cert ./cert.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite.com
without problems!!!
That being said... I think the best solution is to split the certificates into separate file and use them separately like Petter Ivarsson wrote:
curl --insecure --key key.pem --cacert ca.pem --cert client.pem:KeyChoosenByMeWhenIrunOpenSSL https://thesite.com