Skip to content

Commit

Permalink
Logic fix for changed external behavour (#21)
Browse files Browse the repository at this point in the history
* ValidateOrderAsync Exception info null guard

* Log OrderInvalidException before throwing it

* bugfix: One valid challenge is enough

don't wait for all to resolve. Issue discussed in #20

* Remove trace logs
  • Loading branch information
zigszigsdk authored and ffMathy committed Dec 4, 2019
1 parent 1d4a426 commit 19ac129
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/FluffySpoon.AspNet.LetsEncrypt/LetsEncryptRenewalService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
Expand Down Expand Up @@ -273,31 +272,32 @@ private async Task ValidateOrderAsync(string[] domains, IOrderContext order)

var challengeExceptions = nonNullChallengeValidationResponses
.Where(x => x.Status == ChallengeStatus.Invalid)
.Select(x => new Exception($"{x.Error.Type}: {x.Error.Detail} (challenge type {x.Type})"))
.Select(x => new Exception($"{x.Error?.Type ?? "errortype null"}: {x.Error?.Detail ?? "null errordetails"} (challenge type {x.Type ?? "null"})"))
.ToArray();

if (challengeExceptions.Length > 0)
if (challengeExceptions.Length > 0)
throw new OrderInvalidException(
"One or more LetsEncrypt orders were invalid. Make sure that LetsEncrypt can contact the domain you are trying to request an SSL certificate for, in order to verify it.",
new AggregateException(challengeExceptions));

}
finally
{
await _persistenceService.DeleteChallengesAsync(challengeDtos);
}
}

private static async Task<Challenge[]> ValidateChallengesAsync(IEnumerable<IChallengeContext> challengeContexts)
private async Task<Challenge[]> ValidateChallengesAsync(IEnumerable<IChallengeContext> challengeContexts)
{
var challenges = await Task.WhenAll(
challengeContexts.Select(x => x.Validate()));

while (true)
{
if (!challenges.Any(x => x.Status == ChallengeStatus.Pending || x.Status == ChallengeStatus.Processing))
if (challenges.Any(x => x.Status == ChallengeStatus.Valid) || challenges.All(x => x.Status == ChallengeStatus.Invalid))
break;

await Task.Delay(1000);
await Task.Delay(1000);
challenges = await Task.WhenAll(challengeContexts.Select(x => x.Resource()));
}

Expand Down

0 comments on commit 19ac129

Please sign in to comment.