<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="rfc7991bis.rnc"?>  <!-- Required for schema
      validation and schema-aware editing --> 

<!DOCTYPE rfc [
  <!ENTITY filename "draft-eastlake-dnsop-rfc2930bis-tkey-05">
  <!ENTITY nbsp     "&#160;">
  <!ENTITY zwsp     "&#8203;">
  <!ENTITY nbhy     "&#8209;">
  <!ENTITY wj       "&#8288;">
]>
<!-- <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?> --> 
<!-- This third-party XSLT can be enabled for direct transformations
in XML processors, including most browsers --> 
<!-- If further character entities are required then they should be
added to the DOCTYPE above. Use of an external entity file is not
recommended. --> 
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>

<rfc
  xmlns:xi="http://www.w3.org/2001/XInclude"
  category="std"
  docName="&filename;"
  ipr="trust200902"
  obsoletes="2930"
  submissionType="IETF"
  xml:lang="en"
  version="3">
<!-- 
    * docName should be the name of your draft * category should be
    one of std, bcp, info, exp, historic * ipr should be one of
    trust200902, noModificationTrust200902, noDerivativesTrust200902,
    pre5378Trust200902 * updates can be an RFC number as NNNN *
    obsoletes can be an RFC number as NNNN
-->


<!-- ____________________FRONT_MATTER____________________ -->

<front> <title abbrev="The DNS TKEY RR">Secret Key Agreement for DNS:
  The TKEY Resource Record</title>
<!-- The abbreviated title is required if the full title is longer
than 39 characters -->

   <seriesInfo name="Internet-Draft"
               value="&filename;"/>

   <author fullname="Donald E. Eastlake 3rd" initials="D."
           surname="Eastlake">
     <organization>Independent</organization>
     <address>
       <postal>
         <street>2386 Panoramic Circle</street>
         <city>Apopka</city>
         <region>Florida</region>
         <code>32703</code>
         <country>USA</country>
       </postal>        
       <phone>+1-508-333-2270</phone>
       <email>d3e3e3@gmail.com</email>
     </address>
   </author>
   
    <author fullname="Mark Andrews" initials="M." surname="Andrews">
      <organization>Internet Systems Consortium</organization>
      <address>
        <email>marka@isc.org</email>
      </address>
    </author>

   <date year="2026" month="3" day="1"/>

   <area>Operations</area>
   <workgroup>DNSOP</workgroup>

   <keyword></keyword>
   <!-- Multiple keywords are allowed.  Keywords are incorporated
        into HTML output files for use by search engines. --> 

<abstract>
  <t>RFC 8945 provides efficient authentication of Domain Name System
  (DNS) protocol messages using shared secret keys and the Transaction
  Signature (TSIG) resource record (RR).  However, it provides no
  mechanism for setting up such keys other than by configuration.
  This document specifies the Transaction Key (TKEY) RR that can be
  used to establish shared secret keys between a DNS resolver and
  server. This document obsoletes RFC 2930.</t>
</abstract>

</front>


<!-- ____________________MIDDLE_MATTER____________________ -->
<middle>
    
<section> <!-- 1. -->
  <name>Introduction</name>

  <t>[[[ NOTE: This draft contains occasional meta comments inside
  triple square brackets like this. These are intended to aid in the
  development of the document and would not appear in any resulting
  RFC. ]]]</t>

  <t> The Domain Name System (DNS) is a hierarchical, distributed,
  highly available database used for bi-directional mapping between
  domain names and IP addresses, for email routing, service access,
  and for other information <xref target="RFC1034"/> <xref
  target="RFC1035"/>.  It has been extended to provide for public
  key-based data authentication <xref target="RFC4034"/> <xref
  target="RFC4035"/> and dynamic update <xref target="RFC3007"/>.
  Familiarity with these RFCs is assumed.</t>

  <t><xref target="RFC8945"/> provides efficient authentication of DNS
  messages using shared secret keys and the Transaction Signature
  (TSIG) resource record (RR) but provides no mechanism for setting up
  such keys other than by configuration. This document specifies the
  Transaction Key (TKEY) RR that can be used to establish and delete
  such shared secret keys between a DNS resolver and server.  This
  document obsoletes <xref target="RFC2930"/> and the significant
  changes from that RFC are list in <xref
  target="changesFrom2930"/>.</t>

  <t>TKEY established keying materials and TSIGs that use them are
  associated with DNS servers and resolvers.  They are not associated
  with DNS zones.  They may be used to authenticate requests and
  transactions but they do not provide zone-based DNS RR data origin or
  denial of existence authentication <xref target="RFC4034"/> <xref
  target="RFC4035"/>.</t>

  <section>
    <name>Terminology</name>

<t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in BCP
14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only
when, they appear in all capitals, as shown here.</t>

<t>General familiarity with DNS terminology <xref target="RFC9499"/>
is assumed in this document. In all cases herein, the term "resolver"
or "requester" includes that part of a server which may initiate
requests including full and incremental <xref target="RFC1995"/> zone
transfer queries, forwarded recursive queries, and the like.</t>

<t>For a message to be "silently ignored" means that is has no
protocol effect but it might still be logged or reported.</t>

  </section>
</section>

<section anchor="General">
  <name>General TKEY Considerations</name>

<t>TKEY is a meta-RR that is not stored or cached and does not appear
in zone master files. It supports a variety of modes for the
establishment and deletion of shared secret keying information between
DNS resolvers and servers. The shared secret keying material agreed to
by using TKEY is an opaque octet sequence.</t>

