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
|
{
|
/// <summary>
|
/// Sets the cert policy.
|
/// </summary>
|
public static WebRequestHandler SetCertificatePolicy2()
|
{
|
var handler = new WebRequestHandler();
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
handler.ServerCertificateValidationCallback += RemoteCertificateValidate;
|
return handler;
|
}
|
|
/// <summary>
|
/// Sets the cert policy.
|
/// </summary>
|
public static HttpClientHandler SetCertificatePolicy3()
|
{
|
HttpClientHandler clientHandler = new HttpClientHandler();
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
|
//clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
|
return clientHandler;
|
}
|
|
/// <summary>
|
/// Sets the cert policy.
|
/// </summary>
|
public static void SetCertificatePolicy()
|
{
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
|
ServicePointManager.ServerCertificateValidationCallback
|
+= RemoteCertificateValidate;
|
}
|
|
/// <summary>
|
/// Remotes the certificate validate.
|
/// </summary>
|
private static bool RemoteCertificateValidate(
|
object sender, X509Certificate cert,
|
X509Chain chain, SslPolicyErrors error)
|
{
|
// trust any certificate!!!
|
System.Console.WriteLine("Warning, trust any certificate");
|
return true;
|
}
|
}
|
}
|