title: 0005 DNS
url: https://github.com/datprotocol/DEPs/blob/master/proposals/0005-dns.md
hash_url: 0507da7e382a02e3c8b490913eb29e60

<article class="markdown-body entry-content" itemprop="text"><p>Title: <strong>DEP-0005: DNS</strong></p>
<p>Short Name: <code>0005-dns</code></p>
<p>Type: Informative</p>
<p>Status: Draft (as of 2018-04-27)</p>
<p>Github PR: <a href="https://github.com/datprotocol/DEPs/pull/25">PR#25</a></p>
<p>Authors: Paul Frazee</p>
<h1><a id="user-content-summary" class="anchor" aria-hidden="true" href="#summary"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Summary</h1>
<p>Dat's data structures (HyperCore, HyperDB, and HyperDrive) are addressed using
cryptographic keys. In the context of Web browsers, a URL scheme is used which
is structured as <code>'dat://' {key} '/' {path...}</code>.</p>
<p>This DEP describes an additional protocol for addressing Dats using DNS short names.</p>
<h1><a id="user-content-motivation" class="anchor" aria-hidden="true" href="#motivation"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Motivation</h1>
<p>The cryptographic keys which address Dats are secure and global, but not human-readable. This creates a usability problem.</p>
<p>The goal of this DEP is to leverage DNS to provide human-readable shortnames which map to Dat's cryptographic addresses. The solution...</p>
<ul>
<li>Must provide a single canonical Dat URL for the domain. It should not be possible for a name to have multiple valid mappings. (No conflict.)</li>
<li>Must not be controllable by non-owners of the domain. It should not be possible for third parties to modify the mapping. (Secure.)</li>
<li>Should be accessible to as many users as possible. (Convenient.)</li>
</ul>
<p>An initial proposal (the <a href="https://web.archive.org/web/20171013151452/https://github.com/beakerbrowser/beaker/wiki/Authenticated-Dat-URLs-and-HTTPS-to-Dat-Discovery" rel="nofollow">".well-known solution"</a>) has had prior usage in the Beaker Browser and Dat CLI. A followup proposal (the <a href="https://web.archive.org/web/20180427202745/https://github.com/beakerbrowser/beaker/wiki/Dat-DNS-TXT-records-with-optional-DNS-over-HTTPS" rel="nofollow">"DNS TXT solution"</a>) was made recently, but has not yet been deployed. This DEP intends to unify these proposals formally.</p>
<h1><a id="user-content-usage-documentation" class="anchor" aria-hidden="true" href="#usage-documentation"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Usage Documentation</h1>
<p>Users may provide a Dat URL to clients with the following structure: <code>'dat://' {name} '/'</code>.</p>
<p>If the <code>name</code> is a 64-character hex string, it should be considered a "key" and no DNS-resolution should occur. If <code>name</code> matches the following RegExp, it is considered a "key":</p>
<pre><code>^[0-9a-f]{64}$
</code></pre>
<p>If the <code>name</code> does not match this RegExp, it is a "domain name" and requires resolution. A Dat client should follow the <a href="#resolution-process">resolution process</a> to do this.</p>
<pre><code>domain: dat://beakerbrowser.com/
key:    dat://87ed2e3b160f261a032af03921a3bd09227d0a4cde73466c17114816cae43336/
</code></pre>
<p>Users have multiple options for creating a domain-name mapping.</p>
<h2><a id="user-content-dns-txt-record" class="anchor" aria-hidden="true" href="#dns-txt-record"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>DNS TXT record</h2>
<p>The first option is to set a DNS TXT record at the domain which maps to a "key"-addressed Dat URL. The client will lookup this TXT record first and load the resulting Dat. That record should fit the following schema:</p>
<pre><code>datkey={key}
</code></pre>
<h2><a id="user-content-well-knowndat" class="anchor" aria-hidden="true" href="#well-knowndat"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>.well-known/dat</h2>
<p>The second option is to run an HTTPS server at the domain name which includes a <code>/.well-known/dat</code> resource. That resource should provide a text file with the following schema:</p>
<pre><code>dat://{key}
TTL={time in seconds}
</code></pre>
<p><code>TTL</code> is optional and will default to <code>3600</code> (one hour). If set to <code>0</code>, the entry is not cached.</p>
<h1><a id="user-content-resolution-process" class="anchor" aria-hidden="true" href="#resolution-process"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Resolution process</h1>
<p>Resolution of a Dat at <code>dat://{name}</code> should follow this process:</p>
<ul>
<li>Client checks its names cache. If a non-expired entry is found, return with the entry.</li>
<li>Client issues a DNS TXT request for <code>name</code>. This request should be issued via a secure transport (see <a href="#dns-over-https">"DNS-over-HTTPS"</a>).</li>
<li>Client iterates all TXT records given (skip if none). If a record's value matches the TXT record schema (see below):
<ul>
<li>If the record includes a non-zero TTL, store the record value in the names cache.</li>
<li>Return the record value.</li>
</ul>
</li>
<li>Client issues an HTTPS GET request to <code>https://{name}/.well-known/dat</code>.
<ul>
<li>If the server responds with a <code>404 Not Found</code> status, client stores a <code>null</code> entry in the names cache with a TTL of 3600 and returns a failed lookup.</li>
<li>If the server responds with anything other than a <code>200 OK</code> status, return a failed lookup.</li>
<li>If the server responds with a malformed file (see below), return a failed lookup.</li>
<li>If the server responds with a well-formed file, store the record value in the names cache (default TTL to <code>3600</code> if not provided) and return the record value.</li>
</ul>
</li>
</ul>
<p>The DNS TXT record must match this schema:</p>
<pre><code>'datkey=' [0-9a-f]{64}
</code></pre>
<p>The <code>/.well-known/dat</code> file must match this schema:</p>
<pre><code>'dat://' [0-9a-f]{64} '/'?
( 'TTL=' [0-9]* )?
</code></pre>
<p>Note that DNS-record responses may not follow a pre-defined order. Therefore the results of a lookup may be undefined if multiple TXT records exist.</p>
<h1><a id="user-content-security-and-privacy" class="anchor" aria-hidden="true" href="#security-and-privacy"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Security and Privacy</h1>
<p>Two issues to consider:</p>
<ul>
<li><strong>Security</strong>: Can we trust the lookup results for a name?</li>
<li><strong>Privacy</strong>: Who sees the DNS lookups?</li>
</ul>
<p>Traditional DNS provides neither security or privacy. All looks occur over plaintext UDP. To provide security, a separate system must authenticate the record. (In the case of HTTPS records, the SSL Certificate provides authentication.)</p>
<p>Dat does not currently have a DNS authentication record (no equivalent to the SSL certificate). Therefore a lookup using UDP can not be secured.</p>
<p>To solve this, this DEP recommends using <a href="#dns-over-https">DNS-over-HTTPS</a>.</p>
<h2><a id="user-content-dns-over-https" class="anchor" aria-hidden="true" href="#dns-over-https"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>DNS-over-HTTPS</h2>
<p>Until PKI can authenticate the DNS lookups (ie via SSL certificates or equivalent) there is a risk that the DNS lookup will be intercepted by an adversary. To protect against this, the client should use DNS-over-HTTPS to lookup the DNS TXT records.</p>
<p>Current providers:</p>

