Accepting Certificates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm attempting to make a secure connection to wesite using a HttpWebRequest
with a "https:" uri. However, attempting to get the response fails because
the trust relationship has not been established. Namely, the issuing
certificate authority is not on the list of trusted authorities. What I
can't figure out is how to accept the certificate and reissue the request,
even accepting all certificates would be fine as I'm just trying to get this
thing working. Can anyone out there help me?
 
Permanently accepting a new root CA is a decision that really ought to
involve deliberate human intervention, and I wouldn't recommend that you add
this to your application. However, if an untrusted root CA should not
prevent the use of https in your application, you may want to consider
creating a custom implementation of the System.Net.ICertificatePolicy
interface for use as the System.Net.ServicePointManager.CertificatePolicy.
(Taken
together, the MSDN topics for the ICertificatePolicy interface and the
CertificatePolicy property form a sample of the technique.)

Even this more limited approach is potentially quite dangerous, and I
wouldn't recommend it, but it does pose less overall risk than blindly
trusting an unknown CA...
 
Create this class

public class TrustedCertificatePolicy : ICertificatePolicy
{
public TrustedCertificatePolicy()
{
}

public bool CheckValidationResult(ServicePoint sp, X509Certificate
certificate, WebRequest request, int problem)
{
return true;
}
}

then somewhere in your calling code, put this

ServicePointManager.CertificatePolicy = new TrustedCertificatePolicy();

Bruce Dunwiddie
http://www.csvreader.com
 
Back
Top