private async Task ResolveAuthorizations(AcmeClient acme) { bool allCompleted = await WaitChallengeCompleteAsync(); if (!allCompleted) { throw new Exception("Failed to complete challenge within timeout"); } var now = DateTime.Now; do { // Wait for all Authorizations to be valid or any one to go invalid int validCount = 0; foreach (KeyValuePair <string, AuthorizationDetails> authz in _authorizations) { switch (authz.Value.Status) { case AuthorizationStatus.Valid: ++validCount; break; } } if (validCount == _authorizations.Count) { _logger.LogInformation("All Authorizations ({0}) are valid", validCount); break; } _logger.LogWarning("Found {0} Authorization(s) NOT YET valid", _authorizations.Count - validCount); if (now.AddSeconds(_options.WaitForAuthorizations) < DateTime.Now) { throw new TimeoutException("Timed out waiting for Authorizations; ABORTING"); } // We wait in 5s increments await Task.Delay(5000); foreach (string authorizeUrl in _order.AuthorizationUrls) { // Update all the Authorizations still pending if (AuthorizationStatus.Pending == _authorizations[authorizeUrl].Status) { _authorizations[authorizeUrl] = await acme.GetAuthorizationDetailsAsync(authorizeUrl, _order.Expires); } } } while (true); }
private async Task ResolveChallenges(AcmeClient acme) { if (_order.Status == OrderStatus.Pending) { _logger.LogInformation("Order is pending, resolving Authorizations"); foreach (string authorizationUrl in _order.AuthorizationUrls) { AuthorizationDetails authorizationDetail = await acme.GetAuthorizationDetailsAsync(authorizationUrl, _order.Expires); _authorizations[authorizationUrl] = authorizationDetail; if (AuthorizationStatus.Pending == authorizationDetail.Status) { foreach (ChallengeDetails challenge in authorizationDetail.Challenges) { if (challenge.ChallengeType == ChallengeType.Http01) { await SaveChallengeDetailsAsync(challenge); _logger.LogInformation("Challenge Handler has handled challenge:"); _logger.LogInformation(JsonSerializer.Serialize(challenge)); // tells the server we are ready for challenge await acme.AnswerChallengeAsync(challenge.Url); _logger.LogInformation("Refreshing Authorization status"); authorizationDetail = await acme.GetAuthorizationDetailsAsync(authorizationUrl, _order.Expires); _logger.LogInformation( $"auth detail {authorizationUrl}: {JsonSerializer.Serialize(authorizationDetail)}"); } } } } } }