public async Task GetChallenge()
        {
            using (var http = _server.CreateClient())
            {
                var dir = await GetDir();

                var signer = new Crypto.JOSE.Impl.RSJwsTool();
                signer.Init();
                using (var acme = new AcmeProtocolClient(http, dir,
                                                         signer: signer))
                {
                    await acme.GetNonceAsync();

                    var acct = await acme.CreateAccountAsync(new[] { "mailto:[email protected]" });

                    acme.Account = acct;

                    var dnsIds = new[] { "foo.mock.acme2.zyborg.io" };
                    var order  = await acme.CreateOrderAsync(dnsIds);

                    Assert.IsNotNull(order?.OrderUrl);
                    Assert.AreEqual(dnsIds.Length, order.Payload.Authorizations?.Length);
                    Assert.AreEqual(dnsIds.Length, order.Payload.Identifiers?.Length);

                    var authzUrl = order.Payload.Authorizations[0];
                    var authz    = await acme.GetAuthorizationDetailsAsync(authzUrl);

                    Assert.IsNotNull(authz);
                    Assert.IsFalse(authz.Wildcard ?? false);
                    Assert.AreEqual(dnsIds[0], authz.Identifier.Value);

                    foreach (var chlng in authz.Challenges)
                    {
                        var chlng2 = await acme.GetChallengeDetailsAsync(chlng.Url);

                        Assert.IsNotNull(chlng2);
                    }
                }
            }
        }
Example #2
0
        internal async Task <Challenge> AnswerChallenge(Challenge challenge)
        {
            // Have to loop to wait for server to stop being pending
            challenge = await Retry(() => _client.AnswerChallengeAsync(challenge.Url));

            var tries = 1;

            while (
                challenge.Status == AuthorizationPending ||
                challenge.Status == AuthorizationProcessing)
            {
                await Task.Delay(_settings.Acme.RetryInterval * 1000);

                _log.Debug("Refreshing authorization ({tries}/{count})", tries, _settings.Acme.RetryCount);
                challenge = await Retry(() => _client.GetChallengeDetailsAsync(challenge.Url));

                tries += 1;
                if (tries > _settings.Acme.RetryCount)
                {
                    break;
                }
            }
            return(challenge);
        }
Example #3
0
 internal Challenge GetChallengeDetails(string url)
 {
     return(Retry(() => _client.GetChallengeDetailsAsync(url).Result));
 }
        public async Task <StatusMessage> SubmitChallenge(ILog log, string challengeType, AuthorizationChallengeItem attemptedChallenge)
        {
            if (attemptedChallenge == null)
            {
                return(new StatusMessage
                {
                    IsOK = false,
                    Message = "Challenge could not be submitted. No matching attempted challenge."
                });
            }

            if (!attemptedChallenge.IsValidated)
            {
                //  IChallengeContext challenge = (IChallengeContext)attemptedChallenge.ChallengeData;
                try
                {
                    var result = await _client.AnswerChallengeAsync(attemptedChallenge.ResourceUri);

                    var attempts = 10;

                    while (attempts > 0 && result.Status == "pending" || result.Status == "processing")
                    {
                        result = await _client.GetChallengeDetailsAsync(attemptedChallenge.ResourceUri);
                    }

                    if (result.Status == "valid")
                    {
                        return(new StatusMessage
                        {
                            IsOK = true,
                            Message = "Submitted"
                        });
                    }
                    else
                    {
                        return(new StatusMessage
                        {
                            IsOK = false,
                            Message = result.Error.ToString()
                        });
                    }
                }
                catch (ACMESharp.Protocol.AcmeProtocolException exp)
                {
                    var msg = $"Submit Challenge failed: {exp.ProblemDetail}";

                    log.Error(msg);

                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = msg
                    });
                }
            }
            else
            {
                return(new StatusMessage
                {
                    IsOK = true,
                    Message = "Validated"
                });
            }
        }