mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-02 13:14:58 +00:00
log cert errors
This commit is contained in:
parent
c4e684fbd3
commit
664ec45360
1 changed files with 27 additions and 6 deletions
|
@ -1,24 +1,45 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using NzbDrone.Common.Extensions;
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Security
|
namespace NzbDrone.Common.Security
|
||||||
{
|
{
|
||||||
public static class IgnoreCertErrorPolicy
|
public static class IgnoreCertErrorPolicy
|
||||||
{
|
{
|
||||||
|
private static Logger _logger = NzbDroneLogger.GetLogger("IgnoreCertErrorPolicy");
|
||||||
|
|
||||||
public static void Register()
|
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;
|
var request = sender as HttpWebRequest;
|
||||||
|
|
||||||
if (request != null && sslpolicyerrors != SslPolicyErrors.None &&
|
if (request == null)
|
||||||
(request.Address.OriginalString.ContainsIgnoreCase("nzbdrone.com") || request.Address.OriginalString.ContainsIgnoreCase("sonarr.tv"))
|
{
|
||||||
)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue