I have a p12 file that contains three certificates (and a private key)
- Client certificate
- Intermediate certificate
- Root certificate
Using openssl s_client the connection is successful, however, using HTTP client the connection isn't.
Inspecting the payload in Wireshark I can see that only two certificates are sent (1,2) and the root (3) is missing.
I've installed the certificates in Current User and Local Machine in My and Root Certificates but nothing changes the result. Where should the certificates be installed?
Fun fact, using var chain = new X509Chain(); chain.Build(certificate)
all intermediate certificates are correctly found.
Update: I tried adding all certificates resolved from the chain but the result is the same.
Code
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
const string thumbprint = "";
using var store = new X509Store(StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false)[0];
var clientHandler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12,
ClientCertificates = { certificate }
};
var client = new HttpClient(clientHandler)
{
BaseAddress = new Uri("url")
};
var response = await client.GetAsync(string.Empty);
// Exception:
// The SSL connection could not be established, see inner exception.' ->
// AuthenticationException: Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'.
I've been follow this SO-post but it doesn't work for me.
Update I removed the root certificate from the crt file used when exercising OpenSSL s_client and more carefully read all of the output. It appears it has never worked...
139645152049040:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:s3_pkt.c:1493:SSL alert number 40
139645152049040:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
I was paying attention to the last part of the output which read
SSL handshake has read 5917 bytes and written 2674 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID:
Session-ID-ctx:
Master-Key: 13838C2676F91215679A69B491D9117198CAD86B24CDBBFE6357A0D34B58317DD6F9C57FAFE99264CB73A94204280300
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
Start Time: 1654810361
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
That gave me the impression that everything was ok. I'll reach back to the provider of the certificate and service since I suspect that the client certificate CA isn't in the allowed list of the server (can't find it in openssl output) which @Oliver pointed out in a comment.
Sorry for wasting your time and thanks for your dito!
Update: @crypt32 They have now successfully installed the necessary certificates on the server and it works using openssl
with
- All three certificates
- Intermediate and client
- Only client (private key is included in all above as part of the pem file)
The .NET (from Windows) still doesn't work.
Update: It works from .NET as well! Case closed