<p>This solution improves on both the security and privacy of DNS lookup:</p>
<ul>
<li><strong>Security</strong>. Requests to the DNS provider are authenticated using the provider's SSL certificate.</li>
<li><strong>Privacy</strong>. DNS lookups are encrypted on the wire and only made visible to the DNS provider.</li>
</ul>
<p>DNS-over-HTTPS still requires trust in the provider to give correct responses, but this is an improvement to UDP DNS lookups, which can be trivially MITMed by malicious actors on the network.</p>
<p>Whereas traditional DNS leaks name lookups to everyone on the network, DNS-over-HTTPS only reveals them to the DNS provider. This still provides some opportunity for tracking, but the opportunity is reduced to the provider alone.</p>
<h1><a id="user-content-drawbacks" class="anchor" aria-hidden="true" href="#drawbacks"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Drawbacks</h1>
<ul>
<li>The use of the <code>.well-known/dat</code> resource over HTTPS creates a dependency on a service.</li>
<li>DNS-over-HTTPS exposes all lookups to the provider and relies on the provider to be honest. However, because this method offsets the risk of MITM attacks, this is a worthwhile trade. Future DEPs should find alternative ways to authenticate domain-name records.</li>
</ul>
<h1><a id="user-content-rationale-and-alternatives" class="anchor" aria-hidden="true" href="#rationale-and-alternatives"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Rationale and alternatives</h1>
<ul>
<li>User-defined names registries could be used instead of DNS, but they would likely suffer from name conflicts without a top-down control.</li>
<li>A blockchain (such as Namecoin) could be used instead of DNS, but blockchains currently have poor throughput and require users to sync large amounts of data.</li>
<li>DNSSEC could be used instead of DNS-over-HTTPS, but it does not have the same level of support among gTLDs that DNS-over-HTTPS has.</li>
</ul>
<h1><a id="user-content-changelog" class="anchor" aria-hidden="true" href="#changelog"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg></a>Changelog</h1>
<ul>
<li>2018-04-27: First complete draft submitted for review</li>
<li>2018-05-07: Add "Security and Privacy" section and rewrite DNS TXT record schema.</li>
<li>2018-05-16: Merged as Draft after WG approval.</li>
</ul>
</article>