<t>The establishment of such a shared secret requires that state be
maintained at both ends and the allocation of the resources to
maintain such state generally requires prior mutual agreement. In the
absence of willingness to provide such state, servers MUST return
error NotImp or Refused for an attempt to use TKEY and resolvers are
free to silently ignore any TKEY RRs they receive.</t>

<t>TKEY RRs are sent in the additional information section of DNS
queries for type TKEY and the corresponding returned TKEY appears in
the answer section of responses to such queries. Some TKEY RRs may
also be spontaneously included in other responses (see <xref
target="spontaneous"/>). Type TKEY queries SHOULD NOT be flagged as
recursive, and servers MUST ignore the recursion desired header bit
(RD) in TKEY queries they receive. Type TKEY responses SHOULD be
flagged as authoritative, and resolvers MUST ignore the authoritative
answer (AA) bit in TKEY responses they receive. TKEY queries contain 1
question section entry with QTYPE TKEY, QCLASS 255 (ANY), and QNAME
the same as the name of the TKEY RR.</t>

<t>[[[ Comment: Although current practice is to have the query QNAME be
the same as the name field of the TKEY RR, this does not appear to be
logically necessary. Space could be saved by using root as the
QNAME. ]]]</t>

<t>TKEY messages (DNS queries and responses) MUST be authenticated
(see <xref target="authenticate"/>) for all modes except GSS-API mode,
which provides its own security. In the absence of required TKEY
authentication, a NotAuth error MUST be returned for a query and a
reply MUST be silently ignored.</t>

<t>Keys established via TKEY can be treated as soft state and need not
be preserved over crashes or reboots. Since DNS transactions are
originated by the resolver, the resolver can simply toss keys,
although it may have to go through another key exchange if it later
needs one. Similarly, the server can discard keys although that will
result in an error on receiving a query with a TSIG using the
discarded key.</t>

</section>
<section anchor="TKEYRR">
  <name>The TKEY Resource Record</name>

  <t>The TKEY resource record (RR) is a meta-RR that has the structure
  shown in Table 1. Its RR type code is 249.</t>

  <table>
    <name>TKEY Resource Record</name>
    <thead>
<tr><th align="center">Field</th><th align="center">Format</th><th
align="center">Comment</th></tr>
    </thead>
    <tbody>
      
<tr><td>NAME</td><td>domain</td><td>See description below.</td></tr>
<tr><td>TTYPE</td><td>u_int16_t</td><td>TKEY, MUST be 249 (0x00F9).</td></tr>
<tr><td>CLASS</td><td>u_int16_t</td><td>MUST be 255 (ANY, 0x00FF).</td></tr>
<tr><td>TTL</td><td>u_int32_t</td><td>MUST be zero.</td></tr>
<tr><td>RDLEN</td><td>u_int16_t</td><td>Size of RDATA.</td></tr>

<tr><td>RDATA:</td><td></td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Algorithm:</td><td>domain
  name</td><td></td></tr> 
<tr><td>&nbsp;&nbsp;&nbsp;Inception:</td><td>u_int32_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Expiration:</td><td>u_int32_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Mode:</td><td>u_int16_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Error:</td><td>u_int16_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Key Size:</td><td>u_int16_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Key
  Data:</td><td>octet-stream</td><td></td></tr> 
<tr><td>&nbsp;&nbsp;&nbsp;Other Size:</td><td>u_int16_t</td><td></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;Other
  Data:</td><td>octet-stream</td><td></td></tr> 

    </tbody>
  </table>
  
 <t>Further information on these fields is provided in the
 subsections below.</t>

<t>There MUST NOT be more than one TKEY RR in a DNS message.  If more
than one appears in a request, a server implementing TKEY MUST return
FormErr. If more than one appears in a response, they MUST all be
ignored.</t>

<t>[[[ Comment: Actually, it could be meaningful to have multiple TKEY
RRs in a DNS message as long as no pair conflicted. For example, a
reply could contain a key agreement TKEY RR in the answer section
along with one or more key deletion TKEY RRs for other keys in the
additional information section. But it seems simpler to prohibit such
messages. ]]]</t>

 <section>
   <name>Name Field</name>

<t>The Name field is a DNS domain name in wire encoding format. It
relates to naming keys and does not normally appear as a node
in the DNS name hierarchy.  It MUST NOT be compressed.  Its meaning
differs somewhat with mode and context as explained in <xref
target="keystore"/>. In some cases where the Name field has a key
name, it would be the same name as used in a TSIG RR <xref
target="RFC8945"/> using that key.</t>

<t>[[[ Comment: The only reason the above specifies that Name not be
compressed is that there was a DNS implementation where such
compression would activate a bug. This was not required in <xref
target="RFC2930"/> and can probably be changed to allow compression of
the TKEY RR Name since RR QNAMEs are normally compressible. It is
domain names appearing within the TKEY RDATA, such as the Algorithm
field, that are not generally compressible. ]]]</t>

<t>Although the DNS protocol is binary clean so that any octet value
should be usable in a label that is part of a domain name, to avoid
possible implementation bugs and to ease user interface and debugging
issues, it is RECOMMENDED that Name be composed of labels consisting
of letters, digits, underscore, and hyphen and that these labels begin
with a letter or digit. To indicate that no Name is present, the Name
field is set to the wire encoding of the domain name of the root node,
that is, the octet string consisting of a single zero value octet.</t>

<t>For more information on Key Names, see <xref
target="KeyNames"/>.</t>

 </section>

 <section>
   <name>The TTL Field</name>

<t>The TTL field is not used in TKEY RRs. It MUST be zero to minimize
the chance that a DNS implementation might not recognizing a TKEY RR
as a meta-RR and would erroneously cache it. Receipt of a TKEY RR with
a non-zero TTL field in a query results in a FormErr error
response.</t>

 </section>

 <section>
   <name>The RDLEN Field</name>

