mirror of
https://github.com/bitwarden/server.git
synced 2025-05-10 06:02:24 -05:00

* Increased timeout of the dns resolve method and changed the lifetime of the dnsResolverService to scoped * Reverted to using singleton as this was recommneded on the docs and also registered lookup client as a singleton * Registerered a singleton service of ILookupClient * replaced unused serviceProvider with a discard
27 lines
772 B
C#
27 lines
772 B
C#
using Bit.Core.Exceptions;
|
|
using DnsClient;
|
|
|
|
namespace Bit.Core.Services;
|
|
|
|
public class DnsResolverService : IDnsResolverService
|
|
{
|
|
private readonly ILookupClient _client;
|
|
|
|
public DnsResolverService(ILookupClient client)
|
|
{
|
|
_client = client;
|
|
}
|
|
public async Task<bool> ResolveAsync(string domain, string txtRecord, CancellationToken cancellationToken = default)
|
|
{
|
|
var result = await _client.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);
|
|
}
|
|
}
|