using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Security;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace DataCapture_MA.Util
{
public static class SSLUtil
{
///
/// Sets the cert policy.
///
public static WebRequestHandler SetCertificatePolicy2()
{
var handler = new WebRequestHandler();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
handler.ServerCertificateValidationCallback += RemoteCertificateValidate;
return handler;
}
///
/// Sets the cert policy.
///
public static HttpClientHandler SetCertificatePolicy3()
{
HttpClientHandler clientHandler = new HttpClientHandler();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
return clientHandler;
}
///
/// Sets the cert policy.
///
public static void SetCertificatePolicy()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback
+= RemoteCertificateValidate;
}
///
/// Remotes the certificate validate.
///
private static bool RemoteCertificateValidate(
object sender, X509Certificate cert,
X509Chain chain, SslPolicyErrors error)
{
// trust any certificate!!!
System.Console.WriteLine("Warning, trust any certificate");
return true;
}
}
}