<t>The RDLEN field MUST equal the length of the RDATA section through
the end of Other Data. Otherwise, the RR is to be considered malformed
and FormErr returned if in a request or the message ignored if it is a
reply.</t>

 </section>

 <section>
   <name>The Algorithm Field</name>

<t>The Algorithm name is a domain name with the same values and
meaning as the Algorithm Name field in TSIG RRs (see <xref
target="RFC8945"/>). It MUST NOT be compressed. The algorithm
determines how keying material agreed to by using the TKEY RR is
actually used to derive the algorithm specific secret key or keys. For
example, it might need to be truncated or extended or split into
multiple keys or otherwise processed.</t>

 </section>

 <section>
   <name>The Inception and Expiration Fields</name>

<t>The Expiration and Inception field values specify a date and time
in the form of a 32-bit unsigned number of seconds elapsed since 1
January 1970 00:00:00 UTC ignoring leap seconds, in network byte
order, modulo 2**32 using ring arithmetic <xref target="RFC1982"/>,
similar to the fields with these names in the RRSIG RR <xref
target="RFC4034"/>. In TKEY DNS messages where these fields are
meaningful, their meaning depends on the mode.</t>

<t>Where the Inception and Expiration fields indicate a time interval,
if the expiration time is before the inception time in a request, the
BADTTIME error is returned in the Error field of the response.</t>

<t>To avoid different interpretations of the inception and expiration
times in TKEY RRs, resolvers and servers exchanging them MUST have the
same idea of what time it is. One way of doing this is with the
Network Time Protocol <xref target="RFC5905"/>. That or other time
synchronization used for this purpose MUST be done securely.</t>

 </section>

 <section>
   <name>The Mode Field</name>

<t>The mode field specifies the general purpose of the TKEY RR, such
as a key agreement method. See <xref target="modes"/> for more
information on the modes specified in this document.</t>

 </section>

 <section anchor="errors">
   <name>The Error Field</name>

<t>The error code field is an extended RCODE <xref
target="RFC6895"/>. In queries, it MUST be sent as zero and ignored on
receipt. The following values, which may appear in replies, are used
and/or specified in this document or <xref target="RFC8945"/>:</t>

<table>
  <name>Error Codes</name>
  <thead>
<tr><th>Value</th><th>Description</th><th>Reference</th></tr>
  </thead>
  <tbody>
<tr><td align="right">0</td><td>- no error</td><td></td></tr>
<tr><td align="right">1</td><td>FormErr</td><td><xref
target="RFC1035"/></td></tr> 
<tr><td align="right">4</td><td>NotImp</td><td><xref
target="RFC1035"/></td></tr> 
<tr><td align="right">5</td><td>Refused</td><td><xref
target="RFC1035"/></td></tr> 
<tr><td align="right">9</td><td>NotAuth</td><td><xref
target="RFC1035"/></td></tr> 
<tr><td align="right">16</td><td>BADSIG</td><td><xref
target="RFC8945"/></td></tr> 
<tr><td align="right">17</td><td>BADKEY</td><td><xref
target="RFC8945"/></td></tr> 
<tr><td align="right">18</td><td>BADTIME</td><td><xref
target="RFC8945"/></td></tr> 
<tr><td align="right">19</td><td>BADMODE</td><td>[this
document]</td></tr> 
<tr><td align="right">20</td><td>BADNAME</td><td>[this
document]</td></tr> 
  </tbody>
</table>

<t>When the TKEY RR Error Field is non-zero in a response to a TKEY
query, the DNS header RCODE field normally indicates no
error. However, it is possible, if a TKEY RR is spontaneously included
in a response (see <xref target="spontaneous"/>), the TKEY RR and DNS
header error fields could have unrelated non-zero error codes.</t>

 </section>

 <section>
   <name>The Key Size and Data Fields</name>

<t>The Key Size Field is an unsigned 16-bit integer in network
octet order. It specifies the size of the Key Data Field in
octets. The meaning of the contents of the Key Data field depends on
the mode and context.</t>

 </section>

 <section>
   <name>The Other Size and Data Fields</name>

<t>The Other Size field is an unsigned 16-bit integer in network order
which specifies the size of the Other Data field in octets. The Other
Data field is intended for future expansion of the TKEY RR.</t>

 </section>
</section>

<section anchor="keystore">
  <name>Key Naming and Key Table</name>

  <t>DNS resolvers and servers that implement TSIG maintain a table of
  (1) keying material shared with other DNS servers and resolvers with
  which they have either been configured or successfully exchanged
  TKEY RRs to establish such keys and (2) information about on going
  attempts to establish such shared keys using TKEY. Each local table
  entry logically contains the information listed below. The actual
  structure and management of this table is a local matter as long as
  the behavior is consistent this document.  For example, it might be
  accessed through one or more hash tables for rapid retrieval or have
  additional information such as when a key was established or be
  broken up into more than one table that are linked together. Some
  fields in this table are further described in the subsections below
  the table.</t>

  <table>
    <name>Key Table Entry</name>
    <thead>
  <tr><th align="center">Field</th><th align="center">Format</th><th
  align="center">Explanation</th></tr>
    </thead>
    <tbody>

<tr><td>Key Name</td><td>domain name</td><td>Key name.</td></tr>
      
<tr><td>Remote Address</td><td>IPv4/IPv6 address</td><td>Address of
remote DNS server/resolver.</td></tr>

