private async Task <bool> EnsureDnsRecordValue(string dnsRecord, string value, int attempt) { try { var dnsClients = await _lookupClientProvider.GetClients(dnsRecord, attempt); foreach (var client in dnsClients) { _logger.LogDebug($"Preliminary validation will now check name server {client.IpAddress}"); var answers = await client.GetTextRecordValues(dnsRecord, attempt); if (!answers.Any()) { _logger.LogWarning($"Preliminary validation at {client.IpAddress} failed: no TXT records found"); return(false); } if (!answers.Contains(value)) { _logger.LogWarning($"Preliminary validation at {client.IpAddress} failed: {value} not found in {string.Join(", ", answers)}"); return(false); } _logger.LogDebug($"Preliminary validation at {client.IpAddress} looks good!"); } } catch (Exception ex) { _logger.LogError(ex, "Preliminary validation failed"); return(false); } _logger.LogInformation("Preliminary validation succeeded"); return(true); }
private async Task <IDnsQueryResponse> RecursivelyFollowCnames(IDnsQueryResponse result, int attempt) { if (result.Answers.CnameRecords().Any()) { var cname = result.Answers.CnameRecords().First(); var recursiveClients = await _provider.GetClients(cname.CanonicalName, attempt); var index = attempt % recursiveClients.Count; var recursiveClient = recursiveClients.ElementAt(index); var txtResponse = await recursiveClient.LookupClient.QueryAsync(cname.CanonicalName, QueryType.TXT); return(await recursiveClient.RecursivelyFollowCnames(txtResponse, attempt)); } return(result); }