C
C#14mo ago
Neteyes

❔ Custom cert validation in http client

I have a HttpClient with a SocketsHttpHandler that I'm trying to add a custom certificate to, because I'm talking to a service that requires it. I'm hitting some issues though, after adding the certificate through handler.SslOptions.ClientCertificates.Add(cert);I'm getting an "unknown certificate" error. Removing the Client Certificate just gives me the "bad certificate" error. So, I thought I'll add the Root CA as well, maybe that's the issue right? But I cannot get the callback on RemoteCertificateValidationCallbackto fire at all. From what I can gather, what's happening is that the ClientCertificate cannot be validated because it's signed by an untrusted Root CA, but since RemoteCertificateValidationCallback isnt being fired, how can I determine if it should be trusted or not? Same result if I just make it a HttpHandler instead. Any ideas here?
2 Replies
Henkypenky
Henkypenky14mo ago
you can probably do something like:
.ConfigurePrimaryHttpMessageHandler(() =>
{
return new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12,
ClientCertificates.Add(new X509Certificate("path.crt"))
};
});
.ConfigurePrimaryHttpMessageHandler(() =>
{
return new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12,
ClientCertificates.Add(new X509Certificate("path.crt"))
};
});
RemoteCertificateValidationCallback this is mostly used for development purposes to ignore ssl validation the above should work you mal also need the password in the X509 certificate constructor
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Android Debugging getting slower and slowerGreetings, I am working on an app for my job. Everything used to be fine but for the past month, deb❔ Converting from binary to integerRecently I had to problem where I would convert an integer to binary and count the ones, the problem❔ Better way to open a "window" to take in text input?As in, when you click a button, a small window appears which exists only to take in the for example ❔ Can someone help me use data from database tables?I have 2 $ and a dream ! Tommorow im going to the national stage of the c# olympiad and i dont even ❔ List string variablesHello, I'm really new to C# and would like to get help. How is the correct way to give variable for❔ EF successfully updated database, but unable to connect to sql server when getting data.Hey guys, getting back into .net after a while. sql server is currently on docker and I am able to c❔ ✅ Writing to response body is slow in .net core 7 web api?Hey guys, I have a stack overflow thread about the issue, but basically, I'm getting significant per❔ update-package : Failed to add reference to 'xyz'. Error HRESULT E_FAIL has been returnedSo I don't really know what happened. Turned my pc on, opened a project I created 2 days ago. My pac❔ help pleaseI’m try to make a 2d racing game in visual studio 2022 with C# but I’m have trouble figuring out how❔ Tailwindcss and . net7 proper installation using vs 2022 previewSo I got tailwind css working just not working properly. I cannot nest classes together like in vs c