When making an HTTPS request to a remote web server, I use WebRequest, which establishes a secure connection to the remote web server. During development, I use a self-signed certificate on the server, and WebRequest cannot establish a secure connection because the certificate is invalid, which is the expected behavior.
I found this code that “removes” the cert check is activated when the SetCertificatePolicy() method is SetCertificatePolicy() in the following code.
public static void SetCertificatePolicy() { ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate; }
I am wondering if it is possible to perform special checks on a remote SSL certificate (for example using the code above) so that I can verify that the remote web server is using a valid SSL certificate, not just any valid certificate, but exactly the one I want ? For example, I want to make sure that I speak on the website www.someplace.com, a certificate issued by ACME Inc, with a fingerprint of 00:11:22: .....
What is the “best practice” approach for this scenario?
Thanks!
mr.b
source share