diff --git a/src/Jackett.Common/Utils/Clients/HttpWebClient.cs b/src/Jackett.Common/Utils/Clients/HttpWebClient.cs index 6496ad5c8..17b15029c 100644 --- a/src/Jackett.Common/Utils/Clients/HttpWebClient.cs +++ b/src/Jackett.Common/Utils/Clients/HttpWebClient.cs @@ -26,19 +26,15 @@ namespace Jackett.Common.Utils.Clients protected static IWebProxy webProxy; [DebuggerNonUserCode] // avoid "Exception User-Unhandled" Visual Studio messages - public static bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + public static bool ValidateCertificate(HttpRequestMessage request, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { - if (sender.GetType() != typeof(HttpWebRequest)) - return sslPolicyErrors == SslPolicyErrors.None; - - var request = (HttpWebRequest)sender; var hash = certificate.GetCertHashString(); trustedCertificates.TryGetValue(hash, out var hosts); if (hosts != null) { - if (hosts.Contains(request.Host)) + if (hosts.Contains(request.RequestUri.Host)) return true; } @@ -125,8 +121,6 @@ namespace Jackett.Common.Utils.Clients ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; }; } - // custom handler for our own internal certificates - ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate; } protected override async Task Run(WebRequest webRequest) @@ -159,6 +153,8 @@ namespace Jackett.Common.Utils.Clients AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }) { + // custom certificate validation handler (netcore version) + clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate; clearanceHandlr.InnerHandler = clientHandlr; using (var client = new HttpClient(clearanceHandlr)) { diff --git a/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs b/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs index a5999d4de..5aa26bc04 100644 --- a/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs +++ b/src/Jackett.Common/Utils/Clients/HttpWebClient2.cs @@ -33,19 +33,15 @@ namespace Jackett.Common.Utils.Clients protected static IWebProxy webProxy; [DebuggerNonUserCode] // avoid "Exception User-Unhandled" Visual Studio messages - public static bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + public static bool ValidateCertificate(HttpRequestMessage request, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { - if (sender.GetType() != typeof(HttpWebRequest)) - return sslPolicyErrors == SslPolicyErrors.None; - - var request = (HttpWebRequest)sender; var hash = certificate.GetCertHashString(); trustedCertificates.TryGetValue(hash, out var hosts); if (hosts != null) { - if (hosts.Contains(request.Host)) + if (hosts.Contains(request.RequestUri.Host)) return true; } @@ -133,6 +129,9 @@ namespace Jackett.Common.Utils.Clients AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; + // custom certificate validation handler (netcore version) + clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate; + clearanceHandlr.InnerHandler = clientHandlr; client = new HttpClient(clearanceHandlr); } @@ -160,9 +159,6 @@ namespace Jackett.Common.Utils.Clients } ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; - - // custom handler for our own internal certificates - ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate; } protected override async Task Run(WebRequest webRequest)