예제 #1
0
 public Task <StatusMessage> SubmitChallenge(ILog log, string challengeType, AuthorizationChallengeItem attemptedChallenge)
 {
     throw new System.NotImplementedException();
 }
예제 #2
0
        /// <summary>
        /// if not already validate, ask ACME CA to check we have answered the nominated challenges correctly
        /// </summary>
        /// <param name="log">  </param>
        /// <param name="challengeType">  </param>
        /// <param name="attemptedChallenge">  </param>
        /// <returns>  </returns>
        public async Task <StatusMessage> SubmitChallenge(ILog log, string challengeType, AuthorizationChallengeItem attemptedChallenge)
        {
            if (!attemptedChallenge.IsValidated)
            {
                IChallengeContext challenge = (IChallengeContext)attemptedChallenge.ChallengeData;
                try
                {
                    Challenge result = await challenge.Validate();

                    int attempts = 10;

                    while (attempts > 0 && result.Status == ChallengeStatus.Pending || result.Status == ChallengeStatus.Processing)
                    {
                        result = await challenge.Resource();
                    }

                    if (result.Status == ChallengeStatus.Valid)
                    {
                        return(new StatusMessage
                        {
                            IsOK = true,
                            Message = "Submitted"
                        });
                    }
                    else
                    {
                        var challengeError = await challenge.Resource();

                        return(new StatusMessage
                        {
                            IsOK = false,
                            Message = challengeError.Error?.Detail
                        });
                    }
                }
                catch (AcmeRequestException exp)
                {
                    var msg = $"Submit Challenge failed: {exp.Error?.Detail}";

                    log.Error(msg);

                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = msg
                    });
                }
            }
            else
            {
                return(new StatusMessage
                {
                    IsOK = true,
                    Message = "Validated"
                });
            }
        }
예제 #3
0
        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"
                });
            }
        }
예제 #4
0
        /// <summary>
        /// if not already validate, ask ACME CA to check we have answered the nominated challenges correctly
        /// </summary>
        /// <param name="log">  </param>
        /// <param name="challengeType">  </param>
        /// <param name="attemptedChallenge">  </param>
        /// <returns>  </returns>
        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)
            {
                try
                {
                    await _acme.HttpClient.ConsumeNonce();
                }
                catch (Exception)
                {
                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = "Failed to resume communication with Certificate Authority API. Try again later."
                    });
                }

                IChallengeContext challenge = (IChallengeContext)attemptedChallenge.ChallengeData;
                try
                {
                    var result = await challenge.Validate();

                    var attempts = 10;

                    while (attempts > 0 && result.Status == ChallengeStatus.Pending || result.Status == ChallengeStatus.Processing)
                    {
                        result = await challenge.Resource();

                        await Task.Delay(500);
                    }

                    if (result.Status == ChallengeStatus.Valid)
                    {
                        return(new StatusMessage
                        {
                            IsOK = true,
                            Message = "Submitted"
                        });
                    }
                    else
                    {
                        var challengeError = await challenge.Resource();

                        return(new StatusMessage
                        {
                            IsOK = false,
                            Message = challengeError.Error?.Detail
                        });
                    }
                }
                catch (AcmeRequestException exp)
                {
                    var msg = $"Submit Challenge failed: {exp.Error?.Detail}";

                    log.Error(msg);

                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = msg
                    });
                }
            }
            else
            {
                return(new StatusMessage
                {
                    IsOK = true,
                    Message = "Validated"
                });
            }
        }
예제 #5
0
        public async Task <StatusMessage> SubmitChallenge(string domainIdentifierId, string challengeType, AuthorizationChallengeItem attemptedChallenge)
        {
            try
            {
                var state = _vaultManager.SubmitChallenge(domainIdentifierId, challengeType);

                return(await Task.FromResult(new StatusMessage
                {
                    IsOK = true,
                    Message = "Submitted"
                }));
            }
            catch (Exception exp)
            {
                return(await Task.FromResult(new StatusMessage
                {
                    IsOK = false,
                    Message = exp.Message,
                    Result = exp
                }));
            }
        }
예제 #6
0
        public async Task <StatusMessage> SubmitChallenge(string domainIdentifierId, string challengeType, AuthorizationChallengeItem attemptedChallenge)
        {
            // if not already validate, ask ACME server to validate we have answered the required
            // challenge correctly
            if (!attemptedChallenge.IsValidated)
            {
                IChallengeContext challenge = (IChallengeContext)attemptedChallenge.ChallengeData;
                try
                {
                    var result = await challenge.Validate();

                    if (result.Status == ChallengeStatus.Valid || result.Status == ChallengeStatus.Pending)
                    {
                        return(new StatusMessage
                        {
                            IsOK = true,
                            Message = "Submitted"
                        });
                    }
                    else
                    {
                        var challengeError = await challenge.Resource();

                        return(new StatusMessage
                        {
                            IsOK = false,
                            Message = challengeError.ToString()
                        });
                    }
                }
                catch (Exception exp)
                {
                    LogAction("SubmitChallenge failed. ", exp.Message);

                    var challengeError = await challenge.Resource();

                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = challengeError.ToString()
                    });
                }
            }
            else
            {
                return(new StatusMessage
                {
                    IsOK = true,
                    Message = "Validated"
                });
            }
        }
예제 #7
0
        /// <summary>
        /// if not already validate, ask ACME CA to check we have answered the nominated challenges correctly
        /// </summary>
        /// <param name="log">  </param>
        /// <param name="challengeType">  </param>
        /// <param name="attemptedChallenge">  </param>
        /// <returns>  </returns>
        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)
            {
                try
                {
                    await _acme.HttpClient.ConsumeNonce();
                }
                catch (Exception)
                {
                    return(new StatusMessage
                    {
                        IsOK = false,
                        Message = "Failed to resume communication with Certificate Authority API. Try again later."
                    });
                }

                var challenge = (IChallengeContext)attemptedChallenge.ChallengeData;
                try
                {
                    var result = await challenge.Validate();

                    var attempts = 10;

                    while (attempts > 0 && (result.Status == ChallengeStatus.Pending || result.Status == ChallengeStatus.Processing) && result.Error?.Detail == null)
                    {
                        log?.Warning($"Challenge response validation still pending. Re-checking [{attempts}]..");

                        await Task.Delay(500);

                        result = await challenge.Resource();

                        attempts--;
                    }

                    if (result.Status == ChallengeStatus.Valid)
                    {
                        return(new StatusMessage
                        {
                            IsOK = true,
                            Message = "Submitted"
                        });
                    }
                    else
                    {
                        var msg = result.Error?.Detail ?? "Validation failed - unknown failure reason";

                        if (result.Error?.Subproblems?.Any() == true)
                        {
                            var subproblems = string.Join(", ", result.Error.Subproblems
                                                          .GroupBy(s => $"{s.Detail}:{s.Identifier}")
                                                          .Select(e => $"{e.FirstOrDefault().Identifier} : {e.FirstOrDefault().Detail}"));

                            msg = $"{result.Error?.Detail} :: {subproblems}";
                        }

                        return(new StatusMessage
                        {
                            IsOK = false,
                            Message = msg
                        });
                    }
                }
                catch (AcmeRequestException exp)
                {
                    var msg = $"Submit Challenge failed: {exp.Error?.Detail}";

                    log.Error(msg);

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