Re: Problems with ServerCertificateValidationCallback
Dean Cleaver <[email protected]> Mon, 23 Nov 2009 11:42:29 +1300
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <8E588B65FD82DF448592A3219102C3957E524E21AB@SXSLAKL001.xceptionsoftware.com> |
No - that's what I mean by the callback failing - it doesn't get called. I have a sample where I'm hitting a page on my server. I click the button, = the callback is called, and then it exits the test function. I click the bu= tton again, and it exits the test function without hitting the ValidateServ= erCertificate. I've tried almost every option for CachePolicy I can see (BypassCache, Relo= ad, NoCacheNoStore) and I still get the same behaviour - it skips the certi= ficate validation on subsequent calls, however in the case of my real appli= cation where it's testing multiple sites in multiple threads, it skips one = or 2 at random, even on the first call to the server. Dino -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[email protected]= E.LSOFT.COM] On Behalf Of John Warner Sent: Monday, 23 November 2009 11:13 a.m. To: [email protected] Subject: Re: [ADVANCED-DOTNET] Problems with ServerCertificateValidationCal= lback 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 >=20 > 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. >=20 > 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. >=20 > Any ideas why? >=20 > Dino >=20 >=20 > private bool checkedCertificate; > public void RunTest(object url) > { > Mutex mutex =3D new Mutex(false, "WebsiteLock"); > mutex.WaitOne(); >=20 > try > { > HttpWebRequest httpWebRequest =3D (HttpWebRequest) > WebRequest.Create(url.ToString()); > ServicePointManager.ServerCertificateValidationCallback =3D > this.ValidateServerCertificate; >=20 > checkedCertificate =3D false; >=20 > HttpWebResponse httpWebResponse =3D (HttpWebResponse) > httpWebRequest.GetResponse(); > } > finally > { > mutex.ReleaseMutex(); > } > } >=20 > public bool ValidateServerCertificate( > object sender, > X509Certificate certificate, > X509Chain chain, > SslPolicyErrors sslPolicyErrors) > { > checkedCertificate =3D true; >=20 > // Allow this client to communicate with unauthenticated servers > return true; > } > } > } >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > View archives and manage your subscription(s) at > http://peach.ease.lsoft.com/archives =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D View archives and manage your subscription(s) at http://peach.ease.lsoft.co= m/archives =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives