C#C
C#3y 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?
Was this page helpful?