Skip to content

Instantly share code, notes, and snippets.

@smithrobs
Created July 11, 2011 14:59
Show Gist options
  • Save smithrobs/1076027 to your computer and use it in GitHub Desktop.
Save smithrobs/1076027 to your computer and use it in GitHub Desktop.
Full trust of all SSL certs
// callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors)
{
bool result = false;
if (cert.Subject.ToUpper().Contains("YourServerName"))
{
result = true;
}
return result;
}
//Trust all certificates
System.Net.ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
// trust sender
System.Net.ServicePointManager.ServerCertificateValidationCallback
= ((sender, cert, chain, errors) => cert.Subject.Contains("YourServerName"));
// validate cert by calling a function
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment