mirror of https://github.com/Jackett/Jackett
Add support for self signed certificates
This commit is contained in:
parent
7b31f81957
commit
cdd9411d5d
|
@ -6,6 +6,8 @@
|
||||||
encoding: UTF-8
|
encoding: UTF-8
|
||||||
links:
|
links:
|
||||||
- https://rapidetracker.net
|
- https://rapidetracker.net
|
||||||
|
certificates:
|
||||||
|
- B0238C547A905BFA119C4E8BACCAEACF36491FF6
|
||||||
|
|
||||||
caps:
|
caps:
|
||||||
categories:
|
categories:
|
||||||
|
|
|
@ -321,7 +321,7 @@ namespace Jackett.Indexers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
virtual public void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
||||||
{
|
{
|
||||||
IProtectionService ps = null;
|
IProtectionService ps = null;
|
||||||
if (useProtectionService)
|
if (useProtectionService)
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace Jackett.Indexers
|
||||||
public string Language { get; set; }
|
public string Language { get; set; }
|
||||||
public string Encoding { get; set; }
|
public string Encoding { get; set; }
|
||||||
public List<string> Links { get; set; }
|
public List<string> Links { get; set; }
|
||||||
|
public List<string> Certificates { get; set; }
|
||||||
public capabilitiesBlock Caps { get; set; }
|
public capabilitiesBlock Caps { get; set; }
|
||||||
public loginBlock Login { get; set; }
|
public loginBlock Login { get; set; }
|
||||||
public ratioBlock Ratio { get; set; }
|
public ratioBlock Ratio { get; set; }
|
||||||
|
@ -296,6 +297,18 @@ namespace Jackett.Indexers
|
||||||
LoadValuesFromJson(null);
|
LoadValuesFromJson(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
||||||
|
{
|
||||||
|
base.LoadValuesFromJson(jsonConfig, useProtectionService);
|
||||||
|
|
||||||
|
// add self signed cert to trusted certs
|
||||||
|
if (Definition.Certificates != null)
|
||||||
|
{
|
||||||
|
foreach (var certificateHash in Definition.Certificates)
|
||||||
|
webclient.AddTrustedCertificate(new Uri(SiteLink).Host, certificateHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Dictionary<string, object> getTemplateVariablesFromConfigData()
|
protected Dictionary<string, object> getTemplateVariablesFromConfigData()
|
||||||
{
|
{
|
||||||
Dictionary<string, object> variables = new Dictionary<string, object>();
|
Dictionary<string, object> variables = new Dictionary<string, object>();
|
||||||
|
|
|
@ -13,7 +13,6 @@ using Jackett.Models.IndexerConfig;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Jackett.Indexers
|
namespace Jackett.Indexers
|
||||||
|
@ -22,6 +21,7 @@ namespace Jackett.Indexers
|
||||||
{
|
{
|
||||||
string IndexUrl { get { return SiteLink + "index.php"; } }
|
string IndexUrl { get { return SiteLink + "index.php"; } }
|
||||||
string LoginCompleteUrl { get { return SiteLink + "index.php?strWebValue=account&strWebAction=login_complete&ancestry=verify"; } }
|
string LoginCompleteUrl { get { return SiteLink + "index.php?strWebValue=account&strWebAction=login_complete&ancestry=verify"; } }
|
||||||
|
static readonly string certificateHash = "6F5CE30D578C2A7AECFB919D0D013976D395055F";
|
||||||
|
|
||||||
new ConfigurationDataCaptchaLogin configData
|
new ConfigurationDataCaptchaLogin configData
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ namespace Jackett.Indexers
|
||||||
logger: l,
|
logger: l,
|
||||||
p: ps,
|
p: ps,
|
||||||
configData: new ConfigurationDataCaptchaLogin())
|
configData: new ConfigurationDataCaptchaLogin())
|
||||||
{
|
{
|
||||||
Encoding = Encoding.GetEncoding("iso-8859-1");
|
Encoding = Encoding.GetEncoding("iso-8859-1");
|
||||||
Language = "de-de";
|
Language = "de-de";
|
||||||
Type = "private";
|
Type = "private";
|
||||||
|
@ -92,6 +92,14 @@ namespace Jackett.Indexers
|
||||||
AddCategoryMapping(71, TorznabCatType.PCMac); // APPLICATIONS/Mac
|
AddCategoryMapping(71, TorznabCatType.PCMac); // APPLICATIONS/Mac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
||||||
|
{
|
||||||
|
base.LoadValuesFromJson(jsonConfig, useProtectionService);
|
||||||
|
|
||||||
|
// add self signed cert to trusted certs
|
||||||
|
webclient.AddTrustedCertificate(new Uri(SiteLink).Host, certificateHash);
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
||||||
{
|
{
|
||||||
var loginPage = await RequestStringWithCookies(IndexUrl, string.Empty);
|
var loginPage = await RequestStringWithCookies(IndexUrl, string.Empty);
|
||||||
|
|
|
@ -8,6 +8,8 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -16,6 +18,8 @@ namespace Jackett.Utils.Clients
|
||||||
{
|
{
|
||||||
public class HttpWebClient : IWebClient
|
public class HttpWebClient : IWebClient
|
||||||
{
|
{
|
||||||
|
static protected Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
||||||
|
|
||||||
public HttpWebClient(IProcessService p, Logger l, IConfigurationService c)
|
public HttpWebClient(IProcessService p, Logger l, IConfigurationService c)
|
||||||
: base(p: p,
|
: base(p: p,
|
||||||
l: l,
|
l: l,
|
||||||
|
@ -30,6 +34,26 @@ namespace Jackett.Utils.Clients
|
||||||
logger.Info(string.Format("HttpWebClient: Disabling certificate validation"));
|
logger.Info(string.Format("HttpWebClient: Disabling certificate validation"));
|
||||||
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 += delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||||
|
{
|
||||||
|
if (sender.GetType() != typeof(HttpWebRequest))
|
||||||
|
return sslPolicyErrors == SslPolicyErrors.None;
|
||||||
|
|
||||||
|
var request = (HttpWebRequest)sender;
|
||||||
|
var hash = certificate.GetCertHashString();
|
||||||
|
|
||||||
|
ICollection<string> hosts;
|
||||||
|
|
||||||
|
trustedCertificates.TryGetValue(hash, out hosts);
|
||||||
|
if (hosts != null)
|
||||||
|
{
|
||||||
|
if (hosts.Contains(request.Host))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return sslPolicyErrors == SslPolicyErrors.None;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||||
|
@ -203,5 +227,18 @@ namespace Jackett.Utils.Clients
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override public void AddTrustedCertificate(string host, string hash)
|
||||||
|
{
|
||||||
|
hash = hash.ToUpper();
|
||||||
|
ICollection<string> hosts;
|
||||||
|
trustedCertificates.TryGetValue(hash.ToUpper(), out hosts);
|
||||||
|
if (hosts == null)
|
||||||
|
{
|
||||||
|
hosts = new HashSet<string>();
|
||||||
|
trustedCertificates[hash] = hosts;
|
||||||
|
}
|
||||||
|
hosts.Add(host);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -24,6 +26,8 @@ namespace Jackett.Utils.Clients
|
||||||
HttpClientHandler clientHandlr;
|
HttpClientHandler clientHandlr;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
|
|
||||||
|
static protected Dictionary<string, ICollection<string>> trustedCertificates = new Dictionary<string, ICollection<string>>();
|
||||||
|
|
||||||
public HttpWebClient2(IProcessService p, Logger l, IConfigurationService c)
|
public HttpWebClient2(IProcessService p, Logger l, IConfigurationService c)
|
||||||
: base(p: p,
|
: base(p: p,
|
||||||
l: l,
|
l: l,
|
||||||
|
@ -62,6 +66,26 @@ namespace Jackett.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 += delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||||
|
{
|
||||||
|
if (sender.GetType() != typeof(HttpWebRequest))
|
||||||
|
return sslPolicyErrors == SslPolicyErrors.None;
|
||||||
|
|
||||||
|
var request = (HttpWebRequest)sender;
|
||||||
|
var hash = certificate.GetCertHashString();
|
||||||
|
|
||||||
|
ICollection<string> hosts;
|
||||||
|
|
||||||
|
trustedCertificates.TryGetValue(hash, out hosts);
|
||||||
|
if (hosts != null)
|
||||||
|
{
|
||||||
|
if (hosts.Contains(request.Host))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return sslPolicyErrors == SslPolicyErrors.None;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
override protected async Task<WebClientByteResult> Run(WebRequest webRequest)
|
||||||
|
|
|
@ -17,6 +17,11 @@ namespace Jackett.Utils.Clients
|
||||||
protected IConfigurationService configService;
|
protected IConfigurationService configService;
|
||||||
protected IProcessService processService;
|
protected IProcessService processService;
|
||||||
|
|
||||||
|
virtual public void AddTrustedCertificate(string host, string hash)
|
||||||
|
{
|
||||||
|
// not implemented by default
|
||||||
|
}
|
||||||
|
|
||||||
public IWebClient(IProcessService p, Logger l, IConfigurationService c)
|
public IWebClient(IProcessService p, Logger l, IConfigurationService c)
|
||||||
{
|
{
|
||||||
processService = p;
|
processService = p;
|
||||||
|
|
Loading…
Reference in New Issue