Skip to content

Commit

Permalink
Improvement DNS-01 error message (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Mar 26, 2023
1 parent cddd1ef commit 55027fa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Functions/GetInstanceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<IActionResult> HttpStart(

var status = await starter.GetStatusAsync(instanceId);

if (status == null)
if (status is null)
{
return BadRequest();
}
Expand Down
19 changes: 14 additions & 5 deletions KeyVault.Acmebot/Functions/SharedActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task Dns01Precondition([ActivityTrigger] IReadOnlyList<string> dnsN
.MaxBy(x => x.Name.Length);

// マッチする DNS zone が見つからない場合はエラー
if (zone == null)
if (zone is null)
{
notFoundZoneDnsNames.Add(dnsName);
continue;
Expand Down Expand Up @@ -213,7 +213,12 @@ public async Task Dns01Precondition([ActivityTrigger] IReadOnlyList<string> dnsN
var authorization = await acmeProtocolClient.GetAuthorizationDetailsAsync(authorizationUrl);

// DNS-01 Challenge の情報を拾う
var challenge = authorization.Challenges.First(x => x.Type == "dns-01");
var challenge = authorization.Challenges.FirstOrDefault(x => x.Type == "dns-01");

if (challenge is null)
{
throw new PreconditionException("DNS-01 cannot be used for domains for which a certificate has already been issued using HTTP-01.");
}

var challengeValidationDetails = AuthorizationDecoder.ResolveChallengeForDns01(authorization, challenge, acmeProtocolClient.Signer);

Expand All @@ -237,8 +242,12 @@ public async Task Dns01Precondition([ActivityTrigger] IReadOnlyList<string> dnsN
var dnsRecordName = lookup.Key;

var zone = zones.Where(x => dnsRecordName.EndsWith($".{x.Name}", StringComparison.OrdinalIgnoreCase))
.OrderByDescending(x => x.Name.Length)
.First();
.MaxBy(x => x.Name.Length);

if (zone is null)
{
throw new PreconditionException($"DNS zone is not found. DnsRecordName = {dnsRecordName}");
}

// Challenge の詳細から DNS 向けにレコード名を作成
var acmeDnsRecordName = dnsRecordName.Replace($".{zone.Name}", "", StringComparison.OrdinalIgnoreCase);
Expand Down Expand Up @@ -318,7 +327,7 @@ public async Task CheckIsReady([ActivityTrigger] (OrderDetails, IReadOnlyList<Ac
{
var challenge = await acmeProtocolClient.GetChallengeDetailsAsync(challengeResult.Url);

if (challenge.Status != "invalid" || challenge.Error == null)
if (challenge.Status != "invalid" || challenge.Error is null)
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/Internal/AcmeProtocolClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<AcmeProtocolClient> CreateClientAsync()

var acmeProtocolClient = new AcmeProtocolClient(_baseUri, directory, account, accountKey?.GenerateSigner(), usePostAsGet: true);

if (directory == null)
if (directory is null)
{
try
{
Expand All @@ -55,7 +55,7 @@ public async Task<AcmeProtocolClient> CreateClientAsync()

await acmeProtocolClient.GetNonceAsync();

if (acmeProtocolClient.Account == null)
if (acmeProtocolClient.Account is null)
{
var externalAccountBinding = directory.Meta.ExternalAccountRequired ?? false ? CreateExternalAccountBinding(acmeProtocolClient) : null;

Expand Down
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/Internal/CertificateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static bool IsAcmebotManaged(this CertificateProperties properties, strin
{
var tags = properties.Tags;

if (tags == null)
if (tags is null)
{
return false;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ public static CertificateItem ToCertificateItem(this KeyVaultCertificateWithPoli

private static string ToHexString(byte[] bytes)
{
if (bytes == null)
if (bytes is null)
{
throw new ArgumentNullException(nameof(bytes));
}
Expand Down
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Models/CertificatePolicyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CertificatePolicy ToCertificatePolicy()

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (DnsNames == null || DnsNames.Length == 0)
if (DnsNames is null || DnsNames.Length == 0)
{
yield return new ValidationResult($"The {nameof(DnsNames)} is required.", new[] { nameof(DnsNames) });
}
Expand Down
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Providers/DnsZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public string Name

public bool Equals(DnsZone other)
{
if (other == null)
if (other is null)
{
return false;
}
Expand Down

0 comments on commit 55027fa

Please sign in to comment.