mafintosh / dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets
MIT License
205 stars 71 forks source link

Proper Encoding/Decoding for Email Name Representation for SOA and RP Records #93

Closed M4t7e closed 1 year ago

M4t7e commented 1 year ago

According to RFC 1035 (but initially defined in RFC 883), email addresses can be represented as domain names in SOA (RNAME) and RP (MBOX) Records. An email address consists of two parts, a local part and the domain (<local part>@<domain>). Currently, dns-packet does not support proper processing of email addresses if the local part contains dots (.). E-mail DNS labels in the local part are allowed to contain a dot, which must be escaped by \. in the representation format. With wire format, the label size is simply set to span the entire label, including all dots.

SOA (RFC 1035):

The DNS encodes the <local-part> as a single label, and encodes the <mail-domain> as a domain name. The single label from the <local-part> is prefaced to the domain name from <mail-domain> to form the domain name corresponding to the mailbox. Thus the mailbox HOSTMASTER@SRI-NIC.ARPA is mapped into the domain name HOSTMASTER.SRI-NIC.ARPA. If the <local-part> contains dots or other special characters, its representation in a master file will require the use of backslash quoting to ensure that the domain name is properly encoded. For example, the mailbox Action.domains@ISI.EDU would be represented as Action\.domains.ISI.EDU.

RP (RFC 1183):

The first field, <mbox-dname>, is a domain name that specifies the mailbox for the responsible person. Its format in master files uses the DNS convention for mailbox encoding, identical to that used for the RNAME mailbox field in the SOA RR.

dig example:

# dig soa powerdns.com
; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> soa powerdns.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59258
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;powerdns.com.          IN  SOA

;; ANSWER SECTION:
powerdns.com.       2023    IN  SOA pdns-public-ns1.powerdns.com. peter\.van\.dijk.powerdns.com. 2023082401 10800 3600 604800 3600

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Fri Aug 25 11:30:41 CEST 2023
;; MSG SIZE  rcvd: 108

dns-packet example after this change: image

peter\.van\.dijk.powerdns.com -> peter.van.dijk@powerdns.com

This PR should also fix #90

codecov-commenter commented 1 year ago

Codecov Report

Merging #93 (2741e95) into master (519f55d) will increase coverage by 0.01%. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   97.97%   97.99%   +0.01%     
==========================================
  Files           6        6              
  Lines        2026     2046      +20     
==========================================
+ Hits         1985     2005      +20     
  Misses         41       41              
Files Changed Coverage Δ
index.js 98.06% <100.00%> (+0.02%) :arrow_up: