diff options
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | docs/reference/settings.md | 16 | ||||
-rw-r--r-- | src/main.lib/Services/Interfaces/ISettingsService.cs | 2 | ||||
-rw-r--r-- | src/main.lib/Services/PluginService.cs | 15 | ||||
-rw-r--r-- | src/main.lib/Services/SettingsService.cs | 19 | ||||
-rw-r--r-- | src/main.test/Tests/BindingTests/Bindings.cs | 47 | ||||
-rw-r--r-- | src/main/Program.cs | 8 | ||||
-rw-r--r-- | src/main/settings.json | 2 |
8 files changed, 98 insertions, 13 deletions
diff --git a/appveyor.yml b/appveyor.yml index 0185702..ac81d8d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.1.0.{build} +version: 2.1.1.{build} image: Visual Studio 2019 platform: Any CPU shallow_clone: true diff --git a/docs/reference/settings.md b/docs/reference/settings.md index 9387e50..b9943de 100644 --- a/docs/reference/settings.md +++ b/docs/reference/settings.md @@ -22,7 +22,8 @@ be used. Default: `null` Change the location where the program stores its (temporary) files. If not specified -this resolves to `%programdata%\{ClientName}\{BaseUri}` +this resolves to `%programdata%\{ClientName}\{BaseUri}`. Values should be JSON-encoded, +e.g. `"C:\\"` (note the double backslash). ### `LogPath` Default: `null` @@ -45,10 +46,12 @@ Default: `50` The number of items to display per page in list views. ### `TextEncoding` -Default: `"unicode"` +Default: `"utf8"` Encoding to use for the console output. A list of possible values can be found [here](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=netcore-3.0). +For certain languages `"unicode"` might give better results displaying the characters, +but note that this reduces compatibility with other programs processing the output. ## ACME @@ -115,7 +118,8 @@ Default: `null` The path where certificates and request files are cached. If not specified or invalid, this defaults to `{ConfigurationPath}\Certificates`. If you are using [Central SSL](//win-acme/reference/plugins/store/centralssl), this can **not** -be set to the same path. +be set to the same path. Values should be JSON-encoded, e.g. `"C:\\"` +(note the double backslash). ### `ReuseDays` Default: `1` @@ -302,7 +306,8 @@ When using `--store centralssl` this path is used by default, saving you the effort from providing it manually. Filling this out makes the `--centralsslstore` parameter unnecessary in most cases. Renewals created with the default path will automatically change to any future default value, meaning this is also a good -practice for maintainability. +practice for maintainability. Values should be JSON-encoded, e.g. `"C:\\"` +(note the double backslash). ### `DefaultCentralSslPfxPassword` Default: `null` @@ -320,4 +325,5 @@ When using `--store pemfiles` this path is used by default, saving you the effor from providing it manually. Filling this out makes the `--pemfilespath` parameter unnecessary in most cases. Renewals created with the default path will automatically change to any future default value, meaning this is also a good practice for -maintainability.
\ No newline at end of file +maintainability. Values should be JSON-encoded, e.g. `"C:\\"` +(note the double backslash).
\ No newline at end of file diff --git a/src/main.lib/Services/Interfaces/ISettingsService.cs b/src/main.lib/Services/Interfaces/ISettingsService.cs index 6ac8be3..b6504ef 100644 --- a/src/main.lib/Services/Interfaces/ISettingsService.cs +++ b/src/main.lib/Services/Interfaces/ISettingsService.cs @@ -4,7 +4,7 @@ using static PKISharp.WACS.Services.SettingsService; namespace PKISharp.WACS.Services { public interface ISettingsService - { + { string ExePath { get; } Uri BaseUri { get; } UiSettings UI { get; } diff --git a/src/main.lib/Services/PluginService.cs b/src/main.lib/Services/PluginService.cs index 0ebe54c..e0763b7 100644 --- a/src/main.lib/Services/PluginService.cs +++ b/src/main.lib/Services/PluginService.cs @@ -105,6 +105,21 @@ namespace PKISharp.WACS.Services _csr = GetResolvable<ICsrPlugin>(); _store = GetResolvable<IStorePlugin>(); _installation = GetResolvable<IInstallationPlugin>(); + + ListPlugins(_target, "target"); + ListPlugins(_validation, "validation"); + ListPlugins(_csr, "csr"); + ListPlugins(_store, "store"); + ListPlugins(_installation, "installation"); + } + + private void ListPlugins(IEnumerable<Type> list, string type) + { + list.Where(x => x.Assembly != typeof(PluginService).Assembly). + All(x => { + _log.Verbose("Loaded {type} plugin {name} from {location}", type, x.Name, x.Assembly.Location); + return false; + }); } internal IEnumerable<Type> GetTypesFromAssembly(Assembly assembly) diff --git a/src/main.lib/Services/SettingsService.cs b/src/main.lib/Services/SettingsService.cs index 9c9ace4..fc55f4b 100644 --- a/src/main.lib/Services/SettingsService.cs +++ b/src/main.lib/Services/SettingsService.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Security.Permissions; namespace PKISharp.WACS.Services { @@ -13,6 +12,7 @@ namespace PKISharp.WACS.Services private readonly ILogService _log; private readonly IArgumentsService _arguments; + public bool Valid { get; private set; } = false; public ClientSettings Client { get; private set; } = new ClientSettings(); public UiSettings UI { get; private set; } = new UiSettings(); public AcmeSettings Acme { get; private set; } = new AcmeSettings(); @@ -41,14 +41,23 @@ namespace PKISharp.WACS.Services settingsTemplate.CopyTo(settings.FullName); } - new ConfigurationBuilder() - .AddJsonFile(Path.Combine(installDir, "settings.json"), true, true) - .Build() - .Bind(this); + try + { + new ConfigurationBuilder() + .AddJsonFile(Path.Combine(installDir, "settings.json"), true, true) + .Build() + .Bind(this); + } + catch (Exception ex) + { + _log.Error(new Exception("Invalid settings.json", ex), "Unable to start program"); + return; + } CreateConfigPath(); CreateLogPath(); CreateCachePath(); + Valid = true; } public Uri BaseUri diff --git a/src/main.test/Tests/BindingTests/Bindings.cs b/src/main.test/Tests/BindingTests/Bindings.cs index b8254d2..1908ac0 100644 --- a/src/main.test/Tests/BindingTests/Bindings.cs +++ b/src/main.test/Tests/BindingTests/Bindings.cs @@ -768,5 +768,52 @@ namespace PKISharp.WACS.UnitTests.Tests.BindingTests iis.AddOrUpdateBindings(new[] { "new.example.com" }, bindingOptions, scopeCert); Assert.AreEqual(expectedBindings, dup2.Bindings.Count); } + + [DataRow(7, "")] + [DataRow(10, "")] + [DataRow(7, "exists.example.com")] + [DataRow(10, "exists.example.com")] + [TestMethod] + public void IPv4andIPv6(int iisVersion, string host) + { + var dup1 = new MockSite() + { + Id = 1, + Bindings = new List<MockBinding> { + new MockBinding() { + IP = DefaultIP, + Port = DefaultPort, + Host = host, + Protocol = "https", + CertificateHash = oldCert1, + CertificateStoreName = DefaultStore + }, + new MockBinding() { + IP = "FE80:CD00:0000:0CDE:1257:0000:211E:729C", + Port = DefaultPort, + Host = host, + Protocol = "https", + CertificateHash = oldCert1, + CertificateStoreName = DefaultStore + } + } + }; + + var iis = new MockIISClient(log, iisVersion) + { + MockSites = new[] { dup1 } + }; + + var bindingOptions = new BindingOptions(). + WithSiteId(1). + WithIP(DefaultIP). + WithPort(DefaultPort). + WithStore(DefaultStore). + WithThumbprint(newCert); + + iis.AddOrUpdateBindings(new[] { "exists.example.com" }, bindingOptions, oldCert1); + Assert.AreEqual(iis.WebSites.First().Bindings.First().CertificateHash , newCert); + Assert.AreEqual(iis.WebSites.First().Bindings.Last().CertificateHash, newCert); + } } }
\ No newline at end of file diff --git a/src/main/Program.cs b/src/main/Program.cs index 7e4aa75..383695c 100644 --- a/src/main/Program.cs +++ b/src/main/Program.cs @@ -19,6 +19,10 @@ namespace PKISharp.WACS.Host { // Setup DI var container = GlobalScope(args); + if (container == null) + { + return; + } // Default is Tls 1.0 only, change to Tls 1.2 or 1.3 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13; @@ -55,6 +59,10 @@ namespace PKISharp.WACS.Host var argumentsParser = new ArgumentsParser(logger, pluginService, args); var argumentsService = new ArgumentsService(logger, argumentsParser); var settingsService = new SettingsService(logger, argumentsService); + if (!settingsService.Valid) + { + return null; + } logger.SetDiskLoggingPath(settingsService.Client.LogPath); _ = builder.RegisterInstance(argumentsService); diff --git a/src/main/settings.json b/src/main/settings.json index 76a046f..a7ea8ea 100644 --- a/src/main/settings.json +++ b/src/main/settings.json @@ -7,7 +7,7 @@ "UI": { "PageSize": 50, "DateFormat": "yyyy/M/d H:mm:ss", - "TextEncoding": "unicode" + "TextEncoding": "utf-8" }, "Acme": { "DefaultBaseUri": "https://acme-v02.api.letsencrypt.org/", |