Git Product home page Git Product logo

net-dns's Introduction

net-dns

build status travis build Coverage Status Version docs

DNS data model with serializer/deserializer for the wire and "master file" format.

Features

  • Serialization for the wire and master file formats
  • Pretty printing of messages
  • Supports compressed domain names
  • Supports multiple strings in TXT records
  • Supports the extended 12-bit RCODE
  • Future proof: handles unknown resource records and EDNS options
  • Graceful truncation of messages
  • A name server that answeres DNS questions
  • Data models for
    • RFC 1035 Domain Names (DNS)
    • RFC 1183 New DNS RR Definitions
    • RFC 1996 Zone Changes (DNS NOTIFY)
    • RFC 2136 Dynamic Updates (DNS UPDATE)
    • RFC 2845 Secret Key Transaction Authentication for DNS (TSIG)
    • RFC 2930 Secret Key Establishment for DNS (TKEY RR)
    • RFC 3225 Indicating Resolver Support of DNSSEC
    • RFC 3599 DNS Extensions to Support IPv6
    • RFC 4034 Resource Records for the DNS Security Extensions (DNSSEC)
    • RFC 5001 DNS Name Server Identifier (NSID) Option
    • RFC 6672 DNAME Redirection in the DNS
    • RFC 6891 Extension Mechanisms for DNS (EDNS(0))
    • RFC 7828 The edns-tcp-keepalive EDNS0 Option
    • RFC 7830 The EDNS(0) Padding Option
  • Targets .Net Framework 4.5 and 4.7.2 and .NET Standard 1.4 and 2.0
  • CI on Travis (Ubuntu Trusty and OSX) and AppVeyor (Windows Server 2016)

Getting started

Published releases are available on NuGet. To install, run the following command in the Package Manager Console.

PM> Install-Package Makaretu.Dns

Usage

Name Server

Create a name server that can answer questions for a zone.

using Makaretu.Dns.Resolving;

var catalog = new Catalog();
catalog.IncludeZone(...);
catalog.IncludeRootHints();
var resolver = new NameServer { Catalog = catalog };

Answer a question

var request = new Message();
request.Questions.Add(new Question { Name = "ns.example.com", Type = DnsType.AAAA });
var response = await resolver.ResolveAsync(request);

Data Model

using Makaretu.Dns

var msg = new Message
{
	AA = true,
	QR = true,
	Id = 1234
};
msg.Questions.Add(new Question 
{ 
	Name = "emanon.org" 
});
msg.Answers.Add(new ARecord 
{ 
	Name = "emanon.org",
	Address = IPAddress.Parse("127.0.0.1") 
});
msg.AuthorityRecords.Add(new SOARecord
{
	Name = "emanon.org",
	PrimaryName = "erehwon",
	Mailbox = "hostmaster.emanon.org"
});
msg.AdditionalRecords.Add(new ARecord 
{ 
	Name = "erehwon", 
	Address = IPAddress.Parse("127.0.0.1") 
});

Related projects

  • net-mdns - client and server for multicast DNS
  • net-udns - client for unicast DNS, DNS over HTTPS (DOH) and DNS over TLS (DOT)
  • DNSSEC - What Is It and Why Is It Important?

License

Copyright © 2018 Richard Schneider ([email protected])

The package is licensed under the MIT license. Refer to the LICENSE file for more information.

Buy Me A Coffee

net-dns's People

Contributors

richardschneider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

net-dns's Issues

DnsObject extras

Value equality, hashing and deep cloning can be implemented because of object serialisation.

Malformed RDATA

An exception (InvalidateDataException maybe) should be thrown by Read(DnsReader reader)after calling ReadData if the position and RDLEN do not agree. This is the inverse of Buffer Overflow

Escaped strings

DnsWriter.WriteString must quote the string if it contains a quote, backslash or space.

Empty TXT record

Reading a TXT record with no strings is treated as malformed. It should be accepted.

2018/07/09 13:48:59:489 [WARN]  Makaretu.Dns.MulticastService - Received malformed message
=======================================================(inner most exception)===
 (1) System.IO.EndOfStreamException
================================================================================
Method        :  ReadBytes
Type          :  Makaretu.Dns.DnsReader
Assembly      :  Makaretu.Dns, Version=0.11.0.0, Culture=neutral, PublicKeyToken=null
Assembly Path :  C:\Users\Owner\Documents\GitHub\net-mdns\test\bin\Debug\net461\Makaretu.Dns.dll
Source        :  Makaretu.Dns
Thread        :  6 ''
Helplink      :  

Message:
"Attempted to read past the end of the stream."

