TRAMInternet Engineering Task Force (IETF) M. Petit-HugueninInternet-DraftRequest for Comments: 8489 Impedance Mismatch Obsoletes: 5389(if approved)G. SalgueiroIntended status:Category: Standards Track CiscoExpires: September 22, 2019ISSN: 2070-1721 J. Rosenberg Five9 D. Wing Citrix R. Mahy Unaffiliated P. Matthews NokiaMarch 21,December 2019 Session Traversal Utilities for NAT (STUN)draft-ietf-tram-stunbis-21Abstract Session Traversal Utilities for NAT (STUN) is a protocol that serves as a tool for other protocols in dealing withNetwork Address Translator (NAT)NAT traversal. It can be used by an endpoint to determine the IP address and port allocated to it by a NAT. It can also be used to check connectivity between twoendpoints,endpoints and as a keep-alive protocol to maintain NAT bindings. STUN works with many existingNATs,NATs and does not require any special behavior from them. STUN is not a NAT traversal solution by itself. Rather, it is a tool to be used in the context of a NAT traversal solution. This document obsoletes RFC 5389. Status of This Memo ThisInternet-Draftissubmitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documentsan Internet Standards Track document. This document is a product of the Internet Engineering Task Force (IETF).Note that other groups may also distribute working documents as Internet-Drafts. The listIt represents the consensus ofcurrent Internet- Drafts is at https://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents validthe IETF community. It has received public review and has been approved fora maximumpublication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 ofsix monthsRFC 7841. Information about the current status of this document, any errata, and how to provide feedback on it may beupdated, replaced, or obsoleted by other documentsobtained atany time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on September 22, 2019.https://www.rfc-editor.org/info/rfc8489. Copyright Notice Copyright (c) 2019 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . .54 2. Overview of Operation . . . . . . . . . . . . . . . . . . . .64 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . .87 4. Definitions . . . . . . . . . . . . . . . . . . . . . . . . .87 5. STUN Message Structure . . . . . . . . . . . . . . . . . . .109 6. Base Protocol Procedures . . . . . . . . . . . . . . . . . .1211 6.1. Forming a Request or an Indication . . . . . . . . . . .1211 6.2. Sending the Request or Indication . . . . . . . . . . . .1312 6.2.1. Sending over UDP or DTLS-over-UDP . . . . . . . . . .1413 6.2.2. Sending over TCP or TLS-over-TCP . . . . . . . . . .1514 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP . . . . .1615 6.3. Receiving a STUN Message . . . . . . . . . . . . . . . .1716 6.3.1. Processing a Request . . . . . . . . . . . . . . . .1817 6.3.1.1. Forming a Success or Error Response . . . . . . .1817 6.3.1.2. Sending the Success or Error Response . . . . . .1918 6.3.2. Processing an Indication . . . . . . . . . . . . . .1918 6.3.3. Processing a Success Response . . . . . . . . . . . .2019 6.3.4. Processing an Error Response . . . . . . . . . . . .2019 7. FINGERPRINT Mechanism . . . . . . . . . . . . . . . . . . . .2120 8. DNS Discovery of a Server . . . . . . . . . . . . . . . . . .2120 8.1. STUN URI Scheme Semantics . . . . . . . . . . . . . . . .2221 9. Authentication and Message-Integrity Mechanisms . . . . . . .2322 9.1. Short-Term Credential Mechanism . . . . . . . . . . . . . 23 9.1.1. HMAC Key . . . . . . . . . . . . . . . . . . . . . .2423 9.1.2. Forming a Request or Indication . . . . . . . . . . .2423 9.1.3. Receiving a Request or Indication . . . . . . . . . .2423 9.1.4. Receiving a Response . . . . . . . . . . . . . . . . 25 9.1.5. Sending Subsequent Requests . . . . . . . . . . . . .2625 9.2. Long-Term Credential Mechanism . . . . . . . . . . . . .2625 9.2.1.Bid DownBid-Down Attack Prevention . . . . . . . . . . . . .2827 9.2.2. HMAC Key . . . . . . . . . . . . . . . . . . . . . .2827 9.2.3. Forming a Request . . . . . . . . . . . . . . . . . .2928 9.2.3.1. First Request . . . . . . . . . . . . . . . . . .2928 9.2.3.2. Subsequent Requests . . . . . . . . . . . . . . .2928 9.2.4. Receiving a Request . . . . . . . . . . . . . . . . .3029 9.2.5. Receiving a Response . . . . . . . . . . . . . . . .3231 10. ALTERNATE-SERVER Mechanism . . . . . . . . . . . . . . . . .3332 11. Backwards Compatibility with RFC 3489 . . . . . . . . . . . .3433 12. Basic Server Behavior . . . . . . . . . . . . . . . . . . . .3533 13. STUN Usages . . . . . . . . . . . . . . . . . . . . . . . . .3634 14. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . .3736 14.1. MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . . .3837 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . .3937 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . . . .4038 14.4. USERHASH . . . . . . . . . . . . . . . . . . . . . . . .4039 14.5. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . . . . 40 14.6. MESSAGE-INTEGRITY-SHA256 . . . . . . . . . . . . . . . .4140 14.7. FINGERPRINT . . . . . . . . . . . . . . . . . . . . . .4241 14.8. ERROR-CODE . . . . . . . . . . . . . . . . . . . . . . . 42 14.9. REALM . . . . . . . . . . . . . . . . . . . . . . . . .4443 14.10. NONCE . . . . . . . . . . . . . . . . . . . . . . . . . 44 14.11. PASSWORD-ALGORITHMS . . . . . . . . . . . . . . . . . . 44 14.12. PASSWORD-ALGORITHM . . . . . . . . . . . . . . . . . . . 45 14.13. UNKNOWN-ATTRIBUTES . . . . . . . . . . . . . . . . . . .4645 14.14. SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . 46 14.15. ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . 46 14.16. ALTERNATE-DOMAIN . . . . . . . . . . . . . . . . . . . .4746 15. Operational Considerations . . . . . . . . . . . . . . . . . 47 16. Security Considerations . . . . . . . . . . . . . . . . . . . 47 16.1. Attacks against the Protocol . . . . . . . . . . . . . . 47 16.1.1. Outside Attacks . . . . . . . . . . . . . . . . . . 47 16.1.2. Inside Attacks . . . . . . . . . . . . . . . . . . . 48 16.1.3. Bid-Down Attacks . . . . . . . . . . . . . . . . . .4948 16.2. Attacks Affecting the Usage . . . . . . . . . . . . . .5150 16.2.1. Attack I: Distributed DoS (DDoS) against a Target . 51 16.2.2. Attack II: Silencing a Client . . . . . . . . . . .5251 16.2.3. Attack III: Assuming the Identity of a Client . . . 52 16.2.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . 52 16.3. Hash Agility Plan . . . . . . . . . . . . . . . . . . . 52 17. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 53 18. IANA Considerations . . . . . . . . . . . . . . . . . . . . .5453 18.1. STUN Security Features Registry . . . . . . . . . . . .5453 18.2. STUN Methods Registry . . . . . . . . . . . . . . . . . 54 18.3. STUNAttributeAttributes Registry . . . . . . . . . . . . . . . . 54 18.3.1. Updated Attributes . . . . . . . . . . . . . . . . .5455 18.3.2. New Attributes . . . . . . . . . . . . . . . . . . . 55 18.4. STUN ErrorCodeCodes Registry . . . . . . . . . . . . . . .. 5556 18.5. STUN PasswordAlgorithmAlgorithms Registry . . . . . . . . . . .. 5556 18.5.1. Password Algorithms . . . . . . . . . . . . . . . . 56 18.5.1.1. MD5 . . . . . . . . . . . . . . . . . . . . . . 56 18.5.1.2. SHA-256 . . . . . . . . . . . . . . . . . . . .5657 18.6. STUN UDP and TCP Port Numbers . . . . . . . . . . . . .5657 19. ChangesSincesince RFC 5389 . . . . . . . . . . . . . . . . . . . 57 20. References . . . . . . . . . . . . . . . . . . . . . . . . .5758 20.1. Normative References . . . . . . . . . . . . . . . . . .5758 20.2. Informative References . . . . . . . . . . . . . . . . . 60 Appendix A. C Snippet to Determine STUN Message Types . . . . .6263 Appendix B. Test Vectors . . . . . . . . . . . . . . . . . . . .6364 B.1. Sample Request with Long-Term Authentication with MESSAGE-INTEGRITY-SHA256 and USERHASH . . . . . . . . . .63 Appendix C. Release notes64 Acknowledgements . . . . . . . . . . . . . . . . . . .65 C.1. Modifications between draft-ietf-tram-stunbis-21 and draft-ietf-tram-stunbis-20. . . . . 65 Contributors . . . . . . . . . .65 C.2. Modifications between draft-ietf-tram-stunbis-20 and draft-ietf-tram-stunbis-19. . . . . . . . . . . . . . .65 C.3. Modifications between draft-ietf-tram-stunbis-19 and draft-ietf-tram-stunbis-18 . . . . . . . . . . . . . . . 65 C.4. Modifications between draft-ietf-tram-stunbis-18 and draft-ietf-tram-stunbis-17 . . . . . . . . . . . . . . . 65 C.5. Modifications between draft-ietf-tram-stunbis-17 and draft-ietf-tram-stunbis-16 . . . . . . . . . . . . . . . 65 C.6. Modifications between draft-ietf-tram-stunbis-16 and draft-ietf-tram-stunbis-15 . . . . . . . . . . . . . . . 65 C.7. Modifications between draft-ietf-tram-stunbis-15 and draft-ietf-tram-stunbis-14 . . . . . .. 66 Authors' Addresses . . . . . . . .66 C.8. Modifications between draft-ietf-tram-stunbis-14 and draft-ietf-tram-stunbis-13. . . . . . . . . . . . . . . 66C.9. Modifications between draft-ietf-tram-stunbis-131. Introduction The protocol defined in this specification, Session Traversal Utilities for NAT (STUN), provides a tool for dealing with Network Address Translators (NATs). It provides a means for an endpoint to determine the IP address anddraft-ietf-tram-stunbis-12 . . . . . . . . . . . . . . . 67 C.10. Modifications between draft-ietf-tram-stunbis-12port allocated by a NAT that corresponds to its private IP address anddraft-ietf-tram-stunbis-11 . . . . . . . . . . . . . . . 67 C.11. Modificationsport. It also provides a way for an endpoint to keep a NAT binding alive. With some extensions, the protocol can be used to do connectivity checks betweendraft-ietf-tram-stunbis-11 and draft-ietf-tram-stunbis-10 . . . . . . . . . . . . . . . 67 C.12. Modificationstwo endpoints [RFC8445] or to relay packets betweendraft-ietf-tram-stunbis-10two endpoints [RFC5766]. In keeping with its tool nature, this specification defines an extensible packet format, defines operation over several transport protocols, anddraft-ietf-tram-stunbis-09 . . . . . . . . . . . . . . . 68 C.13. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 68 C.14. Modifications between draft-ietf-tram-stunbis-08 and draft-ietf-tram-stunbis-07 . . . . . . . . . . . . . . . 69 C.15. Modifications between draft-ietf-tram-stunbis-07 and draft-ietf-tram-stunbis-06 . . . . . . . . . . . . . . . 69 C.16. Modifications between draft-ietf-tram-stunbis-06 and draft-ietf-tram-stunbis-05 . . . . . . . . . . . . . . . 69 C.17. Modifications between draft-ietf-tram-stunbis-05 and draft-ietf-tram-stunbis-04 . . . . . . . . . . . . . . . 69 C.18. Modifications between draft-ietf-tram-stunbis-04 and draft-ietf-tram-stunbis-03 . . . . . . . . . . . . . . . 70 C.19. Modifications between draft-ietf-tram-stunbis-03 and draft-ietf-tram-stunbis-02 . . . . . . . . . . . . . . . 70 C.20. Modifications between draft-ietf-tram-stunbis-02 and draft-ietf-tram-stunbis-01 . . . . . . . . . . . . . . . 70 C.21. Modifications between draft-ietf-tram-stunbis-01 and draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 71 C.22. Modifications between draft-salgueiro-tram-stunbis-02 and draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 72 C.23. Modifications between draft-salgueiro-tram-stunbis-02 and draft-salgueiro-tram-stunbis-01 . . . . . . . . . . . . . 72 C.24. Modifications between draft-salgueiro-tram-stunbis-01 and draft-salgueiro-tram-stunbis-00 . . . . . . . . . . . . . 72 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 72 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 73 1. Introduction The protocol defined in this specification, Session Traversal Utilities for NAT, provides a tool for dealing with NATs. It provides a means for an endpoint to determine the IP address and port allocated by a NAT that corresponds to its private IP address and port. It also provides a way for an endpoint to keep a NAT binding alive. With some extensions, the protocol can be used to do connectivity checks between two endpoints [RFC8445], or to relay packets between two endpoints [RFC5766]. In keeping with its tool nature, this specification defines an extensible packet format, defines operation over several transport protocols, and provides for two forms of authentication. STUN is intended to be used in the context of one or more NAT traversal solutions. These solutions are known as STUN usages. Each usage describes how STUN is utilized to achieve the NAT traversal solution. Typically, a usage indicates when STUN messages get sent, which optional attributes to include, what server is used, and what authentication mechanism is to be used. Interactive Connectivity Establishment (ICE) [RFC8445] is one usage of STUN. SIP Outbound [RFC5626] is another usage of STUN. In some cases, a usage will require extensions to STUN. A STUN extension can be in the form of new methods, attributes, or error response codes. More information on STUN usages can be found in Section 13. 2. Overview of Operation This section is descriptive only. /-----\ // STUN \\ | Server | \\ // \-----/ +--------------+ Public Internet ................| NAT 2 |....................... +--------------+ +--------------+ Private NET 2 ................| NAT 1 |....................... +--------------+ /-----\ // STUN \\ | Client | \\ // Private NET 1 \-----/ Figure 1: One Possible STUN Configuration One possible STUN configuration is shown in Figure 1. In this configuration, there are two entities (called STUN agents) that implement the STUN protocol. The lower agent in the figure is the client, and is connected to private network 1. This network connects to private network 2 through NAT 1. Private network 2 connects to the public Internet through NAT 2. The upper agent in the figure is the server, and resides on the public Internet. STUN is a client-server protocol. It supports two types of transactions. One is a request/response transaction in which a client sends a request to a server, and the server returns a response. The second is an indication transaction in which either agent -- client or server -- sends an indication that generates no response. Both types of transactions include a transaction ID, which is a randomly selected 96-bit number. For request/response transactions, this transaction ID allows the client to associate the response with the request that generated it; for indications, the transaction ID serves as a debugging aid. All STUN messages start with a fixed header that includes a method, a class, and the transaction ID. The method indicates which of the various requests or indications this is; this specification defines just one method, Binding, but other methods are expected to be defined in other documents. The class indicates whether this is a request, a success response, an error response, or an indication. Following the fixed header comes zero or more attributes, which are Type-Length-Value extensions that convey additional information for the specific message. This document defines a single method called Binding. The Binding method can be used either in request/response transactions or in indication transactions. When used in request/response transactions, the Binding method can be used to determine the particular "binding" a NAT has allocated to a STUN client. When used in either request/ response or in indication transactions, the Binding method can also be used to keep these "bindings" alive. In the Binding request/response transaction, a Binding request is sent from a STUN client to a STUN server. When the Binding request arrives at the STUN server, it may have passed through one or more NATs between the STUN client and the STUN server (in Figure 1, there were two such NATs). As the Binding request message passes through a NAT, the NAT will modify the source transport address (that is, the source IP address and the source port) of the packet. As a result, the source transport address of the request received by the server will be the public IP address and port created by the NAT closest to the server. This is called a reflexive transport address. The STUN server copies that source transport address into an XOR-MAPPED- ADDRESS attribute in the STUN Binding response and sends the Binding response back to the STUN client. As this packet passes back through a NAT, the NAT will modify the destination transport address in the IP header, but the transport address in the XOR-MAPPED-ADDRESS attribute within the body of the STUN response will remain untouched. In this way, the client can learn its reflexive transport address allocated by the outermost NAT with respect to the STUN server. In some usages, STUN must be multiplexed with other protocols (e.g., [RFC8445], [RFC5626]). In these usages, there must be a way to inspect a packet and determine if it is a STUN packet or not. STUN provides three fields in the STUN header with fixed values that can be used for this purpose. If this is not sufficient, then STUN packets can also contain a FINGERPRINT value, which can further be used to distinguish the packets. STUN defines a set of optional procedures that a usage can decide to use, called mechanisms. These mechanisms include DNS discovery, a redirection technique to an alternate server, a fingerprint attribute for demultiplexing, and two authentication and message-integrity exchanges. The authentication mechanisms revolve around the use of a username, password, and message-integrity value. Two authentication mechanisms, the long-term credential mechanism and the short-term credential mechanism, are defined in this specification. Each usage specifies the mechanisms allowed with that usage. In the long-term credential mechanism, the client and server share a pre-provisioned username and password and perform a digest challenge/ response exchange inspired by (but differing in details) to the one defined for HTTP [RFC7616]. In the short-term credential mechanism, the client and the server exchange a username and password through some out-of-band method prior to the STUN exchange. For example, in the ICE usage [RFC8445] the two endpoints use out-of-band signaling to exchange a username and password. These are used to integrity protect and authenticate the request and response. There is no challenge or nonce used. 3. Terminology 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 [RFC2119][RFC8174] when, and only when, they appear in all capitals, as shown here. 4. Definitions STUN Agent: A STUN agent is an entity that implements the STUN protocol. The entity can be either a STUN client or a STUN server. STUN Client: A STUN client is an entity that sends STUN requests and receives STUN responses and STUN indications. A STUN client can also send indications. In this specification, the terms STUN client and client are synonymous. STUN Server: A STUN server is an entity that receives STUN requests and STUN indications, and sends STUN responses. A STUN server can also send indications. In this specification, the terms STUN server and server are synonymous. Transport Address: The combination of an IP address and port number (such as a UDP or TCP port number). Reflexive Transport Address: A transport address learned by a client that identifies that client as seen by another host on an IP network, typically a STUN server. When there is an intervening NAT between the client and the other host, the reflexive transport address represents the mapped address allocated to the client on the public side of the NAT. Reflexive transport addresses are learned from the mapped address attribute (MAPPED-ADDRESS or XOR- MAPPED-ADDRESS) in STUN responses. Mapped Address: Same meaning as reflexive address. This term is retained only for historic reasons and due to the naming of the MAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. Long-Term Credential: A username and associated password that represent a shared secret between client and server. Long-term credentials are generally granted to the client when a subscriber enrolls in a service and persist until the subscriber leaves the service or explicitly changes the credential. Long-Term Password: The password from a long-term credential. Short-Term Credential: A temporary username and associated password that represent a shared secret between client and server. Short- term credentials are obtained through some kind of protocol mechanism between the client and server, preceding the STUN exchange. A short-term credential has an explicit temporal scope, which may be based on a specific amount of time (such as 5 minutes) or on an event (such as termination of a Session Initiation Protocol (SIP [RFC3261]) dialog). The specific scope of a short-term credential is defined by the application usage. Short-Term Password: The password component of a short-term credential. STUN Indication: A STUN message that does not receive a response. Attribute: The STUN term for a Type-Length-Value (TLV) object that can be added to a STUN message. Attributes are divided into two types: comprehension-required and comprehension-optional. STUN agents can safely ignore comprehension-optional attributes they don't understand, but cannot successfully process a message if it contains comprehension-required attributes that are not understood. RTO: Retransmission TimeOut, which defines the initial period of time between transmission of a request and the first retransmit of that request. 5. STUN Message Structure STUN messages are encoded in binary using network-oriented format (most significant byte or octet first, also commonly known as big- endian). The transmission order is described in detail in Appendix B of [RFC0791]. Unless otherwise noted, numeric constants are in decimal (base 10). All STUN messages comprise a 20-byte header followed by zero or more Attributes. The STUN header contains a STUN message type, message length, magic cookie, and transaction ID. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0| STUN Message Type | Message Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Magic Cookie | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Transaction ID (96 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 2: Format of STUN Message Header The most significant 2 bits of every STUN message MUST be zeroes. This can be used to differentiate STUN packets from other protocols when STUN is multiplexed with other protocols on the same port. The message type defines the message class (request, success response, error response, or indication) and the message method (the primary function) of the STUN message. Although there are four message classes, there are only two types of transactions in STUN: request/response transactions (which consist of a request message and a response message) and indication transactions (which consist of a single indication message). Response classes are split into error and success responses to aid in quickly processing the STUN message. The message type field is decomposed further into the following structure: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ |M |M |M|M|M|C|M|M|M|C|M|M|M|M| |11|10|9|8|7|1|6|5|4|0|3|2|1|0| +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 3: Format of STUN Message Type Field Here the bits in the message type field are shown as most significant (M11) through least significant (M0). M11 through M0 represent a 12-bit encoding of the method. C1 and C0 represent a 2-bit encoding of the class. A class of 0b00 is a request, a class of 0b01 is an indication, a class of 0b10 is a success response, and a class of 0b11 is an error response. This specification defines a single method, Binding. The method and class are orthogonal, so that for each method, a request, success response, error response, and indication are possible for that method. Extensions defining new methods MUST indicate which classes are permitted for that method. For example, a Binding request has class=0b00 (request) and method=0b000000000001 (Binding) and is encoded into the first 16 bits as 0x0001. A Binding response has class=0b10 (success response) and method=0b000000000001, and is encoded into the first 16 bits as 0x0101. Note: This unfortunate encoding is due to assignment of values in [RFC3489] that did not consider encoding Indications, Success, and Errors using bit fields. The magic cookie field MUST contain the fixed value 0x2112A442 in network byte order. In [RFC3489], this field was part of the transaction ID; placing the magic cookie in this location allows a server to detect if the client will understand certain attributes that were added to STUN by [RFC5389]. In addition, it aids in distinguishing STUN packets from packets of other protocols when STUN is multiplexed with those other protocols on the same port. The transaction ID is a 96-bit identifier, used to uniquely identify STUN transactions. For request/response transactions, the transaction ID is chosen by the STUN client for the request and echoed by the server in the response. For indications, it is chosen by the agent sending the indication. It primarily serves to correlate requests with responses, though it also plays a small role in helping to prevent certain types of attacks. The server also uses the transaction ID as a key to identify each transaction uniquely across all clients. As such, the transaction ID MUST be uniformly and randomly chosen from the interval 0 .. 2**96-1, and MUST be cryptographically random. Resends of the same request reuse the same transaction ID, but the client MUST choose a new transaction ID for new transactions unless the new request is bit-wise identical to the previous request and sent from the same transport address to the same IP address. Success and error responses MUST carry the same transaction ID as their corresponding request. When an agent is acting as a STUN server and STUN client on the same port, the transaction IDs in requests sent by the agent have no relationship to the transaction IDs in requests received by the agent. The message length MUST contain the size, in bytes, of the message not including the 20-byte STUN header. Since all STUN attributes are padded to a multiple of 4 bytes, the last 2 bits of this field are always zero. This provides another way to distinguish STUN packets from packets of other protocols. Following the STUN fixed portion of the header are zero or more attributes. Each attribute is TLV (Type-Length-Value) encoded. The details of the encoding, and of the attributes themselves are given in Section 14. 6. Base Protocol Procedures This section defines the base procedures of the STUN protocol. It describes how messages are formed, how they are sent, and how they are processed when they are received. It also defines the detailed processing of the Binding method. Other sections in this document describe optional procedures that a usage may elect to use in certain situations. Other documents may define other extensions to STUN, by adding new methods, new attributes, or new error response codes. 6.1. Forming a Request or an Indication When formulating a request or indication message, the agent MUST follow the rules in Section 5 when creating the header. In addition, the message class MUST be either "Request" or "Indication" (as appropriate), and the method must be either Binding or some method defined in another document. The agent then adds any attributes specified by the method or the usage. For example, some usages may specify that the agent use an authentication method (Section 9) or the FINGERPRINT attribute (Section 7). If the agent is sending a request, it SHOULD add a SOFTWARE attribute to the request. Agents MAY include a SOFTWARE attribute in indications, depending on the method. Extensions to STUN should discuss whether SOFTWARE is useful in new indications. Note that the inclusion of a SOFTWARE attribute may have security implications; see Section 16.1.2 for details. For the Binding method with no authentication, no attributes are required unless the usage specifies otherwise. All STUN messages sent over UDP or DTLS-over-UDP [RFC6347] SHOULD be less than the path MTU, if known. If the path MTU is unknown for UDP, messages SHOULD be the smaller of 576 bytes and the first-hop MTU for IPv4 [RFC1122] and 1280 bytes for IPv6 [RFC8200]. This value corresponds to the overall size of the IP packet. Consequently, for IPv4, the actual STUN message would need to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte UDP header, assuming no IP options are used). If the path MTU is unknown for DTLS-over-UDP, the rules described in the previous paragraph need to be adjusted to take into account the size of the (13-byte) DTLS Record header, the MAC size, and the padding size. STUN provides no ability to handle the case where the request is under the MTU but the response would be larger than the MTU. It is not envisioned that this limitation will be an issue for STUN. The MTU limitation is a SHOULD, and not a MUST, to account for cases where STUN itself is being used to probe for MTU characteristics [RFC5780]. See also [I-D.ietf-tram-stun-pmtud] for a framework that uses STUN to add Path MTU Discovery to protocols that lack one. Outside of this or similar applications, the MTU constraint MUST be followed. 6.2. Sending the Request or Indication The agent then sends the request or indication. This document specifies how to send STUN messages over UDP, TCP, TLS-over-TCP, or DTLS-over-UDP; other transport protocols may be added in the future. The STUN usage must specify which transport protocol is used, and how the agent determines the IP address and port of the recipient. Section 8 describes a DNS-based method of determining the IP address and port of a server that a usage may elect to use. At any time, a client MAY have multiple outstanding STUN requests with the same STUN server (that is, multiple transactions in progress, with different transaction IDs). Absent other limits to the rate of new transactions (such as those specified by ICE for connectivity checks or when STUN is run over TCP), a client SHOULD limit itself to ten outstanding transactions to the same server. 6.2.1. Sending over UDP or DTLS-over-UDP When running STUN over UDP or STUN over DTLS-over-UDP [RFC7350], it is possible that the STUN message might be dropped by the network. Reliability of STUN request/response transactions is accomplished through retransmissions of the request message by the client application itself. STUN indications are not retransmitted; thus, indication transactions over UDP or DTLS-over-UDP are not reliable. A client SHOULD retransmit a STUN request message starting with an interval of RTO ("Retransmission TimeOut"), doubling after each retransmission. The RTO is an estimate of the round-trip time (RTT), and is computed as described in [RFC6298], with two exceptions. First, the initial value for RTO SHOULD be greater or equal to 500 ms. The exception cases for this "SHOULD" are when other mechanisms are used to derive congestion thresholds (such as the ones defined in ICE for fixed rate streams), or when STUN is used in non-Internet environments with known network capacities. In fixed-line access links, a value of 500 ms is RECOMMENDED. Second, the value of RTO SHOULD NOT be rounded up to the nearest second. Rather, a 1 ms accuracy SHOULD be maintained. As with TCP, the usage of Karn's algorithm is RECOMMENDED [KARN87]. When applied to STUN, it means that RTT estimates SHOULD NOT be computed from STUN transactions that result in the retransmission of a request. The value for RTO SHOULD be cached by a client after the completion of the transaction, and used as the starting value for RTO for the next transaction to the same server (based on equality of IP address). The value SHOULD be considered stale and discarded if no transactions have occurred to the same server in the last 10 minutes. Retransmissions continue until a response is received, or until a total of Rc requests have been sent. Rc SHOULD be configurable and SHOULD have a default of 7. If, after the last request, a duration equal to Rm times the RTO has passed without a response (providing ample time to get a response if only this final request actually succeeds), the client SHOULD consider the transaction to have failed. Rm SHOULD be configurable and SHOULD have a default of 16. A STUN transaction over UDP or DTLS-over-UDP is also considered failed if there has been a hard ICMP error [RFC1122]. For example, assuming an RTO of 500ms, requests would be sent at times 0 ms, 500 ms, 1500 ms, 3500 ms, 7500 ms, 15500 ms, and 31500 ms. If the client has not received a response after 39500 ms, the client will consider the transaction to have timed out. 6.2.2. Sending over TCP or TLS-over-TCP For TCP and TLS-over-TCP [RFC5246], the client opens a TCP connection to the server. In some usages of STUN, STUN is sent as the only protocol over the TCP connection. In this case, it can be sent without the aid of any additional framing or demultiplexing. In other usages, or with other extensions, it may be multiplexed with other data over a TCP connection. In that case, STUN MUST be run on top of some kind of framing protocol, specified by the usage or extension, which allows for the agent to extract complete STUN messages and complete application layer messages. The STUN service running on the well- known port or ports discovered through the DNS procedures in Section 8 is for STUN alone, and notprovides forSTUN multiplexed with other data. Consequently, no framing protocols aretwo forms of authentication. STUN is intended to be used inconnections to those servers. When additional framing is utilized,the context of one or more NAT traversal solutions. These solutions are known as "STUN Usages". Each usagewill specifydescribes how STUN is utilized to achieve theclient knowsNAT traversal solution. Typically, a usage indicates when STUN messages get sent, which optional attributes toapply itinclude, what server is used, and whatportauthentication mechanism is toconnect to. For example,be used. Interactive Connectivity Establishment (ICE) [RFC8445] is one usage of STUN. SIP Outbound [RFC5626] is another usage of STUN. In some cases, a usage will require extensions to STUN. A STUN extension can be in thecaseform ofICE connectivity checks, thisnew methods, attributes, or error response codes. More informationis learned through out-of-band negotiation between client and server. Reliabilityon STUN Usages can be found in Section 13. 2. Overview of Operation This section is descriptive only. /-----\ // STUNover TCP and TLS-over-TCP\\ | Server | \\ // \-----/ +--------------+ Public Internet ................| NAT 2 |....................... +--------------+ +--------------+ Private Network 2 ................| NAT 1 |....................... +--------------+ /-----\ // STUN \\ | Client | \\ // Private Network 1 \-----/ Figure 1: One Possible STUN Configuration One possible STUN configuration ishandled by TCP itself, andshown in Figure 1. In this configuration, there areno retransmissions at thetwo entities (called STUNprotocol level. However, for a request/response transaction, ifagents) that implement theclient has not received a response by Ti seconds after it sentSTUN protocol. The lower agent in therequest message, it considersfigure is thetransactionclient, which is connected tohave timed out. Ti SHOULD be configurable and SHOULD have a default of 39.5s.private network 1. Thisvalue has been chosennetwork connects to private network 2 through NAT 1. Private network 2 connects toequalize the TCP and UDP timeouts forthedefault initial RTO. In addition, ifpublic Internet through NAT 2. The upper agent in theclientfigure isunable to establishtheTCP connection, orserver, which resides on theTCP connectionpublic Internet. STUN isreset or fails beforearesponseclient-server protocol. It supports two types of transactions. One isreceived, anya request/response transaction inprogress is considered to have failed. Thewhich a clientMAY send multiple transactions oversends asingle TCP (or TLS- over-TCP) connection, and it MAY send anotherrequestbefore receiving a response to the previous request. The client SHOULD keep the connection open until it: o has no further STUN requests or indications to send over that connection, and o has no planstouse any resources (such asamapped address (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address [RFC5766]) that were learned though STUN requests sent over that connection, and o if multiplexing other application protocols over that port, has finished using those other protocols,server, ando if using that learned port withthe server returns aremote peer, has established communications with that remote peer, as is required by some TCP NAT traversal techniques (e.g., [RFC6544]).response. Thedetails ofsecond is aneventual keep-alive mechanism are left to each STUN Usage. In any case ifindication transaction in which either agent -- client or server -- sends an indication that generates no response. Both types of transactions include a transactionfails because an idle TCP connection doesn't work anymoreID, which is a randomly selected 96-bit number. For request/response transactions, this transaction ID allows the clientSHOULD send an RST and trytoopen a new TCP connection. Atassociate theserver end,response with theserver SHOULD keeprequest that generated it; for indications, theconnection open,transaction ID serves as a debugging aid. All STUN messages start with a fixed header that includes a method, a class, andlet the client close it, unlesstheserver has determined thattransaction ID. The method indicates which of theconnection has timed out (for example, duevarious requests or indications this is; this specification defines just one method, Binding, but other methods are expected to be defined in other documents. The class indicates whether this is a request, a success response, an error response, or an indication. Following theclient disconnecting from the network). Bindings learned byfixed header comes zero or more attributes, which are Type-Length-Value extensions that convey additional information for theclient will remain validspecific message. This document defines a single method called "Binding". The Binding method can be used either inintervening NATs only while the connection remains open. Onlyrequest/response transactions or in indication transactions. When used in request/response transactions, theclient knows how long it needsBinding method can be used to determine thebinding. The server SHOULD NOT closeparticular binding aconnection ifNAT has allocated to a STUN client. When used in either request/ response or in indication transactions, the Binding method can also be used to keep these bindings alive. In the Binding request/response transaction, a Binding requestwas received over that connection for which a response was not sent. A server MUST NOT ever openis sent from aconnection back towards theSTUN clientin ordertosendaresponse. Servers SHOULD follow best practices regarding connection management in cases of overload. 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDPSTUN server. When the Binding request arrives at the STUNis run by itself over TLS-over-TCPserver, it may have passed through one orDTLS-over-UDP,more NATs between theTLS_DHE_RSA_WITH_AES_128_GCM_SHA256 and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suites MUST be implementedSTUN client andother cipher suites MAY be implemented. Perfect Forward Secrecy (PFS) cipher suites MUST be preferred over non-PFS cipher suites. Cipher suites with known weaknesses,the STUN server (in Figure 1, there are two suchas those based on (single) DESNATs). As the Binding request message passes through a NAT, the NAT will modify the source transport address (that is, the source IP address andRC4, MUST NOT be used. Implementations MUST disable TLS-level compression. These recommendations are justthe source port) of the packet. As apartresult, the source transport address of therecommendations in [BCP195] that implementationsrequest received by the server will be the public IP address anddeployments ofport created by the NAT closest to the server. This is called a "reflexive transport address". The STUNUsage using TLS or DTLS MUST follow. When it receivesserver copies that source transport address into an XOR-MAPPED- ADDRESS attribute in theTLS Certificate message,STUN Binding response and sends theclient MUST verifyBinding response back to thecertificate and inspectSTUN client. As this packet passes back through a NAT, the NAT will modify thesite identified bydestination transport address in thecertificate. IfIP header, but thecertificate is invalid or revoked, or if it does not identifytransport address in theappropriate party,XOR-MAPPED-ADDRESS attribute within theclient MUST NOT sendbody of the STUNmessage or otherwise proceed withresponse will remain untouched. In this way, theSTUN transaction. TheclientMUST verifycan learn its reflexive transport address allocated by theidentity ofoutermost NAT with respect to the STUN server.To do that, it follows the identification procedures defined in [RFC6125], with a certificate containing an identifier of type DNS-ID or CN-ID, optionally with a wildcard character as leftmost label, but not of type SRV-ID or URI- ID. WhenIn some usages, STUNis runmust be multiplexed with other protocolsover(e.g., [RFC8445] and [RFC5626]). In these usages, there must be aTLS-over-TCP connection orway to inspect aDTLS-over-UDP association, the mandatory ciphersuitespacket andTLS handling procedures operate as defined by those protocols. 6.3. Receivingdetermine if it is a STUNMessage This section specifiespacket or not. STUN provides three fields in theprocessing of aSTUNmessage. The processing specified here isheader with fixed values that can be used forSTUN messages as defined inthisspecification; additional rules for backwards compatibility are defined in Section 11. Those additional procedures are optional, and usages can elect to utilize them. First, a set of processing operations is applied that is independent of the class. Thispurpose. If this isfollowed by class-specific processing, described in the subsections that follow. Whennot sufficient, then STUN packets can also contain a FINGERPRINT value, which can further be used to distinguish the packets. STUNagent receivesdefines aSTUN message, it first checksset of optional procedures that a usage can decide to use, called "mechanisms". These mechanisms include DNS discovery, a redirection technique to an alternate server, a fingerprint attribute for demultiplexing, and two authentication and message-integrity exchanges. The authentication mechanisms revolve around themessage obeys the rulesuse ofSection 5. It checks thata username, password, and message-integrity value. Two authentication mechanisms, thefirst two bitslong-term credential mechanism and the short-term credential mechanism, are0,defined in this specification. Each usage specifies the mechanisms allowed with that usage. In themagic cookie field haslong-term credential mechanism, thecorrect value, thatclient and server share a pre-provisioned username and password and perform a digest challenge/ response exchange inspired by themessage length is sensible,one defined for HTTP [RFC7616] but differing in details. In the short-term credential mechanism, the client andthatthemethod value isserver exchange asupported method. It checks thatusername and password through some out-of-band method prior to themessage class is allowed forSTUN exchange. For example, in theparticular method. IfICE usage [RFC8445], themessage classtwo endpoints use out-of-band signaling to exchange a username and password. These are used to integrity protect and authenticate the request and response. There is"Success Response"no challenge or"Error Response", thenonce used. 3. Terminology 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 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here. 4. Definitions STUN Agent: A STUN agentchecksis an entity that implements thetransaction ID matchesSTUN protocol. The entity can be either atransaction that is still in progress. If the FINGERPRINT extensionSTUN client or a STUN server. STUN Client: A STUN client isbeing used, the agent checksan entity thatthe FINGERPRINT attribute is presentsends STUN requests andcontains the correct value. If any errors are detected, the message is silently discarded.receives STUN responses and STUN indications. A STUN client can also send indications. In this specification, thecase whenterms "STUN client" and "client" are synonymous. STUN Server: A STUN server isbeing multiplexed with another protocol,anerror may indicateentity thatthis is not really areceives STUNmessage; inrequests and STUN indications and that sends STUN responses. A STUN server can also send indications. In thiscase, the agent should try to parsespecification, themessageterms "STUN server" and "server" are synonymous. Transport Address: The combination of an IP address and port number (such as adifferent protocol. The STUN agent then does any checks that are requiredUDP or TCP port number). Reflexive Transport Address: A transport address learned by aauthentication mechanismclient thatthe usage has specified (see Section 9). Once the authentication checks are done, the STUN agent checks for unknown attributes and known-but-unexpected attributes in the message. Unknown comprehension-optional attributes MUST be ignored by the agent. Known-but-unexpected attributes SHOULD be ignored by the agent. Unknown comprehension-required attributes cause processingidentifies thatdependsclient as seen by another host on an IP network, typically a STUN server. When there is an intervening NAT between themessage classclient andis described below. At this point, further processing dependsthe other host, the reflexive transport address represents the mapped address allocated to the client on themessage classpublic side of therequest. 6.3.1. Processing a Request IfNAT. Reflexive transport addresses are learned from therequest contains onemapped address attribute (MAPPED-ADDRESS ormore unknown comprehension-required attributes,XOR- MAPPED-ADDRESS) in STUN responses. Mapped Address: Same meaning as reflexive address. This term is retained only for historic reasons and due to theserver replies with an error response with an error codenaming of420 (Unknown Attribute), and includes an UNKNOWN-ATTRIBUTES attribute intheresponseMAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. Long-Term Credential: A username and associated password thatlistsrepresent a shared secret between client and server. Long-term credentials are generally granted to theunknown comprehension- required attributes. Otherwiseclient when a subscriber enrolls in a service and persist until theserver then does any additional checking thatsubscriber leaves themethodservice or explicitly changes thespecific usage requires. If allcredential. Long-Term Password: The password from a long-term credential. Short-Term Credential: A temporary username and associated password that represent a shared secret between client and server. Short- term credentials are obtained through some kind of protocol mechanism between thechecks succeed,client and server, preceding theserver formulatesSTUN exchange. A short-term credential has an explicit temporal scope, which may be based on asuccess responsespecific amount of time (such asdescribed below. When run over UDP5 minutes) orDTLS-over-UDP,on an event (such as termination of arequest receivedSession Initiation Protocol (SIP) [RFC3261] dialog). The specific scope of a short-term credential is defined by theserver could be the first requestapplication usage. Short-Term Password: The password component of atransaction, orshort-term credential. STUN Indication: A STUN message that does not receive aretransmission.response. Attribute: Theserver MUST respond to retransmissions suchSTUN term for a Type-Length-Value (TLV) object thatthe following property is preserved: if the client receives the responsecan be added tothe retransmissiona STUN message. Attributes are divided into two types: comprehension-required andnot the responsecomprehension-optional. STUN agents can safely ignore comprehension-optional attributes they don't understand but cannot successfully process a message if it contains comprehension-required attributes thatwas sent to the original request, the overall state on the client and server is identical to the case where only the response to the original retransmission is received, or where both responsesarereceived (innot understood. RTO: Retransmission TimeOut, whichcasedefines theclient will useinitial period of time between transmission of a request and thefirst).first retransmit of that request. 5. STUN Message Structure STUN messages are encoded in binary using network-oriented format (most significant byte or octet first, also commonly known as big- endian). Theeasiest way to meet this requirementtransmission order isfor the server to remember all transaction IDs received over UDP or DTLS-over-UDP and their corresponding responsesdescribed inthe last 40 seconds. However, this requires the server to hold state, and will be inappropriate for any requests whichdetail in Appendix B of [RFC0791]. Unless otherwise noted, numeric constants arenot authenticated. Another way is to reprocess the requestin decimal (base 10). All STUN messages comprise a 20-byte header followed by zero or more attributes. The STUN header contains a STUN message type, message length, magic cookie, andrecompute the response.transaction ID. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0| STUN Message Type | Message Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Magic Cookie | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Transaction ID (96 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 2: Format of STUN Message Header Thelatter techniquemost significant 2 bits of every STUN message MUSTonlybeappliedzeroes. This can be used torequests that are idempotent (a request is considered idempotentdifferentiate STUN packets from other protocols when STUN is multiplexed with other protocols on the samerequest can be safely repeated without impacting the overall state of the system) and result inport. The message type defines thesamemessage class (request, successresponse forresponse, error response, or indication) and thesame request. The Bindingmessage methodis considered to be idempotent. Note that(the primary function) of the STUN message. Although there arecertain rare network events that could cause the reflexive transport address value to change, resulting in a different mapped addressfour message classes, there are only two types of transactions indifferent success responses. Extensions to STUN MUST discuss the implicationsSTUN: request/response transactions (which consist of a requestretransmissions on servers that do not store transaction state. 6.3.1.1. Formingmessage and a response message) and indication transactions (which consist of aSuccess or Errorsingle indication message). ResponseWhen forming the response (success or error), the server followsclasses are split into error and success responses to aid in quickly processing therules of Section 6.STUN message. ThemethodSTUN Message Type field is decomposed further into the following structure: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ |M |M |M|M|M|C|M|M|M|C|M|M|M|M| |11|10|9|8|7|1|6|5|4|0|3|2|1|0| +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 3: Format of STUN Message Type Field Here theresponse isbits in thesameSTUN Message Type field are shown asthatmost significant (M11) through least significant (M0). M11 through M0 represent a 12-bit encoding of therequest,method. C1 and C0 represent a 2-bit encoding of themessageclass. A class of 0b00 is a request, a class of 0b01 iseither "Success Response" or "Error Response". Foranerrorindication, a class of 0b10 is a success response,the server MUST addand a class of 0b11 is anERROR-CODE attribute containing theerrorcode specified in the processing above.response. This specification defines a single method, Binding. Thereason phrase is not fixed, but SHOULD be something suitablemethod and class are orthogonal, so that fortheeach method, a request, success response, errorcode. For certain errors, additional attributesresponse, and indication areadded to the message. These attributespossible for that method. Extensions defining new methods MUST indicate which classes arespelled out in the description wherepermitted for that method. For example, a Binding request has class=0b00 (request) and method=0b000000000001 (Binding) and is encoded into theerror codefirst 16 bits as 0x0001. A Binding response has class=0b10 (success response) and method=0b000000000001 and isspecified. For example, for an error code of 420 (Unknown Attribute),encoded into theserver MUST include an UNKNOWN- ATTRIBUTES attribute. Certain authentication errors also cause attributesfirst 16 bits as 0x0101. Note: This unfortunate encoding is due tobe added (see Section 9). Extensions may define otherassignment of values in [RFC3489] that did not consider encoding indication messages, success responses, and errorsand/or additional attributes to addresponses using bit fields. The Magic Cookie field MUST contain the fixed value 0x2112A442 inerror cases. Ifnetwork byte order. In [RFC3489], theserver authenticated32 bits comprising therequest using an authentication mechanism, thenMagic Cookie field were part of theserver SHOULD addtransaction ID; placing theappropriate authentication attributesmagic cookie in this location allows a server to detect if theresponse (see Section 9). The server also adds anyclient will understand certain attributesrequiredthat were added to STUN bythe specific method or usage.[RFC5389]. In addition, it aids in distinguishing STUN packets from packets of other protocols when STUN is multiplexed with those other protocols on theserver SHOULD addsame port. The transaction ID is aSOFTWARE attribute96-bit identifier, used tothe message.uniquely identify STUN transactions. For request/response transactions, theBinding method, no additional checkingtransaction ID isrequired unlesschosen by theusage specifies otherwise. When formingSTUN client for thesuccess response,request and echoed by the server in the response. For indications, it is chosen by the agent sending the indication. It primarily serves to correlate requests with responses, though it also plays a small role in helping to prevent certain types of attacks. The serveraddsalso uses the transaction ID as aXOR-MAPPED-ADDRESS attributekey to identify each transaction uniquely across all clients. As such, theresponse, wheretransaction ID MUST be uniformly and randomly chosen from thecontentsinterval 0 .. 2**96-1 and MUST be cryptographically random. Resends of theattribute aresame request reuse thesource transport address ofsame transaction ID, but the client MUST choose a new transaction ID for new transactions unless the new requestmessage. For UDP or DTLS-over-UDP thisis bit-wise identical to thesource IP address and source UDP port of theprevious requestmessage. For TCPandTLS- over-TCP, this issent from thesource IPsame transport address to the same IP address. Success andsource TCP port oferror responses MUST carry theTCP connectionsame transaction ID asseen bytheir corresponding request. When an agent is acting as a STUN server and STUN client on theserver. 6.3.1.2. Sendingsame port, theSuccess or Error Response The response (success or error) istransaction IDs in requests sentoverby thesame transport asagent have no relationship to therequest wastransaction IDs in requests receivedon. Ifby therequest was received over UDP or DTLS-over-UDPagent. The message length MUST contain thedestination IP address and portsize of theresponse aremessage in bytes, not including thesource IP address and port20-byte STUN header. Since all STUN attributes are padded to a multiple of 4 bytes, thereceived request message, and the source IP address and portlast 2 bits ofthe responsethis field areequalalways zero. This provides another way tothe destination IP address and portdistinguish STUN packets from packets of other protocols. Following thereceived request message. IfSTUN fixed portion of therequest was received over TCPheader are zero orTLS-over-TCP, the responsemore attributes. Each attribute issent back onTLV (Type-Length-Value) encoded. Details of thesame TCP connection asencoding and therequest was received on. The server is allowed to send responsesattributes themselves are given ina different order than it received the requests. 6.3.2. Processing an Indication IfSection 14. 6. Base Protocol Procedures This section defines theindication contains unknown comprehension-required attributes,base procedures of theindication is discardedSTUN protocol. It describes how messages are formed, how they are sent, and how they are processed when they are received. It also defines the detailed processingceases. Otherwiseof theagent then does any additional checkingBinding method. Other sections in this document describe optional procedures thatthe method or the specifica usagerequires. If all the checks succeed, the agent then processes the indication. Nomay elect to use in certain situations. Other documents may define other extensions to STUN, by adding new methods, new attributes, or new error responseis generated forcodes. 6.1. Forming a Request or anindication. For the Binding method, no additional checkingIndication When formulating a request orprocessing is required, unless the usage specifies otherwise. The mere receipt of the message byindication message, the agenthas refreshedMUST follow the"bindings"rules in Section 5 when creating theintervening NATs. Since indications are not re-transmitted over UDP or DTLS-over-UDP (unlike requests), there is no need to handle re-transmissions of indications at the sending agent. 6.3.3. Processing a Success Response If the success response contains unknown comprehension-required attributes, the response is discarded andheader. In addition, thetransaction is considered to have failed. Otherwisemessage class MUST be either "Request" or "Indication" (as appropriate), and theclientmethod must be either Binding or some method defined in another document. The agent thendoesadds anyadditional checking thatattributes specified by the method or thespecific usage requires. If all the checks succeed, the client then processes the success response.usage. Forthe Binding method, the client checksexample, some usages may specify that theXOR-MAPPED-ADDRESSagent use an authentication method (Section 9) or the FINGERPRINT attribute (Section 7). If the agent ispresent insending a request, it SHOULD add a SOFTWARE attribute to theresponse. The client checksrequest. Agents MAY include a SOFTWARE attribute in indications, depending on theaddress family specified. If itmethod. Extensions to STUN should discuss whether SOFTWARE isan unsupported address family,useful in new indications. Note that the inclusion of a SOFTWARE attributeSHOULD be ignored. If it is an unexpected but supported address family (for example,may have security implications; see Section 16.1.2 for details. For the Bindingtransaction wasmethod with no authentication, no attributes are required unless the usage specifies otherwise. All STUN messages sent overIPv4, butUDP or DTLS-over-UDP [RFC6347] SHOULD be less than theaddress family specifiedpath MTU, if known. If the path MTU isIPv6), thenunknown for UDP, messages SHOULD be theclient MAY acceptsmaller of 576 bytes andusethevalue. 6.3.4. Processing an Error Responsefirst-hop MTU for IPv4 [RFC1122] and 1280 bytes for IPv6 [RFC8200]. This value corresponds to the overall size of the IP packet. Consequently, for IPv4, the actual STUN message would need to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte UDP header, assuming no IP options are used). If theerror response containspath MTU is unknowncomprehension-required attributes, or iffor DTLS-over-UDP, theerror response does not contain an ERROR-CODE attribute, thenrules described in thetransaction is simply consideredprevious paragraph need tohave failed. Otherwise the client then does any processing specified bybe adjusted to take into account theauthentication mechanism (see Section 9). This may result in a new transaction attempt. The processing at this point depends onsize of theerror code,(13-byte) DTLS Record header, themethod,Message Authentication Code (MAC) size, and theusage; the following arepadding size. STUN provides no ability to handle thedefault rules: o Ifcase where theerror coderequest is300 through 399,smaller than theclient SHOULD considerMTU but thetransaction as failed unlessresponse is larger than theALTERNATE-SERVER extension (Section 10)MTU. It is not envisioned that this limitation will be an issue for STUN. The MTU limitation is a SHOULD, not a MUST, to account for cases where STUN itself is beingused. o Ifused to probe for MTU characteristics [RFC5780]. See also [STUN-PMTUD] for a framework that uses STUN to add Path MTU Discovery to protocols that lack such a mechanism. Outside of this or similar applications, the MTU constraint MUST be followed. 6.2. Sending the Request or Indication The agent then sends the request or indication. This document specifies how to send STUN messages over UDP, TCP, TLS-over-TCP, or DTLS-over-UDP; other transport protocols may be added in theerror codefuture. The STUN Usage must specify which transport protocol is400 through 499,used and how theclient declaresagent determines thetransaction failed; inIP address and port of thecaserecipient. Section 8 describes a DNS-based method of420 (Unknown Attribute),determining theresponse should containIP address and port of aUNKNOWN-ATTRIBUTES attributeserver thatgives additional information. o If the error code is 500 through 599, thea usage may elect to use. At any time, a client MAYresend the request; clients that do so MUST limithave multiple outstanding STUN requests with thenumber of times they do this. Unless a specific error code specifies asame STUN server (that is, multiple transactions in progress, with differentvalue,transaction IDs). Absent other limits to thenumberrate ofretransmissionsnew transactions (such as those specified by ICE for connectivity checks or when STUN is run over TCP), a client SHOULDbe limitedlimit itself to4. Any other error code causes the clientten outstanding transactions toconsiderthetransaction failed. 7. FINGERPRINT Mechanism This section describes an optional mechanism forsame server. 6.2.1. Sending over UDP or DTLS-over-UDP When running STUN over UDP or STUN over DTLS-over-UDP [RFC7350], it is possible thataids in distinguishingthe STUNmessages from packetsmessage might be dropped by the network. Reliability of STUN request/response transactions is accomplished through retransmissions ofother protocols whenthetwo are multiplexed onrequest message by thesame transport address. This mechanism is optional, andclient application itself. STUN indications are not retransmitted; thus, indication transactions over UDP or DTLS-over-UDP are not reliable. A client SHOULD retransmit a STUNusage must describe if and when it is used.request message starting with an interval of RTO ("Retransmission TimeOut"), doubling after each retransmission. TheFINGERPRINT mechanismRTO isnot backwards compatible with RFC3489,an estimate of the round-trip time (RTT) andcannot be used in environments where such compatibilityisrequired. In some usages, STUN messages are multiplexed on the same transport address as other protocols, suchcomputed asthe Real Time Transport Protocol (RTP). In order to apply the processingdescribed inSection 6, STUN messages must first[RFC6298], with two exceptions. First, the initial value for RTO SHOULD beseparated fromgreater than or equal to 500 ms. The exception cases for this "SHOULD" are when other mechanisms are used to derive congestion thresholds (such as theapplication packets. Section 5 describes three fixed fieldsones defined intheICE for fixed-rate streams) or when STUNheader that can beis usedfor this purpose. However,insome cases, these three fixed fields may not be sufficient. When the FINGERPRINT extensionnon- Internet environments with known network capacities. In fixed-line access links, a value of 500 ms isused, an agent includesRECOMMENDED. Second, theFINGERPRINT attribute in messages it sendsvalue of RTO SHOULD NOT be rounded up toanother agent. Section 14.7 describestheplacement and valuenearest second. Rather, a 1 ms accuracy SHOULD be maintained. As with TCP, the usage ofthis attribute.Karn's algorithm is RECOMMENDED [KARN87]. Whenthe agent receives whatapplied to STUN, itbelieves ismeans that RTT estimates SHOULD NOT be computed from STUN transactions that result in the retransmission of a request. The value for RTO SHOULD be cached by aSTUN message, then, in addition to other basic checks,client after theagent also checks thatcompletion of themessage contains a FINGERPRINT attributetransaction andthatused as theattribute containsstarting value for RTO for thecorrect value. Section 6.3 describes when innext transaction to theoverall processingsame server (based on equality ofa STUN messageIP address). The value SHOULD be considered stale and discarded if no transactions have occurred to theFINGERPRINT check is performed. This additional check helpssame server in theagent detect messageslast 10 minutes. Retransmissions continue until a response is received or until a total ofother protocols that might otherwise seem toRc requests have been sent. Rc SHOULD beSTUN messages. 8. DNS Discovery ofconfigurable and SHOULD have aServer This section describes an optional procedure for STUN that allowsdefault of 7. If, after the last request, aclient to use DNSduration equal todetermineRm times theIP address and port ofRTO has passed without aserver. A STUN usage must describeresponse (providing ample time to get a response ifand when this extension is used. To useonly thisprocedure,final request actually succeeds), the clientmust knowSHOULD consider the transaction to have failed. Rm SHOULD be configurable and SHOULD have a default of 16. A STUNURI [RFC7064]; the usage musttransaction over UDP or DTLS-over-UDP is alsodescribe howconsidered failed if there has been a hard ICMP error [RFC1122]. For example, assuming an RTO of 500 ms, requests would be sent at times 0 ms, 500 ms, 1500 ms, 3500 ms, 7500 ms, 15500 ms, and 31500 ms. If the clientobtains this URI. Hard- codinghas not received aSTUN URI into software is NOT RECOMMENDED in caseresponse after 39500 ms, thedomain name is lost or needs to change for legal or other reasons. When aclientwishes to locate a STUN server on the public Internet that accepts Binding request/response transactions,will consider theSTUN URI scheme is "stun". When it wishestransaction tolocate a STUN server that accepts Binding request/response transactionshave timed out. 6.2.2. Sending overa TLS,TCP orDTLS session, the URI scheme is "stuns". The syntax of the "stun"TLS-over-TCP For TCP and"stuns" URIs are defined in Section 3.1 of [RFC7064]. STUN usages MAY define additional URI schemes. 8.1. STUN URI Scheme Semantics IfTLS-over-TCP [RFC8446], the<host> part ofclient opens a"stun" URI contains an IP address, then this IP address is used directlyTCP connection tocontactthe server.A "stuns" URI containing an IP address MUST be rejected. A futureIn some usages of STUN, STUNextension or usage may relaxis the only protocol over the TCP connection. In thisrequirement providedcase, itdemonstrates how to authenticatecan be sent without the aid of any additional framing or demultiplexing. In other usages, or with other extensions, it may be multiplexed with other data over a TCP connection. In that case, STUNserver and prevent man in the middle attacks. If the URI does not contain an IP address, the domain name contained inMUST be run on top of some kind of framing protocol, specified by the<host> part is resolved to a transport address usingusage or extension, which allows for theSRV procedures specified in [RFC2782].agent to extract complete STUN messages and complete application-layer messages. TheDNS SRVSTUN servicename isrunning on thecontent ofwell- known port or ports discovered through the<scheme> part. The protocolDNS procedures inthe SRV lookupSection 8 isthe transport protocol the client will run STUN over: "udp"forUDPSTUN alone, and"tcp"not forTCP. The procedures of RFC 2782STUN multiplexed with other data. Consequently, no framing protocols arefollowed to determine the serverused in connections tocontact. RFC 2782 spells outthose servers. When additional framing is utilized, thedetails ofusage will specify howa set of SRV records is sorted and then tried. However, RFC 2782 only states thatthe clientshould "try to connectknows tothe (protocol, address, service)" without giving any details onapply it and whathappensport to connect to. For example, in theeventcase offailure. When following these procedures, ifICE connectivity checks, this information is learned through out-of-band negotiation between client and server. Reliability of STUN over TCP and TLS-over-TCP is handled by TCP itself, and there are no retransmissions at the STUNtransaction times out without receipt ofprotocol level. However, for aresponse,request/response transaction, if the clientSHOULD retryhas not received a response by Ti seconds after it sent the requestto the next server inmessage, it considers theordered defined by RFC 2782. Suchtransaction to have timed out. Ti SHOULD be configurable and SHOULD have aretry is only possible for request/response transmissions, since indication transactions generate no response or timeout.default of 39.5 s. This value has been chosen to equalize the TCP and UDP timeouts for the default initial RTO. In addition,instead of querying either the A orif theAAAA resource records for a domain name, a dual-stack IPv4/IPv6clientMUST query both and tryis unable to establish therequests with allTCP connection, or theIP addressesTCP connection is reset or fails before a response is received,as specifiedany request/response transaction in[RFC8305]. The default port for STUN requestsprogress is3478, for both TCP and UDP.considered to have failed. Thedefault port for STUNclient MAY send multiple transactions overTLSa single TCP (or TLS- over-TCP) connection, and it MAY send another request before receiving a response to the previous request. The client SHOULD keep the connection open until it: o has no further STUNover DTLSrequestsis 5349. Servers can run STUNor indications to send overDTLS on the same portthat connection, o has no plans to use any resources (such asSTUN over UDP if the server software supports determining whether the initial message isaDTLSmapped address (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address [RFC5766]) that were learned though STUNmessage. Servers can run STUNrequests sent overTLS on the samethat connection, o if multiplexing other application protocols over that port, has finished using those other protocols, o if using that learned port with a remote peer, has established communications with that remote peer, as is required by some TCP NAT traversal techniques (e.g., [RFC6544]). The details of an eventual keep-alive mechanism are left to each STUNoverUsage. In any case, if a transaction fails because an idle TCP connection doesn't work anymore, the client SHOULD send a RST and try to open a new TCPifconnection. At the serversoftware supports determining whetherend, theinitial message is a TLS or STUN message. Administrators of STUN serversserver SHOULDuse these ports in their SRV records for UDP and TCP. In all cases,keep theport in DNS MUST reflectconnection open and let theone on whichclient close it, unless the serveris listening. If no SRV records were found,has determined that the connection has timed out (for example, due to the clientperforms both an A and AAAA record lookup ofdisconnecting from thedomain name, as described in [RFC8305]. The resultnetwork). Bindings learned by the client willbe a list of IP addresses, each of which can be simultaneously contacted atremain valid in intervening NATs only while thedefault port using UDP or TCP, independent ofconnection remains open. Only theSTUN usage. For usagesclient knows how long it needs the binding. The server SHOULD NOT close a connection if a request was received over thatrequire TLS,connection for which a response was not sent. A server MUST NOT ever open a connection back towards the clientconnectsin order tothe IP addresses using the defaultsend a response. Servers SHOULD follow best practices regarding connection management in cases of overload. 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP When STUN is run by itself overTLS port. For usagesTLS-over-TCP or DTLS-over-UDP, the TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ciphersuites MUST be implemented (for compatibility with older versions of this protocol), except if deprecated by rules of a specific STUN usage. Other ciphersuites MAY be implemented. Note thatrequire DTLS, the client connects to the IP addresses using the defaultSTUNover DTLS port. 9. Authenticationclients andMessage-Integrity Mechanisms This section defines two mechanisms for STUNservers thata client and server can useimplement TLS version 1.3 [RFC8446] or subsequent versions are also required toprovide authenticationimplement mandatory ciphersuites from those specifications andmessage integrity; these two mechanisms areSHOULD disable usage of deprecated ciphersuites when they detect support for those specifications. Perfect Forward Secrecy (PFS) ciphersuites MUST be preferred over non-PFS ciphersuites. Ciphersuites with known weaknesses, such asthe short-term credential mechanismthose based on (single) DES andthe long-term credential mechanism.RC4, MUST NOT be used. Implementations MUST disable TLS-level compression. Thesetwo mechanisms are optional, and each usage must specify if and when these mechanismsrecommendations areused. Consequently, both clients and servers will know which mechanism (if any) to follow based on knowledge of which usage applies. For example,just aSTUN server on the public Internet supporting ICE would have no authentication, whereas the STUN server functionality in an agent supporting connectivity checks would utilize short-term credentials. An overviewpart ofthese two mechanisms is given in Section 2. Each mechanism specifies the additional processing required to use that mechanism, extendingtheprocessing specified in Section 6. The additional processing occursrecommendations inthree different places: when forming a message, when receiving a message immediately after the basic checks have been performed,[BCP195] that implementations andwhen doing the detailed processingdeployments oferror responses. Note that agentsa STUN Usage using TLS or DTLS MUSTignore all attributes that follow MESSAGE- INTEGRITY, withfollow. When it receives theexception ofTLS Certificate message, theMESSAGE-INTEGRITY-SHA256 and FINGERPRINT attributes. Similarly agentsclient MUSTignore all attributes that followverify theMESSAGE-INTEGRITY-SHA256 attribute ifcertificate and inspect theMESSAGE- INTEGRITY attributesite identified by the certificate. If the certificate is invalid or revoked, or if it does notpresent,identify the appropriate party, the client MUST NOT send the STUN message or otherwise proceed with theexceptionSTUN transaction. The client MUST verify the identity of theFINGERPRINT attribute. 9.1. Short-Term Credential Mechanism The short-term credential mechanism assumesserver. To do that,prior toit follows the identification procedures defined in [RFC6125], with a certificate containing an identifier of type DNS-ID or CN-ID, optionally with a wildcard character as the leftmost label, but not of type SRV-ID or URI-ID. When STUNtransaction,is run multiplexed with other protocols over a TLS-over-TCP connection or a DTLS-over-UDP association, theclientmandatory ciphersuites andserver have used some other protocol to exchangeTLS handling procedures operate as defined by those protocols. 6.3. Receiving acredential inSTUN Message This section specifies theformprocessing of ausername and password. This credential is time-limited.STUN message. Thetime limitprocessing specified here is for STUN messages as definedby the usage. As an example,inthe ICE usage [RFC8445], the two endpoints use out- of-band signaling to agree on a username and password, andthisusername and password are applicablespecification; additional rules forthe duration of the media session. This credential is used to form a message-integrity checkbackwards compatibility are defined ineach requestSection 11. Those additional procedures are optional, andin many responses. Thereusages can elect to utilize them. First, a set of processing operations isno challenge and response as in the long-term mechanism; consequently, replayapplied that islimited by virtue of the time-limited natureindependent of thecredential. 9.1.1. HMAC Key For short-term credentials the HMAC key is defined as follow: key = OpaqueString(password) where the OpaqueString profileclass. This isdefinedfollowed by class-specific processing, described in[RFC8265]. The encoding used is UTF-8 [RFC3629]. 9.1.2. Formingthe subsections that follow. When aRequest or Indication ForSTUN agent receives arequest or indicationSTUN message, it first checks that theagent MUST includemessage obeys theUSERNAME, MESSAGE-INTEGRITY-SHA256, and MESSAGE-INTEGRITY attributes inrules of Section 5. It checks that themessage unlessfirst two bits are 0, that theagent knows from an external indication which message integrity algorithm is supported by both agents. In this case either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 MUST be included in addition to USERNAME. The HMAC forMagic Cookie field has theMESSAGE- INTEGRITY attributecorrect value, that the message length iscomputed as described in Section 14.5sensible, and that theHMAC for the MESSAGE-INTEGRITY-SHA256 attributesmethod value iscomputed as described in Section 14.6. Notea supported method. It checks that thepasswordmessage class isnever included inallowed for therequest or indication. 9.1.3. Receiving a Requestparticular method. If the message class is "Success Response" orIndication After"Error Response", the agenthas donechecks that thebasic processing oftransaction ID matches amessage,transaction that is still in progress. If theagent performsFINGERPRINT extension is being used, the agent checkslisted below in order specified: o Ifthat themessage does not contain 1) a MESSAGE-INTEGRITY or a MESSAGE-INTEGRITY-SHA256FINGERPRINT attribute is present and2) a USERNAME attribute: *contains the correct value. If any errors are detected, the message isa request, the server MUST rejectsilently discarded. In therequestcase when STUN is being multiplexed with another protocol, an errorresponse. This response MUST use an error code of 400 (Bad Request). * If the messagemay indicate that this isan indication,not really a STUN message; in this case, the agentMUST silently discard the indication. o Ifshould try to parse theUSERNAMEmessage as a different protocol. The STUN agent then doesnot containany checks that are required by ausername value currently valid withinauthentication mechanism that theserver: * Ifusage has specified (see Section 9). Once the authentication checks are done, the STUN agent checks for unknown attributes and known-but-unexpected attributes in the message. Unknown comprehension-optional attributes MUST be ignored by the agent. Known-but-unexpected attributes SHOULD be ignored by the agent. Unknown comprehension-required attributes cause processing that depends on the message class and isa request,described below. At this point, further processing depends on theserver MUST rejectmessage class of the request. 6.3.1. Processing a Request If the request contains one or more unknown comprehension-required attributes, the server replies with an errorresponse. ThisresponseMUST usewith an error code of401 (Unauthenticated). * If the message is420 (Unknown Attribute) and includes anindication,UNKNOWN-ATTRIBUTES attribute in theagent MUST silently discardresponse that lists theindication. o Ifunknown comprehension- required attributes. Otherwise, theMESSAGE-INTEGRITY-SHA256 attribute is present computeserver then does any additional checking that thevalue formethod or themessage integrityspecific usage requires. If all the checks succeed, the server formulates a success response as describedin Section 14.6, usingbelow. When run over UDP or DTLS-over-UDP, a request received by thepassword associated withserver could be theusername. Iffirst request of a transaction or could be a retransmission. The server MUST respond to retransmissions such that theMESSAGE- INTEGRITY-SHA256 attributefollowing property isnot present, then use the same password to computepreserved: if thevalue forclient receives themessage integrity as described in Section 14.5. Ifresponse to theresulting value doesretransmission and notmatch the contents ofthecorresponding attribute (MESSAGE-INTEGRITY- SHA256 or MESSAGE-INTEGRITY): * Ifresponse that was sent to themessage is aoriginal request, the overall state on the client and serverMUST rejectis identical to the case where only therequest with an error response. ThisresponseMUST use an error code of 401 (Unauthenticated). * Ifto themessageoriginal retransmission isan indication, the agent MUST silently discardreceived or where both responses are received (in which case theindication. If these checks pass,client will use theagent continuesfirst). The easiest way toprocessmeet this requirement is for therequestserver to remember all transaction IDs received over UDP orindication. Any response generated by aDTLS-over-UDP and their corresponding responses in the last 40 seconds. However, this requires the server toa requesthold state and is inappropriate for any requests thatcontains a MESSAGE-INTEGRITY-SHA256 attributeare not authenticated. Another way is to reprocess the request and recompute the response. The latter technique MUSTincludeonly be applied to requests that are idempotent (a request is considered idempotent when the same request can be safely repeated without impacting the overall state of theMESSAGE-INTEGRITY-SHA256 attribute, computed usingsystem) and result in thepassword utilized to authenticatesame success response for the same request.Any response generated by a serverThe Binding method is considered to be idempotent. Note that there are certain rare network events that could cause the reflexive transport address value to change, resulting in a different mapped address in different success responses. Extensions to STUN MUST discuss the implications of request retransmissions on servers thatcontains onlydo not store transaction state. 6.3.1.1. Forming aMESSAGE-INTEGRITY attribute MUST includeSuccess or Error Response When forming theMESSAGE-INTEGRITY attribute, computed usingresponse (success or error), thepassword utilized to authenticateserver follows therequest. This means that only onerules ofthese attributes can appear in a response.Section 6. The method of the responseMUST NOT containis theUSERNAME attribute. If anysame as that of thechecks fail, arequest, and the message class is either "Success Response" or "Error Response". For an error response, the server MUSTNOT include a MESSAGE- INTEGRITY-SHA256, MESSAGE-INTEGRITY, or USERNAMEadd an ERROR-CODE attributeincontaining the errorresponse. This is because,code specified inthese failure cases, the server cannot determine the shared secret necessary to computetheMESSAGE- INTEGRITY-SHA256 or MESSAGE-INTEGRITY attributes. 9.1.4. Receiving a Responseprocessing above. Theclient looksreason phrase is not fixed but SHOULD be something suitable for theMESSAGE-INTEGRITY orerror code. For certain errors, additional attributes are added to theMESSAGE-INTEGRITY- SHA256 attributemessage. These attributes are spelled out in theresponse. If present and ifdescription where theclient only sent only oneerror code is specified. For example, for an error code ofMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256420 (Unknown Attribute), the server MUST include an UNKNOWN- ATTRIBUTES attribute. Certain authentication errors also cause attributes to be added (see Section 9). Extensions may define other errors and/or additional attributes to add in error cases. If therequest (because ofserver authenticated theexternal indication in Section 9.1.2, or this being a subsequentrequestas defined in Section 9.1.5)using an authentication mechanism, then thealgorithm inserver SHOULD add theresponse hasappropriate authentication attributes tomatch otherwisethe responseMUST be discarded.(see Section 9). Theclient then computes the message integrity overserver also adds any attributes required by theresponse as defined in Section 14.5specific method orSection 14.6, respectively, usingusage. In addition, thesame password it utilized forserver SHOULD add a SOFTWARE attribute to therequest. Ifmessage. For theresulting value matchesBinding method, no additional checking is required unless thecontents ofusage specifies otherwise. When forming theMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, respectively,success response, theresponse is considered authenticated. Ifserver adds an XOR-MAPPED-ADDRESS attribute to thevalue does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 were absent,response; this attribute contains theprocessing depends onsource transport address of the requestbeen sent over a reliablemessage. For UDP oran unreliable transport. IfDTLS-over-UDP, this is therequest was sent over an unreliable transport,source IP address and source UDP port of theresponse MUST be discarded, as if it was never received. This means that retransmits, if applicable, will continue. If allrequest message. For TCP and TLS-over-TCP, this is theresponses received are discarded then insteadsource IP address and source TCP port ofsignaling a timeout after endingthetransactionTCP connection as seen by the server. 6.3.1.2. Sending thelayer MUST signal thatSuccess or Error Response The response (success or error) is sent over theintegrity protectionsame transport as the request wasviolated.received on. If the request wassentreceived overa reliable transport,UDP or DTLS-over-UDP, theresponse MUST be discardeddestination IP address and port of thelayer MUST immediately endresponse are thetransactionsource IP address andsignal that the integrity protection was violated. 9.1.5. Sending Subsequent Requests A client sending subsequent requests to the same server MUST send only the MESSAGE-INTEGRITY-SHA256 or the MESSAGE-INTEGRITY attribute that matchesport of theattribute that wasreceivedinrequest message, and the source IP address and port of the response are equal to theinitial request. Here same server means samedestination IP address and portnumber, not justof thesame URIreceived request message. If the request was received over TCP orSRV lookup result. 9.2. Long-Term Credential Mechanism The long-term credential mechanism relies on a long-term credential, inTLS-over-TCP, theform of a username and password that are shared between client and server. The credential is considered long-term since it is assumed that itresponse isprovisioned for a user, and remains in effect untilsent back on theuser is no longer a subscriber ofsame TCP connection as thesystem, or is changed. Thisrequest was received on. The server isbasically a traditional "log-in" username and password given to users. Because these usernames and passwords are expectedallowed tobe valid for extended periods of time, replay prevention is providedsend responses in a different order than it received the requests. 6.3.2. Processing an Indication If the indication contains unknown comprehension-required attributes, theform of a digest challenge. In this mechanism,indication is discarded and processing ceases. Otherwise, theclient initially sends a request, without offeringagent then does anycredentialsadditional checking that the method orany integrity checks. The server rejects this request, providingtheuser a realm (used to guidespecific usage requires. If all the checks succeed, theuser oragentin selection of a username and password) and a nonce. The nonce provides a limited replay protection. Itthen processes the indication. No response isa cookie, selectedgenerated for an indication. For the Binding method, no additional checking or processing is required, unless the usage specifies otherwise. The mere receipt of the message by theserver, and encodedagent has refreshed the bindings insuch a way asthe intervening NATs. Since indications are not re-transmitted over UDP or DTLS-over-UDP (unlike requests), there is no need toindicate a durationhandle re-transmissions ofvalidity or client identity from which itindications at the sending agent. 6.3.3. Processing a Success Response If the success response contains unknown comprehension-required attributes, the response isvalid. Onlydiscarded and theserver needstransaction is considered toknow about the internal structure ofhave failed. Otherwise, thecookie. Theclientretriesthen does any additional checking that therequest, this time including its username andmethod or therealm, and echoingspecific usage requires. If all thenonce provided bychecks succeed, theserver. Theclientalso includes one ofthen processes themessage-integrity attributes defined in this document, which provides an HMAC oversuccess response. For theentire request, includingBinding method, the client checks that the XOR-MAPPED-ADDRESS attribute is present in thenonce.response. Theserver validates the nonce andclient checks themessage integrity.address family specified. Ifthey match, the requestit isauthenticated. Ifan unsupported address family, thenonce is no longer valid,attribute SHOULD be ignored. If it isconsidered "stale", and the server rejectsan unexpected but supported address family (for example, therequest, providing a new nonce. In subsequent requests toBinding transaction was sent over IPv4, but thesame server,address family specified is IPv6), then the clientreuses the nonce, username, realm,MAY accept andpassword it used previously. In this way, subsequent requests are not rejected until the nonce becomes invalid by the server, in which case the rejection provides a new nonce touse theclient. Note thatvalue. 6.3.4. Processing an Error Response If thelong-term credential mechanism cannot be used to protect indications, since indications cannot be challenged. Usages utilizing indications must either use a short-term credentialerror response contains unknown comprehension-required attributes, oromit authentication and message integrity for them. To indicate that it supports this specification, a server MUST prependif theNONCE attribute value witherror response does not contain an ERROR-CODE attribute, then thecharacter string composed of "obMatJos2" concatenated withtransaction is simply considered to have failed. Otherwise, the(4 character) Base64 [RFC4648] encoding ofclient then does any processing specified by the24 bit STUN Security Features as defined inauthentication mechanism (see Section18.1.9). This may result in a new transaction attempt. The24 bit Security Feature set is encoded as 3 bytes, with bit 0 asprocessing at this point depends on themost significant bit oferror code, thefirst bytemethod, andbit 23 astheleast significant bit ofusage; thethird byte. If no security featuresfollowing areused, then a byte array with all 24 bits set to zero MUST be encoded instead. Fortheremainder of this documentdefault rules: o If theterm "nonce cookie" will refer toerror code is 300 through 399, thecomplete 13 character string prepended toclient SHOULD consider theNONCE attribute value. Sincetransaction as failed unless thelong-term credential mechanismALTERNATE-SERVER extension (Section 10) issusceptible to offline dictionary attacks, deployments SHOULD utilize passwords that are difficult to guess. In cases wherebeing used. o If thecredentials are not entered byerror code is 400 through 499, theuser, but are rather placed on aclientdevice during device provisioning,declares thepassword SHOULD have at least 128 bits of randomness. In cases wheretransaction failed; in thecredentials are entered bycase of 420 (Unknown Attribute), theuser, theyresponse shouldfollow best current practices around password structure. 9.2.1. Bid Down Attack Prevention This document introduces two new security featurescontain a UNKNOWN-ATTRIBUTES attribute thatprovidegives additional information. o If theability to chooseerror code is 500 through 599, thealgorithm used for password protection as well asclient MAY resend theabilityrequest; clients that do so MUST limit the number of times they do this. Unless a specific error code specifies a different value, the number of retransmissions SHOULD be limited touse4. Any other error code causes the client to consider the transaction failed. 7. FINGERPRINT Mechanism This section describes ananonymous username. Both of these capabilities areoptional mechanism for STUN that aids inorder to remain backwards compatible with previous versionsdistinguishing STUN messages from packets of other protocols when theSTUN protocol. These new capabilitiestwo aresubject to bid-down attacks whereby an attacker inmultiplexed on themessage path can remove these capabilitiessame transport address. This mechanism is optional, andforce weaker security properties. To prevent these kinds of attacks from going undetected, the noncea STUN Usage must describe if and when it isenhanced with additional information.used. Thevalue of the "nonce cookie" will vary basedFINGERPRINT mechanism is not backwards compatible with RFC 3489 and cannot be used in environments where such compatibility is required. In some usages, STUN messages are multiplexed on thespecific STUN Security Features bit values selected. When this document makes referencesame transport address as other protocols, such as the Real-Time Transport Protocol (RTP). In order to apply the"nonce cookie"processing described ina section discussing a specificSection 6, STUNSecurity Feature it is understood thatmessages must first be separated from the application packets. Section 5 describes three fixed fields in thecorrespondingSTUNSecurity Feature bitheader that can be used for this purpose. However, in some cases, these three fixed fields may not be sufficient. When the"nonce cookie"FINGERPRINT extension isset to 1. For example,used, an agent includes the FINGERPRINT attribute in messages it sends to another agent. Section9.2.4 discussing14.7 describes thePASSWORD-ALGORITHMS security feature,placement and value of this attribute. When the agent receives what it believes isimplied that the "Password algorithms" bit, as defineda STUN message, then, inSection 18.1, is setaddition to1 inother basic checks, the"nonce cookie". 9.2.2. HMAC Key For long-term credentialsagent also checks thatdo not usethe message contains adifferent algorithm, as specified byFINGERPRINT attribute and that thePASSWORD-ALGORITHM attribute,attribute contains thekey is 16 bytes: key = MD5(username ":" OpaqueString(realm) ":" OpaqueString(password)) Where MD5 is definedcorrect value. Section 6.3 describes when in[RFC1321] and [RFC6151], andtheOpaqueString profile is defined in [RFC8265]. The encoding used is UTF-8 [RFC3629]. The 16-byte keyoverall processing of a STUN message the FINGERPRINT check isformed by takingperformed. This additional check helps theMD5 hashagent detect messages ofthe resultother protocols that might otherwise seem to be STUN messages. 8. DNS Discovery ofconcatenating the following five fields: (1)a Server This section describes an optional procedure for STUN that allows a client to use DNS to determine theusername, with any quotesIP address andtrailing nulls removed, as taken fromport of a server. A STUN Usage must describe if and when this extension is used. To use this procedure, theUSERNAME attribute (in which case OpaqueString has already been applied); (2)client must know asingle colon; (3)STUN URI [RFC7064]; therealm, with any quotes and trailing nulls removed and after processing using OpaqueString; (4)usage must also describe how the client obtains this URI. Hard- coding asingle colon; and (5)STUN URI into software is NOT RECOMMENDED in case thepassword, with any trailing nulls removed and after processing using OpaqueString. For example, ifdomain name is lost or needs to change for legal or other reasons. When a client wishes to locate a STUN server on theusername was 'user',public Internet that accepts Binding request/response transactions, therealm was 'realm', andSTUN URI scheme is "stun". When it wishes to locate a STUN server that accepts Binding request/response transactions over a TLS or DTLS session, thepassword was 'pass', thenURI scheme is "stuns". The syntax of the16-byte HMAC key would be"stun" and "stuns" URIs is defined in Section 3.1 of [RFC7064]. STUN Usages MAY define additional URI schemes. 8.1. STUN URI Scheme Semantics If theresult<host> part ofperforminga "stun" URI contains anMD5 hash onIP address, then this IP address is used directly to contact thestring 'user:realm:pass',server. A "stuns" URI containing an IP address MUST be rejected. A future STUN extension or usage may relax this requirement, provided it demonstrates how to authenticate theresulting hash being 0x8493fbc53ba582fb4c044c456bdc40eb. The structure ofSTUN server and prevent man-in-the-middle attacks. If thekey when used with long-term credentials facilitates deployment in systems that also utilize SIP [RFC3261]. Typically, SIP systems utilizing SIP's digest authentication mechanism doURI does notactually storecontain an IP address, thepassworddomain name contained in thedatabase. Rather, they store a value called H(A1), which<host> part isequalresolved to a transport address using thekey defined above. For example, this mechanism can be used with the authentication extensions definedSRV procedures specified in[RFC5090]. When a PASSWORD-ALGORITHM[RFC2782]. The DNS SRV service name isused,thekey length and algorithm to use are described in Section 18.5.1. 9.2.3. Forming a Request There are two cases when forming a request. Incontent of the <scheme> part. The protocol in thefirst case, thisSRV lookup is thefirst request fromtransport protocol the client will run STUN over: "udp" for UDP and "tcp" for TCP. The procedures of RFC 2782 are followed to determine the server(as identified by hostname, ifto contact. RFC 2782 spells out theDNS proceduresdetails ofSection 8 are used, else IP addresshow a set of SRV records is sorted and then tried. However, RFC 2782 only states that the client should "try to connect to the (protocol, address, service)" without giving any details on what happens in the event of failure. When following these procedures, ifnot). Inthesecond case,STUN transaction times out without receipt of a response, the clientis submitting a subsequentSHOULD retry the requestonceto the next server in the order defined by RFC 2782. Such apreviousretry is only possible for request/responsetransaction has completed successfully. Forming a request as a consequencetransmissions, since indication transactions generate no response or timeout. In addition, instead ofa 401querying either the A or438 error response is covered in Section 9.2.5 and is not consideredthe AAAA resource records for a"subsequent request"domain name, a dual-stack IPv4/IPv6 client MUST query both andthus does not utilizetry therules describedrequests with all the IP addresses received, as specified inSection 9.2.3.2.[RFC8305]. Thedifference between a first requestdefault port for STUN requests is 3478, for both TCP anda subsequent requestUDP. The default port for STUN over TLS and STUN over DTLS requests is 5349. Servers can run STUN over DTLS on the same port as STUN over UDP if the server software supports determining whether thepresence or absence of some attributes, so omitting or including theminitial message is aMUST. 9.2.3.1. First Request IfDTLS or STUN message. Servers can run STUN over TLS on theclient has not completed a successful request/response transaction withsame port as STUN over TCP if theserver, it MUST omitserver software supports determining whether theUSERNAME, USERHASH, MESSAGE-INTEGRITY, MESSAGE-INTEGRITY-SHA256, REALM, NONCE, PASSWORD- ALGORITHMS,initial message is a TLS or STUN message. Administrators of STUN servers SHOULD use these ports in their SRV records for UDP andPASSWORD-ALGORITHM attributes.TCP. Inother words,all cases, thefirst requestport in DNS MUST reflect the one on which the server issent as if there werelistening. If noauthentication or message integrity applied. 9.2.3.2. Subsequent Requests Once a request/response transaction has completed,SRV records are found, the clientwill have been presented a realmperforms both an A andnonce byAAAA record lookup of theserver, and selecteddomain name, as described in [RFC8305]. The result will be ausername and password withlist of IP addresses, each of whichit authenticated. Thecan be simultaneously contacted at the default port using UDP or TCP, independent of the STUN Usage. For usages that require TLS, the clientSHOULD cacheconnects to theusername, password, realm, and nonce for subsequent communications withIP addresses using theserver. Whendefault STUN over TLS port. For usages that require DTLS, the clientsends a subsequent request, it MUST include eitherconnects to theUSERNAME or USERHASH, REALM, NONCE,IP addresses using the default STUN over DTLS port. 9. Authentication and Message-Integrity Mechanisms This section defines two mechanisms for STUN that a client andPASSWORD-ALGORITHM attributes withserver can use to provide authentication and message integrity; thesecached values. It MUST include a MESSAGE-INTEGRITY attribute or a MESSAGE-INTEGRITY- SHA256 attribute, computedtwo mechanisms are known asdescribed in Section 14.5 and Section 14.6 usingthecached password. The choice betweenshort-term credential mechanism and the long-term credential mechanism. These twoattributes dependsmechanisms are optional, and each usage must specify if and when these mechanisms are used. Consequently, both clients and servers will know which mechanism (if any) to follow based on knowledge of which usage applies. For example, a STUN server on theattribute receivedpublic Internet supporting ICE would have no authentication, whereas the STUN server functionality in an agent supporting connectivity checks would utilize short-term credentials. An overview of these two mechanisms is given in Section 2. Each mechanism specifies theresponseadditional processing required to use that mechanism, extending thefirst request. 9.2.4. Receiving a Request After the server has done the basicprocessingofspecified in Section 6. The additional processing occurs in three different places: when forming arequest, it performsmessage, when receiving a message immediately after the basic checkslisted below inhave been performed, and when doing theorder specified.detailed processing of error responses. Note thatit is RECOMMENDEDagents MUST ignore all attributes that follow MESSAGE- INTEGRITY, with theREALM value be the domain nameexception of theproviderMESSAGE-INTEGRITY-SHA256 and FINGERPRINT attributes. Similarly, agents MUST ignore all attributes that follow the MESSAGE-INTEGRITY-SHA256 attribute if the MESSAGE- INTEGRITY attribute is not present, with the exception of the FINGERPRINT attribute. 9.1. Short-Term Credential Mechanism The short-term credential mechanism assumes that, prior to the STUNserver: o Iftransaction, themessage does not containclient and server have used some other protocol to exchange aMESSAGE-INTEGRITY or MESSAGE- INTEGRITY-SHA256 attribute,credential in theserver MUST generate an error response with an error codeform of401 (Unauthenticated). This response MUST includeaREALM value.username and password. This credential is time-limited. Theresponse MUST include a NONCE, selectedtime limit is defined by theserver. The server MUST NOT chooseusage. As an example, in thesame NONCE for two requests unless they haveICE usage [RFC8445], thesame source IP addresstwo endpoints use out- of-band signaling to agree on a username and password, and this username andport. The server MAY support alternatepasswordalgorithms, in which case it can list them in preferential order in a PASSWORD-ALGORITHMS attribute. Ifare applicable for theserver adds a PASSWORD-ALGORITHMS attribute it MUST setduration of theSTUN Security Feature "Password algorithms" bit setmedia session. This credential is used to1. The server MAY support anonymous username,form a message-integrity check inwhich case it MUST set the STUN Security Feature "Username anonymity" bit set to 1. Theeach request and in many responses. There is no challenge and responseSHOULD NOT contain a USERNAME, USERHASH, MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute. Note: Reusing a NONCE for different source IP addresses or ports was not explicitly forbiddenas in[RFC5389]. o Ifthemessage containslong-term mechanism; consequently, replay is limited by virtue of the time-limited nature of the credential. 9.1.1. HMAC Key For short-term credentials, the Hash-Based Message Authentication Code (HMAC) key is defined as follow: key = OpaqueString(password) where the OpaqueString profile is defined in [RFC8265]. The encoding used is UTF-8 [RFC3629]. 9.1.2. Forming aMESSAGE-INTEGRITYRequest or Indication For aMESSAGE- INTEGRITY-SHA256 attribute, but is missing either the USERNAME or USERHASH, REALM,request orNONCE attribute,indication message, theserveragent MUSTgenerate an error response with an error code of 400 (Bad Request). This response SHOULD NOTincludeathe USERNAME,USERHASH, NONCE, or REALM. The response cannot contain aMESSAGE-INTEGRITY-SHA256, and MESSAGE-INTEGRITYor MESSAGE- INTEGRITY-SHA256 attribute, as theattributesrequired to generate them are missing. o If the NONCE attribute starts within the"nonce cookie" withmessage unless theSTUN Security Feature "Password algorithms" bit setagent knows from an external mechanism which message integrity algorithm is supported by both agents. In this case, either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 MUST be included in addition to1,USERNAME. The HMAC for theserver performs these checksMESSAGE- INTEGRITY attribute is computed as described in Section 14.5, and theorder specified: * If the request contains neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM, thenHMAC for therequestMESSAGE-INTEGRITY-SHA256 attributes isprocessedcomputed asthough PASSWORD-ALGORITHM were MD5 (Notedescribed in Section 14.6. Note thatifthePASSWORD- ALGORITHMS attributepassword ispresent but does not contain MD5, this will resultnever included in the request or indication. 9.1.3. Receiving a400 BadRequestin a later step below). * Otherwise, unless (1) PASSWORD-ALGORITHM and PASSWORD- ALGORITHMS are both present, (2) PASSWORD-ALGORITHMS matchesor Indication After thevalue sent inagent has done theresponse that sent this NONCE, and (3) PASSWORD-ALGORITHM matches onebasic processing of a message, theentriesagent performs the checks listed below inPASSWORD- ALGORITHMS,theserver MUST generate an error response with an error code of 400 (Bad Request).order specified: o If theNONCE is no longer valid and at the same time the MESSAGE- INTEGRITYmessage does not contain 1) a MESSAGE-INTEGRITY or a MESSAGE-INTEGRITY-SHA256 attributeis invalid, the server MUST generate an error response with an error code of 401. This response MUST include NONCE, REALM,andPASSWORD-ALGORITHMS attributes and SHOULD NOT include the USERNAME or USERHASH attribute. The NONCE attribute value MUST be valid. The response MAY include2) aMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, using the previous NONCE to calculate it. oUSERNAME attribute: * If theNONCEmessage isno longer valid,a request, the server MUSTgeneratereject the request with an error response. This responsewithMUST use an error code of438 (Stale Nonce). This response MUST include NONCE, REALM, and PASSWORD-ALGORITHMS attributes and SHOULD NOT include400 (Bad Request). * If theUSERNAME, USERHASH attribute. The NONCE attribute valuemessage is an indication, the agent MUSTbe valid. The response MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, usingsilently discard theprevious NONCE to calculate it. Servers can revoke nonces in order to provide additional security. See Section 5.4 of [RFC7616] for guidelines.indication. o If the USERNAME does not contain a username valueofcurrently valid within theUSERNAME or USERHASH attributeserver: * If the message isnot valid,a request, the server MUSTgeneratereject the request with an error response. This responsewithMUST use an error code of 401 (Unauthenticated).This response MUST include a REALM value. The response MUST include a NONCE, selected by* If theserver. The response MUST include a PASSWORD-ALGORITHMS attribute. The response SHOULD NOT contain a USERNAME, USERHASH attribute. The response MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute, usingmessage is an indication, theprevious key to calculate it.agent MUST silently discard the indication. o If the MESSAGE-INTEGRITY-SHA256 attribute ispresentpresent, compute the value for the message integrity as described in Section 14.6, using the password associated with the username.Else, usingIf the MESSAGE- INTEGRITY-SHA256 attribute is not present, then use the samepassword,password to compute the value for the message integrity as described in Section 14.5. If the resulting value does not match the contents of theMESSAGE-INTEGRITYcorresponding attribute (MESSAGE-INTEGRITY- SHA256 or MESSAGE-INTEGRITY): * If theMESSAGE- INTEGRITY-SHA256 attribute,message is a request, the server MUST reject the request with an error response. This response MUST use an error code of 401 (Unauthenticated).It* If the message is an indication, the agent MUST silently discard the indication. If these checks pass, the agent continues to process the request or indication. Any response generated by a server to a request that contains a MESSAGE-INTEGRITY-SHA256 attribute MUST includeREALM and NONCEthe MESSAGE-INTEGRITY-SHA256 attribute, computed using the password utilized to authenticate the request. Any response generated by a server to a request that contains only a MESSAGE-INTEGRITY attribute MUST include the MESSAGE-INTEGRITY attribute, computed using the password utilized to authenticate the request. This means that only one of these attributesand SHOULDcan appear in a response. The response MUST NOT contain the USERNAME attribute. If any of the checks fail, a server MUST NOT include a MESSAGE- INTEGRITY-SHA256, MESSAGE-INTEGRITY, or USERNAME attribute in the error response. This is because, in these failure cases, the server cannot determine the shared secret necessary to compute the MESSAGE- INTEGRITY-SHA256 or MESSAGE-INTEGRITY attributes. 9.1.4. Receiving a Response The client looks for the MESSAGE-INTEGRITY or the MESSAGE-INTEGRITY- SHA256 attribute in the response. If present and if the client only sent one of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attributes in the request (because of the external indication in Section 9.1.2 or because this is a subsequent request as defined in Section 9.1.5), the algorithm in the response has to match; otherwise, the response MUST be discarded. The client then computes the message integrity over theUSERNAME, USERHASH, MESSAGE-INTEGRITY,response as defined in Section 14.5 for the MESSAGE-INTEGRITY attribute or Section 14.6 for the MESSAGE-INTEGRITY-SHA256attribute. If these checks pass,attribute, using theserver continues to processsame password it utilized for the request.Any response generated byIf theserver MUST includeresulting value matches the contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute,computed usingrespectively, theusernameresponse is considered authenticated. If the value does not match, or if both MESSAGE- INTEGRITY andpassword utilized to authenticateMESSAGE-INTEGRITY-SHA256 are absent, therequest, unlessprocessing depends on whether the request wasprocessed as though PASSWORD-ALGORITHM was MD5 (becausesent over a reliable or an unreliable transport. If the requestcontained neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM). In that casewas sent over an unreliable transport, theMESSAGE-INTEGRITY attributeresponse MUST beuseddiscarded, as if it had never been received. This means that retransmits, if applicable, will continue. If all the responses received are discarded, then instead ofthe MESSAGE- INTEGRITY-SHA256 attribute. The REALM, NONCE, USERNAME and USERHASH attributes SHOULD NOT be included. 9.2.5. Receivingsignaling aResponse Iftimeout after ending theresponse is an error response with an error code of 401 (Unauthenticated) or 438 (Stale Nonce),transaction, theclientlayer MUSTtest if the NONCE attribute value starts withsignal that the"nonce cookie".integrity protection was violated. If thetest succeedsrequest was sent over a reliable transport, the response MUST be discarded, and the"nonce cookie" haslayer MUST immediately end theSTUN Security Feature "Password algorithms" bit set to 1 but no PASSWORD-ALGORITHMS attribute is present, thentransaction and signal that the integrity protection was violated. 9.1.5. Sending Subsequent Requests A client sending subsequent requests to the same server MUSTNOT retrysend only therequest with a new transaction. IfMESSAGE-INTEGRITY-SHA256 or the MESSAGE-INTEGRITY attribute that matches the attribute that was received in the responseis an error response with an error code of 401 (Unauthenticated),to theclient SHOULD retryinitial request. Here, "same server" means same IP address and port number, not just therequest with a new transaction. This request MUST contain a USERNAMEsame URI or SRV lookup result. 9.2. Long-Term Credential Mechanism The long-term credential mechanism relies on aUSERHASH, determined by the client aslong-term credential, in theappropriateform of a username and password that are shared between client and server. The credential is considered long-term since it is assumed that it is provisioned for a user and remains in effect until theREALM from the error response. Ifuser is no longer a subscriber of the"nonce cookie" was presentsystem or until it is changed. This is basically a traditional "log-in" username andhad the STUN Security Feature "Username anonymity" bit setpassword given to users. Because these usernames and passwords are expected to1 then the USERHASH attribute MUSTbeused, elsevalid for extended periods of time, replay prevention is provided in theUSERNAME attribute MUST be used.form of a digest challenge. In this mechanism, the client initially sends a request, without offering any credentials or any integrity checks. Therequest MUST containserver rejects this request, providing theREALM, copied fromuser a realm (used to guide theerror response.user or agent in selection of a username and password) and a nonce. Therequest MUST containnonce provides a limited replay protection. It is a cookie, selected by theNONCE, copiedserver and encoded in such a way as to indicate a duration of validity or client identity from which it is valid. Only theerror response. If the response contains a PASSWORD-ALGORITHMS attribute,server needs to know about therequest MUST containinternal structure of thePASSWORD-ALGORITHMS attribute withcookie. The client retries thesame content. Ifrequest, this time including its username and theresponse contains a PASSWORD-ALGORITHMS attribute,realm andthis attribute contains at least one algorithm that is supportedechoing the nonce provided by the server. The clientthenalso includes one of therequest MUST contain a PASSWORD- ALGORITHM attribute withmessage-integrity attributes defined in this document, which provides an HMAC over thefirst algorithm supported onentire request, including thelist. Ifnonce. The server validates theresponse contains a PASSWORD-ALGORITHMS attribute,nonce andthis attribute does not contain any algorithm that is supported by the client, thenchecks theclient MUST NOT retrymessage integrity. If they match, the requestwith a new transaction. The client MUST NOT perform this retry ifis authenticated. If the nonce is no longer valid, it isnot changingconsidered "stale", and theUSERNAME or USERHASH or REALM or its associated password, fromserver rejects theprevious attempt. Ifrequest, providing a new nonce. In subsequent requests to theresponse is an error response with an error code of 438 (Stale Nonce),same server, the clientMUST retryreuses therequest, usingnonce, username, realm, and password it used previously. In this way, subsequent requests are not rejected until thenew NONCE attribute suppliednonce becomes invalid by the server, in which case the rejection provides a new nonce to the438 (Stale Nonce) response. This retry MUST also include eitherclient. Note that theUSERNAME or USERHASH, REALM andlong-term credential mechanism cannot be used to protect indications, since indications cannot be challenged. Usages utilizing indications must eitherthe MESSAGE-INTEGRITYuse a short-term credential orMESSAGE-INTEGRITY-SHA256 attributes. For all other responses, ifomit authentication and message integrity for them. To indicate that it supports this specification, a server MUST prepend the NONCE attributestartsvalue with the"nonce cookie"character string composed of "obMatJos2" concatenated with the (4-character) base64 [RFC4648] encoding of the 24-bit STUN Security Features as defined in Section 18.1. The 24-bit Security Feature"Password algorithms" bitsetto 1 but PASSWORD-ALGORITHMS is not present, the response MUST be ignored. If the responseisan error responseencoded as 3 bytes, withan error code of 400, and does not contains either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute then the response MUST be discarded,bit 0 asif it was never received. This means that retransmits, if applicable, will continue. Note: In that case the 400 will never reach the application, resulting in a timeout. The client looks for the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute in the response (either success or failure). If present, the client computesthemessage integrity overmost significant bit of theresponsefirst byte and bit 23 asdefined in Section 14.5 or Section 14.6, usingthesame password it utilized forleast significant bit of therequest.third byte. If no security features are used, then a byte array with all 24 bits set to zero MUST be encoded instead. For theresulting value matchesremainder of this document, the term "nonce cookie" will refer to thecontents ofcomplete 13-character string prepended to theMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute,NONCE attribute value. Since theresponselong-term credential mechanism isconsidered authenticated. Ifsusceptible to offline dictionary attacks, deployments SHOULD utilize passwords that are difficult to guess. In cases where thevalue doescredentials are notmatch, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- SHA256 were absent,entered by theprocessing dependsuser, but are rather placed onthe request been sent overareliable or an unreliable transport. Ifclient device during device provisioning, therequest was sent over an unreliable transport,password SHOULD have at least 128 bits of randomness. In cases where theresponse MUST be discarded, as if it was never received.credentials are entered by the user, they should follow best current practices around password structure. 9.2.1. Bid-Down Attack Prevention Thismeansdocument introduces two new security features thatretransmits, if applicable, will continue. If allprovide theresponses receivedability to choose the algorithm used for password protection as well as the ability to use an anonymous username. Both of these capabilities arediscarded then insteadoptional in order to remain backwards compatible with previous versions ofsignaling a timeout after endingthetransaction the layer MUST signal thatSTUN protocol. These new capabilities are subject to bid-down attacks whereby an attacker in theintegrity protection was violated. Ifmessage path can remove these capabilities and force weaker security properties. To prevent these kinds of attacks from going undetected, therequest was sent over a reliable transport,nonce is enhanced with additional information. The value of theresponse MUST be discarded and"nonce cookie" will vary based on thelayer MUST immediately endspecific STUN Security Feature bits selected. When this document makes reference to thetransaction and signal"nonce cookie" in a section discussing a specific STUN Security Feature it is understood that theintegrity protection was violated. Ifcorresponding STUN Security Feature bit in the "nonce cookie" is set to 1. For example, when theresponse contains aPASSWORD-ALGORITHMSattribute, allsecurity feature (defined in Section 9.2.4) is used, thesubsequent requests MUST be authenticated using MESSAGE-INTEGRITY- SHA256 only. 10. ALTERNATE-SERVER Mechanism This section describes a mechanismcorresponding "Password algorithms" bit (defined inSTUN that allows a serverSection 18.1) is set toredirect1 in the "nonce cookie". 9.2.2. HMAC Key For long-term credentials that do not use aclient to another server. This extensiondifferent algorithm, as specified by the PASSWORD-ALGORITHM attribute, the key isoptional,16 bytes: key = MD5(username ":" OpaqueString(realm) ":" OpaqueString(password)) Where MD5 is defined in [RFC1321] anda usage must define if[RFC6151], andwhen this extensionthe OpaqueString profile isused.defined in [RFC8265]. TheALTERNATE-SERVER attribute carries an IP address. A server using this extension redirects a client to another serverencoding used is UTF-8 [RFC3629]. The 16-byte key is formed byreplying to a request message with an error response message with an error codetaking the MD5 hash of300 (Try Alternate). The server MUST include at least one ALTERNATE-SERVER attribute intheerror response, which MUST contain an IP addressresult of concatenating thesame familyfollowing five fields: (1) the username, with any quotes and trailing nulls removed, as taken from the USERNAME attribute (in which case OpaqueString has already been applied); (2) a single colon; (3) thesource IP address ofrealm, with any quotes and trailing nulls removed and after processing using OpaqueString; (4) a single colon; and (5) therequest message. The server SHOULD include an additional ALTERNATE-SERVER attribute,password, with any trailing nulls removed and after processing using OpaqueString. For example, if themandatory one, that contains an IP address ofusername is 'user', theother family thanrealm is 'realm', and thesource IP addresspassword is 'pass', then the 16-byte HMAC key would be the result of performing an MD5 hash on therequest message.string 'user:realm:pass', the resulting hash being 0x8493fbc53ba582fb4c044c456bdc40eb. Theerror response message MAY be authenticated; however, there are use cases for ALTERNATE-SERVER where authenticationstructure of theresponse iskey when used with long-term credentials facilitates deployment in systems that also utilize SIP [RFC3261]. Typically, SIP systems utilizing SIP's digest authentication mechanism do notpossible or practical. Ifactually store thetransaction uses TLS or DTLS and ifpassword in thetransactiondatabase. Rather, they store a value called "H(A1)", which isauthenticated byequal to the key defined above. For example, this mechanism can be used with the authentication extensions defined in [RFC5090]. When aMESSAGE-INTEGRITY-SHA256 attribute and ifPASSWORD-ALGORITHM is used, theserver wants to redirectkey length and algorithm to use are described in Section 18.5.1. 9.2.3. Forming aserver that uses a different certificate, then it MUST include an ALTERNATE-DOMAIN attribute containing the name inside the subjectAltName of that certificate. This series of conditions onRequest The first request from theMESSAGE-INTEGRITY-SHA256 attribute indicates thatclient to thetransaction is authenticated and thatserver (as identified by hostname if theclient implements this specificationDNS procedures of Section 8 are used andtherefore can processby IP address if not) is handled according to the rules in Section 9.2.3.1. When theALTERNATE-DOMAIN attribute. Aclientusing this extension handlesinitiates a300 (Try Alternate) error codesubsequent request once a previous request/response transaction has completed successfully, it follows the rules in Section Section 9.2.3.2. Forming a request asfollows. The client looks for an ALTERNATE-SERVER attributea consequence of a 401 (Unauthenticated) or 438 (Stale Nonce) error response is covered in Section 9.2.5 and is not considered a "subsequent request" and thus does not utilize theerror response.rules described in Section 9.2.3.2. Each of these types of requests have a different mandatory attributes. 9.2.3.1. First Request Ifone is found, thenthe clientconsiders the currenthas not completed a successful request/response transactionas failed, and reattempts the requestwith theserver specified in the attribute, usingserver, it MUST omit thesame transport protocol used forUSERNAME, USERHASH, MESSAGE-INTEGRITY, MESSAGE-INTEGRITY-SHA256, REALM, NONCE, PASSWORD- ALGORITHMS, and PASSWORD-ALGORITHM attributes. In other words, theprevious request. That request,first request is sent as ifauthenticated, MUST utilize the same credentials thatthere were no authentication or message integrity applied. 9.2.3.2. Subsequent Requests Once a request/response transaction has completed, the clientwouldwill haveused in the request tobeen presented a realm and nonce by the serverthat performed the redirection. If the transport protocol uses TLS or DTLS, then theand selected a username and password with which it authenticated. The clientlooks for an ALTERNATE-DOMAIN attribute. If the attribute is found,SHOULD cache thedomain MUST be used to validateusername, password, realm, and nonce for subsequent communications with thecertificate usingserver. When therecommendations in [RFC6125]. The certificateclient sends a subsequent request, it MUSTcontain an identifier of type DNS-IDinclude either the USERNAME orCN-ID, eventuallyUSERHASH, REALM, NONCE, and PASSWORD-ALGORITHM attributes withwildcards, but not of type SRV-ID or URI-ID. If thethese cached values. It MUST include a MESSAGE-INTEGRITY attributeis not found,or a MESSAGE-INTEGRITY- SHA256 attribute, computed as described in Sections 14.5 and 14.6 using thesame domain that was used forcached password. The choice between theoriginal request MUST be used to validatetwo attributes depends on thecertificate. Ifattribute received in theclient has been redirectedresponse to the first request. 9.2.4. Receiving a Request After the serverto which ithasalready sent this request withindone thelast five minutes,basic processing of a request, itMUST ignore the redirection and considerperforms thetransaction to have failed. This prevents infinite ping-ponging between serverschecks listed below incase of redirection loops. 11. Backwards Compatibility with RFC 3489 In addition tothebackward compatibility already described in Section 12 of [RFC5389], DTLS MUST NOTorder specified. Note that it is RECOMMENDED that the REALM value beused with [RFC3489] (also referred to as "classic STUN"). Any STUN request or indication withoutthemagic cookie (see Section 6domain name of[RFC5389]) over DTLS MUST be considered invalid: all requests MUST generate a "500 Server Error" error response and indications MUST be ignored. 12. Basic Server Behavior This section definesthebehaviorprovider ofa basic, stand-alone STUN server. Historically, "classicthe STUN[RFC3489]" only definedserver: o If thebehavior ofmessage does not contain a MESSAGE-INTEGRITY or MESSAGE- INTEGRITY-SHA256 attribute, the serverthat was providing clientsMUST generate an error response withserver reflexive transport addressesan error code of 401 (Unauthenticated). This response MUST include a REALM value. The response MUST include a NONCE, selected byreceiving and replying to STUN Binding requests. [RFC5389] redefinedtheprotocol as an extensible frameworkserver. The server MUST NOT choose the same NONCE for two requests unless they have the same source IP address and port. The server MAY support alternate password algorithms, in which case it can list them in preferential order in a PASSWORD-ALGORITHMS attribute. If the serverfunctionality becameadds a PASSWORD-ALGORITHMS attribute, it MUST set thesole STUN Usage defined in that document. This STUN Usage is also known as BasicSTUNServer.Security Feature "Password algorithms" bit to 1. TheSTUNserverMUSTMAY support anonymous username, in which case it MUST set theBinding method. ItSTUN Security Feature "Username anonymity" bit set to 1. The response SHOULD NOTutilizecontain a USERNAME, USERHASH, MESSAGE-INTEGRITY, or MESSAGE- INTEGRITY-SHA256 attribute. Note: Reusing a NONCE for different source IP addresses or ports was not explicitly forbidden in [RFC5389]. o If theshort-termmessage contains a MESSAGE-INTEGRITY orlong-term credential mechanism. Thisa MESSAGE- INTEGRITY-SHA256 attribute, but isbecausemissing either the USERNAME or USERHASH, REALM, or NONCE attribute, the server MUST generate an error response with an error code of 400 (Bad Request). This response SHOULD NOT include a USERNAME, USERHASH, NONCE, or REALM attribute. The response cannot contain a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, as the attributes required to generate them are missing. o If the NONCE attribute starts with the "nonce cookie" with thework involvedSTUN Security Feature "Password algorithms" bit set to 1, the server performs these checks inauthenticatingthe order specified: * If the requestis more thancontains neither thework in simply processing it. It SHOULD NOT utilizePASSWORD-ALGORITHMS nor theALTERNATE-SERVER mechanism forPASSWORD-ALGORITHM algorithm, then thesame reason. It MUST support UDP and TCP. It MAY support STUN over TCP/TLS or STUN over UDP/DTLS; however, DTLSrequest is processed as though PASSWORD-ALGORITHM were MD5. * Otherwise, unless (1) PASSWORD-ALGORITHM andTLS provide minimal security benefitsPASSWORD- ALGORITHMS are both present, (2) PASSWORD-ALGORITHMS matches the value sent in the response that sent thisbasic modeNONCE, and (3) PASSWORD-ALGORITHM matches one ofoperation. It does not require a keep-alive mechanism because a TCP or TLS-over-TCP connection is closed aftertheendentries in PASSWORD- ALGORITHMS, the server MUST generate an error response with an error code of 400 (Bad Request). o If theBinding transaction. It MAY utilizevalue of theFINGERPRINT mechanism but MUST NOT require it. SinceUSERNAME or USERHASH attribute is not valid, thestand-aloneserveronly runs STUN, FINGERPRINT provides no benefit. Requiring it would break compatibilityMUST generate an error response withRFC 3489, and such compatibility is desirable inan error code of 401 (Unauthenticated). This response MUST include astand-aloneREALM value. The response MUST include a NONCE, selected by the server.Stand-alone STUN serversThe response MUST include a PASSWORD-ALGORITHMS attribute. The response SHOULDsupport backwards compatibility with [RFC3489] clients,NOT contain a USERNAME or USERHASH attribute. The response MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute, using the previous key to calculate it. o If the MESSAGE-INTEGRITY-SHA256 attribute is present, compute the value for the message integrity as described in Section11. It is RECOMMENDED that administrators of STUN servers provide DNS entries14.6, using the password associated with the username. Otherwise, using the same password, compute the value forthose serversthe MESSAGE-INTEGRITY attribute as described in Section8.14.5. Ifboth A and AAAA Resource Records are returned thentheclient can simultaneously send STUN Binding requests toresulting value does not match theIPv4 and IPv6 addresses (as specified in [RFC8305]), ascontents of the MESSAGE-INTEGRITY attribute or the MESSAGE-INTEGRITY-SHA256 attribute, the server MUST reject theBindingrequestis idempotent. Note thatwith an error response. This response MUST use an error code of 401 (Unauthenticated). It MUST include theMAPPED-ADDRESS or XOR-MAPPED-ADDRESSREALM and NONCE attributesthat are returned will not necessarily matchand SHOULD NOT include theaddress family ofUSERNAME, USERHASH, MESSAGE-INTEGRITY, or MESSAGE-INTEGRITY-SHA256 attribute. o If theserver address used. A basic STUN serverNONCE isnot a solution for NAT traversal by itself. However, it can be utilized as partno longer valid, the server MUST generate an error response with an error code ofa solution through STUN usages.438 (Stale Nonce). Thisis discussed furtherresponse MUST include NONCE, REALM, and PASSWORD-ALGORITHMS attributes and SHOULD NOT include the USERNAME and USERHASH attributes. The NONCE attribute value MUST be valid. The response MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, using the previous NONCE to calculate it. Servers can revoke nonces in order to provide additional security. See Section13. 13. STUN Usages STUN5.4 of [RFC7616] for guidelines. If these checks pass, the server continues to process the request. Any response generated byitself is not a solutionthe server MUST include the MESSAGE- INTEGRITY-SHA256 attribute, computed using the username and password utilized to authenticate theNAT traversal problem. Rather, STUN defines a toolrequest, unless the request was processed as though PASSWORD-ALGORITHM was MD5 (because the request contained neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM). In thatcancase, the MESSAGE-INTEGRITY attribute MUST be usedinside a larger solution. The term "STUN usage" is used for any solution that uses STUN as a component. A STUN usage defines how STUN is actually utilized -- when to send requests, what to do withinstead of theresponses,MESSAGE-INTEGRITY-SHA256 attribute, andwhich optional procedures defined here (or in an extension to STUN) are tothe REALM, NONCE, USERNAME, and USERHASH attributes SHOULD NOT beused. A usage also defines: o Which STUN methods are used. o What transports are used.included. 9.2.5. Receiving a Response IfDTLS-over-UDP is used then implementingthedenial-of-service countermeasure described in Section 4.2.1 of [RFC6347]response ismandatory. o What authenticationan error response with an error code of 401 (Unauthenticated) or 438 (Stale Nonce), the client MUST test if the NONCE attribute value starts with the "nonce cookie". If so andmessage-integrity mechanisms are used. o The considerations around manual vs. automatic key derivation fortheintegrity mechanism, as discussed in [RFC4107]. o What mechanisms are used to distinguish STUN messages from other messages. When"nonce cookie" has the STUN Security Feature "Password algorithms" bit set to 1 but no PASSWORD-ALGORITHMS attribute isrun over TCP or TLS-over-TCP, a framing mechanism may be required. o How a STUNpresent, then the clientdeterminesMUST NOT retry theIP address and port ofrequest with a new transaction. If theSTUN server. o How simultaneous useresponse is an error response with an error code ofIPv4 and IPv6 addresses (Happy Eyeballs [RFC8305]) works401 (Unauthenticated), the client SHOULD retry the request withnon-idempotent transactions when both address families are found fora new transaction. This request MUST contain a USERNAME or a USERHASH, determined by theSTUN server. o Whether backwards compatibility to RFC 3489 is required. o What optional attributes defined here (suchclient asFINGERPRINT and ALTERNATE-SERVER) or in other extensions are required. othe appropriate username for the REALM from the error response. IfMESSAGE-INTEGRITY-SHA256 truncationthe "nonce cookie" ispermitted,present and has thelimits permitted for truncation. o The keep-alive mechanism ifSTUNis run over TCP or TLS-over-TCP. o If Anycast addresses canSecurity Feature "Username anonymity" bit set to 1, then the USERHASH attribute MUST beused forused; else, theserver in case TCP or TLS-over-TCP, or authentication areUSERNAME attribute MUST be used.In addition, any STUN usage must considerThe request MUST contain thesecurity implications of using STUN in that usage. A number of attacks against STUN are known (seeREALM, copied from theSecurity Considerations section in this document), and any usage must consider how these attacks can be thwarted or mitigated. Finally, a usage must consider whether its usage of STUN is an example oferror response. The request MUST contain theUnilateral Self-Address Fixing approach to NAT traversal, and if so, addressNONCE, copied from the error response. If the response contains a PASSWORD-ALGORITHMS attribute, thequestions raised in RFC 3424 [RFC3424]. 14. STUN Attributes Afterrequest MUST contain theSTUN header are zero or more attributes. EachPASSWORD-ALGORITHMS attributeMUST be TLV encoded,with the same content. If the response contains a16-bit type, 16-bit length,PASSWORD-ALGORITHMS attribute, andvalue. Each STUN attribute MUST end on a 32-bit boundary. As mentioned above, all fields in anthis attributeare transmitted most significant bit first. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Value (variable) .... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 4: Format of STUN Attributes The value incontains at least one algorithm that is supported by thelength fieldclient, then the request MUST contain a PASSWORD- ALGORITHM attribute with thelength offirst algorithm supported on theValue part oflist. If the response contains a PASSWORD-ALGORITHMS attribute,prior to padding, measured in bytes. Since STUN aligns attributes on 32-bit boundaries, attributes whose content isand this attribute does nota multiple of 4 bytes are padded with 1, 2, or 3 bytes of padding socontain any algorithm thatits value containsis supported by the client, then the client MUST NOT retry the request with amultiple of 4 bytes.new transaction. Thepadding bitsclient MUSTbe set to zero on sending andNOT perform this retry if it is not changing the USERNAME, USERHASH, REALM, or its associated password from the previous attempt. If the response is an error response with an error code of 438 (Stale Nonce), the client MUSTbe ignored byretry thereceiver. Anyrequest, using the new NONCE attributetype MAY appear more than oncesupplied ina STUN message. Unless specified otherwise,theorder of appearance is significant: only438 (Stale Nonce) response. This retry MUST also include either thefirst occurrence needs to be processed by a receiver,USERNAME or USERHASH, the REALM, andany duplicates MAY be ignored by a receiver. To allow future revisions of this specification to add new attributeseither the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute. For all other responses, ifneeded,the NONCE attributespace is divided into two ranges. Attributesstarts with the "nonce cookie" withtype values between 0x0000 and 0x7FFF are comprehension-required attributes, which means thatthe STUNagent cannot successfully processSecurity Feature "Password algorithms" bit set to 1 but PASSWORD-ALGORITHMS is not present, themessage unless it understandsresponse MUST be ignored. If theattribute. Attributesresponse is an error response withtype values between 0x8000an error code of 400 (Bad Request) and0xFFFF are comprehension-optional attributes, which means that those attributes can be ignored bydoes not contain either theSTUN agentMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, then the response MUST be discarded, as if itdoes not understand them. The set of STUN attribute types is maintained by IANA. The initial set defined bywere never received. This means that retransmits, if applicable, will continue. Note: In thisspecification is foundcase, the 400 response will never reach the application, resulting inSection 18.3.a timeout. Therest of this section describesclient looks for the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- SHA256 attribute in theformat ofresponse (either success or failure). If present, thevarious attributesclient computes the message integrity over the response as defined inthis specification. 14.1. MAPPED-ADDRESS The MAPPED-ADDRESS attribute indicates a reflexive transport address ofSections 14.5 or 14.6, using theclient. It consists of an 8-bit address family and a 16-bit port, followed by a fixed-length value representingsame password it utilized for theIP address.request. If theaddress familyresulting value matches the contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, the response isIPv4,considered authenticated. If theaddress MUST be 32 bits.value does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- SHA256 are absent, the processing depends on the request being sent over a reliable or an unreliable transport. If theaddress family is IPv6,request was sent over an unreliable transport, theaddressresponse MUST be128 bits. All fields must be in network byte order. The format of the MAPPED-ADDRESS attribute is: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0 0 0 0 0 0 0| Family | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Address (32 bits or 128 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 5: Format of MAPPED-ADDRESS Attribute The address family can take ondiscarded, as if it had never been received. This means that retransmits, if applicable, will continue. If all thefollowing values: 0x01:IPv4 0x02:IPv6 The first 8 bitsresponses received are discarded, then instead of signaling a timeout after ending theMAPPED-ADDRESStransaction, the layer MUST signal that the integrity protection was violated. If the request was sent over a reliable transport, the response MUST beset to 0discarded, and the layer MUST immediately end the transaction and signal that the integrity protection was violated. If the response contains a PASSWORD-ALGORITHMS attribute, all the subsequent requests MUST beignored by receivers. These bits are present for aligning parameters on natural 32-bit boundaries.authenticated using MESSAGE-INTEGRITY- SHA256 only. 10. ALTERNATE-SERVER Mechanism Thisattributesection describes a mechanism in STUN that allows a server to redirect a client to another server. This extension isused onlyoptional, and a usage must define if and when this extension is used. The ALTERNATE-SERVER attribute carries an IP address. A server using this extension redirects a client to another server byservers for achieving backwards compatibilityreplying to a request message with[RFC3489] clients. 14.2. XOR-MAPPED-ADDRESSan error response message with an error code of 300 (Try Alternate). TheXOR-MAPPED-ADDRESSserver MUST include at least one ALTERNATE-SERVER attributeis identical to the MAPPED-ADDRESS attribute, except thatin thereflexive transporterror response, which MUST contain an IP addressis obfuscated through the XOR function. The formatof theXOR-MAPPED-ADDRESS is: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0 0 0 0 0 0 0| Family | X-Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | X-Address (Variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 6: Formatsame address family as the source IP address ofXOR-MAPPED-ADDRESS Attributethe request message. TheFamily representsserver SHOULD include an additional ALTERNATE-SERVER attribute, after the mandatory one, that contains an IP addressfamily, and is encoded identically toof theFamily in MAPPED-ADDRESS. X-Port is computed by XOR'ingaddress family other than themapped port withsource IP address of themost significant 16 bitsrequest message. The error response message MAY be authenticated; however, there are use cases for ALTERNATE-SERVER where authentication of themagic cookie.response is not possible or practical. If theIP address family is IPv4, X-Addresstransaction uses TLS or DTLS, if the transaction iscomputedauthenticated byXOR'inga MESSAGE-INTEGRITY-SHA256 attribute, and if themapped IP address withserver wants to redirect to a server that uses a different certificate, then it MUST include an ALTERNATE-DOMAIN attribute containing themagic cookie. Ifname inside theIP address familysubjectAltName of that certificate. This series of conditions on the MESSAGE-INTEGRITY-SHA256 attribute indicates that the transaction isIPv6, X-Addressauthenticated and that the client implements this specification and therefore can process the ALTERNATE-DOMAIN attribute. A client using this extension handles a 300 (Try Alternate) error code as follows. The client looks for an ALTERNATE-SERVER attribute in the error response. If one iscomputed by XOR'ingfound, then themapped IP addressclient considers the current transaction as failed and reattempts the request with theconcatenation ofserver specified in the attribute, using the same transport protocol used for the previous request. That request, if authenticated, MUST utilize the same credentials that the client would have used in the request to the server that performed the redirection. If themagic cookie andtransport protocol uses TLS or DTLS, then the96-bit transaction ID. In all cases,client looks for an ALTERNATE-DOMAIN attribute. If theXOR operation works on its inputs in network byte order (that is,attribute is found, theorder they willdomain MUST beencoded inused to validate themessage). The rules for encoding and processingcertificate using thefirst 8 bitsrecommendations in [RFC6125]. The certificate MUST contain an identifier ofthe attribute's value, the rules for handling multiple occurrencestype DNS-ID or CN-ID (eventually with wildcards) but not of type SRV-ID or URI- ID. If theattribute, and the rules for processing address families areattribute is not found, the sameasdomain that was used forMAPPED-ADDRESS. Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only in their encoding ofthetransport address. The former encodesoriginal request MUST be used to validate thetransport address by exclusive-or'ingcertificate. If the client has been redirected to a server to which itwithhas already sent this request within themagic cookie. The latter encodeslast five minutes, itdirectlyMUST ignore the redirection and consider the transaction to have failed. This prevents infinite ping-ponging between servers inbinary.case of redirection loops. 11. Backwards Compatibility with RFC 3489originally specifiedIn addition to the backward compatibility already described in Section 12 of [RFC5389], DTLS MUST NOT be used with [RFC3489] (referred to as "classic STUN"). Any STUN request or indication without the magic cookie (see Section 6 of [RFC5389]) over DTLS MUST be considered invalid: all requests MUST generate a 500 (Server Error) error response, and indications MUST be ignored. 12. Basic Server Behavior This section defines the behavior of a basic, stand-alone STUN server. Historically, "classic STUN" [RFC3489] onlyMAPPED-ADDRESS. However, deployment experience found that some NATs rewritedefined the32-bit binary payloads containingbehavior of a server that was providing clients with server reflexive transport addresses by receiving and replying to STUN Binding requests. [RFC5389] redefined theNAT's public IP address, suchprotocol asSTUN's MAPPED-ADDRESS attribute, inan extensible framework, and thewell-meaning but misguided attempt at providing a generic Application Layer Gateway (ALG) function. Such behavior interferes withserver functionality became theoperation ofsole STUNandUsage defined in that document. This STUN Usage is alsocauses failure of STUN's message-integrity checking. 14.3. USERNAMEknown as "Basic STUN Server". TheUSERNAME attribute is used for message integrity.STUN server MUST support the Binding method. ItidentifiesSHOULD NOT utilize theusername and password combination usedshort-term or long-term credential mechanism. This is because the work involved in authenticating themessage-integrity check. The value of USERNAMErequest isa variable-length value containingmore than theauthentication username.work in simply processing it. ItMUST contain a UTF-8 [RFC3629] encoded sequence of less than 509 bytes, and MUST have been processed usingSHOULD NOT utilize theUsernameCasePreserved profile [RFC8265]. A compliant implementation MUST be able to parse UTF-8 encoded sequence of 763 or less bytes, to be compatible with [RFC5389] that mistakenly assumed up to 6 bytes per characters encoded. 14.4. USERHASH The USERHASH attribute is used as a replacementALTERNATE-SERVER mechanism for theUSERNAME attribute when username anonymity is supported. The valuesame reason. It MUST support UDP and TCP. It MAY support STUN over TCP/TLS or STUN over UDP/DTLS; however, DTLS and TLS provide minimal security benefits in this basic mode ofUSERHASH hasoperation. It does not require afixed lengthkeep-alive mechanism because a TCP or TLS-over-TCP connection is closed after the end of32 bytes. The username MUST have been processed usingtheUsernameCasePreserved profile [RFC8265] andBinding transaction. It MAY utilize therealmFINGERPRINT mechanism but MUSThave been processed usingNOT require it. Since theOpaqueString profile [RFC8265] before hashing. The followingstand-alone server only runs STUN, FINGERPRINT provides no benefit. Requiring it would break compatibility with RFC 3489, and such compatibility isthe operationdesirable in a stand-alone server. Stand-alone STUN servers SHOULD support backwards compatibility with clients using [RFC3489], as described in Section 11. It is RECOMMENDED that administrators of STUN servers provide DNS entries for those servers as described in Section 8. If both A and AAAA resource records are returned, then the clientwill performcan simultaneously send STUN Binding requests tohashtheusername: userhash = SHA-256(UsernameCasePreserved(username) ":" OpaqueString(realm)) 14.5. MESSAGE-INTEGRITY The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104]IPv4 and IPv6 addresses (as specified in [RFC8305]), as the Binding request is idempotent. Note that the MAPPED-ADDRESS or XOR-MAPPED-ADDRESS attributes that are returned will not necessarily match the address family of the server address used. A basic STUNmessage. The MESSAGE-INTEGRITY attributeserver is not a solution for NAT traversal by itself. However, it can bepresentutilized as part of a solution through STUN Usages. This is discussed further inanySection 13. 13. STUNmessage type. Since it uses the SHA-1 hash,Usages STUN by itself is not a solution to theHMAC willNAT traversal problem. Rather, STUN defines a tool that can be20 bytes.used inside a larger solution. Thekeyterm "STUN Usage" is used for any solution that uses STUN as a component. A STUN Usage defines how STUN is actually utilized -- when to send requests, what to do with theHMAC depends onresponses, and whichcredential mechanismoptional procedures defined here (or in an extension to STUN) are to be used. A usage also defines: o Which STUN methods are used. o What transports are used. If DTLS-over-UDP is used, then implementing the denial-of-service countermeasure described inuse.Section9.1.1 defines the key for the short-term credential mechanism4.2.1 of [RFC6347] is mandatory. o What authentication andSection 9.2.2 defines the key for the long-term credential mechanism. Other credentialmessage-integrity mechanismsMUST define theare used. o The considerations around manual vs. automatic keythat is usedderivation for theHMAC. The text usedintegrity mechanism, asinputdiscussed in [RFC4107]. o What mechanisms are used toHMACdistinguish STUN messages from other messages. When STUN istherun over TCP or TLS-over-TCP, a framing mechanism may be required. o How a STUNmessage, up to and includingclient determines theattribute precedingIP address and port of theMESSAGE-INTEGRITY attribute. The length fieldSTUN server. o How simultaneous use of IPv4 and IPv6 addresses (Happy Eyeballs [RFC8305]) works with non-idempotent transactions when both address families are found for the STUNmessage header is adjusted to pointserver. o Whether backwards compatibility to RFC 3489 is required. o What optional attributes defined here (such as FINGERPRINT and ALTERNATE-SERVER) or in other extensions are required. o If MESSAGE-INTEGRITY-SHA256 truncation is permitted, and theend of the MESSAGE-INTEGRITY attribute.limits permitted for truncation. o Thevalue of the MESSAGE-INTEGRITY attributekeep-alive mechanism if STUN isset to a dummy value. Oncerun over TCP or TLS-over-TCP. o If anycast addresses can be used for thecomputationserver in case 1) TCP or TLS-over-TCP or 2) authentication isperformed,used. In addition, any STUN Usage must consider thevaluesecurity implications ofthe MESSAGE-INTEGRITY attribute is filled in, and the valueusing STUN in that usage. A number of attacks against STUN are known (see thelengthSecurity Considerations section inthethis document), and any usage must consider how these attacks can be thwarted or mitigated. Finally, a usage must consider whether its usage of STUNheaderisset to its correct value -- the lengthan example of theentire message. Similarly, when validating the MESSAGE-INTEGRITY,Unilateral Self-Address Fixing approach to NAT traversal and, if so, address thelength fieldquestions raised in RFC 3424 [RFC3424]. 14. STUN Attributes After the STUN headermustare zero or more attributes. Each attribute MUST beadjusted to point toTLV encoded, with a 16-bit type, 16-bit length, and value. Each STUN attribute MUST end on a 32-bit boundary. As mentioned above, all fields in an attribute are transmitted most significant bit first. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Value (variable) .... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 4: Format of STUN Attributes The value in the Length field MUST contain theendlength of theMESSAGE-INTEGRITY attributeValue part of the attribute, prior tocalculating the HMAC over thepadding, measured in bytes. Since STUNmessage, up to and including the attribute preceding the MESSAGE-INTEGRITY attribute. Such adjustmentaligns attributes on 32-bit boundaries, attributes whose content isnecessary when attributes, such as FINGERPRINT and MESSAGE-INTEGRITY-SHA256, appear after MESSAGE-INTEGRITY. See also [RFC5769] for examplesnot a multiple ofsuch calculations. 14.6. MESSAGE-INTEGRITY-SHA256 The MESSAGE-INTEGRITY-SHA256 attribute4 bytes are padded with 1, 2, or 3 bytes of padding so that its value containsan HMAC-SHA256 [RFC2104]a multiple ofthe STUN message.4 bytes. TheMESSAGE-INTEGRITY-SHA256 attribute canpadding bits MUST bepresentset to zero on sending and MUST be ignored by the receiver. Any attribute type MAY appear more than once inanya STUNmessage type. The MESSAGE- INTEGRITY-SHA256 attribute contains an initial portion ofmessage. Unless specified otherwise, theHMAC- SHA-256 [RFC2104]order of appearance is significant: only theSTUN message. The value will be at most 32 bytes, but MUSTfirst occurrence needs to beat least 16 bytes,processed by a receiver, andMUSTany duplicates MAY be ignored by amultiplereceiver. To allow future revisions of4 bytes. The value must bethis specification to add new attributes if needed, thefull 32 bytesattribute space is divided into two ranges. Attributes with type values between 0x0000 and 0x7FFF are comprehension-required attributes, which means that the STUN agent cannot successfully process the message unless it understands the attribute. Attributes with type values between 0x8000 and 0xFFFF are comprehension-optional attributes, which means that those attributes can be ignored by the STUNUsage explicitly specifies that truncationagent if it does not understand them. The set of STUN attribute types isallowed. STUN Usages may specify a minimum length longer than 16 bytes.maintained by IANA. Thekey for the HMAC depends on which credential mechanisminitial set defined by this specification is found inuse.Section9.1.1 defines the key for18.3. The rest of this section describes theshort-term credential mechanism and Section 9.2.2 definesformat of thekey forvarious attributes defined in this specification. 14.1. MAPPED-ADDRESS The MAPPED-ADDRESS attribute indicates a reflexive transport address of thelong-term credential mechanism. Other credential mechanism MUST defineclient. It consists of an 8-bit address family and a 16-bit port, followed by a fixed-length value representing thekey that is used forIP address. If theHMAC. The text used as input to HMACaddress family is IPv4, theSTUN message, up to and includingaddress MUST be 32 bits. If theattribute precedingaddress family is IPv6, theMESSAGE-INTEGRITY-SHA256 attribute.address MUST be 128 bits. All fields must be in network byte order. Thelength fieldformat of theSTUN message header is adjusted to point to the endMAPPED-ADDRESS attribute is: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0 0 0 0 0 0 0| Family | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Address (32 bits or 128 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 5: Format of MAPPED-ADDRESS Attribute The address family can take on theMESSAGE-INTEGRITY-SHA256 attribute.following values: 0x01:IPv4 0x02:IPv6 Thevaluefirst 8 bits of theMESSAGE-INTEGRITY-SHA256 attribute isMAPPED-ADDRESS MUST be set toa dummy value. Once the computation0 and MUST be ignored by receivers. These bits are present for aligning parameters on natural 32-bit boundaries. This attribute isperformed, the value of the MESSAGE- INTEGRITY-SHA256used only by servers for achieving backwards compatibility with [RFC3489] clients. 14.2. XOR-MAPPED-ADDRESS The XOR-MAPPED-ADDRESS attribute isfilled in, and the value ofidentical to thelength inMAPPED-ADDRESS attribute, except that theSTUN headerreflexive transport address isset to its correct value --obfuscated through thelengthXOR function. The format of theentire message. Similarly, when validatingXOR-MAPPED-ADDRESS is: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0 0 0 0 0 0 0| Family | X-Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | X-Address (Variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 6: Format of XOR-MAPPED-ADDRESS Attribute The Family field represents theMESSAGE-INTEGRITY- SHA256,IP address family and is encoded identically to thelengthFamily field in MAPPED-ADDRESS. X-Port is computed by XOR'ing theSTUN header must be adjusted to point tomapped port with theendmost significant 16 bits of theMESSAGE-INTEGRITY-SHA256 attribute prior to calculating the HMAC over the STUN message, up to and including the attribute precedingmagic cookie. If theMESSAGE-INTEGRITY-SHA256 attribute. Such adjustment is necessary when attributes, such as FINGERPRINT, appear after MESSAGE-INTEGRITY-SHA256. See also Appendix B.1 for examples of such calculations. 14.7. FINGERPRINT The FINGERPRINT attribute MAY be present in all STUN messages. The value ofIP address family is IPv4, X-Address is computed by XOR'ing theattributemapped IP address with the magic cookie. If the IP address family is IPv6, X-Address is computedasby XOR'ing theCRC-32mapped IP address with the concatenation of theSTUN message up to (but excluding)magic cookie and theFINGERPRINT attribute itself, XOR'ed with96-bit transaction ID. In all cases, the32-bit value 0x5354554e. (TheXOR operationensures thatworks on its inputs in network byte order (that is, theFINGERPRINT testorder they willnot report a false positive on a packet containing a CRC-32 generated by an application protocol.)be encoded in the message). The32-bit CRC isrules for encoding and processing theone defined in ITU V.42 [ITU.V42.2002], which has a generator polynomialfirst 8 bits ofx^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1. Seethesample codeattribute's value, the rules for handling multiple occurrences of theCRC-32attribute, and the rules for processing address families are the same as for MAPPED-ADDRESS. Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only inSection 8their encoding of[RFC1952]. When present,theFINGERPRINT attribute MUST betransport address. The former encodes thelast attributetransport address by XOR'ing it with the magic cookie. The latter encodes it directly in binary. RFC 3489 originally specified only MAPPED- ADDRESS. However, deployment experience found that some NATs rewrite the 32-bit binary payloads containing the NAT's public IP address, such as STUN's MAPPED-ADDRESS attribute, in themessage, and thus will appear after MESSAGE-INTEGRITYwell-meaning but misguided attempt to provide a generic Application Layer Gateway (ALG) function. Such behavior interferes with the operation of STUN andMESSAGE-INTEGRITY-SHA256.also causes failure of STUN's message-integrity checking. 14.3. USERNAME TheFINGERPRINTUSERNAME attributecan aid in distinguishing STUN packets from packets of other protocols. See Section 7. As with MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256,is used for message integrity. It identifies theCRCusername and password combination used in theFINGERPRINT attribute covers the length field from the STUN message header. Therefore, thismessage-integrity check. The valuemust be correct and include the CRC attribute as partof USERNAME is a variable-length value containing themessage length, prior to computationauthentication username. It MUST contain a UTF-8-encoded [RFC3629] sequence ofthe CRC. Whenfewer than 509 bytes and MUST have been processed using theFINGERPRINT attribute inOpaqueString profile [RFC8265]. A compliant implementation MUST be able to parse amessage, the attribute is first placed into the messageUTF-8-encoded sequence of 763 or fewer octets to be compatible witha dummy value, then[RFC5389]. Note: [RFC5389] mistakenly referenced theCRC is computed,definition of UTF-8 in [RFC2279]. [RFC2279] assumed up to 6 octets per characters encoded. [RFC2279] was replaced by [RFC3629], which allows only 4 octets per character encoded, consistent with changes made in Unicode 2.0 andthenISO/IEC 10646. Note: This specification uses thevalueOpaqueString profile instead of theattribute is updated. IfUsernameCasePreserved profile for username string processing in order to improve compatibility with deployed password stores. Many password databases used for HTTP and SIP Digest authentication store theMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute are also present, then they mustMD5 hash of username:realm:password instead of storing a plain text password. In [RFC3489], STUN authentication was designed to bepresentcompatible with these existing databases to thecorrect message- integrity value before the CRC is computed, since the CRC is done over the valueextent possible, which like SIP and HTTP performed no pre-processing ofthe MESSAGE-INTEGRITYusernames andMESSAGE-INTEGRITY-SHA256 attributes as well. 14.8. ERROR-CODEpasswords other than prohibiting non-space ASCII control characters. TheERROR-CODE attribute isnext revision of the STUN specification, [RFC5389], usedin error response messages. It contains a numeric error code value intherange of 300SASLprep [RFC4013] stringprep [RFC3454] profile to699 plus a textual reason phrase encoded in UTF-8 [RFC3629],pre-process usernames andis consistent in its code assignmentspasswords. SASLprep uses Unicode Normalization Form KC (Compatibility Decomposition, followed by Canonical Composition) [UAX15] andsemantics with SIP [RFC3261]prohibits various control, space, andHTTP [RFC7231].non-text, deprecated, or inappropriate codepoints. Thereason phrase is meant for diagnostic purposes,PRECIS framework [RFC8264] obsoletes stringprep. PRECIS handling of usernames andcan be anything appropriate for the error code. Recommended reason phrases for the defined error codespasswords [RFC8265] uses Unicode Normalization Form C (Canonical Decomposition, followed by Canonical Composition). While there areincluded in the IANA registry for error codes. The reason phrase MUSTspecific cases where different username strings under HTTP Digest could be mapped to aUTF-8 [RFC3629] encoded sequence of less than 128 characters (which can be as long as 509 bytes when encoding them or 763 bytes when decoding them). 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reserved, shouldsingle STUN username processed with OpaqueString, these cases are extremely unlikely and easy to detect and correct. With a UsernameCasePreserved profile, it would be0 |Class| Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reason Phrase (variable) .. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 7: ERROR-CODE Attribute To facilitate processing, the class ofmore likely that valid usernames under HTTP Digest would not match their processed forms (specifically usernames containing bidirectional text and compatibility forms). Operators are free to further restrict theerror code (the hundreds digit)allowed codepoints in usernames to avoid problematic characters. 14.4. USERHASH The USERHASH attribute isencoded separately fromused as a replacement for therestUSERNAME attribute when username anonymity is supported. The value ofthe code, as shown in Figure 7.USERHASH has a fixed length of 32 bytes. TheReserved bits SHOULD be 0,username MUST have been processed using the OpaqueString profile [RFC8265], andare for alignment on 32-bit boundaries. Receiversthe realm MUSTignore these bits.have been processed using the OpaqueString profile [RFC8265] before hashing. TheClass representsfollowing is thehundreds digitoperation that the client will perform to hash the username: userhash = SHA-256(OpaqueString(username) ":" OpaqueString(realm)) 14.5. MESSAGE-INTEGRITY The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of theerror code.STUN message. Thevalue MUSTMESSAGE-INTEGRITY attribute can bebetween 3 and 6.present in any STUN message type. Since it uses the SHA-1 hash, the HMAC will be 20 bytes. TheNumber representskey for thebinary encoding ofHMAC depends on which credential mechanism is in use. Section 9.1.1 defines theerror code modulo 100,key for the short-term credential mechanism, andits valueSection 9.2.2 defines the key for the long-term credential mechanism. Other credential mechanisms MUSTbe between 0define the key that is used for the HMAC. The text used as input to HMAC is the STUN message, up to and99.including the attribute preceding the MESSAGE-INTEGRITY attribute. Thefollowing error codes, along with their recommended reason phrases, are defined: 300 Try Alternate:Length field of the STUN message header is adjusted to point to the end of the MESSAGE-INTEGRITY attribute. Theclient should contact an alternate server for this request. This error response MUST only be sent ifvalue of therequest included either a USERNAME or USERHASHMESSAGE-INTEGRITY attributeandis set to avaliddummy value. Once the computation is performed, the value of the MESSAGE-INTEGRITYor MESSAGE-INTEGRITY-SHA256 attribute; otherwise, it MUST NOT be sentattribute is filled in, anderror code 400 (Bad Request)the value of the length in the STUN header issuggested. This error response MUSTset to its correct value -- the length of the entire message. Similarly, when validating the MESSAGE-INTEGRITY, the Length field in the STUN header must beprotected withadjusted to point to theMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, and receivers MUST validateend of the MESSAGE-INTEGRITYor MESSAGE- INTEGRITY-SHA256 of this response before redirecting themselvesattribute prior toan alternate server. Note: Failurecalculating the HMAC over the STUN message, up togenerateandvalidate message integrityincluding the attribute preceding the MESSAGE-INTEGRITY attribute. Such adjustment is necessary when attributes, such as FINGERPRINT and MESSAGE-INTEGRITY-SHA256, appear after MESSAGE-INTEGRITY. See also [RFC5769] fora 300 response allowsexamples of such calculations. 14.6. MESSAGE-INTEGRITY-SHA256 The MESSAGE-INTEGRITY-SHA256 attribute contains anon-path attacker to falsify a 300 response thus causing subsequentHMAC-SHA256 [RFC2104] of the STUNmessages tomessage. The MESSAGE-INTEGRITY-SHA256 attribute can besent to a victim. 400 Bad Request:present in any STUN message type. Therequest was malformed.MESSAGE- INTEGRITY-SHA256 attribute contains an initial portion of the HMAC- SHA-256 [RFC2104] of the STUN message. The value will be at most 32 bytes, but it MUST be at least 16 bytes and MUST be a multiple of 4 bytes. Theclient SHOULD NOT retryvalue must be therequest without modification fromfull 32 bytes unless theprevious attempt. The serverSTUN Usage explicitly specifies that truncation is allowed. STUN Usages maynot be able to generatespecify avalid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256minimum length longer than 16 bytes. The key forthis error, sotheclient MUST NOT expect a valid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attributeHMAC depends onthis response. 401 Unauthenticated: The request did not containwhich credential mechanism is in use. Section 9.1.1 defines thecorrect credentials to proceed. The client should retrykey for therequest with proper credentials. 420 Unknown Attribute: The server received a STUN packet containing a comprehension-required attribute that it did not understand. The servershort-term credential mechanism, and Section 9.2.2 defines the key for the long-term credential mechanism. Other credential mechanism MUSTput this unknown attribute indefine theUNKNOWN- ATTRIBUTE attribute of its error response. 438 Stale Nonce: The NONCEkey that is usedbyfor theclient was no longer valid.HMAC. Theclient should retry, usingtext used as input to HMAC is theNONCE provided inSTUN message, up to and including theresponse. 500 Server Error: The server has suffered a temporary error.attribute preceding the MESSAGE-INTEGRITY-SHA256 attribute. Theclient should try again. 14.9. REALMLength field of the STUN message header is adjusted to point to the end of the MESSAGE-INTEGRITY-SHA256 attribute. TheREALMvalue of the MESSAGE-INTEGRITY-SHA256 attributemay be present in requestsis set to a dummy value. Once the computation is performed, the value of the MESSAGE- INTEGRITY-SHA256 attribute is filled in, andresponses. It contains text that meetsthegrammar for "realm-value" as describedvalue of the length in[RFC3261] but withoutthedouble quotes and their surrounding whitespace. That is, it is an unquoted realm-value (andSTUN header istherefore a sequence of qdtext or quoted-pair). It MUST be a UTF-8 [RFC3629] encoded sequenceset to its correct value -- the length ofless than 128 characters (which can be as long as 509 bytes when encoding them and as long as 763 bytesthe entire message. Similarly, whendecoding them), and MUST have been processed usingvalidating theOpaqueString profile [RFC8265]. PresenceMESSAGE-INTEGRITY- SHA256, the Length field in the STUN header must be adjusted to point to the end of theREALMMESSAGE-INTEGRITY-SHA256 attributein a request indicates that long-term credentials are being used for authentication. Presence in certain error responses indicates thatprior to calculating theserver wishesHMAC over theclientSTUN message, up touse a long-term credential in that realm for authentication. 14.10. NONCE The NONCE attribute may be present in requestsandresponses. It contains a sequence of qdtext or quoted-pair, which are defined in [RFC3261]. Note that this means thatincluding theNONCEattributewill not containpreceding theactual surrounding quote characters.MESSAGE-INTEGRITY-SHA256 attribute. Such adjustment is necessary when attributes, such as FINGERPRINT, appear after MESSAGE-INTEGRITY-SHA256. See[RFC7616], Section 5.4,also Appendix B.1 forguidance on selectionexamples ofnonce values in a server. It MUST be less than 128 characters (which can be as long as 509 bytes when encoding them and a long as 763 bytes when decoding them). 14.11. PASSWORD-ALGORITHMSsuch calculations. 14.7. FINGERPRINT ThePASSWORD-ALGORITHMSFINGERPRINT attributemayMAY be present inrequests and responses. It contains the list of algorithms that the server can use to derive the long-term password.all STUN messages. Thesetvalue ofknown algorithms is maintained by IANA. The initial set defined by this specification is found in Section 18.5. Thethe attributecontains a list of algorithm numbers and variable length parameters. The algorithm numberisa 16-bit valuecomputed asdefined in Section 18.5. The parameters start withthelength (prior to padding)CRC-32 of theparameters as a 16-bit value, followed by the parameters that are specific to each algorithm. The parameters are paddedSTUN message up toa(but excluding) the FINGERPRINT attribute itself, XOR'ed with the 32-bitboundary, invalue 0x5354554e. (The XOR operation ensures that thesame manner asFINGERPRINT test will not report a false positive on a packet containing a CRC-32 generated by anattribute. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 1 | Algorithm 1 Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 1 Parameters (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 2 | Algorithm 2 Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 2 Parameter (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... Figure 8: Format of PASSWORD-ALGORITHMS Attribute 14.12. PASSWORD-ALGORITHMapplication protocol.) ThePASSWORD-ALGORITHM attribute32-bit CRC ispresent only in requests. It containsthealgorithms thatone defined in ITU V.42 [ITU.V42.2002], which has a generator polynomial of x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1. See theserver must use to derive a key fromsample code for thelong-term password. The set of known algorithms is maintained by IANA. The initial set defined by this specification is foundCRC-32 in Section18.5. The8 of [RFC1952]. When present, the FINGERPRINT attributecontains an algorithm numberMUST be the last attribute in the message andvariable length parameters.thus will appear after MESSAGE-INTEGRITY and MESSAGE- INTEGRITY-SHA256. Thealgorithm number is a 16-bit value as definedFINGERPRINT attribute can aid in distinguishing STUN packets from packets of other protocols. See Section18.5. The parameters starts7. As with MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, thelength (prior to padding) ofCRC used in theparameters as a 16-bit value, followed byFINGERPRINT attribute covers theparameters that are specific toLength field from thealgorithm. The parameters are paddedSTUN message header. Therefore, prior toa 32-bit boundary, in the same manner as an attribute. Similarly,computation of thepadding bits MUSTCRC, this value must beset to zero on sendingcorrect andMUST be ignored byinclude thereceiver. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm | Algorithm Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm Parameters (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 9: Format of PASSWORD-ALGORITHM Attribute 14.13. UNKNOWN-ATTRIBUTES The UNKNOWN-ATTRIBUTESCRC attributeis present only in an error response whenas part of theresponse codemessage length. When using the FINGERPRINT attribute in a message, theERROR-CODEattribute is420. The attribute containsfirst placed into the message with alist of 16-bit values, eachdummy value; then, the CRC is computed, and the value ofwhich represents anthe attributetype that was not understood byis updated. If theserver. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Attribute 1 Type | Attribute 2 Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Attribute 3 Type | Attribute 4 Type ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 10: Format of UNKNOWN-ATTRIBUTES Attribute Note: In [RFC3489], this field was padded to 32 by duplicatingMESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute is also present, then it must be present with thelast attribute. In this version ofcorrect message- integrity value before thespecification,CRC is computed, since thenormal padding rules forCRC is done over the value of the MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 attributesare used instead. 14.14. SOFTWAREas well. 14.8. ERROR-CODE TheSOFTWAREERROR-CODE attribute is used in error response messages. It contains atextual description of the software being used by the agent sendingnumeric error code value in themessage. Itrange of 300 to 699 plus a textual reason phrase encoded in UTF-8 [RFC3629]; it isused by clientsalso consistent in its code assignments andservers. Its value SHOULD include manufacturersemantics with SIP [RFC3261] andversion number.HTTP [RFC7231]. Theattribute has no impact on operation ofreason phrase is meant for diagnostic purposes and can be anything appropriate for the error code. Recommended reason phrases for theprotocol, and serves only as a tooldefined error codes are included in the IANA registry fordiagnostic and debugging purposes.error codes. Thevalue of SOFTWARE is variable length. Itreason phrase MUST be aUTF-8UTF-8-encoded [RFC3629]encodedsequence oflessfewer than 128 characters (which can be as long as 509 bytes when encoding themand as long asor 763 bytes when decoding them).14.15. ALTERNATE-SERVER The alternate server represents an alternate transport address identifying a different STUN server that the STUN client0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reserved, shouldtry. It is encoded in the same way as MAPPED-ADDRESS, and thus refers to a single server by IP address. 14.16. ALTERNATE-DOMAIN The alternate domain represents the domain name that is used to verify the IP address in the ALTERNATE-SERVER attribute when the transport protocol uses TLS or DTLS. The value of ALTERNATE-DOMAIN is variable length. It MUST be a valid DNS name [RFC1123] (including A-labels [RFC5890]) of 255 or less ASCII characters. 15. Operational Considerations STUN MAYbeused with anycast addresses, but only with UDP and in STUN Usages where authentication is not used. 16. Security Considerations Implementations and deployments0 |Class| Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reason Phrase (variable) .. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 7: Format ofa STUN Usage using TLS or DTLS MUST followERROR-CODE Attribute To facilitate processing, therecommendations in [BCP195]. Implementations and deploymentsclass ofa STUN Usage usingtheLong-Term Credential Mechanism (Section 9.2) MUST followerror code (the hundreds digit) is encoded separately from therecommendations in Section 5rest of[RFC7616]. 16.1. Attacks againsttheProtocol 16.1.1. Outside Attacks An attacker can try to modify STUN messages in transit, in order to cause a failurecode, as shown inSTUN operation. These attacksFigure 7. The Reserved bits SHOULD be 0 and aredetectedforboth requests and responses throughalignment on 32-bit boundaries. Receivers MUST ignore these bits. The Class represents themessage-integrity mechanism, using either a short-term or long-term credential. Of course, once detected,hundreds digit of themanipulated packets willerror code. The value MUST bedropped, causingbetween 3 and 6. The Number represents theSTUN transaction to effectively fail. This attack is possible only by an on-path attacker. An attacker that can observe, but not modify, STUN messages in- transit (for example, an attacker present on a shared access medium, such as Wi-Fi), can see a STUN request,binary encoding of the error code modulo 100, andthen immediately send a STUN response, typically anits value MUST be between 0 and 99. The following errorresponse, in order to disrupt STUN processing. This attack is also preventedcodes, along with their recommended reason phrases, are defined: 300 Try Alternate: The client should contact an alternate server formessages that utilize MESSAGE-INTEGRITY. However, somethis request. This errorresponses, those related to authentication in particular, cannotresponse MUST only beprotected by MESSAGE- INTEGRITY. When STUN itself is run over a secure transport protocol (e.g., TLS), these attacks are completely mitigated. Depending onsent if theSTUN usage, these attacks mayrequest included either a USERNAME or USERHASH attribute and a valid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute; otherwise, it MUST NOT be sent and error code 400 (Bad Request) is suggested. This error response MUST be protected with the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, and receivers MUST validate the MESSAGE-INTEGRITY or MESSAGE- INTEGRITY-SHA256 ofminimal consequencethis response before redirecting themselves to an alternate server. Note: Failure to generate andthus do not requirevalidate message integrity for a 300 response allows an on-path attacker tomitigate. For example, whenfalsify a 300 response thus causing subsequent STUNis usedmessages to be sent to abasic STUNvictim. 400 Bad Request: The request was malformed. The client SHOULD NOT retry the request without modification from the previous attempt. The server may not be able todiscovergenerate aserver reflexive candidatevalid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 forusage with ICE, authentication and message integrity are not required since these attacks are detected duringthis error, so theconnectivity check phase.client MUST NOT expect a valid MESSAGE-INTEGRITY or MESSAGE- INTEGRITY-SHA256 attribute on this response. 401 Unauthenticated: Theconnectivity checks themselves, however, require protection for proper operation of ICE overall. As described in Section 13, STUN usages describe when authentication and message integrity are needed. Since STUN usesrequest did not contain theHMAC of a shared secret for authentication and integrity protection, it is subjectcorrect credentials tooffline dictionary attacks. When authentication is utilized, it SHOULD beproceed. The client should retry the request with proper credentials. 420 Unknown Attribute: The server received astrong password that is not readily subject to offline dictionary attacks. Protection of the channel itself, using TLS or DTLS, mitigates these attacks.STUNsupports both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, which is subject to bid-down attacks by an on-path attackerpacket containing a comprehension-required attribute thatwould strip the MESSAGE-INTEGRITY-SHA256it did not understand. The server MUST put this unknown attributeleaving onlyin theMESSAGE-INTEGRITYUNKNOWN- ATTRIBUTE attributeand exploiting a potential vulnerability. Protectionof its error response. 438 Stale Nonce: The NONCE used by thechannel itself,client was no longer valid. The client should retry, usingTLS or DTLS, mitigates these attacks. Timely removal ofthesupport of MESSAGE-INTEGRITYNONCE provided ina future version of STUN is necessary. Note:the response. 500 Server Error: Theuse of SHA-256 for password hashing does not meet modern standards, which are aimed at slowing down exhaustive password search by providingserver has suffered arelatively slow minimum time to compute the hash. Although better algorithms such as Argon2 [I-D.irtf-cfrg-argon2] are available, SHA-256 was chosen for consistency with [RFC7616]. 16.1.2. Inside Attacks A roguetemporary error. The clientmayshould tryto launch a DoS attack against a server by sendingagain. 14.9. REALM The REALM attribute may be present in requests and responses. It contains text that meets the grammar for "realm-value" as described in [RFC3261] but without the double quotes and their surrounding whitespace. That is, it is an unquoted realm-value (and is therefore alarge numbersequence ofSTUN requests. Fortunately, STUN requests canqdtext or quoted-pair). It MUST beprocessed statelessly by a server, making such attacks hard to launch effectively. A rogue client may useaSTUN serverUTF-8-encoded [RFC3629] sequence of fewer than 128 characters (which can be as long as 509 bytes when encoding them and asa reflector, sending it requests with a falsified source IP addresslong as 763 bytes when decoding them) andport. In such a case,MUST have been processed using theresponse would be delivered to that source IP and port. There is no amplificationOpaqueString profile [RFC8265]. Presence of thenumber of packets with this attack (the STUN server sends one packetREALM attribute in a request indicates that long-term credentials are being used foreach packet sent byauthentication. Presence in certain error responses indicates that theclient), though there isserver wishes the client to use asmall increaselong-term credential inthe amountthat realm for authentication. 14.10. NONCE The NONCE attribute may be present in requests and responses. It contains a sequence ofdata, since STUN responsesqdtext or quoted-pair, which aretypically larger than requests. This attack is mitigated by ingress source address filtering. Revealing the specific software version of the agent throughdefined in [RFC3261]. Note that this means that theSOFTWARENONCE attributemight allow them to become more vulnerable to attacks against software that is known towill not containsecurity holes. Implementers SHOULD make usage oftheSOFTWAREactual surrounding quote characters. The NONCE attribute MUST be fewer than 128 characters (which can be as long as 509 bytes when encoding them and aconfigurable option. 16.1.3. Bid-Down Attacks This document adds the possibilitylong as 763 bytes when decoding them). See Section 5.4 ofselecting different algorithms[RFC7616] forprotecting the confidentiality of the passwords stored on the server side when using the Long-Term Credential Mechanism, while still ensuring compatibility with MD5, which was the algorithm usedguidance on selection of nonce values in aprevious version of this protocol.server. 14.11. PASSWORD-ALGORITHMS The PASSWORD-ALGORITHMS attribute may be present in requests and responses. Itworks by havingcontains the list of algorithms that the serversend backcan use to derive theclient the listlong-term password. The set of known algorithmssupportedis maintained by IANA. The initial set defined by this specification is found in Section 18.5. The attribute contains aPASSWORD-ALGORITHMS attribute,list of algorithm numbers andhaving the client send back a PASSWORD-ALGORITHM attribute containing thevariable length parameters. The algorithmselected. Because the PASSWORD-ALGORITHMS attribute has to be sent in an unauthenticated response, an on-path attacker wanting to exploit an eventual vulnerabilitynumber is a 16-bit value as defined inMD5 can just strip the PASSWORD-ALGORITHMS attribute fromSection 18.5. The parameters start with theunprotected response, thus makinglength (prior to padding) of theserver subsequently actparameters asif the client was implementingaprevious version of this protocol. To protect against this attack and other similar bid-down attacks,16-bit value, followed by thenonce is enriched withparameters that are specific to each algorithm. The parameters are padded to aset32-bit boundary, in the same manner as an attribute. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 1 | Algorithm 1 Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 1 Parameters (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 2 | Algorithm 2 Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm 2 Parameters (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... Figure 8: Format ofsecurity bits which indicates which security features arePASSWORD-ALGORITHMS Attribute 14.12. PASSWORD-ALGORITHM The PASSWORD-ALGORITHM attribute is present only inuse. In the case of the selection ofrequests. It contains thepasswordalgorithm that thematching bitserver must use to derive a key from the long-term password. The set of known algorithms is maintained by IANA. The initial setin the nonce returneddefined bythe serverthis specification is found inthe same response thatSection 18.5. The attribute containsthe PASSWORD- ALGORITHMS attribute. Because the nonce used in subsequent authenticated transactionsan algorithm number and variable length parameters. The algorithm number isverified bya 16-bit value as defined in Section 18.5. The parameters starts with theserver to be identicallength (prior towhat was originally sent, it cannot be modifiedpadding) of the parameters as a 16-bit value, followed byan on-path attacker. Additionally,theclient is mandatedparameters that are specific tocopythereceived PASSWORD-ALGORITHMS attribute in the next authenticated transactionalgorithm. The parameters are padded tothat server. An on-path attack that removesa 32-bit boundary, in thePASSWORD-ALGORITHMS will be detected becausesame manner as an attribute. Similarly, theclient will notpadding bits MUST beable to send it backset to zero on sending and MUST be ignored by theserver in the next authenticated transaction.receiver. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm | Algorithm Parameters Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Algorithm Parameters (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 9: Format of PASSWORD-ALGORITHM Attribute 14.13. UNKNOWN-ATTRIBUTES Theclient will detect that attack because the security bit is set, but the matchingUNKNOWN-ATTRIBUTES attribute ismissing, ending the session. A client usingpresent only in anolder version of this protocol will not senderror response when thePASSWORD-ALGORITHMS back but can only use MD5 anyway, soresponse code in theattackERROR-CODE attribute isinconsequential.420 (Unknown Attribute). Theon-path attack may also try to remove the security bit together with the PASSWORD-ALGORITHMS attribute, but the server will discover that when the next authenticated transactionattribute contains a list of 16-bit values, each of which represents aninvalid nonce. An on-path attack that removes some algorithms from the PASSWORD- ALGORITHMSattributewill be equally defeated becausetype thatattribute will be different fromwas not understood by theoriginal one whenserver. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Attribute 1 Type | Attribute 2 Type | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Attribute 3 Type | Attribute 4 Type ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 10: Format of UNKNOWN-ATTRIBUTES Attribute Note: In [RFC3489], this field was padded to 32 by duplicating theserver verifies it inlast attribute. In this version of thesubsequent authenticated transaction. Note thatspecification, thebid-down protection mechanism introduced in this document is inherently limited bynormal padding rules for attributes are used instead. 14.14. SOFTWARE The SOFTWARE attribute contains a textual description of thefact that it is not possible to detect an attack untilsoftware being used by theserver receivesagent sending thesecond request aftermessage. It is used by clients and servers. Its value SHOULD include manufacturer and version number. The attribute has no impact on operation of the401 response. SHA-256 was chosenprotocol and serves only asthe new default for password hashinga tool forits compatibility with [RFC7616] but because SHA-256 (like MD5)diagnostic and debugging purposes. The value of SOFTWARE is variable length. It MUST be acomparatively fast algorithm, it does little to deter brute force attacks. Specifically, this means that if the user hasUTF-8-encoded [RFC3629] sequence of fewer than 128 characters (which can be as long as 509 when encoding them and as long as 763 bytes when decoding them). 14.15. ALTERNATE-SERVER The alternate server represents an alternate transport address identifying aweak password: o An attacker who capturesdifferent STUN server that theserver's password file can often determineSTUN client should try. It is encoded in theuser's passwordsame way as MAPPED-ADDRESS and thusimpersonate the user to other servers where they have used that password. Note that such an attacker can impersonate the userrefers tothe server itself without any brute force attack. o An attacker who capturesa singleexchange can brute force the user's password and thus potentially impersonateserver by IP address. 14.16. ALTERNATE-DOMAIN The alternate domain represents theuserdomain name that is used to verify theserver and other servers where they have usedIP address in thesame password. A stronger (whichALTERNATE-SERVER attribute when the transport protocol uses TLS or DTLS. The value of ALTERNATE-DOMAIN isto say slower) algorithm, like Argon2 [I-D.irtf-cfrg-argon2], would help bothvariable length. It MUST be a valid DNS name [RFC1123] (including A-labels [RFC5890]) ofthese cases,255 or fewer ASCII characters. 15. Operational Considerations STUN MAY be used with anycast addresses, but only with UDP and inthe caseSTUN Usages where authentication is not used. 16. Security Considerations Implementations and deployments of a STUN Usage using TLS or DTLS MUST follow thefirst attack, only after until the database entry for this user is updated to exclusively use that stronger mechanism. The bid-down defensesrecommendations inthis protocol prevent an attacker from forcing the client[BCP195]. Implementations andserver to completedeployments of ahandshakeSTUN Usage usingweaker algorithms than they jointly support, but only iftheweakest joint algorithm is strong enough that it cannot be brute-forced. However, this does not defendlong-term credential mechanism (Section 9.2) MUST follow the recommendations in Section 5 of [RFC7616]. 16.1. Attacks againstmany attacks on those algorithms; specifically, an on-paththe Protocol 16.1.1. Outside Attacks An attackermight perform a bid-down attack oncan try to modify STUN messages in transit, in order to cause aclient which supported both Argon2 [I-D.irtf-cfrg-argon2] and SHA-256failure in STUN operation. These attacks are detected forpassword hashingboth requests anduse that to collectresponses through the message-integrity mechanism, using either aMESSAGE- INTEGRITY-SHA256 value which it uses for an offline brute-force attack. This would be detected whenshort-term or long-term credential. Of course, once detected, theserver receivesmanipulated packets will be dropped, causing thesecond request, butSTUN transaction to effectively fail. This attack is possible only by an on-path attacker. An attacker thatdoescan observe, but notprevent the attacker from obtaining the MESSAGE-INTEGRITY-SHA256 value. Similarly,modify, STUN messages in- transit (for example, anattack against the USERHASH mechanism will not succeed in establishingattacker present on asessionshared access medium, such asthe server will detect that the feature was discarded on-path, but the client would still have been convinced toWi-Fi) can see a STUN request and then immediately sendits username in cleara STUN response, typically an error response, inthe USERNAME attribute, thus disclosing itorder tothe attacker. Finally, when the bid-down protection mechanismdisrupt STUN processing. This attack isemployedalso prevented fora future upgrade of the HMAC algorithm usedmessages that utilize MESSAGE-INTEGRITY. However, some error responses, those related toprotect message, it will offer only a limited protection if the current HMAC algorithmauthentication in particular, cannot be protected by MESSAGE- INTEGRITY. When STUN itself isalready compromised. 16.2. Attacks Affectingrun over a secure transport protocol (e.g., TLS), these attacks are completely mitigated. Depending on theUsage This section listsSTUN Usage, these attacksthat mightmay belaunched against a usageofSTUN. Eachminimal consequence and thus do not require message integrity to mitigate. For example, when STUN is used to a basic STUN server to discover a server reflexive candidate for usagemust consider whetherwith ICE, authentication and message integrity are not required since these attacks areapplicable to it, and if so, discuss counter-measures. Most of the attacks in this section revolve around an attacker modifyingdetected during thereflexive address learned by aconnectivity check phase. The connectivity checks themselves, however, require protection for proper operation of ICE overall. As described in Section 13, STUNclient through a Binding request/response transaction.Usages describe when authentication and message integrity are needed. Since STUN uses theusageHMAC ofthe reflexive addressa shared secret for authentication and integrity protection, it is subject to offline dictionary attacks. When authentication is utilized, it SHOULD be with afunctionstrong password that is not readily subject to offline dictionary attacks. Protection of theusage, the applicability and remediation ofchannel itself, using TLS or DTLS, mitigates these attacks. STUN supports both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, which makes STUN subject to bid-down attacksare usage-specific. In common situations, modification of the reflexive addressby an on-path attacker. An attackeris easy to do. Consider, for example, the common situation where STUN is run directly over UDP. In this case, an on-path attacker can modify the source IP address of the Binding request before it arrives atcould strip theSTUN server. The STUN server will then return this IP address inMESSAGE-INTEGRITY-SHA256 attribute, leaving only theXOR-MAPPED-ADDRESSMESSAGE-INTEGRITY attributeto the client, and send the response back to that (falsified) IP addressandport. If the attacker can also intercept this response, it can direct it back towards the client. Protecting against this attack by using a message-integrity check is impossible, sincethus exploiting amessage- integrity value cannot cover the source IP address, sincepotential vulnerability. Protection of theintervening NAT must be able to modify this value. Instead, one solution to preventingchannel itself, using TLS or DTLS, mitigates these attacks. Timely removal of theattacks listed belowsupport of MESSAGE-INTEGRITY in a future version of STUN is necessary. Note: The use of SHA-256 forthe clientpassword hashing does not meet modern standards, which are aimed at slowing down exhaustive password searches by providing a relatively slow minimum time toverifycompute thereflexive address learned,hash. Although better algorithms such asis done in ICE [RFC8445]. Other usagesArgon2 [Argon2] are available, SHA-256 was chosen for consistency with [RFC7616]. 16.1.2. Inside Attacks A rogue client mayuse other meanstry toprevent these attacks. 16.2.1. Attack I: Distributedlaunch a DoS(DDoS)attack against aTarget In this attack, the attacker provides one or more clients with the same faked reflexive address that points to the intended target. This will trick the STUN clients into thinking that their reflexive addresses are equal to thatserver by sending it a large number ofthe target. If the clients hand out that reflexive address in orderSTUN requests. Fortunately, STUN requests can be processed statelessly by a server, making such attacks hard toreceive traffic onlaunch effectively. A rogue client may use a STUN server as a reflector, sending it(for example, in SIP messages),requests with a falsified source IP address and port. In such a case, thetraffic will insteadresponse would besentdelivered tothe target. This attack can provide substantial amplification, especially when used with clientsthatare using STUN to enable multimedia applications. However, it can only be launched against targets for which packets fromsource IP and port. There is no amplification of the number of packets with this attack (the STUN serverto the target pass through the attacker, limitingsends one packet for each packet sent by thecases in which itclient), though there ispossible. 16.2.2. Attack II: SilencingaClient In this attack,small increase in theattacker provides aamount of data, since STUNclient with a faked reflexive address. The reflexive address it providesresponses are typically larger than requests. This attack isa transportmitigated by ingress source addressthat routes to nowhere. As a result,filtering. Revealing theclient won't receive anyspecific software version of thepackets it expects to receive when it hands outagent through thereflexive address. This exploitationSOFTWARE attribute might allow them to become more vulnerable to attacks against software that isnot very interesting forknown to contain security holes. Implementers SHOULD make usage of theattacker. It impactsSOFTWARE attribute asingle client, which is frequently not the desired target. Moreover, any attacker that can mountconfigurable option. 16.1.3. Bid-Down Attacks This document adds theattack could also deny servicepossibility of selecting different algorithms to protect theclient by other means, such as preventing the client from receiving any response from the STUN server, or even a DHCP server. As with the attack in Section 16.2.1, this attack is only possible whenconfidentiality of theattacker ispasswords stored onpath for packets sent fromtheSTUNservertowards this unused IP address. 16.2.3. Attack III: Assuming the Identity of a Client This attack is similar to attack II. However,side when using thefaked reflexive address points tolong-term credential mechanism while still ensuring compatibility with MD5, which was theattacker itself.algorithm used in [RFC5389]. Thisallowsselection works by having theattackerserver send toreceive traffic that was destined fortheclient. 16.2.4. Attack IV: Eavesdropping In this attack,client theattacker forceslist of algorithms supported in a PASSWORD-ALGORITHMS attribute and having the clientto usesend back areflexive address that routes to itself. It then forwards any packets it receives toPASSWORD-ALGORITHM attribute containing theclient. This attack would allowalgorithm selected. Because theattackerPASSWORD-ALGORITHMS attribute has toobserve all packetsbe sentto the client. However,inorder to launch the attack, thean unauthenticated response, an on-path attackermust have already been able to observe packets from the clientwanting to exploit an eventual vulnerability in MD5 can just strip theSTUN server. In most cases (such as when the attack is launchedPASSWORD-ALGORITHMS attribute froman access network), this means thattheattacker could already observe packets sent tounprotected response, thus making theclient. This attack is,server subsequently act asa result, only useful for observing traffic by attackers on the path fromif the clientto the STUN server, but not generally onwas implementing thepathversion ofpackets being routed towards the client. Note thatthis protocol defined in [RFC5389]. To protect against this attackcan be trivially launched byand other similar bid-down attacks, theSTUN server itself, so usersnonce is enriched with a set ofSTUN servers should havesecurity bits that indicates which security features are in use. In thesame levelcase oftrust in them as any other node that can insert themselves intothecommunication flow. 16.3. Hash Agility Plan This specification uses both HMAC-SHA256 for computationselection of themessage integrity, sometimespassword algorithm, the matching bit is set in the nonce returned by the server incombination with HMAC-SHA1. If, at a later time, HMAC-SHA256the same response that contains the PASSWORD- ALGORITHMS attribute. Because the nonce used in subsequent authenticated transactions isfoundverified by the server to becompromised,identical to what was originally sent, it cannot be modified by an on-path attacker. Additionally, thefollowingclient is mandated to copy theremedyreceived PASSWORD-ALGORITHMS attribute in the next authenticated transaction to that server. An on-path attack that removes the PASSWORD-ALGORITHMS will beapplied: o Both a new message-integrity attribute and a new STUN Security Feature bitdetected because the client will not beallocatedable to send it back to the server ina Standard Track document.the next authenticated transaction. Thenew message-integrity attributeclient willhave its value computed using a new hash. The STUN Security Featuredetect that attack because the security bit is set but the matching attribute is missing; this willbe used to simultaneously signal to a STUNend the session. A client usingthe Long Term Credential Mechanism thatan older version of this protocol will not send the PASSWORD-ALGORITHMS back but can only use MD5 anyway, so the attack is inconsequential. The on-path attack may also try to remove the security bit together with the PASSWORD-ALGORITHMS attribute, but the serversupports this new hash algorithm, andwillprevent bid-down attacks ondiscover that when thenew message- integrity attribute. o STUN Clients and Servers usingnext authenticated transaction contains an invalid nonce. An on-path attack that removes some algorithms from theShort Term Credential MechanismPASSWORD- ALGORITHMS attribute willneed to updatebe equally defeated because that attribute will be different from the original one when theexternal mechanism that they use to signal what message-integrity attributes areserver verifies it inuse. Thethe subsequent authenticated transaction. Note that the bid-down protection mechanismdescribedintroduced in this document isnew, and thus cannot currently protect against a bid-down attack that lowers the strength ofinherently limited by thehash algorithm to HMAC-SHA1. This is why, after a transition period, a new document updating this document will assign a new STUN Security Feature bit for deprecating HMAC-SHA1. When used, this bit will signalfact thatHMAC-SHA1 is deprecated and should no longer be used. Similarly, if SHA256it isfound to be compromised, a new user-hash attribute and a new STUN Security Feature bit will be allocated in a Standards Track document. The new user-hash attribute will have its value computed using a new hash. The STUN Security Feature bit will be used to simultaneously signalnot possible toa STUN client usingdetect an attack until theLong Term Credential Mechanism that thisserversupports this new hash algorithm for the user-hash attribute, and will prevent bid-down attacks onreceives thenew user-hash attribute. 17. IAB Considerations The IAB has studiedsecond request after theproblem of Unilateral Self-Address Fixing (UNSAF), which is401 (Unauthenticated) response. SHA-256 was chosen as thegeneral process by which a client attempts to determinenew default for password hashing for itsaddress in another realm on the other side of a NAT throughcompatibility with [RFC7616], but because SHA-256 (like MD5) is acollaborative protocol reflection mechanism ([RFC3424]). STUN can be usedcomparatively fast algorithm, it does little toperform this function using a Binding request/ response transactiondeter brute-force attacks. Specifically, this means that ifone agent is behind a NAT and the other is on the public side oftheNAT. The IABuser hassuggesteda weak password, an attacker thatprotocols developed for this purpose documentcaptures aspecific set of considerations. Because some STUN usages provide UNSAF functions (such as ICE [RFC8445] ),single exchange can use a brute-force attack to learn the user's password andothers do not (such as SIP Outbound [RFC5626]), answersthen potentially impersonate the user tothese considerations needthe server and tobe addressed byother servers where theusages themselves. 18. IANA Considerations 18.1. STUN Security Features Registrysame password was used. Note that such an attacker can impersonate the user to the server itself without any brute-force attack. ASTUN Security Feature set defines 24 bit as flags. IANAstronger (which isrequestedtocreate a new registry containingsay, slower) algorithm, like Argon2 [Argon2], would help both of these cases; however, in theSTUN Security Features that are protected byfirst case, it would only help after the database entry for this user is updated to exclusively use that stronger mechanism. The bid-downattack prevention mechanism describeddefenses insection Section 9.2.1. The initial STUN Security Features are: Bit 0: Password algorithms Bit 1: Username anonymity Bit 2-23: Unassigned Bits are assigned startingthis protocol prevent an attacker from forcing themost significant side of the bit set, so Bit 0 is the leftmost bitclient andBit 23server to complete a handshake using weaker algorithms than they jointly support, but only if therightmost bit. New Security Features are assignedweakest joint algorithm is strong enough that it cannot be compromised by aStandards Action [RFC8126]. 18.2. STUN Methods Registry IANA is requested to update the namebrute- force attack. However, this does not defend against many attacks on those algorithms; specifically, an on-path attacker might perform a bid-down attack on a client that supports both Argon2 [Argon2] and SHA-256 formethod 0x002password hashing andthe reference from RFC 5389use that toRFC-to-becollect a MESSAGE- INTEGRITY-SHA256 value that it can then use for an offline brute- force attack. This would be detected when thefollowing STUN methods: 0x000: (Reserved) 0x001: Binding 0x002: (Reserved; prior to [RFC5389] this was SharedSecret) 18.3. STUN Attribute Registry 18.3.1. Updated Attributes IANA is requested to updateserver receives thenames for attributes 0x0002, 0x0004, 0x0005, 0x0007, and 0x000B, andsecond request, but that does not prevent thereferenceattacker fromRFC 5389 to RFC- to-be for the following STUN methods: Comprehension-required range (0x0000-0x7FFF): 0x0000: (Reserved) 0x0001: MAPPED-ADDRESS 0x0002: (Reserved; prior to [RFC5389] this was RESPONSE-ADDRESS) 0x0004: (Reserved; prior to [RFC5389] this was SOURCE-ADDRESS) 0x0005: (Reserved; prior to [RFC5389] this was CHANGED-ADDRESS) 0x0006: USERNAME 0x0007: (Reserved; prior to [RFC5389] this was PASSWORD) 0x0008: MESSAGE-INTEGRITY 0x0009: ERROR-CODE 0x000A: UNKNOWN-ATTRIBUTES 0x000B: (Reserved; prior to [RFC5389] this was REFLECTED-FROM) 0x0014: REALM 0x0015: NONCE 0x0020: XOR-MAPPED-ADDRESS Comprehension-optional range (0x8000-0xFFFF) 0x8022: SOFTWARE 0x8023: ALTERNATE-SERVER 0x8028: FINGERPRINT 18.3.2. New Attributes IANA is requested to add the following attribute toobtaining theSTUN Attribute Registry: Comprehension-required range (0x0000-0x7FFF): 0xXXXX:MESSAGE-INTEGRITY-SHA2560xXXXX: PASSWORD-ALGORITHM 0xXXXX:value. Similarly, an attack against the USERHASHComprehension-optional range (0x8000-0xFFFF) 0xXXXX: PASSWORD-ALGORITHMS 0xXXXX: ALTERNATE-DOMAIN 18.4. STUN Error Code Registry IANA is requested to updatemechanism will not succeed in establishing a session as thereference from RFC 5389server will detect that the feature was discarded on path, but the client would still have been convinced toRFC-to-be forsend its username in theError Codes givenclear inSection 14.8. IANA is requestedthe USERNAME attribute, thus disclosing it tochangethename ofattacker. Finally, when the401 Error Code from "Unauthorized" to "Unauthenticated". 18.5. STUN Password Algorithm Registry IANAbid-down protection mechanism isrequested to create a new registryemployed forPassword Algorithm. A Password Algorithm isahex number in the range 0x0000 - 0xFFFF. The initial Password Algorithms are: 0x0000: Reserved 0x0001: MD5 0x0002: SHA-256 0x0003-0xFFFF: Unassigned Password Algorithms in the first halffuture upgrade of therange (0x0000 - 0x7FFF) are assigned by IETF Review [RFC8126]. Password Algorithms in the second half ofHMAC algorithm used to protect messages, it will offer only a limited protection if therange (0x8000 - 0xFFFF) are assigned by Designated Expert [RFC8126]. 18.5.1. Password Algorithms 18.5.1.1. MD5 This passwordcurrent HMAC algorithm istaken from [RFC1321]. The key length is 16 bytes andalready compromised. 16.2. Attacks Affecting theparameters value is empty. Note:Usage Thisalgorithm MUST onlysection lists attacks that might beused for compatibility with legacy systems. key = MD5(username ":" OpaqueString(realm) ":" OpaqueString(password)) 18.5.1.2. SHA-256 This password algorithm is taken from [RFC7616]. The key length is 32 bytes and the parameters value is empty. key = SHA-256(username ":" OpaqueString(realm) ":" OpaqueString(password)) 18.6.launched against a usage of STUN. Each STUNUDP and TCP Port Numbers IANA is requestedUsage must consider whether these attacks are applicable toupdateit and, if so, discuss countermeasures. Most of thereference from RFC 5389 to RFC-to-be forattacks in this section revolve around an attacker modifying the reflexive address learned by a STUN client through a Binding request/response transaction. Since the usage of the reflexive address is a function of thefollowing ports inusage, theService Nameapplicability andTransport Protocol Port Number Registry. stun 3478/tcp Session Traversal Utilities for NAT (STUN) port stun 3478/udp Session Traversal Utilities for NAT (STUN) port stuns 5349/tcp Session Traversal Utilities for NAT (STUN) port 19. Changes Since RFC 5389 This specification obsoletes [RFC5389]. This specification differs from RFC 5389 inremediation of these attacks are usage-specific. In common situations, modification of thefollowing ways: o Added supportreflexive address by an on-path attacker is easy to do. Consider, forDTLS-over-UDP [RFC6347]. o Made clear thatexample, theRTO is considered stale if therecommon situation where STUN isno transactions withrun directly over UDP. In this case, an on-path attacker can modify theserver. o Alignedsource IP address of theRTO calculation with [RFC6298]. o UpdatedBinding request before it arrives at thecipher suites for TLS. o Added support forSTUNURI [RFC7064]. o Added support for SHA256 message integrity. o Updatedserver. The STUN server will then return this IP address in thePRECIS supportXOR-MAPPED-ADDRESS attribute to[RFC8265]. o Added protocolthe client andregistrysend the response back tochoosethat (falsified) IP address and port. If thepassword encryption algorithm. o Added support for anonymous username. o Added protocolattacker can also intercept this response, it can direct it back towards the client. Protecting against this attack by using a message-integrity check is impossible, since a message- integrity value cannot cover the source IP address andregistrythe intervening NAT must be able to modify this value. Instead, one solution to prevent the attacks listed below is forpreventing biddownthe client to verify the reflexive address learned, as is done in ICE [RFC8445]. Other usages may use other means to prevent these attacks.o Sharing16.2.1. Attack I: Distributed DoS (DDoS) against aNONCE is no longer permitted. o AddedTarget In this attack, thepossibilityattacker provides one or more clients with the same faked reflexive address that points to the intended target. This will trick the STUN clients into thinking that their reflexive addresses are equal to that ofusing a domain name inthealternate server mechanism. o Added more C snippets. o Added test vector. 20. References 20.1. Normative References [ITU.V42.2002] International Telecommunications Union, "Error-correcting Procedures for DCEs Using Asynchronous-to-Synchronous Conversion", ITU-T Recommendation V.42, 2002. [KARN87] Karn, P. and C. Partridge, "Improving Round-Trip Time Estimatestarget. If the clients hand out that reflexive address inReliable Transport Protocols", August 1987. [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, DOI 10.17487/RFC0791, September 1981, <https://www.rfc-editor.org/info/rfc791>. [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - Communication Layers", STD 3, RFC 1122, DOI 10.17487/RFC1122, October 1989, <https://www.rfc-editor.org/info/rfc1122>. [RFC1123] Braden, R., Ed., "Requirements for Internet Hosts - Application and Support", STD 3, RFC 1123, DOI 10.17487/RFC1123, October 1989, <http://www.rfc-editor.org/info/rfc1123>. [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, DOI 10.17487/RFC1321, April 1992, <https://www.rfc-editor.org/info/rfc1321>. [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- Hashing for Message Authentication", RFC 2104, DOI 10.17487/RFC2104, February 1997, <https://www.rfc-editor.org/info/rfc2104>. [RFC2119] Bradner, S., "Key words for useorder to receive traffic on it (for example, inRFCsSIP messages), the traffic will instead be sent to the target. This attack can provide substantial amplification, especially when used with clients that are using STUN toIndicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, <http://www.rfc-editor.org/info/rfc2119>. [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RRenable multimedia applications. However, it can only be launched against targets forspecifyingwhich packets from thelocation of services (DNS SRV)", RFC 2782, DOI 10.17487/RFC2782, February 2000, <https://www.rfc-editor.org/info/rfc2782>. [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2003, <https://www.rfc-editor.org/info/rfc3629>. [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, <https://www.rfc-editor.org/info/rfc4648>. [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security (TLS) Protocol Version 1.2", RFC 5246, DOI 10.17487/RFC5246, August 2008, <https://www.rfc-editor.org/info/rfc5246>. [RFC5890] Klensin, J., "Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework", RFC 5890, DOI 10.17487/RFC5890, August 2010, <http://www.rfc-editor.org/info/rfc5890>. [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) CertificatesSTUN server to the target pass through the attacker, limiting the cases in which it is possible. 16.2.2. Attack II: Silencing a Client In this attack, theContextattacker provides a STUN client with a faked reflexive address. The reflexive address it provides is a transport address that routes to nowhere. As a result, the client won't receive any ofTransport Layer Security (TLS)", RFC 6125, DOI 10.17487/RFC6125, March 2011, <https://www.rfc-editor.org/info/rfc6125>. [RFC6151] Turner, S. and L. Chen, "Updated Security Considerationsthe packets it expects to receive when it hands out the reflexive address. This exploitation is not very interesting for theMD5 Message-Digest andattacker. It impacts a single client, which is frequently not the desired target. Moreover, any attacker that can mount theHMAC-MD5 Algorithms", RFC 6151, DOI 10.17487/RFC6151, March 2011, <http://www.rfc-editor.org/info/rfc6151>. [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, "Computing TCP's Retransmission Timer", RFC 6298, DOI 10.17487/RFC6298, June 2011, <https://www.rfc-editor.org/info/rfc6298>. [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, January 2012, <https://www.rfc-editor.org/info/rfc6347>. [RFC7064] Nandakumar, S., Salgueiro, G., Jones, P., and M. Petit- Huguenin, "URI Scheme forattack could also deny service to theSession Traversal Utilities for NAT (STUN) Protocol", RFC 7064, DOI 10.17487/RFC7064, November 2013, <https://www.rfc-editor.org/info/rfc7064>. [RFC7350] Petit-Huguenin, M. and G. Salgueiro, "Datagram Transport Layer Security (DTLS)client by other means, such asTransport for Session Traversal Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, August 2014, <https://www.rfc-editor.org/info/rfc7350>. [RFC7616] Shekh-Yusef, R., Ahrens, D., and S. Bremer, "HTTP Digest Access Authentication", RFC 7616, DOI 10.17487/RFC7616, September 2015, <https://www.rfc-editor.org/info/rfc7616>. [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, <http://www.rfc-editor.org/info/rfc8174>. [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 (IPv6) Specification", RFC 8200, STD 86, DOI 10.17487/RFC8200, July 2017, <https://www.rfc-editor.org/info/rf8200>. [RFC8265] Saint-Andre, P. and A. Melnikov, "Preparation, Enforcement, and Comparison of Internationalized Strings Representing Usernames and Passwords", RFC 8265, DOI 10.17487/RFC8265, October 2017, <https://www.rfc-editor.org/info/rfc8265>. [RFC8305] Schinazi, D. and T. Pauly, "Happy Eyeballs Version 2: Better Connectivity Using Concurrency", RFC 8305, DOI 10.17487/RFC8305, December 2017, <https://www.rfc-editor.org/info/rfc8305>. 20.2. Informative References [BCP195] Sheffer, Y., Holz, R., and P. Saint-Andre, "Recommendationspreventing the client from receiving any response from the STUN server, or even a DHCP server. As with the attack described in Section 16.2.1, this attack is only possible when the attacker is on path forSecure Usepackets sent from the STUN server towards this unused IP address. 16.2.3. Attack III: Assuming the Identity ofTransport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)", BCP 195, RFC 7525, DOI 10.17487/RFC7525, May 2015, <https://www.rfc-editor.org/info/rfc7525>. [I-D.ietf-tram-stun-pmtud] Petit-Huguenin, M. and G. Salgueiro, "Path MTU Discovery Using Session Traversal Utilitiesa Client This attack is similar to attack II. However, the faked reflexive address points to the attacker itself. This allows the attacker to receive traffic that was destined forNAT (STUN)", draft- ietf-tram-stun-pmtud-10 (workthe client. 16.2.4. Attack IV: Eavesdropping In this attack, the attacker forces the client to use a reflexive address that routes to itself. It then forwards any packets it receives to the client. This attack allows the attacker to observe all packets sent to the client. However, inprogress), September 2018. [I-D.irtf-cfrg-argon2] Biryukov, A., Dinu, D., Khovratovich, D., and S. Josefsson, "The memory-hard Argon2 password hash and proof-of-work function", draft-irtf-cfrg-argon2-04 (workorder to launch the attack, the attacker must have already been able to observe packets from the client to the STUN server. In most cases (such as when the attack is launched from an access network), this means that the attacker could already observe packets sent to the client. This attack is, as a result, only useful for observing traffic by attackers on the path from the client to the STUN server, but not generally on the path of packets being routed towards the client. Note that this attack can be trivially launched by the STUN server itself, so users of STUN servers should have the same level of trust inprogress), November 2018. [RFC1952] Deutsch, P., "GZIP file formatthe users of STUN servers as any other node that can insert itself into the communication flow. 16.3. Hash Agility Plan This specificationversion 4.3", RFC 1952, DOI 10.17487/RFC1952, May 1996, <https://www.rfc-editor.org/info/rfc1952>. [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, A., Peterson, J., Sparks, R., Handley, M., and E. Schooler, "SIP: Session Initiation Protocol", RFC 3261, DOI 10.17487/RFC3261, June 2002, <https://www.rfc-editor.org/info/rfc3261>. [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerationsuses HMAC-SHA256 forUNilateral Self-Address Fixing (UNSAF) Across Network Address Translation", RFC 3424, DOI 10.17487/RFC3424, November 2002, <https://www.rfc-editor.org/info/rfc3424>. [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, "STUN - Simple Traversalcomputation ofUser Datagram Protocol (UDP) Through Network Address Translators (NATs)", RFC 3489, DOI 10.17487/RFC3489, March 2003, <https://www.rfc-editor.org/info/rfc3489>. [RFC4107] Bellovin, S. and R. Housley, "Guidelines for Cryptographic Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, June 2005, <https://www.rfc-editor.org/info/rfc4107>. [RFC5090] Sterman, B., Sadolevsky, D., Schwartz, D., Williams, D., and W. Beck, "RADIUS Extension for Digest Authentication", RFC 5090, DOI 10.17487/RFC5090, February 2008, <http://www.rfc-editor.org/info/rfc5090>. [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, "Session Traversal Utilities for NAT (STUN)", RFC 5389, DOI 10.17487/RFC5389, October 2008, <https://www.rfc-editor.org/info/rfc5389>. [RFC5626] Jennings, C., Ed., Mahy, R., Ed., and F. Audet, Ed., "Managing Client-Initiated Connections intheSession Initiation Protocol (SIP)", RFC 5626, DOI 10.17487/RFC5626, October 2009, <https://www.rfc-editor.org/info/rfc5626>. [RFC5766] Mahy, R., Matthews, P.,message integrity, sometimes in combination with HMAC-SHA1. If, at a later time, HMAC-SHA256 is found to be compromised, the following remedy should be applied: o Both a new message-integrity attribute andJ. Rosenberg, "Traversal Using Relays around NAT (TURN): Relay Extensionsa new STUN Security Feature bit will be allocated in a Standards Track document. The new message-integrity attribute will have its value computed using a new hash. The STUN Security Feature bit will be used toSession Traversal Utilities for NAT (STUN)", RFC 5766, DOI 10.17487/RFC5766, April 2010, <https://www.rfc-editor.org/info/rfc5766>. [RFC5769] Denis-Courmont, R., "Test Vectors for Session Traversal Utilities for NAT (STUN)", RFC 5769, DOI 10.17487/RFC5769, April 2010, <https://www.rfc-editor.org/info/rfc5769>. [RFC5780] MacDonald, D.simultaneously 1) signal to a STUN client using the long-term credential mechanism that this server supports this new hash algorithm andB. Lowekamp, "NAT Behavior Discovery Using Session Traversal Utilities for NAT (STUN)", RFC 5780, DOI 10.17487/RFC5780, May 2010, <https://www.rfc-editor.org/info/rfc5780>. [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B.,2) prevent bid-down attacks on the new message- integrity attribute. o STUN clients andA. Roach, "TCP Candidates with Interactive Connectivity Establishment (ICE)", RFC 6544, DOI 10.17487/RFC6544, March 2012, <https://www.rfc-editor.org/info/rfc6544>. [RFC7231] Fielding, R.servers using the short-term credential mechanism will need to update the external mechanism that they use to signal what message-integrity attributes are in use. The bid-down protection mechanism described in this document is new andR. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Semanticsthus cannot currently protect against a bid-down attack that lowers the strength of the hash algorithm to HMAC-SHA1. This is why, after a transition period, a new document updating this one will assign a new STUN Security Feature bit for deprecating HMAC-SHA1. When used, this bit will signal that HMAC-SHA1 is deprecated andContent", RFC 7231, DOI 10.17487/RFC7231, June 2014, <https://www.rfc-editor.org/info/rfc7231>. [RFC8126] Cotton, M., Leiba, B.,should no longer be used. Similarly, if HMAC-SHA256 is found to be compromised, a new userhash attribute andT. Narten, "Guidelinesa new STUN Security Feature bit will be allocated in a Standards Track document. The new userhash attribute will have its value computed using a new hash. The STUN Security Feature bit will be used to simultaneously 1) signal to a STUN client using the long- term credential mechanism that this server supports this new hash algorithm forWriting an IANAthe userhash attribute and 2) prevent bid-down attacks on the new userhash attribute. 17. IAB ConsiderationsSectionThe IAB has studied the problem of Unilateral Self-Address Fixing (UNSAF), which is the general process by which a client attempts to determine its address inRFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, May 2008, <https://www.rfc-editor.org/info/rfc8126>. [RFC8445] Keranen, A., Holmberg, C.,another realm on the other side of a NAT through a collaborative protocol reflection mechanism [RFC3424]. STUN can be used to perform this function using a Binding request/ response transaction if one agent is behind a NAT andJ. Rosenberg, "Interactive Connectivity Establishment (ICE): A Protocolthe other is on the public side of the NAT. The IAB has suggested that protocols developed forNetwork Address Translator (NAT) Traversal", RFC 8445, DOI 10.17487/RFC8445, July 2018, <https://www.rfc-editor.org/info/rfc8445>. Appendix A. C Snippetthis purpose document a specific set of considerations. Because some STUN Usages provide UNSAF functions (such as ICE [RFC8445]) and others do not (such as SIP Outbound [RFC5626]), answers toDeterminethese considerations need to be addressed by the usages themselves. 18. IANA Considerations 18.1. STUNMessage Types GivenSecurity Features Registry A STUN Security Feature set defines 24 bits as flags. IANA has created a16-bitnew registry containing the STUNmessage type value in host byte orderSecurity Features that are protected by the bid-down attack prevention mechanism described inmsg_type parameter, belowSection 9.2.1. The initial STUN Security Features are: Bit 0: Password algorithms Bit 1: Username anonymity Bit 2-23: Unassigned Bits areC macros to determineassigned starting from the most significant side of the bit set, so Bit 0 is the leftmost bit and Bit 23 is the rightmost bit. New Security Features are assigned by Standards Action [RFC8126]. 18.2. STUNmessage types: <CODE BEGINS> #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) <CODE ENDS>Methods Registry Afunction to convertSTUN method is a hex number in the range 0x000-0xFFF. The encoding of a STUN methodand classinto a STUN messagetype: <CODE BEGINS> int type(int method, int cls) { return (method & 0x1F80) << 2 | (method & 0x0070) << 1 | (method & 0x000F) | (cls & 0x0002) << 7 | (cls & 0x0001) << 4; } <CODE ENDS> A functionis described in Section 5. STUN methods in the range 0x000-0x07F are assigned by IETF Review [RFC8126]. STUN methods in the range 0x080-0x0FF are assigned by Expert Review [RFC8126]. The responsibility of the expert is toextractverify that the selected codepoint(s) is not in use and that the request is not for an abnormally large number of codepoints. Technical review of the extension itself is outside the scope of the designated expert responsibility. IANA has updated the name for method 0x002 as described below as well as updated the reference from RFC 5389 to RFC 8489 for themessage type: <CODE BEGINS> int method(int type) { return (type & 0x3E00) >> 2 | (type & 0x00E0) >> 1 | (type & 0x000F); } <CODE ENDS> A functionfollowing STUN methods: 0x000: Reserved 0x001: Binding 0x002: Reserved; was SharedSecret prior toextract[RFC5389] 18.3. STUN Attributes Registry A STUN attribute type is a hex number in theclass fromrange 0x0000-0xFFFF. STUN attribute types in themessage type: <CODE BEGINS> int cls(int type) { return (type & 0x0100) >> 7 | (type & 0x0010) >> 4; } <CODE ENDS> Appendix B. Test Vectors This section augmentsrange 0x0000-0x7FFF are considered comprehension-required; STUN attribute types in thelistrange 0x8000-0xFFFF are considered comprehension-optional. A STUN agent handles unknown comprehension-required and comprehension-optional attributes differently. STUN attribute types in the first half oftest vectors definedthe comprehension-required range (0x0000-0x3FFF) and in[RFC5769] with MESSAGE-INTEGRITY-SHA256. Alltheformatsfirst half of the comprehension- optional range (0x8000-0xBFFF) are assigned by IETF Review [RFC8126]. STUN attribute types in the second half of the comprehension-required range (0x4000-0x7FFF) anddefinitions listedinSection 2the second half of the comprehension- optional range (0xC000-0xFFFF) are assigned by Expert Review [RFC8126]. The responsibility of the expert is to verify that the selected codepoint(s) are not in use and that the request is not for an abnormally large number of codepoints. Technical review of the extension itself is outside the scope of[RFC5769] apply here. B.1. Sample Request with Long-Term Authentication with MESSAGE- INTEGRITY-SHA256the designated expert responsibility. 18.3.1. Updated Attributes IANA has updated the names for attributes 0x0002, 0x0004, 0x0005, 0x0007, andUSERHASH This request uses0x000B as well as updated the reference from RFC 5389 to RFC 8489 for each the followingparameters: Username: "<U+30DE><U+30C8><U+30EA><U+30C3><U+30AF><U+30B9>" (without quotes) unaffected by OpaqueString [RFC8265] processing Password: "The<U+00AD>M<U+00AA>tr<U+2168>" and "TheMatrIX" (without quotes) respectively before and after OpaqueString processing Nonce: "obMatJos2QAAAf//499k954d6OL34oL9FSTvy64sA" (without quotes) Realm: "example.org" (without quotes) 00 01 00 9c Request type and message length 21 12 a4 42 Magic cookie 78 ad 34 33 } c6 ad 72 c0 } Transaction ID 29 da 41 2e } XX XX 00 20 USERHASH attribute header 4a 3c f3 8f } ef 69 92 bd } a9 52 c6 78 } 04 17 da 0f } Userhash value (32 bytes) 24 81 94 15 } 56 9e 60 b2 } 05 c4 6e 41 } 40 7f 17 04 } 00 15 00 29 NONCESTUN methods. In addition, [RFC5389] introduced a mistake in the name of attributeheader 6f 62 4d 61 } 74 4a 6f 73 } 32 41 41 41 } 43 66 2f 2f } 34 39 39 6b } Nonce value and padding (3 bytes) 39 35 34 64 } 36 4f 4c 33 } 34 6f 4c 39 } 46 53 54 76 } 79 36 34 73 } 41 00 00 00 } 00 14 00 0b0x0003; [RFC5389] called it CHANGE-ADDRESS when it was actually previously called CHANGE-REQUEST. Thus, IANA has updated the description for 0x0003 to read "Reserved; was CHANGED-REQUEST prior to [RFC5389]". Comprehension-required range (0x0000-0x7FFF): 0x0000: Reserved 0x0001: MAPPED-ADDRESS 0x0002: Reserved; was RESPONSE-ADDRESS prior to [RFC5389] 0x0003: Reserved; was CHANGED-REQUEST prior to [RFC5389] 0x0004: Reserved; was SOURCE-ADDRESS prior to [RFC5389] 0x0005: Reserved; was CHANGED-ADDRESS prior to [RFC5389] 0x0006: USERNAME 0x0007: Reserved; was PASSWORD prior to [RFC5389] 0x0008: MESSAGE-INTEGRITY 0x0009: ERROR-CODE 0x000A: UNKNOWN-ATTRIBUTES 0x000B: Reserved; was REFLECTED-FROM prior to [RFC5389] 0x0014: REALM 0x0015: NONCE 0x0020: XOR-MAPPED-ADDRESS Comprehension-optional range (0x8000-0xFFFF) 0x8022: SOFTWARE 0x8023: ALTERNATE-SERVER 0x8028: FINGERPRINT 18.3.2. New Attributes IANA has added the following attributeheader 65 78 61 6d } 70 6c 65 2e } Realm value (11 bytes) and padding (1 byte) 6f 72 67 00 } XX XX 00 20to the "STUN Attributes" registry: Comprehension-required range (0x0000-0x7FFF): 0x001C: MESSAGE-INTEGRITY-SHA256attribute header c4 ec a2 b6 } 24 6f 260x001D: PASSWORD-ALGORITHM 0x001E: USERHASH Comprehension-optional range (0x8000-0xFFFF) 0x8002: PASSWORD-ALGORITHMS 0x8003: ALTERNATE-DOMAIN 18.4. STUN Error Codes Registry A STUN error code is a number in the range 0-699. STUN error codes are accompanied by a textual reason phrase in UTF-8 [RFC3629] that is intended only for human consumption and can be} bc 2f 77 49 } 07 c2 00 a3 } HMAC-SHA256 value 76 c7 c2 8e } b4 d1 26 60 } bb fe 9f 28 } 0e 85 71 f2 } Note: Before publication,anything appropriate; this document proposes only suggested values. STUN error codes are consistent in codepoint assignments and semantics with SIP [RFC3261] and HTTP [RFC7231]. New STUN error codes are assigned based on IETF Review [RFC8126]. The specification must carefully consider how clients that do not understand this error code will process it before granting the request. See the rules in Section 6.3.4. IANA has updated the reference from RFC 5389 to RFC 8489 for the error codes defined in Section 14.8. IANA has changed the name of the 401 error code from "Unauthorized" to "Unauthenticated". 18.5. STUN Password Algorithms Registry IANA has created a new registry titled "STUN Password Algorithms". A password algorithm is a hex number in theXX XX placeholder must be replacedrange 0x0000-0xFFFF. The initial contents of the "Password Algorithm" registry are as follows: 0x0000: Reserved 0x0001: MD5 0x0002: SHA-256 0x0003-0xFFFF: Unassigned Password algorithms in the first half of the range (0x0000-0x7FFF) are assigned by IETF Review [RFC8126]. Password algorithms in thevaluesecond half of the range (0x8000-0xFFFF) are assignedto MESSAGE-INTEGRITY-SHA256 and USERHASHbyIANA.Expert Review [RFC8126]. 18.5.1. Password Algorithms 18.5.1.1. MD5 This password algorithm is taken from [RFC1321]. TheMESSAGE-INTEGRITY-SHA256 attributekey length is 16 bytes, and the parameters valuewill need to be updated after this. Appendix C. Release notesis empty. Note: Thissection mustalgorithm MUST only beremoved before publication as an RFC. C.1. Modifications between draft-ietf-tram-stunbis-21 and draft-ietf- tram-stunbis-20 o Final edits to clean up bid down protection text to address Eric Rescorla's DISCUSSused for compatibility with legacy systems. key = MD5(username ":" OpaqueString(realm) ":" OpaqueString(password)) 18.5.1.2. SHA-256 This password algorithm is taken from [RFC7616]. The key length is 32 bytes, andcomments. C.2. Modifications between draft-ietf-tram-stunbis-20the parameters value is empty. key = SHA-256(username ":" OpaqueString(realm) ":" OpaqueString(password)) 18.6. STUN UDP anddraft-ietf- tram-stunbis-19 o UpdatesTCP Port Numbers IANA has updated the reference from RFC 5389 toaddress Eric Rescorla's DISCUSS and comments. o Addressed nits raised by Noriyuki Torii C.3. Modifications between draft-ietf-tram-stunbis-19 and draft-ietf- tram-stunbis-18 o Updates following Adam Roach DISCUSS and comments. C.4. Modifications between draft-ietf-tram-stunbis-18 and draft-ietf- tram-stunbis-17 o Nits. C.5. Modifications between draft-ietf-tram-stunbis-17 and draft-ietf- tram-stunbis-16 o ModificationsRFC 8489 for the followingIESG, GENART and SECDIR reviews. C.6. Modifications between draft-ietf-tram-stunbis-16ports in the "Service Name anddraft-ietf- tram-stunbis-15 o Replace "failure response" with "error response". o Fix wrong section number.Transport Protocol Port Number Registry". stun 3478/tcp Session Traversal Utilities for NAT (STUN) port stun 3478/udp Session Traversal Utilities for NAT (STUN) port stuns 5349/tcp Session Traversal Utilities for NAT (STUN) port 19. Changes since RFC 5389 This specification obsoletes [RFC5389]. This specification differs from RFC 5389 in the following ways: oUse "Username anonymity" everywhere.Added support for DTLS-over-UDP [RFC6347]. oAlignMade clear that the RTO is considered stale if there are no transactions withUTF-8 deprecation. o Fix MESSAGE-INTEGRITY-256. o Update references.the server. oUpdates inAligned theIANA sections.RTO calculation with [RFC6298]. os/HMAC-SHA-1/HMAC-SHA1/, s/HMAC-SHA-256/HMAC-SHA256/, s/SHA1/SHA- 1/, and s/SHA256/SHA-256/.Updated the ciphersuites for TLS. oFixed definitions ofAdded support for STUNclients/servers.URI [RFC7064]. oFixed STUNAdded support for SHA256 messagestructure definition.integrity. oMissing text.Updated the Preparation, Enforcement, and Comparison of Internationalized Strings (PRECIS) support to [RFC8265]. oAdd text explicitly saying that responses do not haveAdded protocol and registry tobe inchoose thesame orders than requests.password encryption algorithm. o Added support for anonymous username. o/other application/other protocol/Added protocol and registry for preventing bid-down attacks. oAdd text explicitly sayingSpecified thatthe security feature encodingsharing a NONCE is4 character. o Fixed discrepancy in section 9.2.3/9.2.3.1. o s/invalidate/revoke/.no longer permitted. oRemoved sentences about checking USERHASHAdded the possibility of using a domain name inresponses, as this should not happen.the alternate server mechanism. oSpecify that ALTERNATE-SERVER carries an IP address.Added more C snippets. oMore modifications following review... C.7. Modifications between draft-ietf-tram-stunbis-15Added test vector. 20. References 20.1. Normative References [ITU.V42.2002] International Telecommunication Union, "Error-correcting procedures for DCEs using asynchronous-to-synchronous conversion", ITU-T Recommendation V.42, March 2002. [KARN87] Karn, P. anddraft-ietf- tram-stunbis-14 o RevertedC. Partridge, "Improving Round-Trip Time Estimates in Reliable Transport Protocols", SIGCOMM '87, Proceedings of theRFC 2119 boilerplate to what wasACM workshop on Frontiers in computer communications technology, Pages 2-7, DOI 10.1145/55483.55484, August 1987. [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, DOI 10.17487/RFC0791, September 1981, <https://www.rfc-editor.org/info/rfc791>. [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - Communication Layers", STD 3, RFC 1122, DOI 10.17487/RFC1122, October 1989, <https://www.rfc-editor.org/info/rfc1122>. [RFC1123] Braden, R., Ed., "Requirements for Internet Hosts - Application and Support", STD 3, RFC 1123, DOI 10.17487/RFC1123, October 1989, <https://www.rfc-editor.org/info/rfc1123>. [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC5389. o Reverted the V.42 reference to the 2002 version. o Updated some references. C.8. Modifications between draft-ietf-tram-stunbis-141321, DOI 10.17487/RFC1321, April 1992, <https://www.rfc-editor.org/info/rfc1321>. [RFC2104] Krawczyk, H., Bellare, M., anddraft-ietf- tram-stunbis-13 o Reorder the paragraphs in section 9.1.4. o The realm is now processed through Opaque in section 9.2.2. o Make clear in section 9.2.4 that it is an exclusive-xor. o Removed text that implied that nonce sharing was explicitly permitted inR. Canetti, "HMAC: Keyed- Hashing for Message Authentication", RFC5389. o In same section, s/username/value/2104, DOI 10.17487/RFC2104, February 1997, <https://www.rfc-editor.org/info/rfc2104>. [RFC2119] Bradner, S., "Key words forUSERCASH. o Modify the IANA requests to explicitly say that the reserved codepoints were prioruse in RFCs to Indicate Requirement Levels", BCP 14, RFC5389. C.9. Modifications between draft-ietf-tram-stunbis-13 and draft-ietf- tram-stunbis-12 o Update references. o Fixes some text following Shepherd review. o Update co-author info. C.10. Modifications between draft-ietf-tram-stunbis-122119, DOI 10.17487/RFC2119, March 1997, <https://www.rfc-editor.org/info/rfc2119>. [RFC2782] Gulbrandsen, A., Vixie, P., anddraft-ietf- tram-stunbis-11 o Clarifies the procedure to define a new hash algorithm for message-integrity. o Explain the procedure to deprecate SHA1 as message-integrity. o Added procedureL. Esibov, "A DNS RR forHappy Eyeballs (RFC 6555). o Added verification that Happy Eyeballs works inspecifying theSTUN Usage checklist. o Add reference tolocation of services (DNS SRV)", RFC 2782, DOI 10.17487/RFC2782, February 2000, <https://www.rfc-editor.org/info/rfc2782>. [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2003, <https://www.rfc-editor.org/info/rfc3629>. [RFC4648] Josefsson, S., "The Base16, Base32, and Base64RFC. o Changed co-author affiliation. C.11. Modifications between draft-ietf-tram-stunbis-11Data Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, <https://www.rfc-editor.org/info/rfc4648>. [RFC5890] Klensin, J., "Internationalized Domain Names for Applications (IDNA): Definitions anddraft-ietf- tram-stunbis-10 o Made clear that the same HMAC than receivedDocument Framework", RFC 5890, DOI 10.17487/RFC5890, August 2010, <https://www.rfc-editor.org/info/rfc5890>. [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) Certificates inresponsethe Context ofshort term credential must be usedTransport Layer Security (TLS)", RFC 6125, DOI 10.17487/RFC6125, March 2011, <https://www.rfc-editor.org/info/rfc6125>. [RFC6151] Turner, S. and L. Chen, "Updated Security Considerations forsubsequent transactions. o s/URL/URI/ o The "nonce cookie" is now mandatory to signal that SHA256 must be used inthenext transaction. o s/SHA1/SHA256/ o Changed co-author affiliation. C.12. Modifications between draft-ietf-tram-stunbis-10MD5 Message-Digest anddraft-ietf- tram-stunbis-09 o Removed the reserved value in the security registry, as it does not make sense in a bitset. o Updated change list. o Updated the minimum truncation size for M-I-256 to 16 bytes. o Changedthetruncation order to matchHMAC-MD5 Algorithms", RFC7518. o Fixed bugs in truncation boundary text. o Stated that STUN Usages have to explicitly state that they can use truncation. o Removed truncation from the MESSAGE-INTEGRITY attribute. o Add reference to C code in6151, DOI 10.17487/RFC6151, March 2011, <https://www.rfc-editor.org/info/rfc6151>. [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, "Computing TCP's Retransmission Timer", RFC1952. o Replaced6298, DOI 10.17487/RFC6298, June 2011, <https://www.rfc-editor.org/info/rfc6298>. [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer Security Version 1.2", RFC2818 reference to6347, DOI 10.17487/RFC6347, January 2012, <https://www.rfc-editor.org/info/rfc6347>. [RFC7064] Nandakumar, S., Salgueiro, G., Jones, P., and M. Petit- Huguenin, "URI Scheme for the Session Traversal Utilities for NAT (STUN) Protocol", RFC6125. C.13. Modifications between draft-ietf-tram-stunbis-097064, DOI 10.17487/RFC7064, November 2013, <https://www.rfc-editor.org/info/rfc7064>. [RFC7350] Petit-Huguenin, M. anddraft-ietf- tram-stunbis-08 o Packets discarded in a reliable or unreliable transaction triggers an attack error instead of a timeout error. An attack error on a reliable transport is signaled immediately insteadG. Salgueiro, "Datagram Transport Layer Security (DTLS) as Transport for Session Traversal Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, August 2014, <https://www.rfc-editor.org/info/rfc7350>. [RFC7616] Shekh-Yusef, R., Ed., Ahrens, D., and S. Bremer, "HTTP Digest Access Authentication", RFC 7616, DOI 10.17487/RFC7616, September 2015, <https://www.rfc-editor.org/info/rfc7616>. [RFC8174] Leiba, B., "Ambiguity ofwaiting for the timeout. o Explicitly state that a received 400 response without authentication will be dropped until timeout. o Clarify the SHOULD omit/include rulesUppercase vs Lowercase inLTCM. o If the nonceRFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, <https://www.rfc-editor.org/info/rfc8174>. [RFC8200] Deering, S. andthe hmac are both invalid, then a 401 is sent instead of a 438. o The 401R. Hinden, "Internet Protocol, Version 6 (IPv6) Specification", STD 86, RFC 8200, DOI 10.17487/RFC8200, July 2017, <https://www.rfc-editor.org/info/rfc8200>. [RFC8265] Saint-Andre, P. and438 error response to subsequent requests may use the previous NONCE/password to authenticate, if they are still available. o Change "401 Unauthorized" to "401 Unauthenticated" o Make clear that in some cases it is impossible to add a MI or MI2 even if the text says SHOULD NOT. C.14. Modifications between draft-ietf-tram-stunbis-08A. Melnikov, "Preparation, Enforcement, anddraft-ietf- tram-stunbis-07 o Updated listComparison ofchanges sinceInternationalized Strings Representing Usernames and Passwords", RFC5389. o More examples are automatically generated. o Message integrity truncation is fixed at a multiple of 4 bytes, because the padding will not decrease by more than this. o USERHASH contains the 32 bytes of the hash, not a character string. o Updated the example to use the USERHASH attribute8265, DOI 10.17487/RFC8265, October 2017, <https://www.rfc-editor.org/info/rfc8265>. [RFC8305] Schinazi, D. andthe modified NONCE attribute. o Updated ICEbis reference. C.15. Modifications between draft-ietf-tram-stunbis-07T. Pauly, "Happy Eyeballs Version 2: Better Connectivity Using Concurrency", RFC 8305, DOI 10.17487/RFC8305, December 2017, <https://www.rfc-editor.org/info/rfc8305>. 20.2. Informative References [Argon2] Biryukov, A., Dinu, D., Khovratovich, D., anddraft-ietf- tram-stunbis-06 o Add USERHASH attribute to carry the hashed version of the username. o Add IANA registryS. Josefsson, "The memory-hard Argon2 password hash and proof-of-work function", Work in Progress, draft-irtf- cfrg-argon2-09, November 2019. [BCP195] Sheffer, Y., Holz, R., andnonce encodingP. Saint-Andre, "Recommendations for Secure Use of Transport Layer SecurityFeatures that need to be protected from bid-down attacks. o Modified MESSAGE-INTEGRITY(TLS) andMESSAGE-INTEGRITY-SHA256 to support truncation limits (pending cryptographic review), C.16. Modifications between draft-ietf-tram-stunbis-06Datagram Transport Layer Security (DTLS)", BCP 195, RFC 7525, May 2015, <https://www.rfc-editor.org/info/bcp195>. [RFC1952] Deutsch, P., "GZIP file format specification version 4.3", RFC 1952, DOI 10.17487/RFC1952, May 1996, <https://www.rfc-editor.org/info/rfc1952>. [RFC2279] Yergeau, F., "UTF-8, a transformation format of ISO 10646", RFC 2279, DOI 10.17487/RFC2279, January 1998, <https://www.rfc-editor.org/info/rfc2279>. [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, A., Peterson, J., Sparks, R., Handley, M., anddraft-ietf- tram-stunbis-05 o Changed I-D references toE. Schooler, "SIP: Session Initiation Protocol", RFCreferences. o Changed CHANGE-ADDRESS to CHANGE-REQUEST (Errata #4233). o Added test vector3261, DOI 10.17487/RFC3261, June 2002, <https://www.rfc-editor.org/info/rfc3261>. [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations forMESSAGE-INTEGRITY-SHA256. oUNilateral Self-Address Fixing (UNSAF) Across Network Addressadditional review comments from Jonathan LennoxTranslation", RFC 3424, DOI 10.17487/RFC3424, November 2002, <https://www.rfc-editor.org/info/rfc3424>. [RFC3454] Hoffman, P. andBrandon Williams. C.17. Modifications between draft-ietf-tram-stunbis-05M. Blanchet, "Preparation of Internationalized Strings ("stringprep")", RFC 3454, DOI 10.17487/RFC3454, December 2002, <https://www.rfc-editor.org/info/rfc3454>. [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., anddraft-ietf- tram-stunbis-04 oR. Mahy, "STUN - Simple Traversal of User Datagram Protocol (UDP) Through Network Addressreview comments from Jonathan Lennox and Brandon Williams. C.18. Modifications between draft-ietf-tram-stunbis-04Translators (NATs)", RFC 3489, DOI 10.17487/RFC3489, March 2003, <https://www.rfc-editor.org/info/rfc3489>. [RFC4013] Zeilenga, K., "SASLprep: Stringprep Profile for User Names anddraft-ietf- tram-stunbis-03 o Remove SCTP. o Remove DANE. o s/MESSAGE-INTEGRITY2/MESSAGE-INTEGRITY-SHA256/ o Remove Salted SHA256 password hash. o The RTO delay between transactions is removed. o Make clear that reusing NONCE will trigger a wasted round trip. C.19. Modifications between draft-ietf-tram-stunbis-03Passwords", RFC 4013, DOI 10.17487/RFC4013, February 2005, <https://www.rfc-editor.org/info/rfc4013>. [RFC4107] Bellovin, S. anddraft-ietf- tram-stunbis-02 o SCTP prefix is now 0b00000101 instead of 0x11. o Add SCTP at various places it was needed. o Update the hash agility plan to take in account HMAC-SHA-256. o Adds the bid-down attack on message-integrity in the security section. C.20. Modifications between draft-ietf-tram-stunbis-02R. Housley, "Guidelines for Cryptographic Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, June 2005, <https://www.rfc-editor.org/info/rfc4107>. [RFC5090] Sterman, B., Sadolevsky, D., Schwartz, D., Williams, D., anddraft-ietf- tram-stunbis-01 o STUN hash algorithm agility (currently only SHA-1 is allowed). o Clarify terminology, textW. Beck, "RADIUS Extension for Digest Authentication", RFC 5090, DOI 10.17487/RFC5090, February 2008, <https://www.rfc-editor.org/info/rfc5090>. [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., andguidanceD. Wing, "Session Traversal Utilities forSTUN fragmentation. o Clarify whether it's valid to share nonces across TURN allocations. o Prevent the server to allocate the same NONCE to clients with different IP address and/or different port. This prevent sharing the nonce between TURN allocationsNAT (STUN)", RFC 5389, DOI 10.17487/RFC5389, October 2008, <https://www.rfc-editor.org/info/rfc5389>. [RFC5626] Jennings, C., Ed., Mahy, R., Ed., and F. Audet, Ed., "Managing Client-Initiated Connections inTURN. o Add reference to draft-ietf-uta-tls-bcp o Add a new attribute ALTERNATE-DOMAIN to verify the certificate oftheALTERNATE-SERVER after a 300 over (D)TLS. o The RTP delay between transactions applies only to parallel transactions, notSession Initiation Protocol (SIP)", RFC 5626, DOI 10.17487/RFC5626, October 2009, <https://www.rfc-editor.org/info/rfc5626>. [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using Relays around NAT (TURN): Relay Extensions toserial transactions. That prevents a 3RTT delay between the first transactionSession Traversal Utilities for NAT (STUN)", RFC 5766, DOI 10.17487/RFC5766, April 2010, <https://www.rfc-editor.org/info/rfc5766>. [RFC5769] Denis-Courmont, R., "Test Vectors for Session Traversal Utilities for NAT (STUN)", RFC 5769, DOI 10.17487/RFC5769, April 2010, <https://www.rfc-editor.org/info/rfc5769>. [RFC5780] MacDonald, D. andthe second transactionB. Lowekamp, "NAT Behavior Discovery Using Session Traversal Utilities for NAT (STUN)", RFC 5780, DOI 10.17487/RFC5780, May 2010, <https://www.rfc-editor.org/info/rfc5780>. [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B., and A. Roach, "TCP Candidates withlong term authentication. o Add text saying ORIGIN can increase a request size beyond the MTUInteractive Connectivity Establishment (ICE)", RFC 6544, DOI 10.17487/RFC6544, March 2012, <https://www.rfc-editor.org/info/rfc6544>. [RFC7231] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer Protocol (HTTP/1.1): Semantics andso requireContent", RFC 7231, DOI 10.17487/RFC7231, June 2014, <https://www.rfc-editor.org/info/rfc7231>. [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing anSCTPoUDP transport. o Move the AcknowledgmentsIANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, June 2017, <https://www.rfc-editor.org/info/rfc8126>. [RFC8264] Saint-Andre, P. andContributor sections to the endM. Blanchet, "PRECIS Framework: Preparation, Enforcement, and Comparison ofthe document,Internationalized Strings inaccordance withApplication Protocols", RFC7322 section 4. C.21. Modifications between draft-ietf-tram-stunbis-018264, DOI 10.17487/RFC8264, October 2017, <https://www.rfc-editor.org/info/rfc8264>. [RFC8445] Keranen, A., Holmberg, C., anddraft-ietf- tram-stunbis-00 o Add negotiation mechanismJ. Rosenberg, "Interactive Connectivity Establishment (ICE): A Protocol fornew password algorithms. o Describe the MESSAGE-INTEGRITY/MESSAGE-INTEGRITY2 protocol. o Add supportNetwork Address Translator (NAT) Traversal", RFC 8445, DOI 10.17487/RFC8445, July 2018, <https://www.rfc-editor.org/info/rfc8445>. [RFC8446] Rescorla, E., "The Transport Layer Security (TLS) Protocol Version 1.3", RFC 8446, DOI 10.17487/RFC8446, August 2018, <https://www.rfc-editor.org/info/rfc8446>. [STUN-PMTUD] Petit-Huguenin, M., Salgueiro, G., and F. Garrido, "Path MTU Discovery Using Session Traversal Utilities forSCTPNAT (STUN)", Work in Progress, draft-ietf-tram-stun-pmtud-14, November 2019. [UAX15] Unicode Standard Annex #15, "Unicode Normalization Forms", edited by Mark Davis and Ken Whistler. An integral part of The Unicode Standard, <http://unicode.org/reports/tr15/>. Appendix A. C Snippet tosolve the fragmentation problem. o Merge RFC 7350: * Split the "Sending over..." sectionsDetermine STUN Message Types Given a 16-bit STUN message type value in3. * Add DTLS-over-UDP as transport. * Updatehost byte order in msg_type parameter, below are C macros to determine thecipher suitesSTUN message types: <CODE BEGINS> #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) <CODE ENDS> A function to convert method andcipher/compression restrictions. *class into a message type: <CODE BEGINS> int type(int method, int cls) { return (method & 0x1F80) << 2 | (method & 0x0070) << 1 | (method & 0x000F) | (cls & 0x0002) << 7 | (cls & 0x0001) << 4; } <CODE ENDS> Astuns uri with an IP address is rejected. * Replace most offunction to extract theRFC 3489 compatibility by a referencemethod from the message type: <CODE BEGINS> int method(int type) { return (type & 0x3E00) >> 2 | (type & 0x00E0) >> 1 | (type & 0x000F); } <CODE ENDS> A function to extract the class from the message type: <CODE BEGINS> int cls(int type) { return (type & 0x0100) >> 7 | (type & 0x0010) >> 4; } <CODE ENDS> Appendix B. Test Vectors This sectionin RFC 5389. * Updateaugments theSTUN Usageslist of test vectors defined in [RFC5769] withtransport applicability. o Merge RFC 7064: * DNS discovery is done from the URI. * Reorganized the text about default ports. o Add more C snippets. o Make clear thatMESSAGE-INTEGRITY-SHA256. All thecached RTO is discarded only if there is no new translations for 10 minutes. C.22. Modifications between draft-salgueiro-tram-stunbis-02 and draft- ietf-tram-stunbis-00 o Draft adopted as WG item. C.23. Modifications between draft-salgueiro-tram-stunbis-02formats anddraft- salgueiro-tram-stunbis-01 o Add definitiondefinitions listed in Section 2 ofMESSAGE-INTEGRITY2. o Update text[RFC5769] apply here. B.1. Sample Request with Long-Term Authentication with MESSAGE- INTEGRITY-SHA256 andreference from RFC 2988 to RFC 6298. o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). o Fix the figure forUSERHASH This request uses theUNKNOWN-ATTRIBUTES (Errata #2972). o Fix section numberfollowing parameters: Username: "<U+30DE><U+30C8><U+30EA><U+30C3><U+30AF><U+30B9>" (without quotes) unaffected by OpaqueString [RFC8265] processing Password: "The<U+00AD>M<U+00AA>tr<U+2168>" andmake clear that the original domain name is used for the server certificate verification. This is consistent with what RFC 5922 (section 4) is doing. (Errata #2010) o Remove text transitioning from RFC 3489. o Add definition of MESSAGE-INTEGRITY2. o Update text"TheMatrIX" (without quotes) respectively before andreference from RFC 2988 to RFC 6298. o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). o Fix section numberafter OpaqueString [RFC8265] processing Nonce: "obMatJos2AAACf//499k954d6OL34oL9FSTvy64sA" (without quotes) Realm: "example.org" (without quotes) 00 01 00 9c Request type andmake clear that the original domain name is used for the server certificate verification. This is consistent with what RFC 5922 (section 4) is doing. (Errata #2010) C.24. Modifications between draft-salgueiro-tram-stunbis-01message length 21 12 a4 42 Magic cookie 78 ad 34 33 } c6 ad 72 c0 } Transaction ID 29 da 41 2e } 00 1e 00 20 USERHASH attribute header 4a 3c f3 8f } ef 69 92 bd } a9 52 c6 78 } 04 17 da 0f } Userhash value (32 bytes) 24 81 94 15 } 56 9e 60 b2 } 05 c4 6e 41 } 40 7f 17 04 } 00 15 00 29 NONCE attribute header 6f 62 4d 61 } 74 4a 6f 73 } 32 41 41 41 } 43 66 2f 2f } 34 39 39 6b } Nonce value anddraft- salgueiro-tram-stunbis-00 o Restore the RFC 5389 text. o Add list of open issues.padding (3 bytes) 39 35 34 64 } 36 4f 4c 33 } 34 6f 4c 39 } 46 53 54 76 } 79 36 34 73 } 41 00 00 00 } 00 14 00 0b REALM attribute header 65 78 61 6d } 70 6c 65 2e } Realm value (11 bytes) and padding (1 byte) 6f 72 67 00 } 00 1c 00 20 MESSAGE-INTEGRITY-SHA256 attribute header e4 68 6c 8f } 0e de b5 90 } 13 e0 70 90 } 01 0a 93 ef } HMAC-SHA256 value cc bc cc 54 } 4c 0a 45 d9 } f8 30 aa 6d } 6f 73 5a 01 } Acknowledgements Thanks to Michael Tuexen, Tirumaleswar Reddy, Oleg Moskalenko, Simon Perreault, Benjamin Schwartz, Rifaat Shekh-Yusef, Alan Johnston, Jonathan Lennox, Brandon Williams, Olle Johansson, Martin Thomson, Mihaly Meszaros, Tolga Asveren, Noriyuki Torii, Spencer Dawkins, Dale Worley, Matthew Miller, Peter Saint-Andre, Julien Elie, Mirja Kuehlewind, Eric Rescorla, Ben Campbell, Adam Roach, Alexey Melnikov, and Benjamin Kaduk for the comments, suggestions, and questions that helped improve this document. TheauthorsAcknowledgements section of RFC 5389 appeared as follows: The authors would like to thank Cedric Aoun, Pete Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, Magnus Westerlund, Miguel Garcia, Bruce Lowekamp, and Chris Sullivan for their comments, and Baruch Sterman and Alan Hawrylyshen for initial implementations. Thanks for Leslie Daigle, Allison Mankin, Eric Rescorla, and Henning Schulzrinne for IESG and IAB input on this work. Contributors Christian Huitema and Joel Weinberger were originalco-authorscoauthors of RFC 3489. Authors' Addresses Marc Petit-Huguenin Impedance Mismatch Email: marc@petit-huguenin.org Gonzalo Salgueiro Cisco 7200-12 Kit Creek Road Research Triangle Park, NC 27709USUnited States of America Email: gsalguei@cisco.com Jonathan Rosenberg Five9 Edison, NJUSUnited States of America Email: jdrosen@jdrosen.net URI: http://www.jdrosen.net Dan Wing Citrix Systems, Inc. United States of America Email: dwing-ietf@fuggles.com Rohan Mahy Unaffiliated Email: rohan.ietf@gmail.com Philip Matthews Nokia 600 March Road Ottawa, Ontario K2K 2T6 Canada Phone: 613-784-3139 Email: philip_matthews@magma.ca