From f92b517edae2629b8f0d61f19c6199fdeb10d17d Mon Sep 17 00:00:00 2001 From: softworkz Date: Tue, 29 Dec 2015 14:36:54 +0100 Subject: ServerConfigurationManager: Check if a specified SSL certificate can be used when configuration is saved Emby can only use certificates in PFX format which include a private key, and where the private key is not protected with a password. Checking these conditions early helps to avoid misconfigurations and reduce troubleshooting time... --- .../Configuration/ServerConfigurationManager.cs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index a7d3854e7..f8266a43f 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -171,12 +171,49 @@ namespace MediaBrowser.Server.Implementations.Configuration ValidateItemByNamePath(newConfig); ValidatePathSubstitutions(newConfig); ValidateMetadataPath(newConfig); + ValidateSslCertificate(newConfig); EventHelper.FireEventIfNotNull(ConfigurationUpdating, this, new GenericEventArgs { Argument = newConfig }, Logger); base.ReplaceConfiguration(newConfiguration); } + + /// + /// Validates the SSL certificate. + /// + /// The new configuration. + /// + private void ValidateSslCertificate(BaseApplicationConfiguration newConfig) + { + var serverConfig = (ServerConfiguration)newConfig; + + var certPath = serverConfig.CertificatePath; + + if (!string.IsNullOrWhiteSpace(certPath)) + { + // Validate + if (!File.Exists(certPath)) + { + throw new FileNotFoundException(string.Format("Certificate file '{0}' does not exist.", certPath)); + } + + try + { + var cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath); + + if (cert.PrivateKey == null) + { + throw new ArgumentException("Certificate does not contain a private key!"); + } + } + catch (Exception ex) + { + throw new ArgumentException(string.Format("Exception loading certificate: '{0}' - {1}", certPath, ex.Message)); + } + } + } + private void ValidatePathSubstitutions(ServerConfiguration newConfig) { foreach (var map in newConfig.PathSubstitutions) -- cgit v1.2.3 From 2f75af85638284e32e695694db68c11b5061accf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 29 Dec 2015 12:15:19 -0500 Subject: update ValidateSslCertificate --- .../Configuration/ServerConfigurationManager.cs | 23 +++++----------------- 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index f8266a43f..2f4c3f5ee 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -188,28 +188,15 @@ namespace MediaBrowser.Server.Implementations.Configuration { var serverConfig = (ServerConfiguration)newConfig; - var certPath = serverConfig.CertificatePath; + var newPath = serverConfig.CertificatePath; - if (!string.IsNullOrWhiteSpace(certPath)) + if (!string.IsNullOrWhiteSpace(newPath) + && !string.Equals(Configuration.CertificatePath ?? string.Empty, newPath)) { // Validate - if (!File.Exists(certPath)) - { - throw new FileNotFoundException(string.Format("Certificate file '{0}' does not exist.", certPath)); - } - - try - { - var cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath); - - if (cert.PrivateKey == null) - { - throw new ArgumentException("Certificate does not contain a private key!"); - } - } - catch (Exception ex) + if (!FileSystem.FileExists(newPath)) { - throw new ArgumentException(string.Format("Exception loading certificate: '{0}' - {1}", certPath, ex.Message)); + throw new FileNotFoundException(string.Format("Certificate file '{0}' does not exist.", newPath)); } } } -- cgit v1.2.3 From 772dba319f0a0c3a6b5485c976c4640f93179bbf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 26 Jan 2016 13:19:05 -0500 Subject: deprecate options --- MediaBrowser.Api/StartupWizardService.cs | 2 -- .../Configuration/ServerConfiguration.cs | 3 --- .../Configuration/ServerConfigurationManager.cs | 27 ++-------------------- 3 files changed, 2 insertions(+), 30 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 365a9bfa8..06db1de74 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -66,8 +66,6 @@ namespace MediaBrowser.Api { _config.Configuration.IsStartupWizardCompleted = true; _config.Configuration.EnableLocalizedGuids = true; - _config.Configuration.MergeMetadataAndImagesByName = true; - _config.Configuration.EnableStandaloneMetadata = true; _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.EnableDateLastRefresh = true; _config.SaveConfiguration(); diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 2b43cdb50..81c1bd610 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -162,9 +162,6 @@ namespace MediaBrowser.Model.Configuration /// The dashboard source path. public string DashboardSourcePath { get; set; } - public bool MergeMetadataAndImagesByName { get; set; } - public bool EnableStandaloneMetadata { get; set; } - /// /// Gets or sets the image saving convention. /// diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 2f4c3f5ee..1a5c35df8 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -35,7 +35,6 @@ namespace MediaBrowser.Server.Implementations.Configuration public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) : base(applicationPaths, logManager, xmlSerializer, fileSystem) { - UpdateItemsByNamePath(); UpdateMetadataPath(); } @@ -73,7 +72,6 @@ namespace MediaBrowser.Server.Implementations.Configuration /// protected override void OnConfigurationUpdated() { - UpdateItemsByNamePath(); UpdateMetadataPath(); base.OnConfigurationUpdated(); @@ -86,19 +84,6 @@ namespace MediaBrowser.Server.Implementations.Configuration UpdateTranscodingTempPath(); } - /// - /// Updates the items by name path. - /// - private void UpdateItemsByNamePath() - { - if (!Configuration.MergeMetadataAndImagesByName) - { - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? - null : - Configuration.ItemsByNamePath; - } - } - /// /// Updates the metadata path. /// @@ -121,20 +106,12 @@ namespace MediaBrowser.Server.Implementations.Configuration ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = metadataPath; - if (Configuration.MergeMetadataAndImagesByName) - { - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath; - } + ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath; } private string GetInternalMetadataPath() { - if (Configuration.EnableStandaloneMetadata) - { - return Path.Combine(ApplicationPaths.ProgramDataPath, "metadata"); - } - - return null; + return Path.Combine(ApplicationPaths.ProgramDataPath, "metadata"); } /// -- cgit v1.2.3 From 95ae1c5f7b2dd0a9905ab78c3c42e056b5417d1c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 27 Jan 2016 01:31:31 -0500 Subject: add back MergeMetadataAndImagesByName --- MediaBrowser.Api/StartupWizardService.cs | 1 + MediaBrowser.Model/Configuration/ServerConfiguration.cs | 3 +++ .../Configuration/ServerConfigurationManager.cs | 15 +++++++++++++++ 3 files changed, 19 insertions(+) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 06db1de74..6556807c4 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -68,6 +68,7 @@ namespace MediaBrowser.Api _config.Configuration.EnableLocalizedGuids = true; _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.EnableDateLastRefresh = true; + _config.Configuration.MergeMetadataAndImagesByName = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 81c1bd610..ced5210c5 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -162,6 +162,8 @@ namespace MediaBrowser.Model.Configuration /// The dashboard source path. public string DashboardSourcePath { get; set; } + public bool MergeMetadataAndImagesByName { get; set; } + /// /// Gets or sets the image saving convention. /// @@ -211,6 +213,7 @@ namespace MediaBrowser.Model.Configuration /// public ServerConfiguration() { + MergeMetadataAndImagesByName = true; Migrations = new string[] { }; ImageSavingConvention = ImageSavingConvention.Compatible; diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 1a5c35df8..8e934f348 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -35,6 +35,7 @@ namespace MediaBrowser.Server.Implementations.Configuration public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) : base(applicationPaths, logManager, xmlSerializer, fileSystem) { + UpdateItemsByNamePath(); UpdateMetadataPath(); } @@ -72,6 +73,7 @@ namespace MediaBrowser.Server.Implementations.Configuration /// protected override void OnConfigurationUpdated() { + UpdateItemsByNamePath(); UpdateMetadataPath(); base.OnConfigurationUpdated(); @@ -84,6 +86,19 @@ namespace MediaBrowser.Server.Implementations.Configuration UpdateTranscodingTempPath(); } + /// + /// Updates the items by name path. + /// + private void UpdateItemsByNamePath() + { + if (!Configuration.MergeMetadataAndImagesByName) + { + ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? + null : + Configuration.ItemsByNamePath; + } + } + /// /// Updates the metadata path. /// -- cgit v1.2.3 From 32013f5ae50950f5da2f3113b5fb12a943a83c16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Feb 2016 11:04:18 -0500 Subject: deprecate merge setting --- MediaBrowser.Api/StartupWizardService.cs | 1 - MediaBrowser.Model/Configuration/ServerConfiguration.cs | 2 -- .../Configuration/ServerConfigurationManager.cs | 15 --------------- 3 files changed, 18 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 6556807c4..06db1de74 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -68,7 +68,6 @@ namespace MediaBrowser.Api _config.Configuration.EnableLocalizedGuids = true; _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.EnableDateLastRefresh = true; - _config.Configuration.MergeMetadataAndImagesByName = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 0b472ec22..3cb543e5d 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -161,8 +161,6 @@ namespace MediaBrowser.Model.Configuration /// /// The dashboard source path. public string DashboardSourcePath { get; set; } - - public bool MergeMetadataAndImagesByName { get; set; } /// /// Gets or sets the image saving convention. diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 8e934f348..1a5c35df8 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -35,7 +35,6 @@ namespace MediaBrowser.Server.Implementations.Configuration public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer, IFileSystem fileSystem) : base(applicationPaths, logManager, xmlSerializer, fileSystem) { - UpdateItemsByNamePath(); UpdateMetadataPath(); } @@ -73,7 +72,6 @@ namespace MediaBrowser.Server.Implementations.Configuration /// protected override void OnConfigurationUpdated() { - UpdateItemsByNamePath(); UpdateMetadataPath(); base.OnConfigurationUpdated(); @@ -86,19 +84,6 @@ namespace MediaBrowser.Server.Implementations.Configuration UpdateTranscodingTempPath(); } - /// - /// Updates the items by name path. - /// - private void UpdateItemsByNamePath() - { - if (!Configuration.MergeMetadataAndImagesByName) - { - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? - null : - Configuration.ItemsByNamePath; - } - } - /// /// Updates the metadata path. /// -- cgit v1.2.3