Created
July 11, 2011 14:59
-
-
Save smithrobs/1076027 to your computer and use it in GitHub Desktop.
Full trust of all SSL certs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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