private async Task <AccountDetails> LoadAccount(IJwsTool signer) { AccountDetails account = null; if (File.Exists(AccountPath)) { if (signer != null) { _log.Debug("Loading account information from {registrationPath}", AccountPath); account = JsonConvert.DeserializeObject <AccountDetails>(File.ReadAllText(AccountPath)); _client.Account = account; // Maybe we should update the account details // on every start of the program to figure out // if it hasn't been suspended or cancelled? // UpdateAccount(); } else { _log.Error("Account found but no valid signer could be loaded"); } } else { var contacts = await GetContacts(); var(_, filename, content) = await _client.GetTermsOfServiceAsync(); if (!_arguments.MainArguments.AcceptTos) { var tosPath = Path.Combine(_settings.Client.ConfigurationPath, filename); File.WriteAllBytes(tosPath, content); _input.Show($"Terms of service", tosPath); if (await _input.PromptYesNo($"Open in default application?", false)) { Process.Start(tosPath); } if (!await _input.PromptYesNo($"Do you agree with the terms?", true)) { return(null); } } account = await _client.CreateAccountAsync(contacts, termsOfServiceAgreed : true); _log.Debug("Saving registration"); var accountKey = new AccountSigner { KeyType = _client.Signer.JwsAlg, KeyExport = _client.Signer.Export(), }; AccountSigner = accountKey; File.WriteAllText(AccountPath, JsonConvert.SerializeObject(account)); } return(account); }
internal void EncryptSigner() { try { var signer = AccountSigner; AccountSigner = signer; //forces a re-save of the signer _log.Information("Signer re-saved"); } catch { _log.Error("Cannot re-save signer as it is likely encrypted on a different machine"); } }
private async Task <AccountDetails> LoadAccount(IJwsTool signer) { AccountDetails account = null; if (File.Exists(AccountPath)) { if (signer != null) { _log.Debug("Loading account information from {registrationPath}", AccountPath); account = JsonConvert.DeserializeObject <AccountDetails>(File.ReadAllText(AccountPath)); } else { _log.Error("Account found but no valid Signer could be loaded"); } } else { var contacts = GetContacts(); var(contentType, filename, content) = await _client.GetTermsOfServiceAsync(); if (!_optionsService.MainArguments.AcceptTos) { var tosPath = Path.Combine(_settings.ConfigPath, filename); File.WriteAllBytes(tosPath, content); _input.Show($"Terms of service", tosPath); if (_input.PromptYesNo($"Open in default application?")) { Process.Start(tosPath); } if (!_input.PromptYesNo($"Do you agree with the terms?")) { return(null); } } account = await _client.CreateAccountAsync(contacts, termsOfServiceAgreed : true); _log.Debug("Saving registration"); var accountKey = new AccountSigner { KeyType = _client.Signer.JwsAlg, KeyExport = _client.Signer.Export(), }; AccountSigner = accountKey; File.WriteAllText(AccountPath, JsonConvert.SerializeObject(account)); } return(account); }
private async Task <AccountDetails?> LoadAccount(AcmeProtocolClient client, IJwsTool?signer) { AccountDetails?account = null; if (File.Exists(AccountPath)) { if (signer != null) { _log.Debug("Loading account information from {registrationPath}", AccountPath); account = JsonConvert.DeserializeObject <AccountDetails>(File.ReadAllText(AccountPath)); client.Account = account; // Maybe we should update the account details // on every start of the program to figure out // if it hasn't been suspended or cancelled? // UpdateAccount(); } else { _log.Error("Account found but no valid signer could be loaded"); } } else { var contacts = await GetContacts(); var(_, filename, content) = await client.GetTermsOfServiceAsync(); if (!string.IsNullOrEmpty(filename)) { if (!await AcceptTos(filename, content)) { return(null); } } account = await client.CreateAccountAsync(contacts, termsOfServiceAgreed : true); _log.Debug("Saving registration"); var accountKey = new AccountSigner { KeyType = client.Signer.JwsAlg, KeyExport = client.Signer.Export(), }; AccountSigner = accountKey; File.WriteAllText(AccountPath, JsonConvert.SerializeObject(account)); } return(account); }