<tr><td>Inception</td><td>u_int32_t</td><td>Keying information
inception time.</td></tr>
<tr><td>Expiration</td><td>u_int32_t</td><td>Keying information
expiration time.</td></tr>

<tr><td>Key</td><td>octet-string</td><td>The opaque shared secret keying
information.</td></tr>

<tr><td>State</td><td>unspecified</td><td>See below.</td></tr>

<tr><td>Algorithm</td><td>domain name</td><td>Key use
algorithm.</td></tr>

<tr><td>Last Used</td><td>u_int32_t</td><td>The time at which a TSIG
using this key was most recently sent or received and
validated.</td></tr>
    
    </tbody>
  </table>

<section anchor="KeyNames">
  <name>Key Name</name>
    
<t>At any DNS server or resolver only one octet string of keying
material and TSIG algorithm may be in place for any particular key
name.  An attempt to establish agreement for a different set of keying
material for an existing name returns a BADNAME error. Since a DNS
TKEY reply message could be lost, it is a normal case and not an error
for a server to receive a TKEY request message to establish a key that
is the same as a key that the server state indicates is already
established.</t>

<t>To avoid confusion while managing or debugging a network, it is
RECOMMENDED that key names be globally unique. A key name generation
strategy for resolvers and servers is described below.</t>

<section>
  <name>A Resolver Key Name Generation Strategy</name>
  
<t>For a TKEY RR with a non-root Name appearing in a query, the TKEY
Name field SHOULD be a domain name locally unique at the querier,
less than 128 octets long in wire encoding, and meaningful to the
resolver to assist in distinguishing keys and/or key agreement
sessions. This length limit is suggested so that, when a resolver
provided name portion is concatenated with a server provided name
portion, the result will fit within the DNS protocol wire encoding
name length limit of 255 octets.</t>

</section>
<section>
  <name>A Server Key Name Generation Strategy</name>
  
<t>For a TKEY RR appearing in a response to a query, the TKEY RR Name
field SHOULD be a globally unique server assigned name unless the
response indicates a TKEY error in which case the name from the query
SHOULD be copied in the response.</t>

<t>A reasonable server key name generation strategy is as follows:</t>

<ul>

  <li>If the key is generated by a server as the result of a query
  with root as its owner name, then the server SHOULD create a
  globally unique domain name to be the key name. A suggested method
  is prefixing a domain name of the server with a pseudo-random <xref
  target="RFC4086"/> label having at least 128 bits of entropy using
  the "file name safe" Base 64 encoding (Section 5 of <xref
  target="RFC4648"/>). For example,
  a8s9ZW_n3mDgokX072pp3.serv1.example.com. If generation of a new
  pseudo-random name in each case is an excessive computation load or
  entropy drain, a serial number prefix can be added to a fixed
  pseudo-random name generated at DNS server start time, such as
  1234.a8s9ZW_n3mDgokX072pp3.serv1.example.com, with a new
  pseudo-random portion being generated periodically and on
  reboot.</li>

  <li>If the key is generated as the result of a query with a non-root
  name, say 789.resolv.example, then use the concatenation of that
  name, after deletion of its terminal root label, with a name of the
  server. For example,
  789.resolv.example.serv1.example.com.</li>

</ul>

<t>In the unlikely event that the unique TKEY NAME produced by
whatever strategy is in use exceeds the wire encoding size limit of
255 octets, it may be shortened to fit within that limit with only an
insignificant probability of losing uniqueness by replacing an initial
portion of the excessively long name with the shorter encoding of a
strong hash of that initial portion. For example, cut the excessively
long name between labels so that the right part is no longer than 206
octets in wire encoding. Then take the prefix label or labels
constituting the left part, apply SHA-256 <xref target="RFC6234"/> to
them treated as a name in wire encoding, truncate the resulting hash
to 30 octets, base32 <xref target="RFC4648"/> encode the result of
that truncation yielding 48 octets, and add the output of the base32
encoding as a new single prefix label.</t>

</section>
</section>

<section>
  <name>Remote Address</name>

  <t>This is the address of the remote DNS server or resolver with
  which the key is shared or is to be shared. It MUST be possible to
  have table entries for more than one key for such a remote server or
  resolver so that, for example, a new key can be established before a
  key in use expires or is disabled.</t>
  
</section>

<section>
  <name>State</name>

  <t>This field is intended to encode an indication of the mode used
  in setting the key, whether the local DNS processor was filling the
  role of a resolver or server in the TKEY message exchange, and the
  status of any in progress key negotiation. The details of this
  field's value are implementation dependent.</t>
  
</section>

<section>
  <name>Last Used</name>

  <t>This is the time signed from the most recent DNS message TSIG
  received and validated or sent using this Key using the same
  encoding as the inception and expiration TKEY fields. This field
  might be used to discard keys based on the least recently used or
  the like.</t>
  
</section>
</section>

<section>
  <name>TKEY Modes</name>

<t>The following subsections describe the TKEY modes that are
specified in this document and the messages used for each mode.</t>

<t>Servers and resolvers supporting this specification MUST implement
the ECDH (6) mode (see <xref target="ecdh"/>), Key Deletion (5) mode
(see <xref target="deletion"/>), and TKEY Ping (8) (see <xref
target="ping"/>) mode. Diffie-Hellman (2) mode is NOT RECOMMENDED.
Resolver Assignment (4) and Server Assignment (1) modes SHOULD NOT be
implemented and by definition Documentation (7) mode MUST NOT be
implemented.</t>

<t>A server supporting TKEY that receives a TKEY request with a mode
it does not support MUST return the BADMODE error.</t>

<section anchor="modes">
  <name>Key Agreement Modes</name>

