|
|
|
@ -257,7 +257,7 @@ namespace Emby.Server.Core
|
|
|
|
|
internal IPowerManagement PowerManagement { get; private set; }
|
|
|
|
|
internal IImageEncoder ImageEncoder { get; private set; }
|
|
|
|
|
|
|
|
|
|
private readonly Action<string, string> _certificateGenerator;
|
|
|
|
|
private readonly Action<string, string, string> _certificateGenerator;
|
|
|
|
|
private readonly Func<string> _defaultUserNameFactory;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -274,7 +274,7 @@ namespace Emby.Server.Core
|
|
|
|
|
ISystemEvents systemEvents,
|
|
|
|
|
IMemoryStreamFactory memoryStreamFactory,
|
|
|
|
|
INetworkManager networkManager,
|
|
|
|
|
Action<string, string> certificateGenerator,
|
|
|
|
|
Action<string, string, string> certificateGenerator,
|
|
|
|
|
Func<string> defaultUsernameFactory)
|
|
|
|
|
: base(applicationPaths,
|
|
|
|
|
logManager,
|
|
|
|
@ -609,8 +609,8 @@ namespace Emby.Server.Core
|
|
|
|
|
|
|
|
|
|
RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
|
|
|
|
|
|
|
|
|
|
CertificatePath = GetCertificatePath(true);
|
|
|
|
|
Certificate = GetCertificate(CertificatePath);
|
|
|
|
|
CertificateInfo = GetCertificateInfo(true);
|
|
|
|
|
Certificate = GetCertificate(CertificateInfo);
|
|
|
|
|
|
|
|
|
|
HttpServer = HttpServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, MemoryStreamFactory, "Emby", "web/index.html", textEncoding, SocketFactory, CryptographyProvider, JsonSerializer, XmlSerializer, EnvironmentInfo, Certificate, FileSystemManager, SupportsDualModeSockets);
|
|
|
|
|
HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
|
|
|
|
@ -745,8 +745,10 @@ namespace Emby.Server.Core
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ICertificate GetCertificate(string certificateLocation)
|
|
|
|
|
private ICertificate GetCertificate(CertificateInfo info)
|
|
|
|
|
{
|
|
|
|
|
var certificateLocation = info == null ? null : info.Path;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(certificateLocation))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
@ -759,7 +761,7 @@ namespace Emby.Server.Core
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
X509Certificate2 localCert = new X509Certificate2(certificateLocation);
|
|
|
|
|
X509Certificate2 localCert = new X509Certificate2(certificateLocation, info.Password);
|
|
|
|
|
//localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
|
|
|
|
|
if (!localCert.HasPrivateKey)
|
|
|
|
|
{
|
|
|
|
@ -1064,7 +1066,7 @@ namespace Emby.Server.Core
|
|
|
|
|
SyncManager.AddParts(GetExports<ISyncProvider>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string CertificatePath { get; set; }
|
|
|
|
|
private CertificateInfo CertificateInfo { get; set; }
|
|
|
|
|
private ICertificate Certificate { get; set; }
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetUrlPrefixes()
|
|
|
|
@ -1080,7 +1082,7 @@ namespace Emby.Server.Core
|
|
|
|
|
"http://"+i+":" + HttpPort + "/"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CertificatePath))
|
|
|
|
|
if (CertificateInfo != null)
|
|
|
|
|
{
|
|
|
|
|
prefixes.Add("https://" + i + ":" + HttpsPort + "/");
|
|
|
|
|
}
|
|
|
|
@ -1123,17 +1125,21 @@ namespace Emby.Server.Core
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCertificatePath(bool generateCertificate)
|
|
|
|
|
private CertificateInfo GetCertificateInfo(bool generateCertificate)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.CertificatePath))
|
|
|
|
|
{
|
|
|
|
|
// Custom cert
|
|
|
|
|
return ServerConfigurationManager.Configuration.CertificatePath;
|
|
|
|
|
return new CertificateInfo
|
|
|
|
|
{
|
|
|
|
|
Path = ServerConfigurationManager.Configuration.CertificatePath
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate self-signed cert
|
|
|
|
|
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
|
|
|
|
|
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + (certHost + "1").GetMD5().ToString("N") + ".pfx");
|
|
|
|
|
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + (certHost + "2").GetMD5().ToString("N") + ".pfx");
|
|
|
|
|
var password = "embycert";
|
|
|
|
|
|
|
|
|
|
if (generateCertificate)
|
|
|
|
|
{
|
|
|
|
@ -1143,7 +1149,7 @@ namespace Emby.Server.Core
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_certificateGenerator(certPath, certHost);
|
|
|
|
|
_certificateGenerator(certPath, certHost, password);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -1153,7 +1159,11 @@ namespace Emby.Server.Core
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return certPath;
|
|
|
|
|
return new CertificateInfo
|
|
|
|
|
{
|
|
|
|
|
Path = certPath,
|
|
|
|
|
Password = password
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -1189,7 +1199,11 @@ namespace Emby.Server.Core
|
|
|
|
|
requiresRestart = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(CertificatePath, GetCertificatePath(false), StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
var currentCertPath = CertificateInfo == null ? null : CertificateInfo.Path;
|
|
|
|
|
var newCertInfo = GetCertificateInfo(false);
|
|
|
|
|
var newCertPath = newCertInfo == null ? null : newCertInfo.Path;
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(currentCertPath, newCertPath, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
requiresRestart = true;
|
|
|
|
|
}
|
|
|
|
@ -1779,6 +1793,11 @@ namespace Emby.Server.Core
|
|
|
|
|
{
|
|
|
|
|
Container.Register(typeInterface, typeImplementation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class CertificateInfo
|
|
|
|
|
{
|
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|