mirror of
https://github.com/bitwarden/server.git
synced 2026-02-11 03:13:16 +08:00
22 lines
677 B
C#
22 lines
677 B
C#
|
|
using Bit.Core.Exceptions;
|
|||
|
|
using DnsClient;
|
|||
|
|
|
|||
|
|
namespace Bit.Core.Services;
|
|||
|
|
|
|||
|
|
public class DnsResolverService : IDnsResolverService
|
|||
|
|
{
|
|||
|
|
public async Task<bool> ResolveAsync(string domain, string txtRecord, CancellationToken cancellationToken = default)
|
|||
|
|
{
|
|||
|
|
var lookup = new LookupClient();
|
|||
|
|
var result = await lookup.QueryAsync(new DnsQuestion(domain, QueryType.TXT), cancellationToken);
|
|||
|
|
if (!result.HasError)
|
|||
|
|
{
|
|||
|
|
return result.Answers.TxtRecords()
|
|||
|
|
.Select(t => t?.EscapedText?.FirstOrDefault())
|
|||
|
|
.Any(t => t == txtRecord);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
throw new DnsQueryException(result.ErrorMessage);
|
|||
|
|
}
|
|||
|
|
}
|