HTTP Client authentication using three .pem files (client cert, CA cert and key)

351 views Asked by At

I'm trying to add a certificate to my HTTP Client (my HTTP request really) but I'm not quite sure what I'm doing.

I have three files:

key.pem
cert.pem
cacert.pem

I'm aware that the cacert.pem file does not require a key since it's just the public part, so I'm not looking for a key for that or trying to use my key.pem.

So what is it I'm exactly supposed to do? My endgoal is to simply have a request like

curl -k http://example.com -v -key c:\path\key.pem -cacert c:\path\cacert.pem -cert c:\path\cert.pem

from my HttpClient.

I know HTTP Client uses a collection of X509Certificate2 which can be extracted from a .pem file (and a key.pem file), but it doesn't look like it can be built from two. I also know there's a X509Chain which seems like something that could be useful but it also seems significantly more customizable than a simple "combine two certficats" tool would be.

I should mention that I am in no way versed in certificates or anything crypto, I'm a simple grease monkey mostly qualified in business logic, so please assume nothing except that I know very little on the subject and the tools needed for it.

UPD: One limitation I forgot to mention: I am using .NET Core 3.1 with no way to upgrade to .NET 5. Legacy code and all that.

0

There are 0 answers