Re: Problems with ServerCertificateValidationCallback
John Warner <[email protected]> Sun, 22 Nov 2009 17:12:40 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Organization | House |
| Message-ID | <066801ca6bc0$e89fa570$b9def050$@com> |
Does ValidateServerCertificate get called when the callback fails? John Warner > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [email protected]] On Behalf Of Dean Cleaver > Sent: Sunday, November 22, 2009 4:47 PM > To: [email protected] > Subject: [ADVANCED-DOTNET] Problems with > ServerCertificateValidationCallback > > I'm using the below code (trimmed a bit of unimportant stuff out) to check a > given page on a site, and validate the server certificates. However, it seems to > not call the callback at all for some sites, despite the url being https, and > manual checking of the site indicates a valid certificate. > > I'm using an instance level function and a mutex so I can ensure that I'm > checking one at a time. I've even stepped through the code, and the callback > just doesn't get called for some sites. > > Any ideas why? > > Dino > > > private bool checkedCertificate; > public void RunTest(object url) > { > Mutex mutex = new Mutex(false, "WebsiteLock"); > mutex.WaitOne(); > > try > { > HttpWebRequest httpWebRequest = (HttpWebRequest) > WebRequest.Create(url.ToString()); > ServicePointManager.ServerCertificateValidationCallback = > this.ValidateServerCertificate; > > checkedCertificate = false; > > HttpWebResponse httpWebResponse = (HttpWebResponse) > httpWebRequest.GetResponse(); > } > finally > { > mutex.ReleaseMutex(); > } > } > > public bool ValidateServerCertificate( > object sender, > X509Certificate certificate, > X509Chain chain, > SslPolicyErrors sslPolicyErrors) > { > checkedCertificate = true; > > // Allow this client to communicate with unauthenticated servers > return true; > } > } > } > > =================================== > View archives and manage your subscription(s) at > http://peach.ease.lsoft.com/archives =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives