mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Mono: check if the certificate store was initialized
This commit is contained in:
@@ -21,6 +21,8 @@ namespace Jackett
|
||||
{
|
||||
public class Engine
|
||||
{
|
||||
public static Type WebClientType;
|
||||
|
||||
private static IContainer container = null;
|
||||
private static bool _automapperInitialised = false;
|
||||
|
||||
|
@@ -61,32 +61,37 @@ namespace Jackett.Common.Plumbing
|
||||
switch (_runtimeSettings.ClientOverride)
|
||||
{
|
||||
case "httpclient":
|
||||
builder.RegisterType<HttpWebClient>().As<WebClient>();
|
||||
RegisterWebClient<HttpWebClient>(builder);
|
||||
break;
|
||||
case "httpclient2":
|
||||
builder.RegisterType<HttpWebClient2>().As<WebClient>();
|
||||
RegisterWebClient<HttpWebClient2>(builder);
|
||||
break;
|
||||
case "safecurl":
|
||||
builder.RegisterType<UnixSafeCurlWebClient>().As<WebClient>();
|
||||
RegisterWebClient<UnixSafeCurlWebClient>(builder);
|
||||
break;
|
||||
case "libcurl":
|
||||
builder.RegisterType<UnixLibCurlWebClient>().As<WebClient>();
|
||||
RegisterWebClient<UnixLibCurlWebClient>(builder);
|
||||
break;
|
||||
case "automatic":
|
||||
default:
|
||||
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
|
||||
{
|
||||
builder.RegisterType<HttpWebClient>().As<WebClient>();
|
||||
RegisterWebClient<HttpWebClient>(builder);
|
||||
break;
|
||||
}
|
||||
var usehttpclient = DetectMonoCompatabilityWithHttpClient();
|
||||
if (usehttpclient)
|
||||
builder.RegisterType<HttpWebClient>().As<WebClient>();
|
||||
RegisterWebClient<HttpWebClient>(builder);
|
||||
else
|
||||
builder.RegisterType<UnixLibCurlWebClient>().As<WebClient>();
|
||||
RegisterWebClient<UnixLibCurlWebClient>(builder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterWebClient<WebClientType>(ContainerBuilder builder)
|
||||
{
|
||||
Engine.WebClientType = typeof(WebClientType);
|
||||
builder.RegisterType<WebClientType>().As<WebClient>();
|
||||
}
|
||||
|
||||
private ServerConfig BuildServerConfig(IComponentContext ctx)
|
||||
|
@@ -19,6 +19,8 @@ using System.Threading;
|
||||
using System.Web;
|
||||
using Jackett.Services.Interfaces;
|
||||
using Jacket.Common;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Jackett.Services
|
||||
{
|
||||
@@ -204,6 +206,53 @@ namespace Jackett.Services
|
||||
logger.Error(e.Message + " Most likely the mono-locale-extras package is not installed.");
|
||||
Engine.Exit(2);
|
||||
}
|
||||
|
||||
if (Engine.WebClientType == typeof(HttpWebClient) || Engine.WebClientType == typeof(HttpWebClient2))
|
||||
{
|
||||
// check if the certificate store was initialized using Mono.Security.X509.X509StoreManager.TrustedRootCertificates.Count
|
||||
try
|
||||
{
|
||||
var monoSecurity = Assembly.Load("Mono.Security");
|
||||
Type monoX509StoreManager = monoSecurity.GetType("Mono.Security.X509.X509StoreManager");
|
||||
if (monoX509StoreManager != null)
|
||||
{
|
||||
var TrustedRootCertificatesProperty = monoX509StoreManager.GetProperty("TrustedRootCertificates");
|
||||
var TrustedRootCertificates = (ICollection)TrustedRootCertificatesProperty.GetValue(null);
|
||||
|
||||
logger.Info("TrustedRootCertificates count: " + TrustedRootCertificates.Count);
|
||||
|
||||
if (TrustedRootCertificates.Count == 0)
|
||||
{
|
||||
var CACertificatesFiles = new string[] {
|
||||
"/etc/ssl/certs/ca-certificates.crt", // Debian based
|
||||
"/etc/pki/tls/certs/ca-bundle.c", // RedHat based
|
||||
"/etc/ssl/ca-bundle.pem", // SUSE
|
||||
};
|
||||
|
||||
var notice = "The mono certificate store is not initialized.<br/>\n";
|
||||
var logSpacer = " ";
|
||||
var CACertificatesFile = CACertificatesFiles.Where(f => File.Exists(f)).FirstOrDefault();
|
||||
var CommandRoot = "curl -sS https://curl.haxx.se/ca/cacert.pem | cert-sync /dev/stdin";
|
||||
var CommandUser = "curl -sS https://curl.haxx.se/ca/cacert.pem | cert-sync --user /dev/stdin";
|
||||
if (CACertificatesFile != null)
|
||||
{
|
||||
CommandRoot = "cert-sync " + CACertificatesFile;
|
||||
CommandUser = "cert-sync --user " + CACertificatesFile;
|
||||
}
|
||||
notice += logSpacer + "Please run the following command as root:<br/>\n";
|
||||
notice += logSpacer + "<pre>" + CommandRoot + "</pre><br/>\n";
|
||||
notice += logSpacer + "If you don't have root access, please run the following command as the jackett user (" + Environment.UserName + "):<br/>\n";
|
||||
notice += logSpacer + "<pre>" + CommandUser + "</pre>";
|
||||
_notices.Add(notice);
|
||||
logger.Error(Regex.Replace(notice, "<.*?>", String.Empty));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e, "Error while chekcing the mono certificate store");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
Reference in New Issue
Block a user