From b89d9c22b9ee2cb0034f1bde65e30d63c84d7e68 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 2 May 2014 14:52:24 -0700 Subject: [PATCH] Fixed: Changing the SSL cert will re-register with the new cert (when running as admin) --- src/NzbDrone.Host/AccessControl/SslAdapter.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/NzbDrone.Host/AccessControl/SslAdapter.cs b/src/NzbDrone.Host/AccessControl/SslAdapter.cs index ddb2e7201..56319a318 100644 --- a/src/NzbDrone.Host/AccessControl/SslAdapter.cs +++ b/src/NzbDrone.Host/AccessControl/SslAdapter.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text.RegularExpressions; using NLog; using NzbDrone.Core.Configuration; @@ -13,6 +14,7 @@ namespace NzbDrone.Host.AccessControl public class SslAdapter : ISslAdapter { private const string APP_ID = "C2172AF4-F9A6-4D91-BAEE-C2E4EE680613"; + private static readonly Regex CertificateHashRegex = new Regex(@"^\s+(?:Certificate Hash\s+:\s+)(?\w+)", RegexOptions.Compiled); private readonly INetshProvider _netshProvider; private readonly IConfigFileProvider _configFileProvider; @@ -54,7 +56,32 @@ namespace NzbDrone.Host.AccessControl if (output == null || !output.Standard.Any()) return false; + var hashLine = output.Standard.SingleOrDefault(line => CertificateHashRegex.IsMatch(line)); + + if (hashLine != null) + { + var match = CertificateHashRegex.Match(hashLine); + + if (match.Success) + { + if (match.Groups["hash"].Value != _configFileProvider.SslCertHash) + { + Unregister(); + + return false; + } + } + } + return output.Standard.Any(line => line.Contains(ipPort)); } + + private void Unregister() + { + var ipPort = "0.0.0.0:" + _configFileProvider.SslPort; + var arguments = String.Format("http delete sslcert ipport={0}", ipPort); + + _netshProvider.Run(arguments); + } } }