<t>A resolver and a server can agree on shared secret keying material
for use in TSIG through DNS requests from the resolver which are
syntactically DNS queries for type TKEY and answering responses from
the server. Such queries MUST have a TKEY RR in the additional
information section and the response MUST have a TKEY RR in the answer
section to indicate the mode in use and containing other information
where required by that mode.  The query and response MUST be
authenticated (see <xref target="authenticate"/>) except when GSS-API
mode (<xref target="GSS"/>) is used.</t>

<t>The inception and expiration time in TKEY RRs with a mode intended
to result in key agreement refer to a secret key validity interval,
except in the case of GSS-API mode (see <xref target="GSS"/>). The
inception and expiration times in the query TKEY RR are those
requested for the keying material. The inception and expiration times
in the key agreement response TKEY RRs are the period the server
intends to consider the keying material valid which may be a
sub-interval or overlapping interval of the query specified time
interval. Servers may expire keys early, so this is not a
guarantee.</t>

<t>If the expiration time in the resolver query is in the past or if
it is before the inception time, a BADTIME error MUST be returned. If
the inception time in the resolver query is in the future, indicating
an attempt to agree on a future key, a BADTIME error MAY be returned
by the server.</t>

<aside>
  <t>Both DNS transaction security and DNSSEC data security originally
  used the SIG (type = 24) and KEY (type = 25) RRs <xref
  target="RFC2535"/>. DNSSEC was changed to use the RRSIG (type = 46)
  and DNSKEY (type = 48) RRs <xref target="RFC4034"/>; however,
  transaction security, including TKEY and SIG(0) <xref
  target="rfc2931bis"/>, continue to use the SIG and KEY RRs.</t>
</aside>

<section anchor="ecdh">
  <name>ECDH Exchanged Keying (Mode 6)</name>

<t>Elliptic Curve Diffie-Hellman (ECDH) key exchange is a means
whereby two parties can derive shared secret information without
requiring secrecy of the messages they exchange <xref
target="Schneier"/> <xref target="RFC8418"/>.</t>

<t>To use this mode, there need to be compatible elliptic curve public
keys for the resolver and server involved <xref
target="RFC6605"/>. However, there could be multiple keys available
for each of them. The purpose of the TKEY message exchange is to
select the elliptic key to be used for the resolver and the elliptic
key to be used for the server, to provide nonce information, and to
establish the key name and associated key value and TSIG algorithm for
the resulting shared key.</t>

<t>A resolver sends a query for type TKEY accompanied by a TKEY RR in
the additional information section specifying the ECDH exchange mode
and accompanied by a KEY RR also in the additional information section
specifying a resolver elliptic curve key. The TKEY RR algorithm field
is set to the authentication algorithm the resolver plans to use in
any TSIG RRs using the resulting key. Any "key data" provided in the
TKEY in the query is used as a random <xref target="RFC4086"/> nonce
to avoid always deriving the same keying material for the same pair of
KEY RRs.</t>

<t>The server response contains a TKEY in its answer section with the
ECDH assignment mode and echoes back the algorithm field from the
query. If there is "key data" provided in this server TKEY, it is used
as an additional nonce to avoid always deriving the same keying
material for the same pair of KEY RRs but an anycast group of servers
is only supported if such data is the same for all servers in that
group. If the TKEY error field is non-zero, the query failed for the
reason given. FORMERR is given if the query included no elliptic curve
KEY. BADKEY is given if the query included an incompatible elliptic
curve KEY.</t>

<t>If the response TKEY error field is zero, a server elliptic KEY RR
MUST be present in the answer section of the response. The resolver
supplied elliptic curve KEY RR SHOULD be echoed in the additional
information section. Both parties then calculate the same shared
secret quantity from the pair of elliptic curve KEY RRs used <xref
target="Schneier"/> (provided they are compatible) and the data in the
TKEY RRs using HKDF <xref target="RFC5869"/> as follows where "|"
indicates concatenation and the string in double quotes indicates the
octet string of the ASCII <xref target="RFC0020"/> for that character
string without any terminating zero octet or leading length octet or
surrounding quotes:</t>

<artwork align="center" type="ascii-art">
  IKM = shared secret from ECDH with resolver and server keys
  salt = resolver-TKEY-data | server-TKEY-data
  info = "IETF-TKEY-ECDH"
               
  OKM = HKDF-Expand(HMAC-Hash(salt, IKM), info, L)
</artwork>

<t>SHA-256 <xref target="RFC6234"/> is used in the HMAC-Hash <xref
target="RFC2104"/>. L is the length of the keying material needed for
use in the Algorithm specified. and OKM is the output keying material
to use with TSIG.</t>

</section>

<section anchor="ServAssign">
  <name>Server Assigned Keying (Mode 1, Deprecated)</name>
  
<t>A mode was specified in the previous <xref target="RFC2930"/> to
this document whereby a server can assign keying to be shared with the
resolver. So far as is known, this mode was never implemented and
SHOULD NOT be implemented now. It is not specified in this
document.</t>

</section>

<section anchor="ResolvAssign">
  <name>Resolver Assigned Keying (Mode 4, Deprecated)</name>

<t>A mode was specified in the previous <xref target="RFC2930"/> to
this document whereby a server can accept a resolver assigned key. So
far as is known, this mode was never implemented and SHOULD NOT be
implemented now. It is not specified in this document.</t>

</section>

<section anchor="GSS">
  <name>GSS-API Establishment (Mode 3)</name>

