mhinze.com archive

this is an archive of the old blog, ended 6/16/08





    19
    Mar

    consuming web services / crafting webrequests using ssl where the cert is expired or otherwise hosed

    with 1.1, we'd do this:

     

    internal class AcceptAllCertificatePolicy : System.Net.ICertificatePolicy
    {
        public bool CheckValidationResult(System.Net.ServicePoint sPoint,
            System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest wRequest,int certProb)
        {
            return true;
        }
    }//acceptallcertificatepolicy

     

    and then in the consumer

    System.Net.ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

     

    but try this in 2.0 and you get a warning:

    System.Net.ServicePointManager.CertificatePolicy' is obsolete: 'CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead.

    we don't have to implement ICertificatePolicy any longer.  and we can use anonymous delegates to craft a better solution:

    System.Net.ServicePointManager.ServerCertificateValidationCallback +=
        delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                System.Security.Cryptography.X509Certificates.X509Chain chain,
                                System.Net.Security.SslPolicyErrors sslPolicyErrors)
            {
                return true;
            };

    One Response to “consuming web services / crafting webrequests using ssl where the cert is expired or otherwise hosed”

    1. Bob On Development » Accepting a Flaky Certificate When Doing an SSL POST Says:

      [...] Update:  I ran across the .NET 2.0 solution to this issue here: [...]

    Leave a Reply

    You must be logged in to post a comment.

    © 2007 mhinze.com