internal static void RaiseOnCertificateIssue(object sender, CertificateIssueCancelEventArgs e) { string url = e.WebRequest.RequestUri.CanonicalizedUri(); ICollection trusted = null; if (_trustedCertificateIssues != null) { lock (_trustedCertificateIssues) { if (_trustedCertificateIssues.ContainsKey(url)) { trusted = (ICollection)_trustedCertificateIssues[url]; } } } if (trusted != null && trusted.Count > 0) { if (trusted.Cast <CertificateIssue>().Any(trustedIssue => trustedIssue == e.CertificateIssue)) { e.Cancel = false; // is an yet accepted certificate isse return; } } var handler = OnCertificateIssue; if (handler != null) { try { handler(sender, e); } catch (Exception ex) { Log.Error("OnCertificateIssue() event impl. caused an error", ex); } } }
// this is marked obsolete by MS in the CLR 2.0 public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest req, int problem) { try { if (problem != 0) { // move bits around to get it casted from an signed int to a normal long enum type: CertificateIssue issue = (CertificateIssue)(((problem << 1) >> 1) + 0x80000000); // this is marked obsolete by MS in the CLR 2.0 // It seems also they has broken the old impl., we don't get a valid cert object now (handle is 0) on WinXP SP2 // via parameter, so we now use that of the servicepoint as a workaround: CertificateIssueCancelEventArgs args = new CertificateIssueCancelEventArgs(issue, sp.Certificate, req, true); AsyncWebRequest.RaiseOnCertificateIssue(sp, args); return(!args.Cancel); } } catch (Exception ex) { Trace.WriteLine("TrustSelectedCertificatePolicy.CheckValidationResult() error: " + ex.Message); } // The 1.1 framework calls this method with a problem of 0, even if nothing is wrong return(problem == 0); }