Esempio n. 1
0
        private async Task <AcmeContext> GetOrCreateAcmeContext(Uri acmeDirectoryUri, string email)
        {
            AcmeContext acme     = null;
            string      filename = $"account{email}--{acmeDirectoryUri.Host}";
            var         secret   = await this.certificateStore.GetSecret(filename);

            if (string.IsNullOrEmpty(secret))
            {
                acme = new AcmeContext(acmeDirectoryUri);
                var account = acme.NewAccount(email, true);

                // Save the account key for later use
                var pemKey = acme.AccountKey.ToPem();
                await certificateStore.SaveSecret(filename, pemKey);

                await Task.Delay(10000); //Wait a little before using the new account.

                acme = new AcmeContext(acmeDirectoryUri, acme.AccountKey, new AcmeHttpClient(acmeDirectoryUri, new HttpClient()));
            }
            else
            {
                var accountKey = KeyFactory.FromPem(secret);
                acme = new AcmeContext(acmeDirectoryUri, accountKey, new AcmeHttpClient(acmeDirectoryUri, new HttpClient()));
            }

            return(acme);
        }