Stack Trace:
   at Makaretu.Dns.DnsReader.ReadBytes(Int32 length)
   at Makaretu.Dns.DnsReader.ReadString()
   at Makaretu.Dns.TXTRecord.ReadData(DnsReader reader, Int32 length)
   at Makaretu.Dns.ResourceRecord.Read(DnsReader reader)
   at Makaretu.Dns.Message.Read(DnsReader reader)
   at Makaretu.Dns.DnsObject.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Makaretu.Dns.MulticastService.OnDnsMessage(Byte[] datagram, Int32 length) in C:\Users\Owner\Documents\GitHub\net-mdns\src\MulticastService.cs:line 403```

UpdateMessage

Do you have plans to support this project?
Will be good to have a possibility to update DNS records

Domain name labels

The standard requires that domain name labels consist of only USASCII letters, digits or '-'. This is somewhat mitigated by Internationalized Domain Names .

WireFormat.ReadDomainName should throw InvalidDataExecption for characters outside this range. For the time being, WireFormat.WriteDomainName show throw InvalidArgumentException.

PresentationFormat is not affected, because it can be UNICODE.

From https://tools.ietf.org/html/rfc1035#section-2.3.1


<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]

<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>

<let-dig-hyp> ::= <let-dig> | "-"

<let-dig> ::= <letter> | <digit>

<letter> ::= any one of the 52 alphabetic characters A through Z in
upper case and a through z in lower case

<digit> ::= any one of the ten digits 0 through 9

Note that while upper and lower case letters are allowed in domain
names, no significance is attached to the case.  That is, two names with
the same spelling but different case are to be treated as if identical.

The labels must follow the rules for ARPANET host names.  They must
start with a letter, end with a letter or digit, and have as interior
characters only letters, digits, and hyphen.  There are also some
restrictions on the length.  Labels must be 63 characters or less.

Cannot read Message

The following unecrypted Message (in base-64) can not be decoded. It came from cloudflare using DNS over TLS (DOT).

EjSBgAABAAEAAAAABGlwZnMCaW8AABAAAcAMABAAAQAAADwAPTxkbnNsaW5rPS9pcGZzL1FtWU5RSm9LR05IVHBQeENCUGg5S2tEcGFFeGdkMmR1TWEzYUY2eXRNcEhkYW8=

Reading resource record fails

2018/05/27 22:16:47:905 [DEBUG] Makaretu.Dns.DotClient - using dns server 'cloudflare-dns.com' 1.1.1.1.
2018/05/27 22:16:47:906 [DEBUG] Makaretu.Dns.DotClient - Starting reader thread
2018/05/27 22:16:47:906 [DEBUG] Makaretu.Dns.DotClient - query #15311 for 'www.opinionstage.com A'
2018/05/27 22:16:47:924 [ERROR] Makaretu.Dns.DotClient - System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Makaretu.Dns.ResourceRecord.Read(DnsReader reader)
   at Makaretu.Dns.Message.Read(DnsReader reader)
   at Makaretu.Dns.DnsObject.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Makaretu.Dns.DotClient.ReadResponses(Stream stream) in C:\Users\Owner\Documents\GitHub\net-udns\src\DotClient.cs:line 380

Adding Additional Records

Currently the NameServer will add most likely needed resources to the AdditionalRecords. For example a query for a PTR will return the SRV and TXT as additional records and a SRV query will return the target host address (A/AAAA) records.

A query for a PTR should also return the address for the target host.

This is needed by some peer-to-peer systems, where they expect the PTR response to contain all the information needed to contact the peer.

ASCII strings

All DNS strings are USASCII.

WireWriter.WriteString and WireReader.ReadString must enforce this.

RFC 1183

Add the resource records for https://tools.ietf.org/html/rfc1183

  • AFSDB - Andrew File System Database
  • RP - Responsible Person
  • X25 - X.25 (Not in current use)
  • ISDN - Integrated Service Digital Network (Not in current use)
  • RT - Route Through (Not in current use)

Update SimpleBase to latest version

Hi @richardschneider , thank you for the repo!
When I update the simplebase to latest version of 3.0.2 I am getting below error:
Error MT2101: Can't resolve the reference 'System.Byte[] SimpleBase.Base16::Decode(System.String)', referenced from the method 'System.Void Makaretu.Dns.DSRecord::ReadData(Makaretu.Dns.PresentationReader)' in 'SimpleBase, Version=1.3.1.0, Culture=neutral, PublicKeyToken=null'.

RRSIG and dates

The SignatureExpiration and SignatureExpiration should use the DateTime type.

Presentation format should always YYYYMMDDHHmmSS format. But accept number seconds since Unix epoch.

Development has moved

Since development has ended here I have continued the project at:
https://github.com/jdomnitz/net-dns

NuGet Packages will continue to be published to:
Makaretu.Dns.New

This includes new features, bug fixes and modern framework targets. Tickets and PRs are welcome.

Road map to v1

  • rename DnsReader/DnsWriter => WireReader/WireWriter
  • rename Class to DnsClass
  • rename to master to presentation
  • add PresentationReader
  • implement TSIG, TKey
  • Add a SecurityAlgoithm registry
  • Fix TODOs, or create an issue
  • More articles
    • describe serialisation
    • describe the registries
    • DSNSEC

Master file escaping

From RFC 1035

\DDD where each D is a digit is the octet corresponding to
the decimal number described by DDD. The resulting
octet is assumed to be text and is not checked for
special meaning.

For some reason the Presention Reader/Writer is treating escaped numbers as octal. They should be treated as decimal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.