/// <summary> /// Runs the LetsEncrypt challenge and verifies that it was completed successfully. /// </summary> /// <param name="options"></param> /// <param name="cfg"></param> /// <param name="cancellationToken"></param> /// <returns>Returns the context, ready to generate certificate from.</returns> private async Task <IOrderContext> ValidateOrderAsync( IAcmeOptions options, CertificateRenewalOptions cfg, CancellationToken cancellationToken) { var authenticationContext = await _authenticationService.AuthenticateAsync(options, cancellationToken); var order = await authenticationContext.AcmeContext.NewOrder(cfg.HostNames); var challenge = await _renewalOptionParser.ParseChallengeResponderAsync(cfg, cancellationToken); var challengeContexts = await challenge.InitiateChallengesAsync(order, cancellationToken); if (challengeContexts.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(challengeContexts)); } try { // validate domain ownership await ValidateDomainOwnershipAsync(challengeContexts, cancellationToken); } finally { await challenge.CleanupAsync(challengeContexts, cancellationToken); } return(order); }
/// <summary> /// Runs the LetsEncrypt challenge and verifies that it was completed successfully. /// </summary> /// <param name="options"></param> /// <param name="cfg"></param> /// <param name="cancellationToken"></param> /// <returns>Returns the context, ready to generate certificate from.</returns> private async Task <IOrderContext> ValidateOrderAsync( IAcmeOptions options, CertificateRenewalOptions cfg, CancellationToken cancellationToken) { _logger.LogInformation($"starting -> _authenticationService.AuthenticateAsync"); var authenticationContext = await _authenticationService.AuthenticateAsync(options, cancellationToken); _logger.LogInformation($"done -> _authenticationService.AuthenticateAsync"); _logger.LogInformation($"starting -> authenticationContext.AcmeContext.NewOrder"); var order = await authenticationContext.AcmeContext.NewOrder(cfg.HostNames); _logger.LogInformation($"done -> authenticationContext.AcmeContext.NewOrder"); _logger.LogInformation($"starting -> renewalOptionParser.ParseChallengeResponderAsync"); var challenge = await _renewalOptionParser.ParseChallengeResponderAsync(cfg, cancellationToken); _logger.LogInformation($"done -> renewalOptionParser.ParseChallengeResponderAsync"); _logger.LogInformation($"starting -> challenge.InitiateChallengesAsync {order.Location}"); var challengeContexts = await challenge.InitiateChallengesAsync(order, cancellationToken); _logger.LogInformation($"challengeContextCount {challengeContexts.Count()}"); foreach (var item in challengeContexts) { _logger.LogInformation($"starting -> itemContext validating"); var result = await item.Validate(); if (result != null) { _logger.LogInformation($"result.value = {result?.Status.Value}"); //_logger.LogInformation($"result.token = {result?.Token}"); //_logger.LogInformation($"result.type = {result?.Type}"); //_logger.LogInformation($"result.Url = {result?.Url?.AbsoluteUri}"); //_logger.LogInformation($"result.Error.Detail = {result?.Error?.Detail}"); //_logger.LogInformation($"result.Error.Identifier.Value = {result?.Error?.Identifier?.Value}"); //_logger.LogInformation($"result.Error.Identifier.Status= {result?.Error?.Status}"); //foreach (var err in result?.Error?.Subproblems) //{ // _logger.LogInformation($"result.Error.Identifier.Subproblems= {err.Detail}"); //} //_logger.LogInformation($"result.Error.Identifier.Type= {result?.Error?.Type}"); } } _logger.LogInformation($"done -> challenge.InitiateChallengesAsync"); if (challengeContexts.IsNullOrEmpty()) { _logger.LogError($"starting -> challenge.InitiateChallengesAsync empty challengecontext"); throw new ArgumentNullException(nameof(challengeContexts)); } try { // validate domain ownership _logger.LogInformation($"starting -> ValidateDomainOwnershipAsync"); await ValidateDomainOwnershipAsync(challengeContexts, cancellationToken); _logger.LogInformation($"done -> ValidateDomainOwnershipAsync"); } finally { _logger.LogInformation($"starting -> challenge.CleanupAsync"); await challenge.CleanupAsync(challengeContexts, cancellationToken); _logger.LogInformation($"done -> challenge.CleanupAsync"); } return(order); }