1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 19:56:54 +00:00

log cert errors

This commit is contained in:
Keivan Beigi 2014-12-04 22:28:46 -08:00
parent c4e684fbd3
commit 664ec45360

View file

@ -1,24 +1,45 @@
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using NzbDrone.Common.Extensions;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Instrumentation;
namespace NzbDrone.Common.Security
{
public static class IgnoreCertErrorPolicy
{
private static Logger _logger = NzbDroneLogger.GetLogger("IgnoreCertErrorPolicy");
public static void Register()
{
ServicePointManager.ServerCertificateValidationCallback = ValidationCallback;
ServicePointManager.ServerCertificateValidationCallback = ShouldByPassValidationError;
}
private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
private static bool ShouldByPassValidationError(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors)
{
var request = sender as HttpWebRequest;
if (request != null && sslpolicyerrors != SslPolicyErrors.None &&
(request.Address.OriginalString.ContainsIgnoreCase("nzbdrone.com") || request.Address.OriginalString.ContainsIgnoreCase("sonarr.tv"))
)
if (request == null)
{
return true;
}
if (sslpolicyerrors == SslPolicyErrors.None)
{
return true;
}
_logger.Warn("Request for {0} failed certificated validation. {1}", request.Address, sslpolicyerrors);
if (OsInfo.IsMono)
{
return true;
}
var host = request.Address.Host.ToLower();
if (host.EndsWith("nzbdrone.com") || host.EndsWith("sonarr.tv"))
{
return false;
}