Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DNS in non-Windows environments #185

Open
SteveSyfuhs opened this issue Aug 23, 2020 · 5 comments
Open

Add support for DNS in non-Windows environments #185

SteveSyfuhs opened this issue Aug 23, 2020 · 5 comments

Comments

@SteveSyfuhs
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
DNS lookups only work on Windows today because it calls into win32 APIs directly. .NET doesn't provide a way to query for SRV records.

Describe the solution you'd like
The library needs a way to make DNS queries outside of Windows. The solution should be to provide a way to bring your own DNS implementation that way you can use something like https://github.com/MichaCo/DnsClient.NET on other platforms.

Describe alternatives you've considered
You could rely completely on a krb5 configuration file to provide all the necessary records, but that's complicated and messy.

Additional context
Design should be similar to the CryptoPal so callers can register their DNS mechanisms. A side-car nuget package could be created that wires in the DnsClient.NET implementation.

@SteveSyfuhs
Copy link
Collaborator Author

SteveSyfuhs commented May 26, 2021

For folks running into this issue, there's a super simple platform-independent implementation available in the Bruce tool. It uses the DnsClient.NET library as mentioned above. It's kept out of the main project reduce total external dependencies.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DnsClient;
using Kerberos.NET.Dns;
namespace Kerberos.NET.CommandLine.Dns
{
internal class PlatformIndependentDnsClient : IKerberosDnsQuery
{
private static readonly WindowsDnsQuery WindowsDns = new WindowsDnsQuery();
public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordType type)
{
if (WindowsDns.IsSupported)
{
return await WindowsDns.Query(query, type);
}
var client = new LookupClient();
var response = await client.QueryAsync(query, (QueryType)type);
var srvRecords = response.Answers.SrvRecords().Select(a => new DnsRecord
{
Name = a.DomainName,
Port = a.Port,
Priority = a.Priority,
Target = a.Target,
TimeToLive = a.TimeToLive,
Type = DnsRecordType.SRV,
Weight = a.Weight
}).ToList();
var merged = srvRecords.GroupBy(r => r.Name);
foreach (var srv in srvRecords)
{
var c1 = merged.Where(m => m.Key.Equals(srv.Target, StringComparison.InvariantCultureIgnoreCase));
var canon = c1.SelectMany(r => r);
srv.Canonical = canon.ToList();
}
return srvRecords;
}
}
}

@MageFroh
Copy link

This class is very useful, but a bit hard to find. Is there a NuGet package that includes it? Would be great to be able to include something like Kerberos.NET.Portable, instead of copying the class in all projects that need it.

@SteveSyfuhs
Copy link
Collaborator Author

PR's are accepted to get that working.

@0x5ECF4ULT
Copy link

As requested by the contribution guidelines: I'm working on it

@SteveSyfuhs
Copy link
Collaborator Author

Awesome! The build process is somewhat of a pain to verify, but it should just be a matter of duplicating the kerberos.net lines in the build file and replacing the names with the new project/package name (https://github.com/dotnet/Kerberos.NET/blob/develop/build.yaml)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants