Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p> Hi Tvd,</p> <p>I'm not sure that the solution you provide is actually a valid solution for the problem. Also, some of your comments regarding <code>HttpWebRequest.ClientCertificates</code> indicate this.</p> <p>First, it is important to distinguish between the server validating a client certificate and the client validating a server certificate. Collection <code>HttpWebRequest.ClientCertificates</code> is used to send client certificates to the server, so the server can validate who the client is. Your question (as far as I understand it) was how server certificate which does not pass the default validation (such as a self-signed cert) can be validated against a certificate locally stored at the client.</p> <p>In this case a solution is indeed to use <code>System.Net.ServicePointManager.ServerCertificateValidationCallback</code> and provide a custom validation. However, your validation method seems wrong: it verifies the local certificate and does not care about the cert send by the server. What I'd use is something like this:</p> <pre class="lang-cs prettyprint-override"><code>public static bool customXertificateValidation( Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; return clientCert.Equals(certificate); }; </code></pre> <p>This method ensures that if the server certificate passes the default validation (no errors) it will accept it and then it compares the local, client copy of the certificate with what has been provided by the server. Only, if Equals test passes the client can safely proceed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload