public async Task CanDeleteRegistration()
        {
            using (var client = new AcmeClient(WellKnownServers.LetsEncryptStaging))
            {
                var reg = await client.NewRegistraton();

                await client.DeleteRegistration(reg);
            }
        }
        public async Task CanChangeKey()
        {
            using (var client = new AcmeClient(WellKnownServers.LetsEncryptStaging))
            {
                var reg = await client.NewRegistraton();

                var newKey = new AccountKey().Export();
                await client.ChangeKey(reg, newKey);

                await client.DeleteRegistration(reg);
            }
        }
Пример #3
0
        public static async Task <Uri> GetAcmeUriV1()
        {
            if (stagingServerV1 != null)
            {
                return(stagingServerV1);
            }

            var key = await Helper.LoadkeyV1();

            foreach (var uri in StagingServersV1)
            {
                var httpSucceed = false;
                try
                {
                    await http.Value.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);

                    httpSucceed = true;
                }
                catch
                {
                }

                if (httpSucceed)
                {
                    using (var client = new AcmeClient(new AcmeHttpHandler(uri, http.Value)))
                    {
                        client.Use(key.Export());

                        try
                        {
                            var account = await client.NewRegistraton();

                            account.Data.Agreement = account.GetTermsOfServiceUri();
                            await client.UpdateRegistration(account);
                        }
                        catch
                        {
                            // account already exists
                        }

                        return(stagingServerV1 = uri);
                    }
                }
            }

            throw new Exception("Staging server unavailable.");
        }
Пример #4
0
        public async Task CanCreateRegistration()
        {
            var accountKey = await Helper.LoadkeyV1();

            var regLocation = new Uri("http://example.com/reg/1");
            var mock        = MockHttp(async req =>
            {
                if (req.Method == HttpMethod.Post && req.RequestUri == acmeDir.NewReg)
                {
                    var payload = await ParsePayload <RegistrationEntity>(req);
                    Assert.Equal(ResourceTypes.NewRegistration, payload.Resource);
                    Assert.Equal(1, payload.Contact?.Count);
                    Assert.Equal(email, payload.Contact[0]);

                    var respJson = new
                    {
                        contact  = payload.Contact,
                        resource = ResourceTypes.Registration
                    };

                    var resp = CreateResponse(respJson, HttpStatusCode.Created, regLocation);
                    resp.Headers.Add("Link", $"<{tos}>; rel=\"terms-of-service\"");
                    return(resp);
                }

                return(null);
            });

            using (var http = new HttpClient(mock.Object))
                using (var handler = new AcmeHttpHandler(server, http))
                {
                    using (var client = new AcmeClient(handler))
                    {
                        client.Use(accountKey.Export());

                        var account = await client.NewRegistraton(email);

                        Assert.Equal(ResourceTypes.Registration, account.Data.Resource);
                        Assert.Null(account.Data.Agreement);
                        Assert.Equal(regLocation, account.Location);
                        Assert.Equal(tos, account.GetTermsOfServiceUri());
                    }

                    mock.As <IDisposable>().Verify(x => x.Dispose(), Times.Never());
                }
        }
Пример #5
0
        public async Task CanNewRegistraton()
        {
            var accountKey = await Helper.LoadkeyV1();

            var contacts    = new string[] { "mailto:[email protected]" };
            var regLocation = new Uri("http://example.com/reg/1");
            var mock        = MockHttp(async req =>
            {
                if (req.Method == HttpMethod.Post && req.RequestUri == Helper.MockDirectoryV1.NewReg)
                {
                    var payload = await ParsePayload <RegistrationEntity>(req);
                    Assert.Equal(ResourceTypes.NewRegistration, payload.Resource);
                    Assert.Equal(contacts.Clone(), payload.Contact);

                    var respJson = new
                    {
                        contact   = payload.Contact,
                        agreement = payload.Agreement,
                        resource  = ResourceTypes.Registration
                    };

                    var resp = CreateResponse(respJson, HttpStatusCode.Created, regLocation);
                    resp.Headers.Add("Link", $"<{tos}>; rel=\"terms-of-service\"");
                    return(resp);
                }

                return(null);
            });

            using (var http = new HttpClient(mock.Object))
                using (var handler = new AcmeHttpHandler(server, http))
                {
                    using (var client = new AcmeClient(handler))
                    {
                        client.Use(accountKey.Export());
                        var result = await client.NewRegistraton(contacts);

                        Assert.Equal(ResourceTypes.Registration, result.Data.Resource);
                        Assert.Equal(regLocation, result.Location);
                    }

                    mock.Protected().Verify("Dispose", Times.Never(), true);
                }
        }
Пример #6
0
        public async Task RunAccountFlow(KeyAlgorithm algorithm)
        {
            var dirUri = await IntegrationHelper.GetAcmeUriV1();

            var key = new AccountKey(algorithm);

            using (var client = new AcmeClient(IntegrationHelper.GetAcmeHttpHandler(dirUri)))
            {
                client.Use(key.Export());
                var reg = await client.NewRegistraton();

                reg.Data.Agreement = reg.GetTermsOfServiceUri();

                await client.UpdateRegistration(reg);

                var newKey = new AccountKey().Export();
                await client.ChangeKey(reg, newKey);

                await client.DeleteRegistration(reg);
            }
        }