core: fix ignoresslerrors cli option (#9657)

This commit is contained in:
Diego Heras
2020-09-26 19:50:58 +02:00
committed by GitHub
parent bbe99c4123
commit 7279edf354
5 changed files with 24 additions and 52 deletions

View File

@@ -63,6 +63,7 @@ namespace Jackett.Common.Models.Config
{ {
var options = this; var options = this;
var runtimeSettings = new RuntimeSettings(); var runtimeSettings = new RuntimeSettings();
// Logging // Logging
if (options.Logging) if (options.Logging)
runtimeSettings.LogRequests = true; runtimeSettings.LogRequests = true;
@@ -83,11 +84,11 @@ namespace Jackett.Common.Models.Config
// Use Proxy // Use Proxy
if (options.ProxyConnection != null) if (options.ProxyConnection != null)
{
runtimeSettings.ProxyConnection = options.ProxyConnection.ToLowerInvariant(); runtimeSettings.ProxyConnection = options.ProxyConnection.ToLowerInvariant();
}
// Ignore SSL errors on Curl // Ignore SSL errors on Curl
runtimeSettings.IgnoreSslErrors = options.IgnoreSslErrors; runtimeSettings.IgnoreSslErrors = options.IgnoreSslErrors;
runtimeSettings.NoRestart = options.NoRestart; runtimeSettings.NoRestart = options.NoRestart;
runtimeSettings.NoUpdates = options.NoUpdates; runtimeSettings.NoUpdates = options.NoUpdates;

View File

@@ -37,31 +37,26 @@ namespace Jackett.Common.Utils.Clients
var request = (HttpWebRequest)sender; var request = (HttpWebRequest)sender;
var hash = certificate.GetCertHashString(); var hash = certificate.GetCertHashString();
trustedCertificates.TryGetValue(hash, out var hosts); trustedCertificates.TryGetValue(hash, out var hosts);
if (hosts != null) if (hosts != null && hosts.Contains(request.Host))
{
if (hosts.Contains(request.Host))
return true; return true;
}
if (sslPolicyErrors != SslPolicyErrors.None)
{
// Throw exception with certificate details, this will cause a "Exception User-Unhandled" when running it in the Visual Studio debugger. // Throw exception with certificate details, this will cause a "Exception User-Unhandled" when running it in the Visual Studio debugger.
// The certificate is only available inside this function, so we can't catch it at the calling method. // The certificate is only available inside this function, so we can't catch it at the calling method.
throw new Exception("certificate validation failed: " + certificate.ToString()); if (sslPolicyErrors != SslPolicyErrors.None)
} throw new Exception("certificate validation failed: " + certificate);
return sslPolicyErrors == SslPolicyErrors.None; return sslPolicyErrors == SslPolicyErrors.None;
} }
public override void Init() public override void Init()
{ {
ServicePointManager.DefaultConnectionLimit = 1000;
base.Init(); base.Init();
// custom handler for our own internal certificates // custom handler for our own internal certificates
if (serverConfig.RuntimeSettings.IgnoreSslErrors == true)
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
else
ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate; ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;
} }

View File

@@ -40,20 +40,14 @@ namespace Jackett.Common.Utils.Clients
{ {
var hash = certificate.GetCertHashString(); var hash = certificate.GetCertHashString();
trustedCertificates.TryGetValue(hash, out var hosts); trustedCertificates.TryGetValue(hash, out var hosts);
if (hosts != null) if (hosts != null && hosts.Contains(request.RequestUri.Host))
{
if (hosts.Contains(request.RequestUri.Host))
return true; return true;
}
if (sslPolicyErrors != SslPolicyErrors.None)
{
// Throw exception with certificate details, this will cause a "Exception User-Unhandled" when running it in the Visual Studio debugger. // Throw exception with certificate details, this will cause a "Exception User-Unhandled" when running it in the Visual Studio debugger.
// The certificate is only available inside this function, so we can't catch it at the calling method. // The certificate is only available inside this function, so we can't catch it at the calling method.
throw new Exception("certificate validation failed: " + certificate.ToString()); if (sslPolicyErrors != SslPolicyErrors.None)
} throw new Exception("certificate validation failed: " + certificate);
return sslPolicyErrors == SslPolicyErrors.None; return sslPolicyErrors == SslPolicyErrors.None;
} }
@@ -75,6 +69,9 @@ namespace Jackett.Common.Utils.Clients
}; };
// custom certificate validation handler (netcore version) // custom certificate validation handler (netcore version)
if (serverConfig.RuntimeSettings.IgnoreSslErrors == true)
clientHandlr.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
else
clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate; clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate;
clearanceHandlr.InnerHandler = clientHandlr; clearanceHandlr.InnerHandler = clientHandlr;
@@ -94,8 +91,6 @@ namespace Jackett.Common.Utils.Clients
public override void Init() public override void Init()
{ {
ServicePointManager.DefaultConnectionLimit = 1000;
base.Init(); base.Init();
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

View File

@@ -193,15 +193,7 @@ namespace Jackett.Common.Utils.Clients
protected virtual async Task<WebResult> Run(WebRequest webRequest) => throw new NotImplementedException(); protected virtual async Task<WebResult> Run(WebRequest webRequest) => throw new NotImplementedException();
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
public virtual void Init() public virtual void Init() => ServicePointManager.DefaultConnectionLimit = 1000;
{
if (serverConfig.RuntimeSettings.IgnoreSslErrors == true)
{
logger.Info($"WebClient({ClientType}): Disabling certificate validation");
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };
}
}
public virtual void OnCompleted() => throw new NotImplementedException(); public virtual void OnCompleted() => throw new NotImplementedException();

View File

@@ -13,35 +13,24 @@ namespace Jackett.Server
{ {
if (runtimeSettings.ClientOverride != "httpclient" && runtimeSettings.ClientOverride != "httpclient2") if (runtimeSettings.ClientOverride != "httpclient" && runtimeSettings.ClientOverride != "httpclient2")
{ {
logger.Error($"Client override ({runtimeSettings.ClientOverride}) has been deprecated, please remove it from your start arguments"); logger.Error($"Client override ({runtimeSettings.ClientOverride}) has been deprecated, please remove it from your start arguments.");
Environment.Exit(1); Environment.Exit(1);
} }
if (runtimeSettings.LogRequests) if (runtimeSettings.LogRequests)
{
logger.Info("Logging enabled."); logger.Info("Logging enabled.");
}
if (runtimeSettings.TracingEnabled) if (runtimeSettings.TracingEnabled)
{
logger.Info("Tracing enabled."); logger.Info("Tracing enabled.");
}
// https://github.com/Jackett/Jackett/issues/6229 if (runtimeSettings.IgnoreSslErrors == true)
//if (runtimeSettings.IgnoreSslErrors == true) logger.Info("Ignore SSL errors enabled.");
//{
// logger.Error($"The IgnoreSslErrors option has been deprecated, please remove it from your start arguments");
//}
if (!string.IsNullOrWhiteSpace(runtimeSettings.CustomDataFolder)) if (!string.IsNullOrWhiteSpace(runtimeSettings.CustomDataFolder))
{
logger.Info("Jackett Data will be stored in: " + runtimeSettings.CustomDataFolder); logger.Info("Jackett Data will be stored in: " + runtimeSettings.CustomDataFolder);
}
if (runtimeSettings.ProxyConnection != null) if (runtimeSettings.ProxyConnection != null)
{ logger.Info("Proxy enabled: " + runtimeSettings.ProxyConnection);
logger.Info("Proxy enabled. " + runtimeSettings.ProxyConnection);
}
} }
public static void ProcessWindowsSpecificArgs(ConsoleOptions consoleOptions, IProcessService processService, ServerConfig serverConfig, Logger logger) public static void ProcessWindowsSpecificArgs(ConsoleOptions consoleOptions, IProcessService processService, ServerConfig serverConfig, Logger logger)