<t>This mode is described in "Generic Security Algorithm for Secret
Key Transaction Authentication for DNS (GSS-TSIG)" <xref
target="RFC3645"/> which should be consulted for the full description.
Basically, the resolver and server can exchange queries and responses
for type TKEY with a TKEY RR specifying the GSS-API mode in the
additional information section and a GSS-API token in the key data
portion of the TKEY RR.</t>

<t>Any issues of possible encryption of parts the GSS-API token data
being transmitted are handled by the GSS-API level.  In addition, the
GSS-API level provides its own authentication so that this mode of
TKEY query and response MAY be, but does not need to be, authenticated
with a TSIG RR <xref target="RFC8945"/> or SIG(0) RR <xref
target="rfc2931bis"/>.</t>

<t>The inception and expiration times in a GSS-API mode TKEY RR are
ignored.</t>

</section>

<section anchor="dh">
  <name>Diffie-Hellman Exchanged Keying (Mode 2, Deprecated)</name>

<t>The use of Diffie-Hellman Exchanged Keying mode is NOT RECOMMENDED
for the reasons given in Appendix A which also contains the
specification for that mode for compatibility with old TKEY
implementations. Use of ECDH Exchanged Keying is RECOMMENDED as an
alternative (see <xref target="ecdh"/>).</t>

</section>

</section> <!-- key agreement modes -->

<section>
  <name>Other Modes</name>

<t>The TKEY modes specified in the subsections below do not provide
for agreement on a key but provide other functions.</t>

<section anchor="deletion">
  <name>TKEY Deletion (Mode 5)</name>

<t>To avoid attempted reliance in requests on keys no longer in
effect, servers MUST implement TKEY Deletion mode whereby the server
"discards" a key on receipt from a resolver of an authenticated TKEY
Deletion mode TKEY RR with that key's name. To be effective, the TKEY
MUST also have an inception time no later than the inception of the
key to be deleted and an expiration time no earlier than the
expiration time of the key to be deleted. This time restriction is
intended to minimize potential insecurities due to replaying deletion
mode TKEY RRs.</t>

<t>If the server has no record of a key with that name, it returns
BADNAME in the TKEY Error field in the reply.  This error condition
may be due to the server having discarded the key. If it has a key
with that name but with a validity period extending outside that in
the deletion request, it returns a BADTIME error.</t>

<t>Key deletion TKEY queries MUST be authenticated (see <xref
target="authenticate"/>). This authentication MAY be a TSIG RR using
the key to be deleted.</t>

<t>For ECDH or Diffie-Hellman keys, the
server SHOULD discard all active state associated with the key name in
its key table.</t>

<t>Keys may also be deleted through spontaneous inclusion of a
deletion mode TKEY RR in a response as specified in <xref
target="spontaneous"/>.</t>

</section>

<section anchor="ping">
  <name>TKEY Ping (Mode 8)</name>

<t>The TKEY Ping Mode is intended for use as a test of basic TKEY
plumbing and to check the synchronization of the resolver and server
clocks. It also provides a means for a resolver to determine if TKEY
is implemented at a server without changing the key storage state.</t>

<t>In a TKEY Ping mode query, the Name and Algorithm fields SHOULD be
set to root to save space and are ignored by the server. The Inception
field MUST be set to the time the query is constructed according to
the resolver's clock. The Expiration field MUST be set to zero in a
query and is
ignored on receipt. A resolver MAY include a sequence number or
identification information or whatever else it might find useful in
the Key field. And the Other Data field SHOULD be sent empty and
ignored by the server.</t>

<t>A server implementing TKEY responds with a Ping Mode TKEY RR in the
answer section of its response copied from the query except that it
MUST set the Expiration field to the value of the server's clock when
the reply is constructed even if the response also indicated an error
such as BADTIME.</t>

</section>

<section anchor="doc">
  <name>Documentation Mode (Mode 7)</name>

<t>This mode is assigned as a TKEY Mode to use in examples or
documentation.  A server responds with BADMODE as the TKEY error
if it receives a TKEY RR indicating this mode. Mode 7 will never be
assigned any other use.</t>

</section>
</section> <!-- Other Modes -->

<section anchor="spontaneous">
  <name>Spontaneous Server Inclusion</name>

<t>A DNS server MAY include a deletion mode (mode 5) TKEY RR
spontaneously in the additional information portion of any DNS query
response.  To avoid confusion, this SHOULD NOT be done unless the
server has reason to believe that the resolver supports TKEY and
SHOULD only be done if the server has deleted the corresponding secret
key.  This technique may be specified or allowed for modes other than
deletion in the future.  A disadvantage of this technique is that
there is no way for the server to get any error or success indication
back and, in the case of UDP transport, no way to even know if the DNS
response reached the resolver.</t>

<t>Such a response MUST be authenticated for the TKEY to be
effective. If it is not authenticated, the resolver should ignore any
included TKEY RR. Failure by a client to receive or properly process
such additional information in a response would mean that the client
might use a key that the server had discarded in a TSIG and would then
get an error indication.</t>

</section>
</section>

