summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Services
diff options
context:
space:
mode:
authorWouter Tinus <win.acme.simple@gmail.com>2020-03-01 13:22:35 +0100
committerGitHub <noreply@github.com>2020-03-01 13:22:35 +0100
commitc76a096f30c702aee7cadfd179421641f2a5fe4a (patch)
tree45fd536f35f098430985498d8316ad0a2c94c85b /src/main.lib/Services
parent2c3e6d331e2a071e34103b28dbaaf6ea7c767b36 (diff)
parent6acf0d45482324a919edf9404776736dfc782ed5 (diff)
downloadletsencrypt-win-simple-2.1.5.zip
letsencrypt-win-simple-2.1.5.tar.gz
letsencrypt-win-simple-2.1.5.tar.bz2
Merge pull request #1429 from win-acme/2.1.5v2.1.5
2.1.5
Diffstat (limited to 'src/main.lib/Services')
-rw-r--r--src/main.lib/Services/ArgumentsService.cs13
-rw-r--r--src/main.lib/Services/CertificateService.cs6
-rw-r--r--src/main.lib/Services/InputService.cs7
-rw-r--r--src/main.lib/Services/Interfaces/IInputService.cs13
-rw-r--r--src/main.lib/Services/LogService.cs11
-rw-r--r--src/main.lib/Services/PluginService.cs2
-rw-r--r--src/main.lib/Services/ProxyService.cs5
-rw-r--r--src/main.lib/Services/RenewalStoreDisk.cs21
-rw-r--r--src/main.lib/Services/SettingsService.cs32
9 files changed, 81 insertions, 29 deletions
diff --git a/src/main.lib/Services/ArgumentsService.cs b/src/main.lib/Services/ArgumentsService.cs
index 4601fc6..685ca55 100644
--- a/src/main.lib/Services/ArgumentsService.cs
+++ b/src/main.lib/Services/ArgumentsService.cs
@@ -8,8 +8,19 @@ namespace PKISharp.WACS.Services
{
private readonly ILogService _log;
private readonly ArgumentsParser _parser;
+ private MainArguments? _mainArguments;
- public MainArguments MainArguments => _parser.GetArguments<MainArguments>();
+ public MainArguments MainArguments
+ {
+ get
+ {
+ if (_mainArguments == null)
+ {
+ _mainArguments = _parser.GetArguments<MainArguments>();
+ }
+ return _mainArguments;
+ }
+ }
public ArgumentsService(ILogService log, ArgumentsParser parser)
{
diff --git a/src/main.lib/Services/CertificateService.cs b/src/main.lib/Services/CertificateService.cs
index d30e601..52f7d11 100644
--- a/src/main.lib/Services/CertificateService.cs
+++ b/src/main.lib/Services/CertificateService.cs
@@ -88,7 +88,7 @@ namespace PKISharp.WACS.Services
/// <param name="renewal"></param>
private void ClearCache(Renewal renewal, string prefix = "*", string postfix = "*")
{
- foreach (var f in _cache.GetFiles($"{prefix}{renewal.Id}{postfix}"))
+ foreach (var f in _cache.EnumerateFiles($"{prefix}{renewal.Id}{postfix}"))
{
_log.Verbose("Deleting {file} from {folder}", f.Name, _cache.FullName);
try
@@ -108,7 +108,7 @@ namespace PKISharp.WACS.Services
/// </summary>
public void Encrypt()
{
- foreach (var f in _cache.GetFiles($"*.keys"))
+ foreach (var f in _cache.EnumerateFiles($"*.keys"))
{
var x = new ProtectedString(File.ReadAllText(f.FullName));
_log.Information("Rewriting {x}", f.Name);
@@ -135,7 +135,7 @@ namespace PKISharp.WACS.Services
var nameAll = GetPath(renewal, "");
var directory = new DirectoryInfo(Path.GetDirectoryName(nameAll));
var allPattern = Path.GetFileName(nameAll);
- var allFiles = directory.GetFiles(allPattern + "*");
+ var allFiles = directory.EnumerateFiles(allPattern + "*");
if (!allFiles.Any())
{
return null;
diff --git a/src/main.lib/Services/InputService.cs b/src/main.lib/Services/InputService.cs
index 0dd4ed2..06416d3 100644
--- a/src/main.lib/Services/InputService.cs
+++ b/src/main.lib/Services/InputService.cs
@@ -339,7 +339,7 @@ namespace PKISharp.WACS.Services
/// Print a (paged) list of choices for the user to choose from
/// </summary>
/// <param name="choices"></param>
- public async Task<T> ChooseFromMenu<T>(string what, List<Choice<T>> choices)
+ public async Task<T> ChooseFromMenu<T>(string what, List<Choice<T>> choices, Func<string, Choice<T>>? unexpected = null)
{
if (!choices.Any())
{
@@ -379,6 +379,11 @@ namespace PKISharp.WACS.Services
_log.Warning($"The option you have chosen is currently disabled. {disabledReason}");
selected = null;
}
+
+ if (selected == null && unexpected != null)
+ {
+ selected = unexpected(choice);
+ }
}
} while (selected == null);
return selected.Item;
diff --git a/src/main.lib/Services/Interfaces/IInputService.cs b/src/main.lib/Services/Interfaces/IInputService.cs
index 78d155c..b59f82c 100644
--- a/src/main.lib/Services/Interfaces/IInputService.cs
+++ b/src/main.lib/Services/Interfaces/IInputService.cs
@@ -8,7 +8,7 @@ namespace PKISharp.WACS.Services
{
Task<TResult?> ChooseOptional<TSource, TResult>(string what, IEnumerable<TSource> options, Func<TSource, Choice<TResult?>> creator, string nullChoiceLabel) where TResult : class;
Task<TResult> ChooseRequired<TSource, TResult>(string what, IEnumerable<TSource> options, Func<TSource, Choice<TResult>> creator);
- Task<TResult> ChooseFromMenu<TResult>(string what, List<Choice<TResult>> choices);
+ Task<TResult> ChooseFromMenu<TResult>(string what, List<Choice<TResult>> choices, Func<string, Choice<TResult>>? unexpected = null);
Task<bool> PromptYesNo(string message, bool defaultOption);
Task<string?> ReadPassword(string what);
Task<string> RequestString(string what);
@@ -27,11 +27,14 @@ namespace PKISharp.WACS.Services
string? description = null,
string? command = null,
bool @default = false,
- bool disabled = false,
- string? disabledReason = null,
+ (bool, string?)? disabled = null,
ConsoleColor? color = null)
{
var newItem = new Choice<TItem>(item);
+ if (disabled == null)
+ {
+ disabled = (false, null);
+ }
// Default description is item.ToString, but it may
// be overruled by the optional parameter here
if (!string.IsNullOrEmpty(description))
@@ -40,8 +43,8 @@ namespace PKISharp.WACS.Services
}
newItem.Command = command;
newItem.Color = color;
- newItem.Disabled = disabled;
- newItem.DisabledReason = disabledReason;
+ newItem.Disabled = disabled.Value.Item1;
+ newItem.DisabledReason = disabled.Value.Item2;
newItem.Default = @default;
return newItem;
}
diff --git a/src/main.lib/Services/LogService.cs b/src/main.lib/Services/LogService.cs
index 3b6fde5..e88997d 100644
--- a/src/main.lib/Services/LogService.cs
+++ b/src/main.lib/Services/LogService.cs
@@ -91,6 +91,7 @@ namespace PKISharp.WACS.Services
{
var defaultPath = path.TrimEnd('\\', '/') + "\\log-.txt";
var defaultRollingInterval = RollingInterval.Day;
+ var defaultRetainedFileCountLimit = 120;
var fileConfig = new ConfigurationBuilder()
.AddJsonFile(_configurationPath, true, true)
.Build();
@@ -104,6 +105,11 @@ namespace PKISharp.WACS.Services
{
pathSection.Value = defaultPath;
}
+ var retainedFileCountLimit = writeTo.GetSection("Args:retainedFileCountLimit");
+ if (string.IsNullOrEmpty(retainedFileCountLimit.Value))
+ {
+ retainedFileCountLimit.Value = defaultRetainedFileCountLimit.ToString();
+ }
var rollingInterval = writeTo.GetSection("Args:rollingInterval");
if (string.IsNullOrEmpty(rollingInterval.Value))
{
@@ -116,7 +122,10 @@ namespace PKISharp.WACS.Services
.MinimumLevel.ControlledBy(_levelSwitch)
.Enrich.FromLogContext()
.Enrich.WithProperty("ProcessId", Process.GetCurrentProcess().Id)
- .WriteTo.File(defaultPath, rollingInterval: defaultRollingInterval)
+ .WriteTo.File(
+ defaultPath,
+ rollingInterval: defaultRollingInterval,
+ retainedFileCountLimit: defaultRetainedFileCountLimit)
.ReadFrom.Configuration(fileConfig, "disk")
.CreateLogger();
}
diff --git a/src/main.lib/Services/PluginService.cs b/src/main.lib/Services/PluginService.cs
index 2f21930..fff7fec 100644
--- a/src/main.lib/Services/PluginService.cs
+++ b/src/main.lib/Services/PluginService.cs
@@ -195,7 +195,7 @@ namespace PKISharp.WACS.Services
}
var installDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).Directory;
- var dllFiles = installDir.GetFiles("*.dll", SearchOption.AllDirectories);
+ var dllFiles = installDir.EnumerateFiles("*.dll", SearchOption.AllDirectories);
#if PLUGGABLE
var allAssemblies = new List<Assembly>();
foreach (var file in dllFiles)
diff --git a/src/main.lib/Services/ProxyService.cs b/src/main.lib/Services/ProxyService.cs
index 22e0353..f2d49a9 100644
--- a/src/main.lib/Services/ProxyService.cs
+++ b/src/main.lib/Services/ProxyService.cs
@@ -1,6 +1,7 @@
using System;
using System.Net;
using System.Net.Http;
+using System.Security.Authentication;
namespace PKISharp.WACS.Services
{
@@ -9,6 +10,7 @@ namespace PKISharp.WACS.Services
private readonly ILogService _log;
private IWebProxy? _proxy;
private readonly ISettingsService _settings;
+ public SslProtocols SslProtocols { get; set; } = SslProtocols.None;
public ProxyService(ILogService log, ISettingsService settings)
{
@@ -29,7 +31,8 @@ namespace PKISharp.WACS.Services
{
var httpClientHandler = new HttpClientHandler()
{
- Proxy = GetWebProxy()
+ Proxy = GetWebProxy(),
+ SslProtocols = SslProtocols
};
if (!checkSsl)
{
diff --git a/src/main.lib/Services/RenewalStoreDisk.cs b/src/main.lib/Services/RenewalStoreDisk.cs
index ce1d6e9..1931f63 100644
--- a/src/main.lib/Services/RenewalStoreDisk.cs
+++ b/src/main.lib/Services/RenewalStoreDisk.cs
@@ -34,20 +34,25 @@ namespace PKISharp.WACS.Services
var list = new List<Renewal>();
var di = new DirectoryInfo(_settings.Client.ConfigurationPath);
var postFix = ".renewal.json";
- foreach (var rj in di.GetFiles($"*{postFix}", SearchOption.AllDirectories))
+ foreach (var rj in di.EnumerateFiles($"*{postFix}", SearchOption.AllDirectories))
{
try
{
var storeConverter = new PluginOptionsConverter<StorePluginOptions>(_plugin.PluginOptionTypes<StorePluginOptions>(), _log);
var result = JsonConvert.DeserializeObject<Renewal>(
File.ReadAllText(rj.FullName),
- new ProtectedStringConverter(_log, _settings),
- new StorePluginOptionsConverter(storeConverter),
- new PluginOptionsConverter<TargetPluginOptions>(_plugin.PluginOptionTypes<TargetPluginOptions>(), _log),
- new PluginOptionsConverter<CsrPluginOptions>(_plugin.PluginOptionTypes<CsrPluginOptions>(), _log),
- storeConverter,
- new PluginOptionsConverter<ValidationPluginOptions>(_plugin.PluginOptionTypes<ValidationPluginOptions>(), _log),
- new PluginOptionsConverter<InstallationPluginOptions>(_plugin.PluginOptionTypes<InstallationPluginOptions>(), _log));
+ new JsonSerializerSettings() {
+ ObjectCreationHandling = ObjectCreationHandling.Replace,
+ Converters = {
+ new ProtectedStringConverter(_log, _settings),
+ new StorePluginOptionsConverter(storeConverter),
+ new PluginOptionsConverter<TargetPluginOptions>(_plugin.PluginOptionTypes<TargetPluginOptions>(), _log),
+ new PluginOptionsConverter<CsrPluginOptions>(_plugin.PluginOptionTypes<CsrPluginOptions>(), _log),
+ storeConverter,
+ new PluginOptionsConverter<ValidationPluginOptions>(_plugin.PluginOptionTypes<ValidationPluginOptions>(), _log),
+ new PluginOptionsConverter<InstallationPluginOptions>(_plugin.PluginOptionTypes<InstallationPluginOptions>(), _log)
+ }
+ });
if (result == null)
{
throw new Exception("result is empty");
diff --git a/src/main.lib/Services/SettingsService.cs b/src/main.lib/Services/SettingsService.cs
index 3b4219c..03aad0f 100644
--- a/src/main.lib/Services/SettingsService.cs
+++ b/src/main.lib/Services/SettingsService.cs
@@ -31,26 +31,42 @@ namespace PKISharp.WACS.Services
_log = log;
_arguments = arguments;
- var installDir = new FileInfo(ExePath).DirectoryName;
- _log.Verbose($"Looking for settings.json in {installDir}");
- var settings = new FileInfo(Path.Combine(installDir, "settings.json"));
- var settingsTemplate = new FileInfo(Path.Combine(installDir, "settings_default.json"));
+ var installDir = new FileInfo(ExePath).DirectoryName;
+ var settingsFileName = "settings.json";
+ var settingsFileTemplateName = "settings_default.json";
+ _log.Verbose($"Looking for {settingsFileName} in {installDir}");
+ var settings = new FileInfo(Path.Combine(installDir, settingsFileName));
+ var settingsTemplate = new FileInfo(Path.Combine(installDir, settingsFileTemplateName));
+ var useFile = settings;
if (!settings.Exists && settingsTemplate.Exists)
{
- _log.Verbose($"Copying settings_default.json to settings.json");
- settingsTemplate.CopyTo(settings.FullName);
+ _log.Verbose($"Copying {settingsFileTemplateName} to {settingsFileName}");
+ try
+ {
+ settingsTemplate.CopyTo(settings.FullName);
+ }
+ catch (Exception)
+ {
+ _log.Error($"Unable to create {settingsFileName}, falling back to {settingsFileTemplateName}");
+ useFile = settingsTemplate;
+ }
}
try
{
new ConfigurationBuilder()
- .AddJsonFile(Path.Combine(installDir, "settings.json"), true, true)
+ .AddJsonFile(useFile.FullName, true, true)
.Build()
.Bind(this);
}
catch (Exception ex)
{
- _log.Error(new Exception("Invalid settings.json", ex), "Unable to start program");
+ _log.Error($"Unable to start program using {useFile.Name}");
+ while (ex.InnerException != null)
+ {
+ _log.Error(ex.InnerException.Message);
+ ex = ex.InnerException;
+ }
return;
}