Disable certificate verification for a single request

In my application, I have situations where I need to make requests to servers with self-signed certificates. I would like to be able to disable certificate verification only for this particular request.

I know that I can turn off certificate verification by setting ServicePointManager.ServerCertificateValidationCallback to specify a callback method and just return true. However, this disables certificate verification for the entire application, which I could just do by installing in app.config.

However, I do not want to disable for the entire application, but rather disconnect a separate request. Is it possible?

The class I'm working with is SmtpClient

+5
source share
1 answer

Disabling certificate verification is usually bad. Why don't you just add your own certificate as a trusted certificate in the system or in your application.

AFAIR this can be done, for example. by implementing your own X509CertificateValidator . Just paste the user certificate into your application and compare it in the X509CertificateValidator if they are both equal.

See also: How Safe is My Custom SSL Validation Logic for Handling Excluded RemoteCertificateNameMismatch?

0
source

All Articles