<section anchor="authenticate">
  <name>TKEY Message Authentication</name>

  <t>Unless otherwise specified, all TKEY queries and responses MUST
  be authenticated. A server receiving a TKEY query that is not
  authenticated but needs to be authenticated returns a NotAuth error
  in the returned TKEY Error field. A resolver receiving a TKEY reply
  that needs to be authenticated but is not authenticated silently
  ignores the TKEY RR.</t>

  <t>To avoid replay attacks, it is necessary that a TKEY response or
  query not be valid if replayed on the order of 2**32 second (about
  136 years), or a multiple thereof, later. To accomplish this, the
  keying material used in any TSIG or SIG(0) RR that authenticates a
  TKEY message MUST NOT have a lifetime of more than 2**31 - 1 seconds
  (about 68 years). Thus, on attempted replay, the authenticating TSIG
  or SIG(0) RR would not be verifiable due to key expiration and a
  replay would fail.</t>

  <t>There are two methods of authentication as specified below.</t>

  <section>
    <name>Secret Key Authentication</name>

    <t>If a shared secret key is in place between the resolver
    and server, then TKEY queries and response can be authenticated
    with TSIG <xref target="RFC8945"/>. So, for example, an existing
    shared secret key could be used to authenticate a TKEY exchange
    that sets up a new key before rolling over to that new key.</t>
    
  </section>

  <section>
    <name>Public Key Authentication</name>

    <t>As an alternative to secret key authentication, public key
    authentication can be used with the SIG(0) RR as specified in
    <xref target="rfc2931bis"/>.</t>
    
  </section>
</section>

<section anchor="IANA">
  <name>IANA Considerations</name>

<t>This section is to be interpreted as provided in <xref
target="RFC8126"/>.</t>

<section>
  <name>Reference Update</name>

  <t>IANA is requested to update all reference to <xref
  target="RFC2930"/> in the DNS Parameters Registry Group to reference
  [this document].</t>
  
</section>

<section>
  <name>Existing Assignments</name>
  
<t>The following assignments have already been made:</t>

<ul>
  <li>RR Type 249 for TKEY.</li>
  <li>Extended RCODE Error values of 19, 20, and 21 as listed in
  <xref target="errors"/>.</li>
</ul>

</section>

<section>
  <name>TSIG/TKEY Registry Group</name>

  <t>IANA is requested to rename the existing "Secret Key Transaction
  Authentication for DNS (TSIG) Algorithm Names" registry to be the
  "DNS TSIG and TKEY Parameters" registry group and include within it
  the existing "TSIG Algorithm Names" registry and the new
  registry created below.</t>
  
<section>
  <name>TKEY Modes Registry</name>
  
<t>IANA is requested to create a "TKEY Modes" Registry as follows:</t>

<artwork>
Name:  TKEY Modes
Reference:  [this document]
Registration Procedures:
   0x0000 - reserved
   0x0001-0x0FFF - standards action
   0x1000-0xFFEF - specification required
   0xFFF0-0xFFFE - experimental use
   0xFFFF - reserved
</artwork>

<t>Initial contents as follows:</t>

<table>
  <thead>
<tr><th>Value</th><th>Description</th><th>Implementation</th><th>Reference</th></tr>
  </thead>
  <tbody>
<tr><td>0x0000</td><td>- reserved</td><td>-</td><td></td></tr>
<tr><td>0x0001</td><td>Server Assignment</td><td>SHOULD NOT</td><td><xref
target="ServAssign"/>, [this
document]</td></tr>
<tr><td>0x0002</td><td>Diffie-Hellman exchange</td><td>SHOULD
NOT</td><td>Appendix A, [this
document]</td></tr>
<tr><td>0x0003</td><td>GSS-API Negotiation</td><td>MAY</td><td><xref
target="GSS"/>, [this
document]</td></tr>
<tr><td>0x0004</td><td>Resolver Assignment</td><td>SHOULD NOT</td><td><xref
target="ResolvAssign"/>, [this
document]</td></tr>
<tr><td>0x0005</td><td>Key Deletion</td><td>MUST</td><td><xref
target="deletion"/>, [this document]</td></tr>
<tr><td>0x0006</td><td>ECDH Agreement</td><td>MUST</td><td><xref
target="ecdh"/> [this document]</td></tr>
<tr><td>0x0007</td><td>Documentation/example</td><td>N/A</td><td><xref
target="doc"/>, [this
document]</td></tr>
<tr><td>0x0008</td><td>TKEY Ping</td><td>MUST</td><td><xref
target="ping"/>, [this document]</td></tr>
<tr><td>0x0009-0x0FFF</td><td>- unassigned</td><td>-</td><td></td></tr>
<tr><td>0x1000-0xFFEF</td><td>- unassigned</td><td>-</td><td></td></tr>
<tr><td>0xFFF0-0xFFFE</td><td>- experimental use</td><td>-</td><td></td></tr>
<tr><td>0xFFFF</td><td>- reserved</td><td>-</td><td></td></tr>
  </tbody>
</table>

</section>
</section>
</section>

<section>
  <name>Security Considerations</name>

<t>This specification is concerned with the secure establishment of
shared secret keys between DNS clients and servers in support of TSIG
<xref target="RFC8945"/>.</t>

<t>Secret keys agreed to using TKEY and the private keys corresponding
to the public key belonging to DNS resolvers and servers are very
sensitive information. All practical steps should be taken to protect
them on every host on which they are stored. Generally, such hosts
need to be physically protected. If they are shared machines, great
care should be taken so that unprivileged processes have no access to
keying material. Resolvers sometimes run unprivileged, which means all
users of a host might be able to see whatever configuration data are
used by the resolver unless appropriate steps are taken to prevent
this.</t>

<t>Protection against denial of service via the use of TKEY is not
provided. DNS servers and resolve should implement appropriate rate
limiting.</t>

<t>More TBD</t>

</section>
        
</middle>


<!-- ____________________BACK_MATTER____________________ -->
<back>

<references>
  <name>Normative References</name>

<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.0020.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.1982.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>

