Showing posts with label Vehicle Tracking. Show all posts
Showing posts with label Vehicle Tracking. Show all posts

Tuesday, January 13, 2009

How to accept an invalid SSL certificate programmatically

In my Arclogistics Navigator application, im sending the location of the vehicles to back to our servers in able to see where the vehicles, i created a web service that receives the raw data and process it but it turns out that the web service that is being called over a web service with a certificate that its name doesn't match the server name, calling the client support to resolve this issue would take ages since people here in kuwait are very slow. so i though i'll google a bit to to to know how to accept any certificate no matter what is the error, well this is a POC ;)

here is how you do it

// callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors policyErrors
)
{
if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreSslErrors"]))
{
// allow any old dodgy certificate...
return true;
}
else
{
return policyErrors == SslPolicyErrors.None;
}
}



what u need to do is to create a parameter in the app.config and give it a key
"IgnoreSslError" and set this to true or false up to ur conviniece and here is how you

streetmps_buffered.TrackingWS.Service m_proxy = new streetmps_buffered.TrackingWS.Service();

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);

m_proxy.WriteDataAsync(m_DriverName, m_CurrentGPSPoint.X.ToString(), m_CurrentGPSPoint.Y.ToString(), (int)SMNavigation.MilesToKilometers(m_CurrentSpeed), DateTime.Now.ToString());


hope it helps others