summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWouter Tinus <wouter.tinus@gmail.com>2020-09-08 20:50:38 +0200
committerWouter Tinus <wouter.tinus@gmail.com>2020-09-08 20:50:38 +0200
commitd93118938f31454f19318ef3ccc872f4bf0800d7 (patch)
tree9259416fe43fc284c0ae1aec66c22b2a17ca2771 /src
parentdb7e9e3b331775fdf30670b13509f93d6dc4a306 (diff)
downloadletsencrypt-win-simple-d93118938f31454f19318ef3ccc872f4bf0800d7.zip
letsencrypt-win-simple-d93118938f31454f19318ef3ccc872f4bf0800d7.tar.gz
letsencrypt-win-simple-d93118938f31454f19318ef3ccc872f4bf0800d7.tar.bz2
Add version to user agent
Diffstat (limited to 'src')
-rw-r--r--src/main.lib/Clients/Acme/AcmeClient.cs4
-rw-r--r--src/main.lib/Clients/EmailClient.cs5
-rw-r--r--src/main.lib/Services/ProxyService.cs8
-rw-r--r--src/main.lib/Services/VersionService.cs29
-rw-r--r--src/main.lib/Wacs.cs42
-rw-r--r--src/main/Program.cs9
6 files changed, 63 insertions, 34 deletions
diff --git a/src/main.lib/Clients/Acme/AcmeClient.cs b/src/main.lib/Clients/Acme/AcmeClient.cs
index e7b5391..ab2642d 100644
--- a/src/main.lib/Clients/Acme/AcmeClient.cs
+++ b/src/main.lib/Clients/Acme/AcmeClient.cs
@@ -83,10 +83,8 @@ namespace PKISharp.WACS.Clients.Acme
{
signer = accountSigner.JwsTool();
}
-
var httpClient = _proxyService.GetHttpClient();
httpClient.BaseAddress = _settings.BaseUri;
- httpClient.DefaultRequestHeaders.Add("User-Agent", "win-acme");
var client = PrepareClient(httpClient, signer);
try
{
@@ -295,7 +293,7 @@ namespace PKISharp.WACS.Clients.Acme
_log.Verbose("Writing terms of service to {path}", tosPath);
await File.WriteAllBytesAsync(tosPath, content);
_input.Show($"Terms of service", tosPath);
- if (_arguments.GetArguments<AccountArguments>().AcceptTos)
+ if (_arguments.GetArguments<AccountArguments>()?.AcceptTos ?? false)
{
return true;
}
diff --git a/src/main.lib/Clients/EmailClient.cs b/src/main.lib/Clients/EmailClient.cs
index 0f7f0a0..bbec75e 100644
--- a/src/main.lib/Clients/EmailClient.cs
+++ b/src/main.lib/Clients/EmailClient.cs
@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
-using System.Reflection;
using System.Threading.Tasks;
namespace PKISharp.WACS.Clients
@@ -32,7 +31,7 @@ namespace PKISharp.WACS.Clients
private readonly string _version;
private readonly IEnumerable<string> _receiverAddresses;
- public EmailClient(ILogService log, ISettingsService settings)
+ public EmailClient(ILogService log, ISettingsService settings, VersionService version)
{
_log = log;
_settings = settings;
@@ -47,7 +46,7 @@ namespace PKISharp.WACS.Clients
if (string.IsNullOrEmpty(_computerName)) {
_computerName = Environment.MachineName;
}
- _version = Assembly.GetEntryAssembly().GetName().Version.ToString();
+ _version = version.SoftwareVersion.ToString();
if (string.IsNullOrWhiteSpace(_senderName))
{
diff --git a/src/main.lib/Services/ProxyService.cs b/src/main.lib/Services/ProxyService.cs
index 17e45fd..6294835 100644
--- a/src/main.lib/Services/ProxyService.cs
+++ b/src/main.lib/Services/ProxyService.cs
@@ -12,12 +12,14 @@ namespace PKISharp.WACS.Services
private readonly ILogService _log;
private IWebProxy? _proxy;
private readonly ISettingsService _settings;
+ private readonly VersionService _version;
public SslProtocols SslProtocols { get; set; } = SslProtocols.None;
- public ProxyService(ILogService log, ISettingsService settings)
+ public ProxyService(ILogService log, ISettingsService settings, VersionService version)
{
_log = log;
_settings = settings;
+ _version = version;
}
/// <summary>
@@ -44,7 +46,9 @@ namespace PKISharp.WACS.Services
{
httpClientHandler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
}
- return new HttpClient(httpClientHandler);
+ var httpClient = new HttpClient(httpClientHandler);
+ httpClient.DefaultRequestHeaders.Add("User-Agent", $"win-acme/{_version.SoftwareVersion} (+https://github.com/win-acme/win-acme)");
+ return httpClient;
}
private class LoggingHttpClientHandler : HttpClientHandler
diff --git a/src/main.lib/Services/VersionService.cs b/src/main.lib/Services/VersionService.cs
new file mode 100644
index 0000000..8519107
--- /dev/null
+++ b/src/main.lib/Services/VersionService.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Reflection;
+
+namespace PKISharp.WACS.Services
+{
+ public class VersionService
+ {
+ public string BuildType
+ {
+ get
+ {
+ var build = "";
+#if DEBUG
+ build += "DEBUG";
+#else
+ build += "RELEASE";
+#endif
+#if PLUGGABLE
+ build += ", PLUGGABLE";
+#else
+ build += ", TRIMMED";
+#endif
+ return build;
+ }
+ }
+
+ public Version SoftwareVersion => Assembly.GetEntryAssembly().GetName().Version;
+ }
+}
diff --git a/src/main.lib/Wacs.cs b/src/main.lib/Wacs.cs
index be8faf9..21293be 100644
--- a/src/main.lib/Wacs.cs
+++ b/src/main.lib/Wacs.cs
@@ -10,7 +10,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Reflection;
using System.Threading.Tasks;
namespace PKISharp.WACS.Host
@@ -30,18 +29,27 @@ namespace PKISharp.WACS.Host
private readonly ExceptionHandler _exceptionHandler;
private readonly IUserRoleService _userRoleService;
private readonly TaskSchedulerService _taskScheduler;
+ private readonly VersionService _versionService;
- public Wacs(ILifetimeScope container)
+ public Wacs(
+ IContainer container,
+ IAutofacBuilder scopeBuilder,
+ ExceptionHandler exceptionHandler,
+ ILogService logService,
+ ISettingsService settingsService,
+ IUserRoleService userRoleService,
+ TaskSchedulerService taskSchedulerService,
+ VersionService versionService)
{
// Basic services
_container = container;
- _scopeBuilder = container.Resolve<IAutofacBuilder>();
- _exceptionHandler = container.Resolve<ExceptionHandler>();
- _log = _container.Resolve<ILogService>();
- _settings = _container.Resolve<ISettingsService>();
- _userRoleService = _container.Resolve<IUserRoleService>();
- _settings = _container.Resolve<ISettingsService>();
- _taskScheduler = _container.Resolve<TaskSchedulerService>();
+ _scopeBuilder = scopeBuilder;
+ _exceptionHandler = exceptionHandler;
+ _log = logService;
+ _settings = settingsService;
+ _userRoleService = userRoleService;
+ _taskScheduler = taskSchedulerService;
+ _versionService = versionService;
try
{
@@ -171,23 +179,11 @@ namespace PKISharp.WACS.Host
/// </summary>
private async Task ShowBanner()
{
- var build = "";
-#if DEBUG
- build += "DEBUG";
-#else
- build += "RELEASE";
-#endif
-#if PLUGGABLE
- build += ", PLUGGABLE";
-#else
- build += ", TRIMMED";
-#endif
- var version = Assembly.GetEntryAssembly().GetName().Version;
var iis = _container.Resolve<IIISClient>().Version;
Console.WriteLine();
_log.Information(LogType.Screen, "A simple Windows ACMEv2 client (WACS)");
- _log.Information(LogType.Screen, "Software version {version} ({build})", version, build);
- _log.Information(LogType.Disk | LogType.Event, "Software version {version} ({build}) started", version, build);
+ _log.Information(LogType.Screen, "Software version {version} ({build})", _versionService.SoftwareVersion, _versionService.BuildType);
+ _log.Information(LogType.Disk | LogType.Event, "Software version {version} ({build}) started", _versionService.SoftwareVersion, _versionService.BuildType);
if (_args != null)
{
_log.Information("ACME server {ACME}", _settings.BaseUri);
diff --git a/src/main/Program.cs b/src/main/Program.cs
index 0c1a2ba..948f10b 100644
--- a/src/main/Program.cs
+++ b/src/main/Program.cs
@@ -42,9 +42,9 @@ namespace PKISharp.WACS.Host
var original = Console.OutputEncoding;
try
- {
- // Load instance of the main class and start the program
- var wacs = new Wacs(container);
+ {
+ // Load instance of the main class and start the program
+ var wacs = container.Resolve<Wacs>(new TypedParameter(typeof(IContainer), container));
Environment.ExitCode = await wacs.Start();
}
catch (Exception ex)
@@ -107,6 +107,7 @@ namespace PKISharp.WACS.Host
_ = builder.RegisterType<ProxyService>().SingleInstance();
_ = builder.RegisterType<PasswordGenerator>().SingleInstance();
_ = builder.RegisterType<RenewalStoreDisk>().As<IRenewalStore>().SingleInstance();
+ _ = builder.RegisterType<VersionService>().SingleInstance();
pluginService.Configure(builder);
@@ -132,6 +133,8 @@ namespace PKISharp.WACS.Host
_ = builder.RegisterType<RenewalCreator>().SingleInstance();
_ = builder.Register(c => c.Resolve<IArgumentsService>().MainArguments).SingleInstance();
+ _ = builder.RegisterType<Wacs>();
+
return builder.Build();
}
}