コード例 #1
0
ファイル: AcmeClient.cs プロジェクト: skyhoshi/win-acme
        /// <summary>
        /// Attempt to create an account using specific parameters
        /// </summary>
        /// <param name="client"></param>
        /// <param name="signer"></param>
        /// <param name="contacts"></param>
        /// <param name="eabAlg"></param>
        /// <param name="eabKid"></param>
        /// <param name="eabKey"></param>
        /// <returns></returns>
        private async Task CreateAccount(
            AcmeProtocolClient client, AccountSigner signer,
            string[]?contacts,
            string eabAlg, string?eabKid, string?eabKey)
        {
            if (client.Account != null)
            {
                throw new Exception("Client already has an account!");
            }
            ExternalAccountBinding?externalAccount = null;

            if (!string.IsNullOrWhiteSpace(eabKey) &&
                !string.IsNullOrWhiteSpace(eabKid))
            {
                externalAccount = new ExternalAccountBinding(
                    eabAlg,
                    JsonConvert.SerializeObject(
                        signer.JwsTool().ExportJwk(),
                        Formatting.None),
                    eabKid,
                    eabKey,
                    client.Directory?.NewAccount ?? "");
            }
            await client.ChangeAccountKeyAsync(signer.JwsTool());

            client.Account = await Retry(client,
                                         () => client.CreateAccountAsync(
                                             contacts,
                                             termsOfServiceAgreed: true,
                                             externalAccountBinding: externalAccount?.Payload() ?? null));

            _accountManager.CurrentSigner  = signer;
            _accountManager.CurrentAccount = client.Account;
        }
コード例 #2
0
ファイル: AcmeClient.cs プロジェクト: skyhoshi/win-acme
        /// <summary>
        /// Load the account, signer and directory
        /// </summary>
        /// <returns></returns>
        internal async Task ConfigureAcmeClient()
        {
            var httpClient = _proxyService.GetHttpClient();

            httpClient.BaseAddress = _settings.BaseUri;
            _log.Verbose("Constructing ACME protocol client...");
            var client = new AcmeProtocolClient(httpClient, usePostAsGet: _settings.Acme.PostAsGet);

            client.Directory = await EnsureServiceDirectory(client);

            // Try to load prexisting account
            if (_accountManager.CurrentAccount != null &&
                _accountManager.CurrentSigner != null)
            {
                _log.Verbose("Using existing ACME account");
                await client.ChangeAccountKeyAsync(_accountManager.CurrentSigner.JwsTool());

                client.Account = _accountManager.CurrentAccount;
            }
            else
            {
                _log.Verbose("No account found, creating new one");
                await SetupAccount(client);
            }
            if (client.Account == null)
            {
                throw new Exception("AcmeClient was unable to find or create an account");
            }
            _client = client;
            _log.Verbose("ACME client initialized");
        }