<reference anchor="rfc2931bis"
	   target="https://datatracker.ietf.org/doc/draft-eastlake-dnsop-rfc2931bis-tsigzero/">
  <front>
  <title>Domain Name System (DNS) Public Key Based
  Request and Transaction Authentication ( SIG(0) )</title>
      <author fullname="Donald E. Eastlake 3rd" initials="D."
	      surname="Eastlake"/>
      <author fullname="Johan Stenstam" initials="J."
           surname="Stenstam">
	<organization>Swedish Internet Foundation</organization>
	<address>
          <email>johan.stenstam@internetstiftelsen.se</email>
        </address>
      </author>
  </front>
  <seriesInfo name="work in" value="process"/>
</reference>

<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.3645.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4034.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4648.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.5869.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6234.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6605.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8418.xml"/>

</references>

<references>
  <name>Informative References</name>

<reference anchor="Schneier">
  <front>
    <title>Applied Cryptography Second Edition: protocols, algorithms,
    and source code in C</title>
    <author fullname="Bruce Schneier" initials="B."
	    surname="Schneier">
    </author>
    <date year="1966"/>
  </front>
  <seriesInfo name="ISBN" value="0-471-11709-9"/>
</reference>

<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.1034.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.1035.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.1995.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2104.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2535.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2539.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2930.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.3007.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4035.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4086.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.5905.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6151.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6895.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8126.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8945.xml"/>
<xi:include
  href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.9499.xml"/>

</references>

<section>
  <name>Diffie-Hellman Exchanged Keying Details</name>

<t>TKEY Mode 2, Diffie-Hellman Exchanged Keying, is deprecated for the
reasons given below. It SHOULD NOT be used unless needed for
compatibility with old TKEY implementations.</t>

<ol>
  <li>The mixing function used does not meet current cryptographic
  standards because it uses MD5 <xref target="RFC6151"/>.</li>

  <li>The ad hoc method of combining the DH derived shared value with
  various nonces is inferior to the HKDF <xref target="RFC5869"/>
  method used with the ECDH TKEY mode specified in this document.</li>
</ol>

<t>Diffie-Hellman (DH) key exchange is means whereby two parties can
derive some shared secret information without requiring any secrecy of
the messages they exchange <xref target="Schneier"/>. When this mode
was originally specified, it was assumed that RSA public/private keys
would be used.  Provisions have been made for the storage of "DH"
(RSA) public keys in the DNS <xref target="RFC2539"/>.</t>

<t>A resolver sends a query for type TKEY accompanied by a TKEY RR in
the additional information section specifying the Diffie-Hellman mode
and accompanied by a KEY RR also in the additional information section
specifying a resolver public key.  The TKEY RR algorithm field
is set to the authentication algorithm the resolver plans to use. The
"key data" provided in the TKEY is used as a random <xref
target="RFC4086"/> nonce to avoid always deriving the same keying
material for the same pair of DH KEYs.</t>

<t>The server response contains a TKEY in its answer section with the
Diffie-Hellman mode. The "key data" provided in this TKEY is used as
an additional nonce to avoid always deriving the same keying material
for the same pair of DH KEYs. If the TKEY error field is non-zero, the
query failed for the reason given. FORMERR is given if the query
included no DH KEY and BADKEY is given if the query included an
incompatible DH KEY.</t>

<t>If the response TKEY error field is zero, the resolver supplied KEY
RR SHOULD be echoed in the additional information section and a server
Diffie-Hellman KEY RR MUST be present in the answer section of the
response.  Both parties can then calculate the same shared secret
quantity from the pair of public keys used <xref target="Schneier"/>
(provided these keys are compatible) and the data in the TKEY RRs.
The TKEY RR data is mixed with the DH result as follows:</t>

<artwork align="center" type="ascii-art">
keying material =
     XOR ( DH value, MD5 ( query data | DH value ) |
                     MD5 ( server data | DH value ) )
</artwork>

<t>Where XOR is the bitwise exclusive-OR operation and "|" is
octet-string concatenation.  The shorter of the two operands to XOR is
octet-wise left justified and padded with zero-valued octets to match
the length of the other operand.  "DH value" is the Diffie-Hellman
value derived from the KEY RRs. Query data and server data are the
values sent in the TKEY RR data fields.  These "query data" and
"server data" nonces are suffixed by the DH value, digested by MD5,
the results concatenated, and then XORed with the DH value.</t>

<t>The inception and expiration times in the query TKEY RR are those
requested for the keying material.  The inception and expiration times
in the response TKEY RR are the maximum period the server will
consider the keying material valid.  Servers may pre-expire keys, so
this is not a guarantee.</t>

</section>

<section anchor="changesFrom2930">
  <name>Changes from <xref target="RFC2930"/></name>

  <t>This document incorporates the following significant changes from
  <xref target="RFC2930"/>:</t>

  <ul>
    <li>Addition of the ECDH Key Agreement mode (#6), the Documentation mode
    (#7), and the TKEY Ping mode (#8).</li>
    <li>Deprecation of Diffie-Hellman Exchanged Keying (mode #2).</li>
    <li>Deprecation of and dropping of the specifications for Server
    Assignment mode (#1) and Resolver Assignment (#4) node.</li>
    <li>Additional material including that concerned with
    authentication of TKEY RRs.</li>
    <li>Editorial changes including some re-organization.</li>
  </ul>
  
</section>

<section anchor="Acknowledgements" numbered="false">
  <name>Acknowledgements</name>

<t>The comments and suggestions of the following are gratefully
acknowledged:</t>

<t indent="4">tbd</t>

<t>The comments and suggestions of the following persons were
incorporated into RFC 2930, which was the previous version of this
document, and are gratefully acknowledged:</t>

<t indent="4">Olafur Gudmundsson, Stuart Kwan, Ed Lewis, Erik
Nordmark, and Brian Wellington.</t>

</section>

</back>

</rfc>
