예제 #1
0
        public async Task LoginAsync(string serializedAccountData)
        {
            if (serializedAccountData == null)
            {
                throw new ArgumentNullException(nameof(serializedAccountData));
            }
            if (string.IsNullOrWhiteSpace(serializedAccountData))
            {
                throw new ArgumentException("Value cannot be empty or whitespace only string.", nameof(serializedAccountData));
            }
            var legacyAccount = JsonConvert.DeserializeObject <AcmeAccount>(serializedAccountData);

            context = new AcmeContext(serverAddress, KeyFactory.FromDer(legacyAccount.Key.PrivateKeyInfo), client);
            Log.Write($"Accepting TOS at {legacyAccount.Data.Agreement}...");
            try {
                var accountContext = await context.Account().ConfigureAwait(true);

                await accountContext.Update(agreeTermsOfService : true).ConfigureAwait(true);
            }
            catch (AcmeRequestException ex) {
                if (ex.Error?.Type != "urn:ietf:params:acme:error:accountDoesNotExist")
                {
                    throw;
                }
                Log.WriteLine("Migrating account...");
                await context.NewAccount(legacyAccount.Data.Contact, true).ConfigureAwait(true);
            }
            Log.WriteLine("OK");
        }
예제 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         client  = null;
         context = null;
     }
 }
예제 #3
0
        public async Task <string> RegisterAndLoginAsync(string email)
        {
            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentException("Value cannot be empty or whitespace only string.", nameof(email));
            }
            if (client == null)
            {
                throw new ObjectDisposedException(nameof(AutoAcmeContext));
            }
            context = new AcmeContext(serverAddress, null, client);
            Log.Write($"Creating registration for '{email}' and accept TOS...");
            var contacts       = new[] { "mailto:" + email };
            var accountContext = await context.NewAccount(contacts, true).ConfigureAwait(true);

            Log.WriteLine("OK");
            // For compatibility with earlier versions, use the V1 account object for storage
            AcmeAccount legacyAccount = new AcmeAccount()
            {
                ContentType = "application/json",
                Key         = new KeyInfo()
                {
                    PrivateKeyInfo = context.AccountKey.ToDer()
                },
                Data =
                {
                    Contact  = contacts,
                    Resource = "reg"
                },
                Location = accountContext.Location
            };

            legacyAccount.Data.Agreement = await context.TermsOfService().ConfigureAwait(true);

            return(JsonConvert.SerializeObject(legacyAccount));
        }