Esempio n. 1
0
        public async Task <AccountModel> GetOrCreateAccountAsync(CancellationToken cancellationToken)
        {
            var account = await _accountRepository.GetAccountAsync(cancellationToken);

            var acmeAccountKey = account != null
                ? KeyFactory.FromDer(account.PrivateKey)
                : null;

            _context = new AcmeContext(AcmeServer, acmeAccountKey);

            if (account != null && await ExistingAccountIsValidAsync(_context))
            {
                return(account);
            }

            return(await CreateAccount(cancellationToken));
        }
Esempio n. 2
0
        public async Task <AccountModel> GetOrCreateAccountAsync(CancellationToken cancellationToken)
        {
            var account = await _accountRepository.GetAccountAsync(cancellationToken);

            _acmeAccountKey = account != null
                ? KeyFactory.FromDer(account.PrivateKey)
                : KeyFactory.NewKey(Certes.KeyAlgorithm.ES256);

            _client = _acmeClientFactory.Create(_acmeAccountKey);

            if (account != null && await ExistingAccountIsValidAsync())
            {
                return(account);
            }

            return(await CreateAccount(cancellationToken));
        }
        public async Task <AccountModel> GetOrCreateAccountAsync(CancellationToken cancellationToken)
        {
            var account = await _accountRepository.GetAccountAsync(cancellationToken);

            var acmeAccountKey = account != null
                ? KeyFactory.FromDer(account.PrivateKey)
                : null;

            var directoryUri = _certificateAuthority.AcmeDirectoryUri;

            _logger.LogInformation("Using certificate authority {directoryUri}", directoryUri);
            _context = new AcmeContext(directoryUri, acmeAccountKey);

            if (account != null && await ExistingAccountIsValidAsync(_context))
            {
                return(account);
            }

            return(await CreateAccount(cancellationToken));
        }
        private async Task EnsureClient()
        {
            var caUri = new Uri(config.CertAuthorityUrl);

            var account = await accountStore.GetAccountAsync();

            if (account != null && account.Account.Kid.Contains(caUri.Host) == false)
            {
                logger.LogWarning("Fetched account KID doesn't contain CA host, ignoring fetched account");
                account = null;
            }

            var client = new AcmeProtocolClient(caUri, null, account?.Account, account?.Signer, usePostAsGet: true, logger: logger);

            client.Directory = await client.GetDirectoryAsync();

            // get nonce, used to communicate w/ server
            await client.GetNonceAsync();

            if (account == null)
            {
                // make request to create account
                var contactEmails = new[] { "mailto:" + config.ContactEmail };
                var newAccount    = await client.CreateAccountAsync(contactEmails, termsOfServiceAgreed : true);

                var accountKey = new AccountKey
                {
                    KeyType   = client.Signer.JwsAlg,
                    KeyExport = client.Signer.Export()
                };

                await accountStore.StoreAccountAsync(newAccount, accountKey);

                client.Account = newAccount;
            }

            this.client = client;
        }