mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Update standard clients to X509Certificate2
This commit is contained in:
@@ -26,19 +26,15 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
protected static IWebProxy webProxy;
|
protected static IWebProxy webProxy;
|
||||||
|
|
||||||
[DebuggerNonUserCode] // avoid "Exception User-Unhandled" Visual Studio messages
|
[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();
|
var hash = certificate.GetCertHashString();
|
||||||
|
|
||||||
|
|
||||||
trustedCertificates.TryGetValue(hash, out var hosts);
|
trustedCertificates.TryGetValue(hash, out var hosts);
|
||||||
if (hosts != null)
|
if (hosts != null)
|
||||||
{
|
{
|
||||||
if (hosts.Contains(request.Host))
|
if (hosts.Contains(request.RequestUri.Host))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,8 +121,6 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };
|
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom handler for our own internal certificates
|
|
||||||
ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||||
@@ -159,6 +153,8 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
|
// custom certificate validation handler (netcore version)
|
||||||
|
clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate;
|
||||||
clearanceHandlr.InnerHandler = clientHandlr;
|
clearanceHandlr.InnerHandler = clientHandlr;
|
||||||
using (var client = new HttpClient(clearanceHandlr))
|
using (var client = new HttpClient(clearanceHandlr))
|
||||||
{
|
{
|
||||||
|
@@ -33,19 +33,15 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
protected static IWebProxy webProxy;
|
protected static IWebProxy webProxy;
|
||||||
|
|
||||||
[DebuggerNonUserCode] // avoid "Exception User-Unhandled" Visual Studio messages
|
[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();
|
var hash = certificate.GetCertHashString();
|
||||||
|
|
||||||
|
|
||||||
trustedCertificates.TryGetValue(hash, out var hosts);
|
trustedCertificates.TryGetValue(hash, out var hosts);
|
||||||
if (hosts != null)
|
if (hosts != null)
|
||||||
{
|
{
|
||||||
if (hosts.Contains(request.Host))
|
if (hosts.Contains(request.RequestUri.Host))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +129,9 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// custom certificate validation handler (netcore version)
|
||||||
|
clientHandlr.ServerCertificateCustomValidationCallback = ValidateCertificate;
|
||||||
|
|
||||||
clearanceHandlr.InnerHandler = clientHandlr;
|
clearanceHandlr.InnerHandler = clientHandlr;
|
||||||
client = new HttpClient(clearanceHandlr);
|
client = new HttpClient(clearanceHandlr);
|
||||||
}
|
}
|
||||||
@@ -160,9 +159,6 @@ namespace Jackett.Common.Utils.Clients
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
||||||
|
|
||||||
// custom handler for our own internal certificates
|
|
||||||
ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
protected override async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||||
|
Reference in New Issue
Block a user