Mono: check if the certificate store was initialized

This commit is contained in:
kaso17
2017-12-07 14:35:50 +01:00
parent 29f111aec4
commit 2c83038ea8
3 changed files with 63 additions and 7 deletions

View File

@@ -21,6 +21,8 @@ namespace Jackett
{
public class Engine
{
public static Type WebClientType;
private static IContainer container = null;
private static bool _automapperInitialised = false;

View File

@@ -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)

View File

@@ -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)