aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-12-29 12:13:27 -0500
committerLuke <luke.pulverenti@gmail.com>2015-12-29 12:13:27 -0500
commitfc1faa65d4e5cc0b4674f15c148c02cddc52aa19 (patch)
tree0119d8bff36450dd632643853de7ced03ce685b9 /MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
parent3f46d8ddd912618e08bfbc78feff690fa29b841f (diff)
parentf92b517edae2629b8f0d61f19c6199fdeb10d17d (diff)
Merge pull request #1382 from softworkz/ConfigCheckCertificate
ServerConfigurationManager: Check if a specified SSL certificate can be used when configuration is saved
Diffstat (limited to 'MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs37
1 files changed, 37 insertions, 0 deletions
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<ServerConfiguration> { Argument = newConfig }, Logger);
base.ReplaceConfiguration(newConfiguration);
}
+
+ /// <summary>
+ /// Validates the SSL certificate.
+ /// </summary>
+ /// <param name="newConfig">The new configuration.</param>
+ /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
+ 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)