Skip to content

Commit

Permalink
handle ACME servers without terms of service #1319
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterTinus committed Dec 11, 2019
1 parent 8ffdaec commit 9e4c5e5
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions src/main.lib/Acme/AcmeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,12 @@ internal async Task EnsureInitialized()
{
var contacts = await GetContacts();
var (_, filename, content) = await _client.GetTermsOfServiceAsync();
var tosPath = Path.Combine(_settings.Client.ConfigurationPath, filename);
File.WriteAllBytes(tosPath, content);
_input.Show($"Terms of service", tosPath);
if (!_arguments.MainArguments.AcceptTos)
if (!string.IsNullOrEmpty(filename))
{
if (await _input.PromptYesNo($"Open in default application?", false))
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = tosPath,
UseShellExecute = true
});
}
catch (Exception ex)
{
_log.Error(ex, "Unable to start PDF reader");
}
}
if (!await _input.PromptYesNo($"Do you agree with the terms?", true))
if (!await AcceptTos(filename, content))
{
return null;
}

}
account = await _client.CreateAccountAsync(contacts, termsOfServiceAgreed: true);
_log.Debug("Saving registration");
Expand All @@ -196,6 +177,40 @@ internal async Task EnsureInitialized()
return account;
}

/// <summary>
/// Ask the user to accept the terms of service dictated
/// by the ACME service operator
/// </summary>
/// <param name="filename"></param>
/// <param name="content"></param>
/// <returns></returns>
private async Task<bool> AcceptTos(string filename, byte[] content)
{
var tosPath = Path.Combine(_settings.Client.ConfigurationPath, filename);
File.WriteAllBytes(tosPath, content);
_input.Show($"Terms of service", tosPath);
if (_arguments.MainArguments.AcceptTos)
{
return true;
}
if (await _input.PromptYesNo($"Open in default application?", false))
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = tosPath,
UseShellExecute = true
});
}
catch (Exception ex)
{
_log.Error(ex, "Unable to start application");
}
}
return await _input.PromptYesNo($"Do you agree with the terms?", true);
}

/// <summary>
/// Get contact information
/// </summary>
Expand Down Expand Up @@ -244,7 +259,7 @@ private async Task<string[]> GetContacts()
/// </summary>
private string AccountPath => Path.Combine(_settings.Client.ConfigurationPath, RegistrationFileName);

private AccountSigner AccountSigner
private AccountSigner? AccountSigner
{
get
{
Expand Down

0 comments on commit 9e4c5e5

Please sign in to comment.