BEHAVE Working Group J. Rosenberg Internet-Draft Cisco Obsoletes: 3489 (if approved) C. Huitema Intended status: Standards Track Microsoft Expires:September 6, 2007January 9, 2008 R. Mahy Plantronics P. Matthews Avaya D. Wing CiscoSystems March 5,July 8, 2007 Session Traversal Utilities for (NAT) (STUN)draft-ietf-behave-rfc3489bis-06draft-ietf-behave-rfc3489bis-07 Status of this Memo By submitting this Internet-Draft, each author represents that any applicable patent or other IPR claims of which he or she is aware have been or will be disclosed, and any of which he or she becomes aware will be disclosed, in accordance with Section 6 of BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet- Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt. The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. This Internet-Draft will expire onSeptember 6, 2007.January 9, 2008. Copyright Notice Copyright (C) The IETF Trust (2007). Abstract Session Traversal Utilities for NAT (STUN) is alightweightprotocol that serves as a tool forapplicationother protocols in dealing with NAT traversal. Itallows a clientcan be used by an endpoint to determine the IP address and port allocated tothemit by aNAT and to keep NAT bindings open.NAT. It can alsoserve as abe used to checkforconnectivity betweena clienttwo endpoints, and as aserver in the presence of NAT, and for the clientkeep-alive protocol todetect failure of the server.maintain NAT bindings. STUN works with many existing NATs, and does not require any special behavior from them.AsSTUN is not aresult,NAT traversal solution by itself. Rather, itallowsis awide variety of applicationstool towork through existingbe used in the context of a NATinfrastructure.traversal solution. This is an important change from the previous version of this specification (RFC 3489), which presented STUN as a complete solution. This document obsoletes RFC 3489. Table of Contents 1.Applicability StatementIntroduction . . . . . . . . . . . . . . . . . . .5 2. Introduction. . . . . . 4 2. Evolution from RFC 3489 . . . . . . . . . . . . . . . . . . .54 3.TerminologyOverview of Operation . . . . . . . . . . . . . . . . . . . . 5 4. Terminology . . . . .6 4. Definitions. . . . . . . . . . . . . . . . . . . . 8 5. Definitions . . . . .6 5. Overview of Operation. . . . . . . . . . . . . . . . . . . .79 6. STUN Message Structure . . . . . . . . . . . . . . . . . . . .1110 7.STUN Transactions .Base Protocol Procedures . . . . . . . . . . . . . . . . . . . 12 7.1. Forming a Request or an Indication . .14 7.1. Request/Response Transactions. . . . . . . . . 12 7.2. Sending the Request or Indication . . . . .14 7.2. Indications. . . . . . . 13 7.2.1. Sending over UDP . . . . . . . . . . . . . . . .15 8. Client Behavior. . . 13 7.2.2. Sending over TCP or TLS-over-TCP . . . . . . . . . . . 14 7.3. Receiving a STUN Message . . . . . . . . .15 8.1. Discovery. . . . . . . 15 7.3.1. Processing a Request . . . . . . . . . . . . . . . . .15 8.2. Obtaining16 7.3.1.1. Forming aShared Secret .Success or Error Response . . . . . . . 17 7.3.1.2. Sending the Success or Error Response . . . . . . 17 7.3.2. Processing an Indication . .16 8.3. Request/Response Transactions. . . . . . . . . . . . . 18 7.3.3. Processing a Success Response .17 8.3.1. Formulating the Request Message. . . . . . . . . . .17 8.3.2.18 7.3.4. ProcessingResponsesan Error Response . . . . . . . . . . . . . 18 8. FINGERPRINT Mechanism . . . .19 8.3.3. Timeouts. . . . . . . . . . . . . . . . 19 9. DNS Discovery of a Server . . . . . . .22 8.4. Indication Transactions. . . . . . . . . . . 19 10. Authentication and Message-Integrity Mechanisms . . . . . .22 9. Server Behavior. 20 10.1. Short-Term Credential Mechanism . . . . . . . . . . . . . 21 10.1.1. Forming a Request or Indication . . . . . . . . .23 9.1. Request/Response Transactions. . 21 10.1.2. Receiving a Request or Indication . . . . . . . . . . 21 10.1.3. Receiving a Response . .23 9.1.1. Receive Request Message. . . . . . . . . . . . . . .23 9.1.2. Constructing the Response22 10.2. Long-term Credential Mechanism . . . . . . . . . . . . . 23 10.2.1. Forming a Request .26 9.1.3. Sending the Response. . . . . . . . . . . . . . . . .27 9.2. Indication Transactions24 10.2.1.1. First Request . . . . . . . . . . . . . . . . .27 10. Demultiplexing of STUN and Application Traffic. 24 10.2.1.2. Subsequent Requests . . . . . . .28 11. STUN Attributes. . . . . . . . 24 10.2.2. Receiving a Request . . . . . . . . . . . . . . .29 11.1. MAPPED-ADDRESS. . 24 10.2.3. Receiving a Response . . . . . . . . . . . . . . . . . 25 11. ALTERNATE-SERVER Mechanism . .29 11.2. USERNAME. . . . . . . . . . . . . . . . 26 12. Backwards Compatibility with RFC 3489 . . . . . . . .30 11.3. PASSWORD. . . . 26 12.1. Changes to Client Processing . . . . . . . . . . . . . . 27 12.2. Changes to Server Processing . . . . . .31 11.4. MESSAGE-INTEGRITY. . . . . . . . 27 13. STUN Usages . . . . . . . . . . . .31 11.5. FINGERPRINT. . . . . . . . . . . . . 28 14. STUN Attributes . . . . . . . . . .31 11.6. ERROR-CODE. . . . . . . . . . . . . 29 14.1. MAPPED-ADDRESS . . . . . . . . . .31 11.7. REALM. . . . . . . . . . . 30 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . .33 11.8. NONCE. . . . 31 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . .33 11.9. UNKNOWN-ATTRIBUTES. . 32 14.4. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . .33 11.10. XOR-MAPPED-ADDRESS. . . 32 14.5. FINGERPRINT . . . . . . . . . . . . . . . .34 11.11. SERVER. . . . . . . 33 14.6. ERROR-CODE . . . . . . . . . . . . . . . . . .35 11.12. ALTERNATE-SERVER. . . . . 33 14.7. REALM . . . . . . . . . . . . . . .35 11.13. REFRESH-INTERVAL. . . . . . . . . . . 34 14.8. NONCE . . . . . . . . .35 12. STUN Usages. . . . . . . . . . . . . . . . . 35 14.9. UNKNOWN-ATTRIBUTES . . . . . . . .36 12.1. Binding Discovery. . . . . . . . . . . 35 14.10. SERVER . . . . . . . . .36 12.1.1. Applicability. . . . . . . . . . . . . . . . 35 14.11. ALTERNATE-SERVER . . . .36 12.1.2. Client Discovery of Server. . . . . . . . . . . . . .37 12.1.3. Server Determination of Usage. . 36 15. Security Considerations . . . . . . . . . .38 12.1.4. New Requests or Indications. . . . . . . . . 36 15.1. Attacks against the Protocol . . . .38 12.1.5. New Attributes. . . . . . . . . . 36 15.1.1. Outside Attacks . . . . . . . . . .38 12.1.6. New Error Response Codes. . . . . . . . . 36 15.1.2. Inside Attacks . . . . . .38 12.1.7. Client Procedures. . . . . . . . . . . . . . 36 15.2. Attacks Affecting the Usage . . . .38 12.1.8. Server Procedures. . . . . . . . . . . 36 15.2.1. Attack I: DDoS Against a Target . . . . . . .38 12.1.9. Security Considerations for Binding Discovery. . . .38 12.2. NAT Keepalives37 15.2.2. Attack II: Silencing a Client . . . . . . . . . . . . 37 15.2.3. Attack III: Assuming the Identity of a Client . . . . 37 15.2.4. Attack IV: Eavesdropping . . . . .39 12.2.1. Applicability. . . . . . . . . . 38 15.3. Hash Agility Plan . . . . . . . . . .39 12.2.2. Client Discovery of Server. . . . . . . . . . 38 16. IAB Considerations . . . .39 12.2.3. Server Determination of Usage. . . . . . . . . . . .39 12.2.4. New Requests or Indications. . . . . . 38 17. IANA Considerations . . . . . . .39 12.2.5. New Attributes. . . . . . . . . . . . . . 39 17.1. STUN Methods Registry . . . . . .40 12.2.6. New Error Response Codes. . . . . . . . . . . . 39 17.2. STUN Attribute Registry . . .40 12.2.7. Client Procedures. . . . . . . . . . . . . . 39 17.3. STUN Error Code Registry . . . .40 12.2.8. Server Procedures. . . . . . . . . . . . 40 18. Changes Since RFC 3489 . . . . . .40 12.2.9. Security Considerations for NAT Keepalives. . . . . .40 12.3. Short-Term Password. . . . . . . . 40 19. Acknowledgements . . . . . . . . . . .41 12.3.1. Applicability. . . . . . . . . . . .. . . . . . . . 41 12.3.2. Client Discovery of Server . . . .42 20. References . . . . . . . . . .41 12.3.3. Server Determination of Usage . . . . .. . . . . . .42 12.3.4. New Requests or Indications . . . .. . . . . . . . . 4212.3.5. New Attributes . . . . . . . . . . . . . . . . . . .20.1. Normative References .43 12.3.6. New Error Response Codes. . . . . . . . . . . . . . .43 12.3.7. Client Procedures. . 42 20.2. Informational References . . . . . . . . . . . . . . . . 4312.3.8. Server Procedures . . . . . . . . . . . . . . .Appendix A. C Snippet to Determine STUN Message Types . . .43 12.3.9. Security Considerations for Short-Term Password. . . 4413. Security Considerations . . . . . . . . . . . . . . . . .Authors' Addresses . .45 13.1. Attacks on STUN. . . . . . . . . . . . . . . . . . . . .45 13.1.1. Attack I: DDoS Against a Target. 44 Intellectual Property and Copyright Statements . . . . . . . . . . 4613.1.2. Attack II: Silencing1. Introduction The protocol defined in this specification, Session Traversal Utilities for NAT, provides aClient . . . . . . . . . . . . 46 13.1.3. Attack III: Assuming the Identitytoolkit of functions for dealing with NATs. It provides aClient . . . . 46 13.1.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . . 46 13.2. Launchingmeans for an endpoint to determine theAttacks . . . . . . . . . . . . . . . . . . 47 13.2.1. Approach I: CompromiseIP address and port allocated by aLegitimate STUN Server . . . 47 13.2.2. Approach II: DNS Attacks . . . . . . . . . . . . . . . 47 13.2.3. Approach III: Rogue Router orNAT. . . . . . . . . . 48 13.2.4. Approach IV: Man in the Middle . . . . . . . . . . . . 48 13.2.5. Approach V: Response Injection Plus DoS . . . . . . . 49 13.2.6. Approach VI: Duplication . . . . . . . . . . . . . . . 49 13.3. Countermeasures . . . . . . . . . . . . . . . . . . . . . 50 13.4. Residual Threats . . . . . . . . . . . . . . . . . . . . 51 14. IAB Considerations . . . . . . . . . . . . . . . . . . . . . . 51 14.1. Problem Definition . . . . . . . . . . . . . . . . . . . 52 14.2. Exit Strategy . . . . . . . . . . . . . . . . . . . . . . 52 14.3. Brittleness Introduced by STUN . . . . . . . . . . . . . 52 14.4. Requirements for a Long Term Solution . . . . . . . . . . 54 14.5. Issues with Existing NAPT Boxes . . . . . . . . . . . . . 55 15. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 55 15.1. STUN Methods Registry . . . . . . . . . . . . . . . . . . 55 15.2. STUN Attribute Registry . . . . . . . . . . . . . . . . . 55 16. Changes Since RFC 3489 . . . . . . . . . . . . . . . . . . . . 56 17. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 57 18. References . . . . . . . . . . . . . . . . . . . . . . . . . . 57 18.1. Normative References . . . . . . . . . . . . . . . . . . 57 18.2. Informational References . . . . . . . . . . . . . . . . 58 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 59 Intellectual Property and Copyright Statements . . . . . . . . . . 61 1. Applicability Statement This protocol is not a cure-all for the problems associated with NAT. It is a tool that is typically used in conjunction with other protocols, such as Interactive Connectivity Establishment (ICE) [13] for a more complete solution. The binding discovery usage, defined by this specification, can be used by itself with numerous application protocols as a solution for NAT traversal. However, when used in that way, STUN will not work with applications that require incoming TCP connections through NAT. It will allow incoming UDP packets through NAT, but only through a subset of existing NAT types. In particular, the STUN binding usage by itself does not enable incoming UDP packets through NATs whose mapping property is address dependent or address and port dependent [14]. Furthermore, the binding usage, when used by itself, does not work when a client is communicating with a peer which happens to be behind the same NAT. Nor will it work when the STUN server is not in a common shared address realm. The STUN relay usage, defined in [16], allows a client to obtain an IP address and port that actually reside on the STUN server. The STUN relay usage, when used by itself, eliminates all of the limitations of using the binding usage by itself, as described above. However, it requires a server to act as a relay for application traffic, which can be expensive to provide, operate, and manage. For multimedia protocols based on the offer/answer model [22], including the Session Initiation Protocol (SIP) [11], Interactive Connectivity Establishment (ICE) uses both the binding usage and relay usage, and furthermore defines a connectivity check usage to help determine which transport address to use. Implementers should be aware of the specific deployment scenarios and the specific protocol (SIP, etc) being used to determine whether NAT traversal can be facilitated by STUN and which STUN usages are required. 2. Introduction Network Address Translators (NATs), while providing many benefits, also come with many drawbacks. The most troublesome of those drawbacks is the fact that they break many existing IP applications and make it difficult to deploy new ones. Guidelines have been developed [20] that describe how to build "NAT friendly" protocols, but many protocols simply cannot be constructed according to those guidelines. Examples of such protocols include almost all peer-to- peer protocols such as multimedia communications, file sharing and games. To combat this problem, Application Layer Gateways (ALGs) have been embedded in NATs. ALGs perform the application layer functions required for a particular protocol to traverse a NAT. Typically, this involves rewriting application layer messages to contain translated addresses, rather than the ones inserted by the sender of the message. ALGs have serious limitations, including scalability, reliability, and speed of deploying new applications. Many existing proprietary protocols, such as those for online games (such as the games described in RFC3027 [21]) and Voice over IP, have developed tricks that allow them to operate through NATs without changing those NATs and without relying on ALG behavior in the NATs. This document takes some of those ideas and codifies them into an interoperable protocol that can meet the needs of many applications. The protocol described here, Session Traversal Utilities for NAT (STUN), provides a toolkit of functions. These functions allow entities behind a NAT to learn the address bindings allocated by the NAT and to keep those bindings open. STUN requires no changes to NATs and works with an arbitrary number of NATs in tandem between the application entity and the public Internet. 3. Terminology In this document, the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in BCP 14, RFC 2119 [1] and indicate requirement levels for compliant STUN implementations. 4. Definitions STUN Client: A STUN client (also just referred to as a client) is an entity that generates STUN requests and receives STUN responses. Clients can also generate STUN indications. STUN Server: A STUN Server (also just referred to as a server) is an entity that receives STUN requests and sends STUN responses. Servers also send STUN indications. Transport Address: The combination of an IP address and transport protocol (such as UDP or TCP) port. 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 binding 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: The source IP address and port of the STUN Binding Request packet received by the STUN server and inserted into the mapped address attribute (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) of the Binding Response message. 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 enrolles 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 which represent a shared secret between client and server. 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 SIP dialog). The specific scope of a short term credential is defined by the application usage. A short term credential can be obtained from a Shared Secret request, though other mechanisms are possible. Short Term Password: The password component of a short term credential. 5. Overview of Operation This section is descriptive only. Normative behavior is described in Section 8 and Section 9 /-----\ // STUN \\ | Server | \\ // \-----/ +--------------+ Public Internet ................| NAT 2 |....................... +--------------+ +--------------+ Private NET 2 ................| NAT 1 |....................... +--------------+ /-----\ // STUN \\ | Client | \\ // Private NET 1 \-----/ Figure 1: Typical STUN Server Configuration The typical STUN configuration is shown in Figure 1. A STUN client 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 STUN server resides on the public Internet. STUN is a simple client-server protocol. It supports two types of transactions. One is a request/response transaction in which client sends a request to a server, and the server returns a response. The second are indications that are initiated by the server or the client and do not elicit a response. There are two types of requests defined in this specification - Binding Requests and Shared Secret Requests. There are no indications defined by this specification. Binding Requests are sent from the client towards the 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 a result, the source transport address of the request received by the server will be the mapped address created by the NAT closest to the server. The STUN server copies that source transport address into a STUN Binding Response and sends it back to the source transport address of the STUN request. Every type of NAT will route that response so that it arrives at the STUN client. From this response, the client knows its transport address allocated by the outermost NAT towards the STUN server. STUN provides several mechanisms for authentication and message integrity. The client and server can share a pre-provisioned shared secret, which is used for a digest challenge/response authentication operation. This is known as a long-term credential or long-term shared secret. Alternatively, if the shared secret is obtained by some out-of-bands means and has a lifetime that is temporally scoped, a simple HMAC is provided, without a challenge operation. This is known as a short term credential or short term password. Short-term passwords are useful when there is no long-term relationship with a STUN server and thus no long-term password is shared between the STUN client and STUN server. Even if there is a long-term password, the issuance of a short-term password is useful to prevent dictionary attacks. STUN itself provides a mechanism for obtaining such short term credentials, using the Shared Secret Request. Shared Secret requests are sent over TLS [5] over TCP. Shared Secret Requests ask the server to return a temporary username and password that can be used in subsequent STUN requests. There are many ways in which these basic mechanisms can be used to accomplish a specific task. As a result, STUN has the notion of a usage. A usage is a specific use case for the STUN protocol. The usage will define what the client does with the mapped address it receives, defines when the client would send Binding requests and why, and would constrain the set of authentication mechanisms or attributes that get used in that usage. STUN usages can also define new attributes and message types, if needed. This specification defines three STUN usages - binding discovery, NAT keepalives, and short-term password. The binding discovery usage is sometimes referred to as 'classic STUN,' since it is the usage originally envisioned in RFC 3489 [15], the predecessor to this specification. The purpose of the binding discovery usage is for the client to obtain a transport address at which it is reachable. The client can include these transport addresses in application layer signaling messages such as the Session Description Protocol (SDP) [19] (present in the body of SIP messages), where it indicates where the client wants to receive Real Time Transport Protocol (RTP [17]) traffic. In this usage, the STUN server is typically located on the public Internet and run by the service provider offering the application service (such as a SIP provider), though this need not be the case. The client would utilize the STUN request just prior to sending a protocol message (such as a SIP INVITE request or 200 OK response) that requires the client to embed its transport address. In the binding keepalive usage, a client sends an application protocol message (such as a SIP REGISTER message) to a server. The server notes the source transport address of the request, and remembers it. Later on, if it needs to reach the client, it sends a message to that transport address. However, this message will only be received by the client if the binding in the NAT is still alive. Since bindings allocated by NAT expire unless refreshed, the client must generate keepalive messages toward the server to refresh the binding. Rather than use expensive application layer messages, a STUN binding request is sent by the client to the server, and is sent to the exact same transport address used by the server for the application protocol. In the case of SIP, this would typically mean port 5060 or 5061. This has the effect of keeping the bindings in the NAT alive. The STUN binding responses also inform the client that the server is still responsive, and also inform the client if its transport address towards the server have changed (its reflexive transport address), in which case it may need application layer protocol messaging to update its transport address as seen by the server. The binding keepalive usage is used by the SIP outbound mechanism, for example [18]. These two usages all utilize the same Binding Request message, and all require the same basic processing on the server. They differ only in where the server is (a standalone server in the network, or embedded in an application layer server), when the Binding Request is used and what the client does with the mapped address that is returned. The short-term password usage makes use of the Shared Secret request and response, and allows a client to obtain a temporary set of credentials to authenticate itself with the STUN server. The credentials obtained from this usage can be used in requests for any other usage. Some usages (such as the binding keepalive) require STUN messages to be sent on the same transport address as some application protocol, such as RTP or SIP. To facilitate the demultiplexing of the two, STUN defines a special field in the message called the magic cookie, which is a fixed 32 bit value that identifies STUN traffic. STUN requests also contain a fingerprint, which is a cryptographic hash of the message, that allow for validation that the message was a STUN request and not a data packet that happened to have the same 32 bit value in the right place in the message. STUN servers can be discovered through DNS, though this is not necessary in all usages. For those usages where it is needed, STUN makes use of SRV records [3] to facilitate discovery. This discovery allows for different transport addresses to be found for different usages. 6. STUN Message Structure STUN messages are TLV (type-length-value) encoded using big endian (network ordered) binary. STUN messages are encoded using binary fields. All integer fields are carried in network byte order, that is, most significant byte (octet) first. This byte order is commonly known as big-endian. The transmission order is described in detail in Appendix B of RFC791 [2]. Unless otherwise noted, numeric constants are in decimal (base 10). All STUN messages start with a single STUN header followed by a STUN payload. The payload is a series of STUN attributes, the set of which depends on the message type. The STUN header contains a STUN message type, magic cookie, transaction ID, and length. The length indicates the total length of the STUN payload, not including the 20-byte header. There are two types of transactions in STUN - request/response transactions, which utilize a request message and a response message, and indication transactions, which utilizes a single indication message. Furthermore, responses are broken into two types - success responses and error responses. Two bits in the message type field of the STUN header indicate the class of the message - whether the message is a request, a success response, an indication, or a failure response. An additional 12 bits in the message type indicate the method, which is the primary function of the message. This specification defines two methods, Binding and Shared Secret. STUN Requests are sent reliably. STUN can run over UDP, TCP or TCP/ TLS. When run over UDP, STUN requests are retransmitted in order to achieve reliability. The transaction ID is used to correlate requests and responses. An indication message can be sent from the client to the server, or from the server to the client. Indication messages can be sent over TCP or UDP. STUN itself does not provide reliability for these messages, though they will be delivered reliably when sent over TCP. The transaction ID is used to distinguish indication messages. All STUN messages consist of a 20 byte header: 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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 2: Format of STUN Message Header The most significant two bits of every STUN message are both zeroes. This, combined with the magic cookie and the fingerprint attribute, aid in differentiating STUN packets from other protocols when STUN is multiplexed with other protocols on the same port. The message type field is decomposed further into the following structure: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |M|M|M|M|M|C|M|M|M|C|M|M|M|M| |1|1|9|8|7|1|6|5|4|0|3|2|1|0| |1|0| | | | | | | | | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 3: Format of STUN Message Type Field M11 through M0 represent a 12-bit encoding of the method. C1 through C0 represent a 2 bit encoding of the class. A class of 0 is a Request, a class of 1 is an indication, a class of 2 is a success response, and a class of 3 is an error response. This specification defines two methods, Binding and Shared Secret. Their method values are enumerated in Section 15. The message length is the size, in bytes, of the message not including the 20 byte STUN header. The magic cookie is a fixed value, 0x2112A442. In the previous version of this specification [15] this field was part of the transaction ID. This fixed value is used as part of the identification of a STUN message when STUN is multiplexed with other protocols on the same port, as is done for example in [13] and [18]. The magic cookie additionally indicates the STUN client is compliant with this specification. The magic cookie is present in all STUN messages -- requests, success responses, error responses and indications. The transaction ID is a 96 bit identifier. STUN transactions are identified by their unique 96-bit transaction ID. For request/ response transactions, the transaction ID is chosen by the STUN client and MUST be unique for each new STUN transaction generated by that STUN client. The transaction ID MUST be uniformly and randomly distributed between 0 and 2**96 - 1. The large range is needed because the transaction ID serves as a form of randomization, helping to prevent replays of previously signed responses from the server. A reponse to the STUN request, whether it be a success or error response, carries the same transaction ID as the request. Indications are also identified by their transaction ID. The transaction ID there MUST also be uniformly and randomly distributed between 0 and 2**96 - 1.As with requests, the value is chosen by the server and MUST be unique for each unique indication generated by the server. Unless a request or indication is bit-wise identical to a previous request, and was sent to the same server from the same transport address, a client MUST choose a new transaction ID for it. After the STUN header are zero or more attributes. Each attribute is TLV encoded, with a 16 bit type, 16 bit length, and variable value. Each STUN attribute ends on a 32 bit boundary: 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 .... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 4: Format of STUN Attributes The Length refers to the length of the actual useful content of the Value portion of the attribute, measured in bytes. Since STUN aligns attributes on 32 bit boundaries, attributes whose content is not a multiple of 4 bytes are padded with 1, 2 or 3 bytes of padding so that they are a multiple of 4 bytes. Such padding is only needed with attributes that take freeform strings, such as USERNAME and PASSWORD. For attributes that contain more structured data, the attributes are constructed to align on 32 bit boundaries. The value in the Length field refers to the length of the Value part of the attribute prior to padding - i.e., the useful content. Consequently, when parsing messages, implementations will need to round up the Length field to the nearest multiple of four in order to find the start of the next attribute. The attribute types defined in this specification are in Section 11 . 7. STUN Transactions STUN defines two types of transactions - request/response transactions and indication transactions. 7.1. Request/Response Transactions STUN clients are allowed to pipeline STUN requests. That is, a STUN client MAY have multiple outstanding STUN requests with different transaction IDs and not wait for completion of a STUN request/ response exchange before sending another STUN request. When running STUN over UDP it is possible that the STUN request or its response might be dropped by the network. Reliability of STUN request message types is accomplished through client retransmissions. Clients SHOULD retransmit the request starting with an interval of RTO, doubling after each retransmission. RTO is an estimate of the round-trip-time, and is computed as described in RFC 2988 [8], with two exceptions. First, the initial value for RTO SHOULD be configurable (rather than the 3s recommended in RFC 2988). In fixed- line access links, a value of 100ms is RECOMMENDED. Secondly, the value of RTO MUST NOT be rounded up to the nearest second. Rather, a 1ms accuracy MUST be maintained. As with TCP, the usage of Karn's algorithm is RECOMMENDED. When applied to STUN, it means that RTT estimates SHOULD NOT be computed from STUN transactions which result in the retransmission of a request. The value for RTO SHOULD be cached by an agent after the completion of the transaction, and used as the starting value for RTO for the next transaction to the same host (based on equality of IP address). The value SHOULD be considered stale and discarded after 10 minutes. Retransmissions continue until a response is received, or a total of 7 requests have been sent. If no response is received by 1.6 seconds after the last request has been sent, the client SHOULD consider the transaction to have failed. A STUN transaction over UDP is also considered failed if there has been a transport failure of some sort, such as a fatal ICMP error. For example, assuming an RTO of 100ms, requests would be sent at times 0ms, 100ms, 300ms, 700ms, 1500ms, 3100ms, and 6300ms. At 7900ms, the agent would consider the transaction to have timed out if no response has been received. When running STUN over TCP, TCP is responsible for ensuring delivery. The STUN application SHOULD NOT retransmit STUN requests when running over TCP. If the client has not received a response after 7900ms, it considers the transaction to have timed out. Regardless of whether TCP or UDP was used for the transaction, if a failure occurs and the client has other servers it can reach (as a consequence of an SRV query which provides a multiplicity of STUN servers Section 8.1, for example), the client SHOULD create a new request, which is identical to the previous, but has a different transaction ID (and consequently a different MESSAGE INTEGRITY and/or FINGERPRINT attribute). 7.2. Indications Indications are sent from the client to the server, or from the server to the client. Though no indications are used by this specification, they are used by the STUN relay usage [16]. When sent over UDP, there are no retransmissions, and reliability is not provided. When sent over TCP, reliability is provided by TCP. Regardless of whether TCP or UDP was used for the indication, if a failure occurs (due to a fatal ICMP error or TCP error), and the client has other servers it can reach (as a consequence of an SRV query which provides a multiplicity of STUN servers Section 8.1, for example), the client SHOULD create a new indication, which is identical to the previous, but has a different transaction ID (and consequently a different MESSAGE INTEGRITY and/or FINGERPRINT attribute). 8. Client Behavior Client behavior can be broken down into several steps. The first is discovery of the STUN server. The next is obtaining a shared secret. For request/response transactions, the next steps are formulating the request and processing the response. For indication transactions, the next step is formulating the indication. 8.1. Discovery Unless stated otherwise by a STUN usage, DNS is used to discover the STUN server following these procedures. The client will be configured with a domain name of the provider of the STUN servers. This domain name is resolved to a transport address using the SRV procedures specified in RFC2782 [3]. The mechanism for configuring the STUN client with the domain name to look up is not in scope of this document. The DNS SRV service name depends on the application usage. For the binding usage, the service name is "stun". The protocol can be "udp" for UDP, "tcp" for TCP and "tls" for TLS over TCP. For the short term password application usage, the service name is "stun-pass". The protocol is always "tls" for TLS over TCP. The binding keepalive usage always starts with a transport address, so no DNS SRV service names are defined for it. New STUN usages MAY define additional DNS SRV service names. These SHOULD start with "stun". The procedures of RFC 2782 are followed to determine the server to contact. RFC 2782 spells out the details of how a set of SRV records are sorted and then tried. However, RFC2782 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; those details for STUN are described in Section 8.3.3. A STUN server supporting multiple usages (such as the short term password and binding discovery usage) MAY use the same ports for different usages, as long as ports are not needed to differentiate the usages. Different ports are not needed to differentiate the usages defined in this specification. Different ports SHOULD be used for TCP and TCP/TLS, so that the server can determine whether the first message it will receive after the TCP connection is set up is a STUN message or a TLS message. The default port for STUN requests is 3478, for both TCP and UDP. There is no default port for STUN over TLS. Administrators SHOULD use this port in their SRV records for UDP and TCP, but MAY use others. If no SRV records were found, the client performs an A or AAAA record lookup of the domain name. The result will be a list of IP addresses, each of which can be contacted at the default port using UDP or TCP, independent of the STUN usage. For usages that require TLS, such as the short term password usage, lack of SRV records is equivalent to a failure of the transaction, since the request or indication MUST NOT be sent unless SRV records provided a transport address specifically for TLS. 8.2. Obtaining a Shared Secret As discussed in Section 13, there are several attacks possible on STUN systems. Many of these attacks are prevented through integrity protection of requests and responses. To provide that integrity, STUN makes use of a shared secret between client and server which is used as the keying material for the MESSAGE-INTEGRITY attribute in STUN messages. STUN allows for the shared secret to be obtained in any way. The application usage defines the mechanism and required implementation strength for shared secrets. Some usages assume that out of band protocols are used to obtain the necessary credentials. Other usages, such as binding keepalives, don't use authentication, as it is not required. Others, such as the binding discovery, allows for authentication using either a long term shared secret or a short term shared secret. The latter can be obtained by using the short term password usage to obtain a short term shared secret. Consequently, the STUN usages define rules for obtaining shared secrets prior to sending a request. 8.3. Request/Response Transactions 8.3.1. Formulating the Request Message The client follows the syntax rules defined in Section 6 and the transmission rules of Section 7. The message class MUST be a request. The client creates a STUN message following the STUN message structure described in Section 6. The client SHOULD add a MESSAGE- INTEGRITY and USERNAME attribute to the Request message if the usage employs authentication. The specific credentials to use are described by the STUN usage, which can specify no credentials, a short term credential, or a long term credential. The procedures for each are: 1. If the STUN usage specifies that no credentials are used, the message is sent without MESSAGE-INTEGRITY 2. If a short term credential is to be used, the STUN Request or STUN Indication would contain the USERNAME and MESSAGE-INTEGRITY attributes. The message MUST NOT contain the REALM attribute. The key for MESSAGE-INTEGRITY is the password. 3. If a long term credential is to be used, the STUN request contains the USERNAME, REALM, and MESSAGE-INTEGRITY attributes. The 16-byte key for MESSAGE-INTEGRITY HMAC is formed by taking the MD5 hash of the result of concatenating the following five fields: (1) The username, with any quotes and trailing nulls removed, (2) A single colon, (3) The realm, with any quotes and trailing nulls removed, (4) A single colon, and (5) The password, with any trailing nulls removed. For example, if the USERNAME field were 'user', the REALM field were '"realm"', and the PASSWORD field were 'pass', then the 16-byte HMAC key would be the result of performing an MD5 hash on the string 'user:realm: pass', or 0x8493fbc53ba582fb4c044c456bdc40eb. This format for the key was chosen so as to enable a common authentication database for SIP, which uses digest authentication as defined in RFC 2617 [7] and STUN, as it is expected that credentials are usually stored in their hashed forms. The NONCE is included in the request only if a short or long term credential is being used, and only if the STUN request is a retry as a consequence of a previous error response which provided the client with a NONCE. For TCP and TLS-over-TCP, the client opens a TCP connection to the server. The TLS_RSA_WITH_AES_128_CBC_SHA ciphersuite MUST be supported at a minimum by implementers when TLS is used with STUN. Implementers MAY also support any other ciphersuite. When it receives the TLS Certificate message, the client SHOULD verify the certificate and inspect the site identified by the certificate. If the certificate is invalid, revoked, or if it does not identify the appropriate party, the client MUST NOT send the STUN message or otherwise proceed with the STUN transaction. The client MUST verify the identity of the server. To do that, it follows the identification procedures defined in Section 3.1 of RFC 2818 [4]. Those procedures assume the client is dereferencing a URI. For purposes of usage with this specification, the client treats the domain name or IP address used in Section 8.1 as the host portion of the URI that has been dereferenced. If DNS was not used, the client MUST be configured with a set of authorized domains whose certificates will be accepted. When STUN is being multiplexed on the same transport address as application data, and there are valid application layer data packets which could be confused with STUN packets (because, for example, bits 32 through 63 can contain an arbitrary binary value which might be equal to 0x2112A442), the FINGERPRINT attribute MUST be present. Otherwise, its inclusion is RECOMMENDED. Next, the client sends the request. For UDP-based requests, reliability is accomplished through client retransmissions, following the procedure in Section 7.1. For TCP (including TLS over TCP), there are no retransmissions. For TCP and TLS over TCP, the client MAY send multiple requests on the connection. When using TCP or TLS over TCP, the client SHOULD keep the connection open until it has no further requests to send, and has no plans to use any resources (such as a mapped address or relayed address [16]) learned though STUN requests sent over that connection. Regardless of the transport protocol, a client MAY pipeline requests (that is, it can have multiple requests outstanding at the same time). 8.3.2. Processing Responses Once the client has received a response to its request that it did not discard, it MUST discard any further responses for the same request. All responses that were not discarded, whether success responses or error responses, MUST first be authenticated by the client. Authentication is performed by first comparing the Transaction ID of the response to an oustanding request. If there is no match, the client MUST discard the response. Then the client SHOULD check the response for a MESSAGE-INTEGRITY attribute. If not present, and the client placed a MESSAGE-INTEGRITY attribute into the associated request, it MUST discard the response. If MESSAGE-INTEGRITY is present, the client computes the HMAC over the response as described in Section 11.4. The key that is used MUST be same as used to compute the MESSAGE-INTEGRITY attribute in the request. If the client did not place a MESSAGE-INTEGRITY attribute into the request, it MUST ignore the MESSAGE-INTEGRITY attribute in the response and continue processing the response. If the computed HMAC matches the one from the response, processing continues. If the response is an Error Response, the client checks the response code from the ERROR-CODE attribute of the response. For a 400 (Bad Request) response code, the client SHOULD display the reason phrase to the user. For a 420 (Unknown Attribute) response code, the client SHOULD retry the request, this time omitting any attributes listed in the UNKNOWN-ATTRIBUTES attribute of the response. If the client receives a 401 (Unauthorized) response and had not included a MESSAGE-INTEGRITY attribute in the request, it is an indication from the server that credentials are required. If the REALM attribute was present in the response, it is a signal to the client to use a long term shared secret and retry the request. The client SHOULD retry the request, using the username and password associated with the REALM (this username and password are assumed to be pre-provisioned into the client through some other means). If the REALM attribute was absent in the response, it is a signal to the client to use a short term shared secret and retry the request. If the client doesn't have a short term shared secret, it SHOULD use the Shared Secret request to obtain one, and then retry the request with the username and password obtained as a result. If the client receives a 401 (Unauthorized) response but had included a MESSAGE-INTEGRITY attribute in the request, there has been an unrecoverable error. This shouldn't ever happen, but if it does, the client SHOULD NOT retry the request. If the client receives a 432 (Missing Username) response, and the client had omitted the USERNAME from the request but included a MESSAGE-INTEGRITY, the client SHOULD retry the request and include both MESSAGE-INTEGRITY and USERNAME. If the client receives a 432 (Missing Username) but had included both MESSAGE-INTEGRITY and USERNAME in the request, there has been an unrecoverable error. This shouldn't ever happen, but if it does, the client SHOULD NOT retry the request. If the client receives a 435 (Missing Nonce) response, but had included a NONCE in the request, an unrecoverable error has occurred and the client SHOULD NOT retry. However, if it had omitted the NONCE in the request and received a 435, or it had included the NONCE but received a 438, it is a request from the server to retry using the same credential, but with a different nonce. The client SHOULD retry the request. If the client receives a 430 (Stale Credentials) response, it means that the client used a short term credential that has expired. If the client had submitted the request using a short term credential obtained from a Shared Secret request, the client SHOULD generate a new Shared Secret request to obtain a new short term credential and then retry the request with that credential. Note that the Shared Secret request may or may not go to the same server which generated the 430 (Stale Credentials) response; the server that receives the Shared Secret request is determined by the DNS procedures defined above. If a 430 (Stale Credentials) response was received and the client had used a short term credential provided through some other means, the client SHOULD obtain a new short term credential using that mechanism. If the client had not used a short term credential in the request, the 430 (Stale Credentials) error is unrecoverable and the request SHOULD NOT be retried. For a 431 (Integrity Check Failure) response code, the client SHOULD alert the user, and if a short term credential obtained from a Shared Secret request had been used previously, the client MAY try the request again after obtaining a new short term username and password. If the client receives a 433 (Use TLS) response, and the request was a Shared Secret request which was not sent over TLS, the client SHOULD retry the request, and MUST send it using TLS. If this response is received to any other request except for a Shared Secret request, or if the client had sent the Shared Secret request over TLS, it is an unrecoverable error and the client SHOULD NOT retry. If the client receives a 434 (Missing Realm) response, and had omitted the REALM in the request, but had included MESSAGE-INTEGRITY, it is an indication that, though a short-term credential was used for the request, the server desires the client to use a long term credential. The client SHOULD retry the request using the username and password associated with the REALM. If the 434 (Missing Realm) was received but the request had contained a REALM, and the REALM in the response differs from the REALM in the request, the client SHOULD retry using the username and password associated with the REALM in the response. If the REALMS were equal, this is an unrecoverable error and the client SHOULD NOT retry. It the client receives a 436 (Unknown Username) response, it means that the username it provided in the request is unknown. For usages where the username was collected from the user, the client SHOULD alert the user. The client SHOULD NOT retry with the same username. If the username was obtained using the Shared Secret request, the client SHOULD obtain a new credential and retry. However, if the retries are repeatedly rejected with a 436 (Unknown Username), it SHOULD cease retrying. For error responses which can contain a NONCE, if the error response results in a retry, the client MUST include the NONCE in a subsequent retry. Furthermore, the client SHOULD cache the nonce, and continue using it in subsequent requests sent to the same server, identified by transport address. For a 300 (Try Alternate) response code, the client SHOULD attempt a new transaction to the server indicated in the ALTERNATE-SERVER attribute. The client SHOULD reuse its credentials (username and password) when retrying. This is useful for load balancing requests across a STUN server cluster, when those requests require some amount of resources to process. Though this specification allows the 300 (Try Alternate) response to be applied to Binding Requests, it is generally not useful to do so, since the work of redirecting a Binding Request is equal to, if not more than, the work of just processing the Binding Request. Consequently, the 300 (Try Alternate) response code is targeted for other usages of STUN, such as the relay usage [16]. For a 500 (Server Error) response code, the client MAY wait several seconds and then retry the request on the same server. Or, if the server was learned through DNS SRV records, the client MAY try the request on the next server in the list. The same username and password MAY be used. For a 600 (Global Failure) response code, client MUST NOT retry the request on this server, or if the server was learned through DNS, any other server found through the DNS resolution procedures. Unknown response codes between 300 and 399 are treated like a 300. Unknown response codes between 400 and 499 are treated like a 400, unknown response codes between 500 and 599 are treated like a 500, and unknown response codes between 600 and 699 are treated like a 600. Any response between 100 and 299 MUST result in the cessation of request retransmissions, but otherwise is discarded. Unknown optional attributes in a response (greater than 0x7FFF) MUST be ignored by the STUN client. Responses containing unknown mandatory attributions (less than or equal to 0x7FFF) MUST be discarded and considered immediately as a failed transaction. For a success response, the client SHOULD cache any nonce present in the response, and continue using it in subsequent requests sent to the same server, identified by transport address. 8.3.3. Timeouts If the STUN transaction times out without receipt of a response, the client SHOULD consider it a failure and retry the request to the next server in the list of servers from the DNS SRV response, as specified in RFC 2782. 8.4. Indication Transactions This section applies to client and server behavior for sending an Indication message. The client or server follows the syntax rules defined in Section 6 and the transmission rules of Section 7. The message class MUST be an indication. Indication messages cannot be challenged or rejected. Consequently, they cannot be authenticated using long term credentials. If a STUN usage specifies that authentication is needed for an indication message, it can only be done using a short term credential. In that case, the client or server MUST add a MESSAGE-INTEGRITY and USERNAME attribute to the Request message. The key for MESSAGE-INTEGRITY is the password. When STUN is being multiplexed on the same transport address as application data, and there are valid application layer data packets which could be confused with STUN packets (because, for example, bits 32 through 63 can contain an arbitrary binary value which might be equal to 0x2112A442), the FINGERPRINT attribute MUST be present. Otherwise, its inclusion is RECOMMENDED. Typically, indication messages are sent to the same transport address, or over the same TCP connections as a previous request message. However, a usage can specify that indication messages are sent based on a DNS query, in which case the discovery procedures in Section 8.1 are followed, along with the TCP/TLS connection establishment procedures defined in Section 8.3.1. Indication message types are not sent reliably, do not elicit a response from the server, and are not retransmitted. For TCP and TLS over TCP, the client or server MAY send multiple indications on the connection. When using TCP or TLS over TCP, the client SHOULD close the connection as soon as it determines it has no further messages to send to the server. By definition, since indications do not generate a response, they can be pipelined, regardless of the transport protocol. 9. Server Behavior As with clients, server behavior depends on whether it is a request/ response transaction or indication. 9.1. Request/Response Transactions 9.1.1. Receive Request Message A STUN server MUST be prepared to receive request messages on the transport addressthatwill be discovered by the STUN client when the STUN client followscorresponds to itsdiscovery procedures described in Section 8.1. Depending on the usage, the STUN server will listen for incoming UDP STUN messages, incoming TCP STUN messages, or incoming TLS exchanges followed by TCP STUN messages. If the request is a retransmission ofprivate IP address and port. It also provides arequestway forwhich the server has already generatedan endpoint to keep aresponse within the last 10 seconds, the server MUST retransmitNAT binding alive. With some extensions, theresponse. A serverprotocol can be used to dothis either by remembering the response it transmitted,connectivity checks between two endpoints [I-D.ietf-mmusic-ice], orby re-processing the request and computing the response. The latter technique can only be appliedtorequests which are idempotentrelay packets between two endpoints [I-D.ietf-behave-turn]. In keeping with its toolkit nature, this specification defines an extensible packet format, defines operation over several transport protocols, andwould result in the same responseprovides forthe same request. Thistwo forms of authentication. STUN isthe case for the Binding Request, but not for the Shared Secret Request. Extensionsintended toSTUN SHOULD state whether their request types have this propertybe used in context of one ornot. When amore NAT traversal solutions. These solutions are known as STUNrequest is received, the server determines the usage. The usages describeusages. Each usage describes howtheSTUNserver makes this determination. Based on the usage,is utilized to achieve the NAT traversal solution. Typically, a usage indicates when STUN messages get sent, which optional attributes to include, what serverdetermines whether the request requires any authenticationis used, andmessage integrity checks. It can require none, short-term credential based authentication, or long- term credential authentication. Ifwhat authentication mechanism isrequired, the server checks for the presenceto be used. Interactive Connectivity Establishment (ICE) [I-D.ietf-mmusic-ice] is one usage of ICE. SIP Outbound [I-D.ietf-sip-outbound] is another usage of ICE. In some cases, a usage will require extensions to STUN. A STUN extension can be in theMESSAGE-INTEGRITY attribute. If not present, the server generates anform of new methods, attributes, or error responsewith an ERROR-CODE attribute andcodes. More information on STUN usages can be found in Section 13. 2. Evolution from RFC 3489 STUN was originally defined in RFC 3489 [RFC3489]. That specification, sometimes referred to as "classic STUN", represented itself as aresponse code of 401 (Unauthorized). If the server wishescomplete solution to the NAT traversal problem. In that solution, a clientto usewould discover whether it was behind ashort term credential, the REALM is omitted fromNAT, determine its NAT type, discover its IP address and port on theresponse. Ifpublic side of theserver wishesoutermost NAT, and then utilize that IP address and port within theclient to use a long term credential,body of protocols, such as theREALM is included inSession Initiation Protocol (SIP) [RFC3261]. However, experience since theresponse containingpublication of RFC 3489 has found that classic STUN simply does not work sufficiently well to be arealm from which the usernamedeployable solution. The address andpasswordport learned through classic STUN arescoped [7]. If the MESSAGE-INTEGRITY attribute was present, the server checkssometimes usable forthe existence of the USERNAME attribute. Ifcommunications with a peer, and sometimes not. Classic STUN provided no way to discover whether it would, in fact, work or not, and it provided no remedy in cases where it did not. Furthermore, classic STUN's algorithm for classification of NAT types was found to be faulty, as many NATs did notpresent,fit cleanly into theserver MUST generate an error response. The error response MUST includetypes defined there. Classic STUN also had security vulnerabilities which required anERROR-CODE attribute with a response code of 432 (Missing Username). Ifextremely complicated mechanism to address, and despite theserver is using a long term credential for authentication,complexity of theresponse MUST includemechanism, were not fully remedied. For these reasons, this specification obsoletes RFC 3489, and instead describes STUN as aREALM. If the servertool that isusing a short-term credential, it MUST NOT includeutilized as part of aREALM in the response. If the servercomplete NAT traversal solution. ICE isusing long term credentialsa complete NAT traversal solutions forauthentication, and the request contained the MESSAGE-INTEGRITY and USERNAME attributes,protocols based on theserver checksoffer/answer [RFC3264] methodology, such as SIP. SIP Outbound is a complete solution forthe existencetraversal ofthe REALM attribute. If the attributeSIP signaling, and it uses STUN in a very different way. Though it isnot present, the server MUST generate an error response. That error response MUST include an ERROR-CODE attribute with response code of 434 (Missing Realm). That error response MUST also includepossible that a protocol may be able to use STUN by itself (classic STUN) as aREALM attribute. If the REALM attribute was presenttraversal solution, such usage is not described here and is strongly discouraged for theserverreasons described above. The on-the-wire protocol described here isusingchanged only slightly from classic STUN. The protocol now runs over TCP in addition to UDP. Extensibility was added to the protocol in along term credentialmore structured way. A magic-cookie mechanism forauthentication,demultiplexing STUN with application protocols was added by stealing 32 bits from theserver checks128 bit transaction ID defined in RFC 3489, allowing the change to be backwards compatible. Mapped addresses are encoded using a new exclusive-or format. There are other, more minor changes. See Section 18 for a more complete listing. Due to theexistencechange in scope, STUN has also been renamed from "Simple Traversal ofthe NONCE attribute. If the NONCE attributeUDP Through NAT" to "Session Traversal Utilities for NAT". The acronym remains STUN, which isnot present, the server MUST generate an error response. That error response MUST include an ERROR-CODE attribute with a response codeall anyone ever remembers anyway. 3. Overview of435 (Missing Nonce). That error response MUST include a REALM attribute. If the NONCE was absent and the serverOperation This section isauthenticating with short term credentials,descriptive only. /--------\ // STUN \\ | Agent | \\ (server) // \--------/ +----------------+ Public Internet ................| NAT 2 |....................... +----------------+ +----------------+ Private NET 2 ................| NAT 1 |....................... +----------------+ /--------\ // STUN \\ | Agent | \\ (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 theserver MAY generate an error response with an ERROR-CODE attribute with a response code of 435 (Missing Nonce).STUN protocol. The lower agent in the figure is connected to private network 1. Thisresponse MUST include a NONCE. Ifnetwork connects to private network 2 through NAT 1. Private network 2 connects to theNONCE was presentpublic Internet through NAT 2. The upper agent in therequest, butfigure resides on theserver has determined itpublic Internet. STUN isstale, the server MUST generate an error response with an ERROR-CODE attribute witharesponse codeclient-server protocol. It supports two types of438 (Stale Nonce). If the servertransactions. One isauthenticating thea request/response transaction in which a client sends a requestwithto ashort term credential, it checks the value of the USERNAME field. If the USERNAME was previously valid but has expired,server, and the servergenerates an error response with an ERROR-CODE attribute withreturns aresponse code of 430 (Stale Credentials). If the serverresponse. The second isauthenticating with either short or long term credentials, it determines whether the USERNAME contains a known entity, andan indication transaction inthe case ofwhich along-term credential, known within the realm of the REALM attribute of the request. Ifclient sends an indication to theUSERNAME is unknown,server and the servergenerates an error response with an ERROR-CODE attribute with a response codedoes not respond. Both types of436 (Unknown Username). For authentication using long-term credentials, that error response MUSTtransactions include aREALM attribute. For authentication using short-term credentials, it MUST NOT includetransaction ID, which is aREALM. Atrandomly selected 96-bit number. For request/response transactions, thispoint, if the server is doing authentication, the request contains everything needed for that purpose. The server computes the HMAC over the request as described in Section 11.4. The key depends ontransaction ID allows thecredential. For short-term credentials, it equalsclient to associate thepassword associatedresponse with theusername. For long term credentials, it is computedrequest that generated it; for indications, this simply serves asdescribed in Section 8.3.1. Ifa debugging aid. All STUN messages start with a fixed header that includes a method, a class, and thecomputed HMAC differs fromtransaction ID. The method indicates which of the various requests or indications this is; this specification defines just onefrom the MESSAGE-INTEGRITY attributemethod, Binding, but other methods are expected to be defined intheother documents. The class indicates whether this is a request,the server MUST generatea (success) response, an errorresponse withresponse, or anERROR-CODE attribute with a response code of 431 (Integrity Check Failure). If long term credentialsindication. Following the fixed header comes zero or more attributes, which arebeing usedtype-length-value extensions that convey additional information forauthentication, this response MUST includethe specific message. This document defines aREALM attribute. If short term credentials are being used, it MUST NOT includesingle 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 aREALM.STUN client. Whenan errorused 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 tobe generated bya 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 serveras(in Figure 1, there were two such NATs). As the Binding Request message passes through aconsequence of authentication problems (error codes 401, 432, 434, 435, 430 and 436, andNAT, theREALM is present inNAT will modify theresponse (signifyingsource transport address (that is, theusagesource IP address and the source port) of the packet. As along term credential),result, the source transport address of the request received by the serverMUST include a NONCE attribute inwill be theresponse. The nonce includespublic IP address and port created by the NAT closest to the server. This is called arandom valuereflexive transport address. The STUN server copies that source transport address into an XOR-MAPPED- ADDRESS attribute in theserver wishesSTUN Binding Response and sends theclientBinding Response back toreflectthe the STUN client. As this packet passes backinthrough asubsequent request (and therefore include inNAT, themessage integrity computation). WhenNAT will modify theREALM is absentdestination transport address, but the transport address in theresponse,XOR-MAPPED-ADDRESS attribute within theserver MAY include a NONCE inbody of the STUN responseif it wishes to use nonces alongwill remain untouched. In this way, the client can learn its reflexive transport address allocated by the outermost NAT withshort-term shared secrets (withrespect to theexception of 435, where NONCE is mandatory even for short term credentials). However,STUN server. In some usages, STUN must be multiplexed with other protocols (e.g., [I-D.ietf-mmusic-ice], [I-D.ietf-sip-outbound]). In these usages, thereis little reasonmust be a way todo so, since the short-term password is, by definition, short-term,inspect a packet andthus additional temporal scoping throughdetermine if it is a STUN packet or not. STUN provides two fields in thenonceSTUN header with fixed values that can be used for this purpose. If this is notneeded. At this point,sufficient, then STUN packets can also contain a FINGERPRINT value which can further be used to distinguish therequestpackets. STUN hasbeenoptional mechanisms for providing authenticationcheckedand message integrityverified. Ifwhen required. These mechanisms revolve around themethoduse of a username, password, and message-integrity value. Two of these mechanisms, therequest is unknown tolong-term credential mechanism and theserver, it MUST generate an error response which includes an ERROR-CORE attributeshort-term credential mechanism, are defined in this specification. Each usage specifies the mechanisms allowed witha 400 response code. Next,that usage. In theserver MUST check for any mandatory attributes inshort-term credential mechanism, therequest (values less than or equal to 0x7fff) which it does not understand. If it encounters any,client and the serverMUST generate an error response, and it MUST include an ERROR-CODE attribute withexchange a420 response code. Any attributes that are known, but are not supposedusername and password through some out-of-band method prior tobe presentthe STUN exchange. For example, in the ICE usage [I-D.ietf-mmusic-ice] the two endpoints use out-of-band signaling to exchange amessage (MAPPED-ADDRESSusername and password. The client then includes the username and a message-integrity value in the request message, where the message-integrity value is computed as arequest, for example) MUST be ignored. 9.1.2. Constructingcryptographic hash of theResponse To constructmessage contents and theSTUN Responsepassword. If theSTUNserverfollows the message structure described in Section 6. The message type MUST indicate eitherreplies with a success response, then the responseor error response class and MUST indicatewill include a message-integrity value (computed using the samemethod as the request. The server MUST copy the transaction ID fromusername and password), but therequest tousername is not included. Error responses are not message-integrity protected. In theresponse. The attributes that get added tolong-term credential mechanism, the client and server share a pre-provisioned username and password and perform a digest challenge/ responsedepend onexchange inspired by (but differing in details) to thetype of response. See Figure 5one defined fora summary. IfHTTP [RFC2617]. Initially, theresponse isclient sends a request message (e.g., atype which can carry either MAPPED-ADDRESS or XOR-MAPPED-ADDRESS (theBindingResponse as defined in this specification meets that criteria), theRequest) without any username or message- integrity value included. The serverexamines the magic cookie inreplies with an error response indicating that theSTUN header. If it hasrequest must be authenticated. This error response includes a realm value and a nonce value. The client then uses the realm value0x2112A442,to help itindicates thatselect a username and password (for example, the clientsupports this version of the specification. The server MUST insertmight have aXOR-MAPPED-ADDRESS into the response, carrying the exclusive-ornumber ofthe source transport addressusername andmagic cookie. Ifpassword combinations stored, each one keyed by a different realm value). The client then retries themagic cookie did not haverequest, thisvalue, it indicates thattime including theclient supportsrealm, theprevious version of this specification. The server MUST insert a MAPPED-ADDRESS attribute intousername, theresponse, carryingnonce, and a message-integrity value in thesouce transport address fromrequest, where therequest. Insertion of either XOR-MAPPED-ADDRESS or MAPPED-ADDRESS happens regardlessmessage-integrity value is computed as a cryptographic hash of thetransport protocol used for the request. XOR-MAPPED-ADDRESSmessage contents andMAPPED-ADDRESS differ only in their encoding ofthetransport address.password. Theformer, as impliednonce is provided by thename, encodes the transport addressserver and merely echoed byexclusive-or'ing them with the magic cookie. The latter encodes them directly in binary. RFC 3489 originally specified only MAPPED-ADDRESS. However, deployment experience found that some NATs rewritethe32-bit binary payloads containingclient into theNAT's public IP address,request. It is chosen by the server suchas STUN's MAPPED-ADDRESS attribute, inthat it encodes information about thewell-meaning but misguidedclient, the time-of-day, or other parameters. In this way, if an attacker should attemptat providing a generic ALG function. Such behavior interferes withto replay theoperation of STUN and also causes failure of STUN's message integrity checking. Ifrequest, therequest containedserver would find theMESSAGE-INTEGRITY attribute,nonce invalid, and then reject the request. If the serverMUST includereplies with aMESSAGE-INTEGRITY attribute insuccess response, then the response will include asuccessful response. The MESSAGE-INTEGRITY attribute MUST usemessage-integrity value (computed using the same username andpassword usedpassword), but realm, username, and nonce are not included. Error responses are not message-integrity protected. If the client has further requests toauthenticatesend, it can try to reuse therequest.same username, realm, and nonce values. Iflong term credentials were used,the server does not accept them, it will reply with an error responseMUST include a NONCE. For short term credentials,giving aNONCE MAYrealm and nonce value again. 4. Terminology In this document, the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" are to beincluded. The server SHOULD include a SERVER attributeinterpreted as described inall responses, indicating the identity of the server generating the response. This is usefulBCP 14, RFC 2119 [RFC2119] and indicate requirement levels fordiagnostic purposes. Whencompliant STUNis being multiplexed onimplementations. 5. Definitions STUN Agent: An entity that implements thesame transport addressSTUN protocol. Agents can act as STUN clients for some transactions and asapplication data, and there are valid application layer data packets which could be confused withSTUNpackets (because,servers forexample, bits 32 through 63 can contain an arbitrary binary value which might be equal to 0x2112A442), the FINGERPRINT attribute MUST be presentother transactions. STUN Client: A logical role in theresponse. Otherwise, its inclusionSTUN protocol. A STUN client sends STUN requests or STUN indications, and receives STUN responses. The term "STUN client" isRECOMMENDED. In cases where the server cannot handle the request, duealso used colloquially to refer toexhaustion of resources, the server MAY generatea300 response with an ALTERNATE-SERVER attribute. This attribute identifies an alternate server which can service the requests. It is not expectedSTUN agent that300 responses or this attribute would be used by the methods definedonly acts as a STUN client. STUN Server: A logical role inthis specification. 9.1.3. SendingtheResponse All UDP response messages are sentSTUN protocol. A STUN server receives STUN requests or STUN indications and sends STUN responses. The term "STUN server" is also used colloquially tothe transportrefer to a STUN agent that only acts as a STUN server. Transport Address: The combination of an IP addressthe associated Binding Request came from,andsent from the transport address the Binding Request was sent to. All TCPport number (such as a UDP orTLS over TCP responses messages are sent on theTCPconnectionsport number). Reflexive Transport Address: A transport address learned by a client thatthe request arrived on. 9.2. Indication Transactions Indication messages cause the server to change its state. Indication message types do not cause the server to sendidentifies that client as seen by another host on an IP network, typically aresponse message. ASTUNserver MUST be prepared to receive indication messages onserver. When there is an intervening NAT between the client and the other host, the reflexive transport addressthat will be discovered byrepresents theSTUN client whenmapped address allocated to theSTUNclientfollows its discovery procedures described in Section 8.1. Dependingon theusage,public side of theSTUN server will listen for incoming UDP STUN messages, incoming TCP STUN messages,NAT. Reflexive transport addresses are learned from the mapped address attribute (MAPPED-ADDRESS orincoming TLS exchanges followed by TCP STUN messages. When aXOR- MAPPED-ADDRESS) in STUNindicationresponses. Mapped Address: Same meaning as Reflexive Address. This term isreceived,retained only for for historic reasons and due to theserver determinesnaming of theusage. The usages describe howMAPPED-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 theSTUN server makes this determination. Based onclient when a subscriber enrolls in a service and persist until theusage,subscriber leaves theserver determines whetherservice or explicitly changes theindication requires any authenticationcredential. Long Term Password: The password from a long term credential. Short Term Credential: A temporary username andmessage integrity checks. It can require none or short-term credential based authentication. If short-termassociated password which represent a shared secret between client and server. Short term credentials areutilized,obtained through some kind of protocol mechanism between theserver followsclient server, preceding thesame procedures as defined in Section 9.1.1, but if those procedures require transmissionSTUN 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 anerror response, the server MUST instead silently discard the indication. Once authenticated (if authentication was in use), the processingevent (such as termination of a SIP dialog). The specific scope of a short term credential is defined by theindication message depends on the method. This specification doesn't define any indication messages. 10. Demultiplexingapplication 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 andApplication Traffic In the binding refresh usage,comprehension-optional. STUNtraffic is multiplexed on the same transport address as application traffic, suchagents 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 6. STUN Message Structure STUN messages are encoded in binary using network-oriented format (most significant byte or octet first, also commonly known asRTP. Inbig- endian). The transmission orderto apply the processingis described inthis specification, STUN messages must first be separated from the application packets. This disambiguation is done identically for all message types. First, alldetail in Appendix B of RFC791 [RFC0791]. Unless otherwise noted, numeric constants are in decimal (base 10). All STUN messages MUST start withtwo bits equal to zero. Ifa 20-byte header followed by zero or more Attributes. The STUN header contains a STUN message type, magic cookie, transaction ID, and message length. 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 STUNis being multiplexed with application traffic where it is known that the topmostMessage Header The most significant two bitsare never zeroes, the presenceofthese two zeroes signalsevery STUNtraffic. If this mechanism doesn't suffice, the magic cookiemessage MUST be zeroes. This can beused. Allused to differentiate STUNmessages have the value 0x2112A442 as the second 32 bit word. If the application traffic can not have this value as the second 32 bit word, then anypacketswith this value arefrom other protocols when STUNpackets. Even ifis multiplexed with other protocols on theapplication packet can have this value (for example, in cases wheresame port. The message type defines theapplication packets contain random binary data), there is only a one in 2^32 chance that an application packet will have a valuemessage class (request, success response, failure response, or indication) and the message method (the primary function) of0x2112A442 in its second 32 bit word. If this probability is deemed sufficiently small fortheapplication at hand (for example, it is considered adequate for Voice over IP applications), then any packet with this value in its second 32 bit word is processed as aSTUNpacket. However, a mis-classificationmessage. Although there are four message classes, there are only two types of1transactions in2^32 may still be too high for some usagesSTUN: request/response transactions (which consist ofSTUN. Consequently, STUN messages can contain a FINGERPRINT attribute. This is a cryptographic hash over the message, covering everything prior to the attribute. This attribute is different from MESSAGE-INTEGRITY. The latter usesakeyed HMAC,request message andthus requiresashared secret. FINGERPRINT does not useresponse message), and indication transactions (which consists apassword,single indication message). Response classes are split into error andcan be computed just by examiningsuccess responses to aid in quickly processing the STUN message.Thus, if a packet appears to be a STUNThe messagebecause it has a valuetype field is decomposed further into the following structure: +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ |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 of0x2112A442STUN Message Type Field Here the bits inits second 32 bit word, a client or server then assumesthe messageistype field are shown as most-significant (M11) through least-significant (M0). M11 through M0 represent aSTUN message, and computes the value for the fingerprint. It then looks for the FINGERPRINT attribute in12- bit encoding of themessage,method. C1 andif the value equals the computed value,C0 represent a 2 bit encoding of themessageclass. A class of 0b00 isconsidered to beaSTUN message. If not, itRequest, a class of 0b01 isconsidered to beanapplication packet. 11. STUN Attributes To allow future revisionsindication, a class ofthis0b10 is a success response, and a class of 0b11 is an error response. This specificationto add new attributes if needed, the attribute spacedefines a single method, Binding. The method and class are orthogonal, so that four each method, a request, success response, error response and indication are defined for that method. For example, a Binding Request has class=0b00 (request) and method=0b000000000001 (Binding), and isdividedencoded intooptionalthe first 16 bits as 0x0001. A Binding response has class=0b10 (success response) andmandatory ones. Attributes withmethod=0b000000000001, and is encoded into the first 16 bits as 0x0101. Note: This unfortunate encoding is due to assignment of valuesgreater than 0x7fff are optional,in [RFC3489] whichmeans thatdid not consider encoding Indications, Success, and Errors using bit fields. The magic cookie field MUST contain themessage can be processed byfixed value 0x2112A442 in network byte order. In RFC 3489 [RFC3489], this field was part of the transaction ID; placing theclient ormagic cookie in this location allows a servereven though the attribute is not understood. Attributes with values less than or equal to 0x7fff are mandatorytounderstand, which means thatdetect if the clientor server cannot successfully process the message unlesswill understand certain attributes that were added in this revised specification. In addition, itunderstands the attribute. The valuesaids in distinguishing STUN packets from packets of other protocols when STUN is multiplexed with those other protocols on themessage attributes are enumerated in Section 15.same port. Thefollowing figure indicates which attributes are presenttransaction ID is a 96 bit identifier, used to uniquely identify STUN transactions. The transaction ID is chosen by the STUN client. It primarily serves to correlate requests with responses, though it also plays a small role inwhich messages. An M indicates that inclusionhelping to prevent certain types of attacks. As such, theattribute intransaction ID MUST be uniformly and randomly chosen from themessage is mandatory, O means its optional, C means it's conditional based on some other aspectinterval 0 .. 2**96-1. Resends of themessage, and - means thatsame request reuse theattributesame transaction ID, but the client MUST choose a new transaction ID for new transactions unless the new request isnot applicablebit- wise identical tothat message type. Error Attribute Request Response Response Indication _______________________________________________________ MAPPED-ADDRESS - C - - USERNAME C - - O PASSWORD - C - - MESSAGE-INTEGRITY O C C O ERROR-CODE - - M - ALTERNATE-SERVER - - C - REALM C - C - NONCE C - C - UNKNOWN-ATTRIBUTES - - C - XOR-MAPPED-ADDRESS - C - - SERVER - O O O REFRESH-INTERVAL - O - - FINGERPRINT O O O O Figure 5: Mandatory Attributesthe previous request andMessage Types 11.1. MAPPED-ADDRESS The MAPPED-ADDRESS attribute indicatessent from themappedsame transportaddress. It consists of an eight bitaddressfamily, and a sixteen bit port, followed by a fixed length value representingto the same IP address.IfSuccess and error responses MUST carry theaddress familysame transaction ID as their corresponding request. When an agent isIPv4,acting as a STUN server and STUN client on theaddress is 32 bits,same port, the transaction IDs innetwork byte order. Ifrequests sent by theaddress family is IPv6,agent have no relationship to theaddress is 128 bitstransaction IDs innetwork byte order.requests received by the agent. Theformat ofmessage length MUST contain theMAPPED-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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |x x x x x x x x| Family | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address (variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 6: Formatsize, in bytes, ofMAPPED-ADDRESS attribute The address family can take onthefollowing values: 0x01:IPv4 0x02:IPv6 The port is a networkmessage not including the 20 byteordered representationSTUN header. Since all STUN attributes are padded to a multiple of four bytes, theport the request arrived from. The first 8last two bits ofthe MAPPED-ADDRESSthis field areignored foralways zero. This provides another way to distinguish STUN packets from packets of other protocols. Following thepurposesSTUN fixed portion ofaligning parameters on natural 32 bit boundaries. It is possible for an IPv4 host to receive a MAPPED-ADDRESS containing an IPv6 address,the header are zero orfor an IPv6 host to receive a MAPPED- ADDRESS containing an IPv4 address. Clients MUST be prepared for this case. 11.2. USERNAME The USERNAMEmore attributes. Each attribute isused for message integrity. It identifies the shared secret used inTLV (type-length-value) encoded. The details of themessage integrity check. Consequently,encoding, and of theUSERNAME MUST be includedattributes themselves is given inany request that containsSection 14. 7. Base Protocol Procedures This section defines theMESSAGE-INTEGRITY attribute. The USERNAME isbase 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 alsoalways present in a Shared Secret Response, along withdefines thePASSWORD, which informs a clientdetailed processing of the Binding method. Other sections in this document describe optional procedures that ashort term password. The value of USERNAME isusage 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. 7.1. Forming avariable length opaque value. Note that, as described above, if the USERNAME is notRequest or an Indication When formulating amultiple of four bytes it is padded for encoding into the STUNrequest or indication message,in which casetheattribute length representsclient MUST follow thelength ofrules in Section 6 when creating theUSERNAME prior to padding. 11.3. PASSWORD Ifheader. In addition, the messagetype is Shared Secret Response itclass MUSTincludebe either "Request" or "Indication" (as appropriate), and thePASSWORD attribute. The value of PASSWORD is a variable length opaque value. The password returnedmethod must be either Binding or some method defined in another document. The client then adds any attributes specified by theShared Secret Response is used asmethod or the usage. For example, some usages may specify that theHMAC key inclient use an authentication method (Section 10) or theMESSAGE-INTEGRITYFINGERPRINT attributeof a subsequent STUN transaction. Note that, as described above, if the USERNAME is not a multiple of four bytes it is padded for encoding into(Section 8). For theSTUN message, in which caseBinding method with no authentication, no attributes are required unless theattribute length representsusage specifies otherwise. 7.2. Sending thelength ofRequest or Indication The client then sends theUSERNAME priorrequest topadding. 11.4. MESSAGE-INTEGRITY The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [10] ofthe server. This document specifies how to send STUNmessage. The MESSAGE-INTEGRITY attribute canmessages over UDP, TCP, or TLS-over-TCP; other transport protocols may bepresentadded inany STUN message type. Since it uses the SHA1 hash,theHMAC will be 20 bytes.future. Thetext used as input to HMACSTUN usage must specify which transport protocol is used, and how theSTUN message, includingclient determines theheader, up toIP address andincluding the attribute precedingport of theMESSAGE- INTEGRITY attribute. That text is then padded with zeroes so as to beserver. Section 9 describes amultipleDNS-based method of64 bytes. As a result, the MESSAGE-INTEGRITY attribute is either the last attribute, ordetermining thenextIP address and port of a server which a usage may elect tolast attribute inuse. At any time, a client MAY have multiple outstanding STUNmessage (depending on whether FINGERPRINT is present). With the exception ofrequests with theFINGERPRINT attribute, which appears after MESSAGE-INTEGRITY, elements MUST ignore all other attributessame STUN server (that is, multiple transactions in progress, with different transaction ids). 7.2.1. Sending over UDP When running STUN over UDP it is possible thatfollow MESSAGE-INTEGRITY. The key used as input to HMAC depends onthe STUNusage and the shared secret mechanism. 11.5. FINGERPRINT The FINGERPRINT attribute canmessage might bepresent in alldropped by the network. Reliability of STUNmessages. Itrequest/response transactions iscomputed as the CRC-32accomplished through retransmissions of theSTUNrequest messageup to (but excluding)by theFINGERPRINT attribute itself, xor-dclient application itself. STUN indications are not retransmitted; thus indication transactions over UDP are not reliable. A client SHOULD retransmit a STUN request message starting withthe 32 bit value 0x5354554e (the XOR helps in cases whereanapplication packet is also using CRC-32 in it).interval of RTO ("Retransmission TimeOut"), doubling after each retransmission. The32 bit CRCRTO is an estimate of theone definedround-trip-time, and is computed as described inITU V.42 [9], which has a generator polynomial of x32+x26+x23+x22+x16+x12+x11+x10+ x8+x7+x5+x4+x2+x+1. When present,RFC 2988 [RFC2988], with two exceptions. First, theFINGERPRINT attribute MUSTinitial value for RTO SHOULD be configurable (rather than thelast attribute in the message. 11.6. ERROR-CODE The ERROR-CODE attribute is present3s recommended inthe Binding Error Response and Shared Secret Error Response. It isRFC 2988). In fixed- line access links, anumericvalueinof 100ms is RECOMMENDED. Secondly, therangevalue of100RTO MUST NOT be rounded up to699 plusthe nearest second. Rather, atextual reason phrase encoded in UTF-8, and is consistent in its code assignments and semantics with SIP [11] and HTTP [12]. The reason phrase is meant for user consumption, and can1ms accuracy MUST beanything appropriate for the response code. Recommended reason phrases for the defined response codes are presented below. To facilitate processing,maintained. As with TCP, theclassusage ofthe error code (the hundreds digit)Karn's algorithm isencoded separatelyRECOMMENDED. When applied to STUN, it means that RTT estimates SHOULD NOT be computed from STUN transactions which result in therestretransmission ofthe code. 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 |Class| Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reason Phrase (variable) .. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+a request. Theclass representsvalue for RTO SHOULD be cached by an client after thehundreds digitcompletion of theresponse code.transaction, and used as the starting value for RTO for the next transaction to the same server (based on equality of IP address). The valueMUSTSHOULD bebetween 1considered stale and6. The number represents thediscarded after 10 minutes. Retransmissions continue until a responsecode modulo 100, and its value MUSTis received, or until a total of 7 requests have been sent. If, after the last request, a duration equal to 16 times the RTO has passed without a response, the client SHOULD consider the transaction to have failed. A STUN transaction over UDP is also considered failed if there has been a transport failure of some sort, such as a fatal ICMP error. For example, assuming an RTO of 100ms, requests would bebetween 0sent at times 0ms, 100ms, 300ms, 700ms, 1500ms, 3100ms, and99.6300ms. If thereason phraseclient hasa length that isnot received amultiple of four bytes, it is padded for encoding intoresponse after 7900ms, theSTUN message, in which caseclient will consider theattribute length representstransaction to have timed out. 7.2.2. Sending over TCP or TLS-over-TCP For TCP and TLS-over-TCP, thelengthclient opens a TCP connection to the server. In some usage of STUN, STUN is sent as theentire ERROR-CODE attribute (includingonly protocol over thereason phrase) prior to padding. The following response codes, along with their recommended reason phrases (in brackets) are defined at this time: 300 (Try Alternate): The client should contact an alternate server forTCP connection. In thisrequest. 400 (Bad Request): The request was malformed. The client should not retry the requestcase, it can be sent withoutmodification from the previous attempt. 401 (Unauthorized): The request did not contain a MESSAGE-INTEGRITY attribute. 420 (Unknown Attribute): The server did not understand a mandatory attribute intherequest. 430 (Stale Credentials): The request did contain a MESSAGE-INTEGRITY attribute, butaid of any additional framing or demultiplexing. In other usages, or with other extensions, itusedmay be multiplexed with other data over ashared secretTCP connection. In thathas expired. The client should obtain a new shared secret and try again. 431 (Integrity Check Failure): The request contained a MESSAGE- INTEGRITY attribute, but the HMAC failed verification. This couldcase, STUN MUST bea signrun ontop ofa potential attack,some kind of framing protocol, specified by the usage orclient implementation error. 432 (Missing Username): The request contained a MESSAGE-INTEGRITY attribute, but not a USERNAME attribute. Both USERNAME and MESSAGE-INTEGRITY must be presentextension, which allows forintegrity checks. 433 (Use TLS): The Shared Secret request hasthe agent to extract complete STUN messages and complete application layer messages. For TLS-over-TCP, the TLS_RSA_WITH_AES_128_CBC_SHA ciphersuite MUST besent over TLS, but was not received over TLS. 434 (Missing Realm): The REALM attribute was not present insupported at a minimum. Implementations MAY also support any other ciphersuite. When it receives therequest. 435 (Missing Nonce): The NONCE attribute was not present inTLS Certificate message, therequest. 436 (Unknown Username): The USERNAME supplied inclient SHOULD verify therequestcertificate and inspect the site identified by the certificate. If the certificate isnot knowninvalid, revoked, orisif it does notknown toidentify theserver. 438 (Stale Nonce):appropriate party, the client MUST NOT send the STUN message or otherwise proceed with the STUN transaction. TheNONCE attribute was presentclient MUST verify the identity of the server. To do that, it follows the identification procedures defined in Section 3.1 of RFC 2818 [RFC2818]. Those procedures assume therequest but wasn't valid. 500 (Server Error): The server has suffered a temporary error. Theclientshould try again. 600 (Global Failure): The serverisrefusing to fulfilldereferencing a URI. For purposes of usage with this specification, therequest. Theclientshouldtreats the domain name or IP address used in Section 8.1 as the host portion of the URI that has been dereferenced. If DNS was notretry. 11.7. REALM The REALM attributeused, the client MUST be configured with a set of authorized domains whose certificates will be accepted. Reliability of STUN over TCP and TLS-over-TCP ispresent in requestshandled by TCP itself, andresponses. It contains text which meetsthere are no retransmissions at thegrammarSTUN protocol level. However, for"realm" as described in RFC 3261 [11], and will thus containaquoted string (including the quotes). Presence ofrequest/response transaction, if theREALM attribute inclient has not received arequest indicates that long-term credentials are being usedresponse after 7900ms, it considers the transaction to have timed out. This value has been chosen to equalize the TCP and UDP timeouts forauthentication. Presence in certain error responses indicates thattheserver wishesdefault initial RTO. In addition, if the client is unable touse a long-term credential for authentication. 11.8. NONCE The NONCE attributeestablish the TCP connection, or the TCP connection ispresent in requests and in error responses. It contains a sequence of qdtextreset orquoted-pair, which are defined in RFC 3261 [11]. See RFC 2617 [7] for guidance on selection of nonce values infails before aserver. 11.9. UNKNOWN-ATTRIBUTES The UNKNOWN-ATTRIBUTES attribute is present only in an error response when theresponsecodeis received, any request/response transaction inthe ERROR-CODE attributeprogress is420.considered to have failed Theattribute containsclient MAY send multiple transactions over alist of 16 bit values, each of which represents an attribute type that was not understood by the server. If the number of unknown attributes is an odd number, one ofsingle TCP (or TLS- over-TCP) connection, and it MAY send another request before receiving a response to theattributes MUST be repeated inprevious. The client SHOULD keep thelist, soconnection open until it o has no further STUN requests or indications to send over thatthe total length of the list is a multiple of 4 bytes. 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 9: Format of UNKNOWN-ATTRIBUTES attribute 11.10. XOR-MAPPED-ADDRESS The XOR-MAPPED-ADDRESS attributeconnection, and; o has no plans to use any resources (such as a mapped address (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address [I-D.ietf-behave-turn]) that were learned though STUN requests sent over that connection, and; o if multiplexing other application protocols over that port, has finished using that other application, and; o if using that learned port with a remote peer, has established communications with that remote peer, as ispresent in responses. It providesrequired by some TCP NAT traversal techniques (e.g., [I-D.ietf-mmusic-ice-tcp]). At thesame information that would present inserver end, theMAPPED- ADDRESS attribute but becauseserver SHOULD keep theNAT's public IP address is obfuscated throughconnection open, and let theXOR function, STUN messages are ableclient close it. If a server becomes overloaded and needs topass through NATsclose connections to free up resources, it SHOULD close an existing connection rather than reject new connection requests. The server SHOULD NOT close a connection if a request was received over that connection for whichwould otherwise interfere with STUN. This attributea response was not sent. A server MUSTalways be present inNOT ever open aBinding Response and may be usedconnection back towards the client inother responses as well. Usages defining new requests and responses should specify if XOR-MAPPED-ADDRESS is applicableorder totheir responses. The format of the XOR-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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |x x x x x x x x| Family | X-Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | X-Address (Variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 10: Formatsend a response. 7.3. Receiving a STUN Message This section specifies the processing ofXOR-MAPPED-ADDRESS Attributea STUN message. TheFamily represents the IP address family, andprocessing specified here isencoded identicallyfor STUN messages as defined in this specification; additional rules for backwards compatibility are defined in in Section 12. Those additional procedures are optional, and usages can elect to utilize them. First, a set of processing operations are applied that are independent of theFamily in MAPPED-ADDRESS. X-Portclass. This is followed by class-specific processing, described in themapped port, exclusive or'd with most significant 16 bitssubsections which follow. When a STUN agent receives a STUN message, it first checks that the message obeys the rules of Section 6. It checks that the first two bits are 0, that the magiccookie. Ifcookie field has theIP address familycorrect value, that the message length isIPv4, X-Addresssensible, and that the method value is a supported method. If the message-class is Success Response or Error Response, themapped IP address exclusive or'd withagent checks that themagic cookie.transaction ID matches a transaction that is still in progress. If theIP address familyFINGERPRINT extension isIPv6,being used, theX-Addressagent checks that the FINGERPRINT attribute is present and contains themapped IP address exclusively or'ed withcorrect value. If any errors are detected, themagic cookie andmessage is silently discarded. In the96- bit transaction ID. For example, usingcase when STUN is being multiplexed with another protocol, an error may indicate that this is not really a STUN message; in this case, the"^" characteragent should try toindicate exclusive or, ifparse the message as a different protocol. The STUN agent then does any checks that are required by a authentication mechanism that the usage has specified (see Section 10. Once theIP address is 192.168.1.1 (0xc0a80101) andauthentication checks are done, theport is 5555 (0x15B3),STUN agent checks for unknown attributes and known-but-unexpected attributes in theX-Port wouldmessage. Unknown comprehension-optional attributes MUST be0x15B3 ^ 0x2112 = 0x34A1, andignored by theX-Address wouldagent. Known-but-unexpected attributes SHOULD be0xc0a80101 ^ 0x2112A442 = 0xe1baa543. Itignored by the agent. Unknown comprehension-required attributes cause processing that depends on the message-class and ispossible for an IPv4 host to receivedescribed below. At this point, further processing depends on the message class of the request. 7.3.1. Processing aXOR-MAPPED-ADDRESS containing an IPv6 address,Request If the request contains one orformore unknown comprehension-required attributes, the server replies with anIPv6 host to receive a XOR- MAPPED-ADDRESS containingerror response with anIPv4 address. Clients MUST be prepared for this case. 11.11. SERVER The server attribute contains a textual descriptionerror code of 420 Unknown attributes, and includes an UNKNOWN-ATTRIBUTES attribute in thesoftware being used byresponse that lists theserver, including manufacturer and version number.unknown comprehension- required attributes. Theattribute has no impact on operation ofserver then does any additional checking that theprotocol, and serves only asmethod or the specific usage requires. If all the checks succeed, the server formulates atool for diagnostic and debugging purposes. The value of SERVER is variable length.success response as described below. If thevalue of SERVERrequest uses UDP transport and isnotamultipleretransmission offour bytes, it is paddeda request forencoding into the STUN message, inwhichcasetheattribute length representsserver has already generated a success response within thelength oflast 10 seconds, theUSERNAME prior to padding. 11.12. ALTERNATE-SERVER The alternateserverrepresents an alternate transport addressMUST retransmit the same success response. One way for adifferent STUNserver totry. Itdo this isencodedto remember all transaction IDs received over UDP and their corresponding responses in thesamelast 10 seconds. Another wayas MAPPED-ADDRESS. This attributeis to reprocess the request and recompute the response. The latter technique MUST onlyappearbe applied to requests which are idempotent and result inan error response. 11.13. REFRESH-INTERVAL The REFRESH-INTERVAL indicates the number of milliseconds that the server suggests the client should use between refreshes oftheNAT bindings betweensame success response for theclient and server. Evensame request. The Binding method is considered to idempotent in this way (even though certain rare network events could cause theserver may not know the binding lifetimes in intervening NATs,reflexive transport address value to change). Extensions to STUN SHOULD state whether their request types have thisattribute serves as a useful configuration mechanism for suggestingproperty or not. 7.3.1.1. Forming avalue for use by the client. Furthermore, whenSuccess or Error Response When forming theNAT Keepalive usage is being used,response (success or error), the servermay become overloaded with Binding Requests that are being used for keepalives.follows the rules of section 6. TheREFRESH-INTERVAL provies a mechanism formethod of theserver to gradually reduceresponse is theload on itself by pushing back onsame as that of theclient. REFRESH-INTERVALrequest, and the message class isspecified aseither "Success Response" or "Error Response". For anunsigned 32 bit integer, and representserror response, the server MUST add aninterval measured in millseconds. It can be presentERROR-CODE attribute containing the error code specified inBinding Responses. 12. STUN Usages STUNthe processing above. The reason phrase isa simple request/response protocol that provides a useful capability in several situations. In this section, different usages of STUN are described. Each usage may differ in how STUN serversnot fixed, but SHOULD be something suitable for the error code. For certain errors, additional attributes arediscovered, whenadded to theSTUN requests are sent, what message types are used, what messagemessage. These attributes areused, and how authentication is performed. This specification definesspelled out in theSTUN usagesdescription where the error code is specified. For example, forbinding discovery (Section 12.1), NAT keepalives (Section 12.2) and short-term password (Section 12.3). New STUN usages mayan error code of 420 Unknown Attribute, the server MUST include an UNKNOWN-ATTRIBUTES attribute. Certain authentication errors also cause attributes to bedefined byadded (see Section 10). Extensions may define otherstandards-track documents. New STUN usages MUST describe their applicability, client discovery oferrors and/or additional attributes to add in error cases. If theSTUN server, howserver authenticated the request using an authentication mechanism, then the serverdeterminesSHOULD add the appropriate authentication attributes to theusage, new message types (requests or indications), new message attributes, new errorresponsecodes, and new client and server procedures. 12.1. Binding Discovery(see Section 10). Theprevious version of this specification, RFC3489 [15], described only this binding discoveryserver also adds any attributes required by the specific method or usage.12.1.1. Applicability Binding discovery is usedIn addition, the server SHOULD add a SERVER attribute tolearn reflexive addresses from servers onthenetwork, generallymessage. For thepublic Internet. That is, itBinding method, no additional checking isused byrequired unless the usage specifies otherwise. When forming the success response, the server adds aclientXOR-MAPPED-ADDRESS attribute todetermine its dynamically-bound 'public' UDPthe response, where the contents of the attribute are the source transport addressthatof the request message. For UDP, this isassignedthe source IP address and source UDP port of the request message. For TCP and TLS-over-TCP, this is the source IP address and source TCP port of the TCP connection as seen bya NAT between a STUN client and a STUNthe server.This7.3.1.2. Sending the Success or Error Response The response (success or error) is sent over the same transport as the request was received on. If the request was received over UDP, the destination IP addresswill be present inand port of themappedresponse is the source IP address and port of theSTUN Binding Response. The mappedreceived request message, and the source IP addresspresent inand port of thebindingresponsecan be used by clients to facilitate traversal of NATs for many applications. NAT traversalisproblematic for applications that require a client to insert a transport address into a message,equal towhich subsequent messages will be delivered by other entities in a network. Normally,theclient would insert the transportdestination IP addressfrom a local interface intoand port of the received request message.However, ifIf theclientrequest was received over TCP or TLS-over-TCP, the response isbehind a NAT, this local interface will be a private address. Clients within other address realms will not be able to send messages to that address. An example of a suchsent back on the same TCP connection as the request was received on. 7.3.2. Processing anapplication is SIP, which requires a client to include transport address information in several places, includingIndication If theSession Description Protocol (SDP [19]) body carried by SIP.indication contains unknown comprehension-required attributes, the indication is discarded and processing ceases. Thetransport address present inserver then does any additional checking that the method or the specific usage requires. If all the checks succeed, theSDPserver then processes the indication. No response isusedgenerated for an indication. For the Binding method, no additional checking or processing is required, unless the usage specifies otherwise. The mere receipt ofmedia. To use STUN as a technique for traversal of SIP and other protocols, whentheclient wishes to send a protocol message, it figures outmessage by the server has refreshed theplaces"bindings" in theprotocol data unit where itintervening NATs. Since indications are not re-transmitted over UDP (unlike requests), there issupposedno need toinsert its own transport address. Insteadhandle re-transmissions ofdirectly using a port allocated from a local interface,indications at theclient allocatesserver. 7.3.3. Processing aport fromSuccess Response If the success response contains unknown comprehension-required attributes, thelocal interface,response is discarded andfrom that port, generates a STUN Binding Request.the transaction is considered to have failed. Themapped address inclient then does any additional checking that theBinding Response (XOR-MAPPED-ADDRESSmethod orMAPPED- ADDRESS) providesthe specific usage requires. If all the checks succeed, the clientwith an alternative transport address that it canthenincludeprocesses the success response. For the Binding method, the client checks that the XOR-MAPPED-ADDRESS attribute is present in theprotocol payload. This transportresponse. The client checks the addressmayfamily specified. If it is an unsupported address family, the attribute SHOULD bewithin a differentignored. If it is an unexpected but supported address familythan(for example, thelocal interfaces used byBinding transaction was sent over IPv4, but theclient. Thisaddress family specified isnotIPv6), then the client MAY accept and use the value. 7.3.4. Processing an Error Response If the errorcondition. In suchresponse contains unknown comprehension-required attributes, or if the error response does not contain an ERROR-CODE attribute, then the transaction is simply considered to have failed. The client then does any processing specified by the authentication mechanism (see Section 10). This may result in acase,new transaction attempt. The processing at this point depends on the error-code, the method, and the usage; the following are the default rules: o If the error code is 300 through 399, the clientwould useSHOULD consider thelearned IP address and porttransaction asiffailed unless the ALTERNATE-SERVER extension is being used. See Section 11. o If the error code is 400 through 499, the clientwas a host with an interface within that address family. Indeclares the transaction failed; in the case ofSIP, to populate420, theSDP appropriately,response should contain aclient would generate two STUN Binding Request messages atUNKNOWN-ATTRIBUTES attribute that gives additional information. o If thetime a call is initiated or answered. Oneerror code isused to obtain500 through 599, thetransport address for RTP, andclient MAY resend theother, forrequest; clients that do so MUST limit the number of times they do this. Any other error code causes theReal Time Control Protocol (RTCP)[17]. Theclientmight also need to use STUNtoobtain transport addressesconsider the transaction failed. 8. FINGERPRINT Mechanism This section describes an optional mechanism forusageSTUN that aids inother partsdistinguishing STUN messages from packets of other protocols when theSIP message. The detailedtwo are multiplexed on the same transport address. This mechanism is optional, and a STUN usageofmust describe if and when it is used. In some usages, STUN messages are multiplexed on the same transport address as other protocols, such as RTP. In order tofacilitate SIP NAT traversal is outsideapply thescope of this specification. As discussed above,processing described in Section 7, STUN messages must first be separated from the application packets. Section 6 describes three fixed fields in thetransport addresses learned bySTUN header that can be used for this purpose. However, in some cases, these three fixed fields may not beusable with all entities with whom a client might wish to communicate. The waysufficient. When the FINGERPRINT extension is used, an agent includes the FINGERPRINT attribute inwhichmessages it sends to another agent. Section 14.5 describes the placement and value of thisproblem is handled depends onattribute. When theapplication protocol. The ideal solutionagent receives what it believes isfor a protocol to allow a client to includeamultiplicity of transport addressesSTUN message, then, in addition to other basic checks, thePDU. One of those can beagent also checks that thetransport address determined from STUN,message contains a FINGERPRINT attribute and that theothers can include transport addresses learned from other techniques. The application protocol would then provide a means for dynamically detecting which one works. An exampleattribute contains the correct value (see Section 7.3. This additional check helps the agent detect messages ofsuch an an approach is Interactive Connectivity Establishment (ICE [13]). 12.1.2. Clientother protocols that might otherwise seem to be STUN messages. 9. DNS Discovery ofServer Clients SHOULD be configured withadomain nameServer This section describes an optional procedure foraSTUNserver to use. In cases where the client has no explicit configuration mechanism for STUN, but knows the domain of its service provider, thethat allows a clientSHOULDto usethat domain (inDNS to determine thecaseIP address and port ofSIP,a server. A STUN usage must describe if and when thiswould beextension is used. To use this procedure, the client must have a domainfrom their Address-of-Record). The discovery mechanisms defined in Section 8.1 are then applied to that domain name. 12.1.3. Server Determination of Usage It is anticipated that servers would advertisename and aspecific port inservice name; theDNS forusage must also describe how theBinding Discovery usage. Thus, whenclient obtains these. When arequest arrives at that particular port,client wishes to locate a STUN server in theserver knowspublic Internet that accepts Binding Request/Response transactions, thebinding usageSRV service name is "stun". STUN usages MAY define additional DNS SRV service names. The domain name is resolved to a transport address using the SRV procedures specified inuse. This fact[RFC2782]. The DNS SRV service name isonly needed for purposes of determiningtheauthentication and message integrity mechanismservice name provided as input toapply. 12.1.4. New Requests or Indications This usage does not define any new message types. 12.1.5. New Attributes This usage does not define any new message attributes. 12.1.6. New Error Response Codes This usage does not define any new error response codes. 12.1.7. Client Proceduresthis procedure. Thebinding discoveryprotocol in the SRV lookup isutilized by athe transport protocol the clientjust priorwill run STUN over: "udp" for UDP, "tcp" for TCP, and "tls" for TLS-over-TCP. If, in the future, additional SRV records are defined for TLS over other transport protocols, those will need togeneratingutilize anapplication PDU that requiresSRV transport token of theclient to include itsform "tls-foo" for transportaddress.protocol "foo". Theclient MAY first obtain a short term credential usingprocedures of RFC 2782 are followed to determine theshort term password STUN usage. The credential that is obtained isserver to contact. RFC 2782 spells out the details of how a set of SRV records are sorted and thenusing in Binding Request messages. A Binding Request message is generated for each distinct transport addresstried. However, RFC2782 only states that the clientrequiresshould "try to connect toformulatetheapplication PDU. A successful response message will carry either an XOR-MAPPED-ADDRESS or MAPPED-ADDRESS attribute, depending(protocol, address, service)" without giving any details on what happens in the event of failure. When following these procedures, if theversionSTUN transaction times out without receipt of a response, theserver. Aclient SHOULDuseretry theXOR-MAPPED-ADDRESS if present. If not, it usesrequest to theMAPPED-ADDRESS. 12.1.8. Server Procedures It is RECOMMENDED that servers utilize short term credentials, obtained bynext server in theclientlist of servers from the DNS SRV response. Such aShared Secret request,retry is only possible forauthentication and message integrity. Consequently, if a Binding Requestrequest/response transmissions, since indication transactions generate no response or timeout. The default port for STUN requests isgenerated without a short term credential, the server SHOULD challenge3478, forone. 12.1.9. Security Considerationsboth TCP and UDP. Administrators SHOULD use this port in their SRV records forBinding DiscoveryUDP and TCP, but MAY use others. Thereareis nosecurity considerationsdefault port forthis usage beyond those described in Section 13. 12.2. NAT Keepalives 12.2.1. Applicability In thisSTUNusage,over TLS, however a STUN server SHOULD use a port number for TLS different from 3478 so that the server can determine whether the first message it will receive after the TCP connection is set up, is a STUN message or a TLS message. If no SRV records were found, the client performs an A or AAAA record lookup of the domain name. The result will be a list of IP addresses, each of which can be contacted at the default port using UDP or TCP, independent of the STUN usage. For usages that require TLS, lack of SRV records isconnectedequivalent to aserverfailure of the transaction, since the request or indication MUST NOT be sent unless SRV records provided a transport address specifically for TLS. 10. Authentication and Message-Integrity Mechanisms This section defines two mechanisms for STUN that aparticular application protocol (for example, a SIP proxy server). The connection is long-lived, allowing for asynchronous messaging from theclient and server can use to provide authentication and message-integrity; these two mechanisms are known as theclient. The clientshort-term credential mechanism and the long-term credential mechanism. These two mechanisms are optional, and each usage must specify if and when these mechanisms are used. An overview of these two mechanisms isconnectedgiven in . Each mechanism specifies the additional processing required to use that mechanism, extending theserver either using TCP,processing specified inwhich case there isSection 7. The additional processing occurs in three different places: when forming along-lived TCP connection frommessage; when receiving a message immediately after theclientthe basic checks have been performed; and when doing the detailed processing of error responses. 10.1. Short-Term Credential Mechanism The short-term credential mechanism assumes that, prior to theserver, or using UDP, in which caseSTUN transaction, the client and serverstoreshave used some other protocol to exchange a credential in thesource transport addressform of amessage from a client (such as SIP REGISTER),username andsends messages topassword. This credential is time-limited. The time-limit is defined by theclient using that transport address. Sinceusage. As an example, in theconnection betweenICE usage [I-D.ietf-mmusic-ice], theclienttwo endpoints use out-of-band signaling to agree on a username andserverpassword, and this username and password isvery-long lived,applicable for thebindings established by that connection needduration of the media session. This credential is used tobe maintainedform a message integrity check in each request and in many responses. There is no challenge and response as inany intervening NATs. Rather than implement expensive application-layer keepalives,thekeepalives can be accomplished using STUN Binding Requests. The client will periodically sendlong term mechanism; consequently, replay is prevented by virtue of the time-limited nature of the credential. 10.1.1. Forming aBindingRequestto the server, usingor Indication For a request or indication message, thesame transport addresses used foragent MUST include theapplication protocol. These Binding Requests are demultiplexed atUSERNAME and MESSAGE-INTEGRITY attributes in theserver usingmessage. The HMAC for themagic cookie and possibly FINGERPRINT.MESSAGE-INTEGRITY attribute is computed as described in Section 14.4. Theresponse fromkey for theserver informsHMAC is theclientpassword. Note that theserverpassword isstill alive. The STUN message also keeps the binding activenever included inintervening NATs. The client can also examinethemapped address inrequest or indication. 10.1.2. Receiving a Request or Indication After theBinding Response. If itagent haschanged, the client can re-initiate application layer procedures to informdone theserver of its new transport address. 12.2.2. Client Discoverybasic processing ofServer In this usage,a message, theSTUN server andagent performs theapplication protocol are usingchecks listed below in order specified: o If thesame fixed port. 12.2.3. Server Determination of Usage The server multiplexesmessage does not contain bothSTUNa MESSAGE-INTEGRITY andits application protocol ona USERNAME attribute: * If thesame port. The server knows itmessage ishas this usage because the URI that gets resolved to this port indicatesa request, the serversupports this multiplexing. 12.2.4. New Requests or IndicationsMUST reject the request with an error response. Thisusage does not define any newresponse MUST use an error code of 400. * If the messagetypes. 12.2.5. New Attributes This usageis an indication, the server MUST silently discard the indication. o If the USERNAME does notdefine any newcontain a username value currently valid within the server: * If the messageattributes. 12.2.6. New Error Response Codes This usage does not define any newis a request, the server MUST reject the request with an error response. This responsecodes. 12.2.7. Client ProceduresMUST use an error code of 401. * If theSTUN Response indicatesmessage is an indication, theclient's mapped address has changed fromserver MUST silently discard theclient's expected mapped address,indication. o Using theclient SHOULD inform other applications of its new mapped address. For example, a SIP client could usepassword associated with thebinding discovery usage to obtain a new mapped address, and then register it using SIP registration procedures. The client SHOULD NOT include a MESSAGE-INTEGRITY attribute unless promptedusername, compute the value forone bytheserver, since authentication ismessage-integrity as described in Section 14.4. If the resulting value does notgenerally used with this STUN usage. 12.2.8. Server Procedures The server SHOULD NOT authenticatematch the contents of theclient or look for aMESSAGE- INTEGRITYattribute. Sinceattribute: * If thekeepalives come with some regularity, and will come for each client thatmessage isconnected toa request, theserver,server MUST reject theprocessing cost associated with authenticating eachrequestis very high. Consequently, authentication should only be used by small servers, for whomwith an error response. This response MUST use an error code of 431. * If theprocessing costmessage isnotanissue, or when used with application protocols whereindication, theconsequences of a fake response are very significant. 12.2.9. Security Considerations for NAT Keepalives This STUN usage does not recommendserver MUST silently discard theusage of message integrityindication. If these checks pass, the server continues to process the request orauthentication. This is becauseindication. Any response generated by theclient never actually usesserver MUST include themapped address fromMESSAGE-INTEGRITY attribute, computed using theSTUN response. It merely treatsusername and password utilized to authenticate the request. If any of the checks fail, the server MUST NOT include achangeMESSAGE- INTEGRITY or USERNAME attribute inthat address asthe error response. 10.1.3. Receiving ahint thatResponse The processing here takes place prior to the processing in Section 7.3.3 or Section 7.3.4. The clientshould re-apply application layer procedureslooks forconnection establishment and registration. An attacker could attempt to inject faked responses, or modify responses in transit. Such an attack would requiretheattacker to be on-pathMESSAGE-INTEGRITY attribute inorder to determinethetransaction ID. Inresponse. If present, theworst case,client computes theattack would causemessage integrity over theclient to see a changeresponse as defined inIP address or port, and then perform an application layer re-registration. Such a re-registration would not useSection 14.4, using thetransport address obtained fromsame password it utilized for theBinding Response. Thus,request. If theworst thatresulting value matches theattacker can docontents of the MESSAGE-INTEGRITY attribute, the response iscauseconsidered authenticated. If theclient to re-register every half minutevalue does not match, orso, when it otherwise wouldn't need to. Givenif MESSAGE-INTEGRITY was absent, thedifficultyresponse MUST be discarded, as if it was never received. This means that retransmits, if applicable, will continue. 10.2. Long-term Credential Mechanism The long-term credential mechanism relies on a long term credential, inlaunching this attack (it requirestheattacker to be on-pathform of a username andto disrupt the actual response from the server) compared to the benefit, therepassword, that are shared between client and server. The credential islittle motivation for authentication or integrity mechanisms. When used with application protocols where the cost of "re- registration"considered long-term since it is assumed that it is provisioned for a user, and remains infact high,effect until thekeepalive usage can still be used without authentication. However,user is no longer a subscriber of theusage would serve ONLYsystem, or is changed. This is basically a traditional "log-in" username and password given to users. Because these usernames and passwords are expected tokeep NAT bindings alive; it would notbeusefulvalid fordetecting failuresextended periods of time, replay prevention is provided in theserver orform ofintervening NAT. In suchacase,digest challenge. In this mechanism, the clientwould not performinitially sends a request, without offering anyapplication layer processing based oncredentials or any integrity checks. The server rejects this request, providing theSTUN response, even if it indicateduser achange in transport address. 12.3. Short-Term Password In orderrealm (used toensure interoperability, this usage describesguide the user or agent in selection of aTLS-based mechanism to obtainusername and password) and ashort-term credential.nonce. Theusage makes use ofnonce provides theShared Secret Request and Response messages.replay protection. It isdefined asaseparate usagecookie, selected by the server, and encoded inorder to allow it to run onsuch aseparate port, and to allow itway as tobe more easily separated from the different STUN usages, only someindicate a duration of validity or client identity from whichrequire this mechanism. 12.3.1. Applicability To thwart some on-path attacks described in Section 13,it isnecessary for the STUNvalid. The client retries the request, this time including its username, the realm, andSTUN server to integrity protectechoing theinformation they exchange over UDP. Innonce provided by theabsence of a long- term secret (password) that is shared between them,server. The client also includes ashort-term password can be obtained usingmessage-integrity, which provides an HMAC over theusage described in this section. The username and password returned inentire request, including theSTUN Shared Secret Response are valid for use in subsequent STUN transactions for nine (9) minutes with any applicable hosts as described in Section 12.3.2.nonce. Theusernameserver validates the nonce, andpassword obtained with this usage are used aschecks theUSERNAMEmessage-integrity. If they match, the request is authenticated. If the nonce is no longer valid, it is considered "stale", andintheHMAC forserver rejects theMESSAGE-INTEGRITY inrequest, providing a new nonce. In subsequentSTUN message, respectively. 12.3.2. Client Discovery of Server The client followsrequests to theprocedures in Section 8.1. The SRV protocol is "tls" andsame server, theservice name "stun-pass". For example aclientwould look up "_stun-pass._tls.example.com" in DNS. 12.3.3. Server Determination of Usage The server advertisesreuses the nonce, username, realm and password it used previously. In thisportway, subsequent requests are not rejected until the nonce becomes invalid by the server, in which case theDNS as capable of receiving TLS over TCP connections, along withrejection provides a new nonce to theShared Secret messagesclient. Note thatrun over it. The server MAY also advertise this same port in DNSthe long-term credential mechanism cannot be used to protect indications, since indications cannot be challenged. Usages utilizing indications must either use a short-term credential, or omit authentication and message integrity forother TLS over TCP usages ifthem. Since theserverlong-term credential mechanism iscapable of multiplexing those different usages.susceptible to offline dictionary attacks, deployments SHOULD utilize strong passwords. Forexample,STUN servers used in conjunction with SIP servers, it is desirable to use theserver could advertisesame credentials for authentication to theshort-term passwordSIP server andbinding discovery usages onSTUN server. Typically, SIP systems utilizing SIP's digest authentication mechanism do not actually store thesame TLS/TCP port. 12.3.4. New Requests or Indications The message type Shared Secret Request and its associated Shared Secret Response and Shared Secret Error Response are defined in this section. Their values are enumeratedpassword inSection 15. The following figure indicatesthe database. Rather, they store a value called H(A1), whichattributes are present inis computed as: H(A1) = MD5(username ":" realm ":" password) If a system wishes to utilize this credential, theShared Secret Request, Response,STUN password would be computed by taking the user-entered username and password, andError Response. An M indicatesusing H(A1) as the STUN password. It is RECOMMENDED thatinclusion ofclients utilize this construction for theattribute inSTUN password. 10.2.1. Forming a Request There are two cases when forming a request. In themessagefirst case, this ismandatory, O means its optional, C means it's conditional based on some other aspect ofthemessage, and - means thatfirst request from theattribute is not applicable to that message type. Attributes not listed are not applicableclient toShared Secret Request, Response, or Error Response. Shared Shared Shared Secret Secret Secret Attribute Request Response Error Response _________________________________________________ USERNAME O M - PASSWORD - M - MESSAGE-INTEGRITY O O O ERROR-CODE - - M ALTERNATE-SERVER - - C UNKNOWN-ATTRIBUTES - - C SERVER - O O REALM C - C NONCE C - C The Shared Secret requests, like other STUN requests, can be authenticated. However, sincethe server (as identified by itspurposeIP address and port). In the second case, the client isto obtainsubmitting ashort-term credential, the Shared Secretsubsequent requestitself cannot be authenticated withonce ashort-term credential. However, it can be authenticated withprevious request/response transaction has completed successfully. 10.2.1.1. First Request If the client has not completed along-term credential. 12.3.5. New Attributes No new attributes are defined by this usage. 12.3.6. New Error Response Codes This usage definessuccessful request/response transaction with the433 error response. Onlyserver, it SHOULD omit the USERNAME, MESSAGE- INTEGRITY,ERROR-CODEREALM, andSERVER attributes are applicable to this response. 12.3.7. Client Procedures Shared Secret requests are formed likeNONCE attributes. In otherSTUN requests, with the following additions. Clients MUST NOT use a short-term credential with a Shared Secret request. They SHOULD sendwords, the very first requestwithis sent as if there were nocredentials (omitting MESSAGE-INTEGRITY and USERNAME). Processing of the Shared Secret response follows that of any other STUN response. Note that clients MUST be prepared to be challenged forauthentication or message integrity applied. 10.2.1.2. Subsequent Requests Once along-term credential. Ifrequest/response transaction has completed successfully, theresponse was a Shared Secret Response, itclient willcontainhave been been presented ashort lived usernamerealm andpassword, encoded innonce by theUSERNAMEserver, andPASSWORD attributes, respectively. Aselected a username and password with which it authenticated. The client SHOULDuse these credentials whenever short term credentials are neededcache the username, password, realm, and nonce forany server discovered usingsubsequent communications with thesame domain name as was used to discoverserver. When theone which returned those credentials. For example, if aclientusedsends adomain name of example.com,subsequent request, itwould have looked up _stun- pass._tls.example.com in DNS, found a server,SHOULD include the USERNAME, REALM, andsent a Shared Secret request that providedNONCE attributes with these cached values. It SHOULD include acredential toMESSAGE- INTEGRITY attributed, computed as described in Section 14.4 using theclient. The client would use this credential withcached password as the key. 10.2.2. Receiving a Request After the serverdiscovered by looking up _stun._udp.example.comhas done the basic processing of a request, it performs the checks listed below in theDNS.order specified: o If theresponse wasmessage: * does not contain aShared Secret Error Response, and ERROR-CODE attribute was present withMESSAGE-INTEGRITY attribute, * OR, it contains aresponse code of 433, and the client hadUSERNAME whose value is notsent the request over TLS, the client SHOULD establishaTLS connection tovalid username, the serverand retry the request over that connection. If the client had used TLS, thisMUST generate an error response with an error code of 401. This response MUST include a REALM value. It isunrecoverable andRECOMENDED that theclient SHOULD NOT retry. 12.3.8. Server Procedures The procedures for general processingREALM value by the domain name of the provider ofSTUN requests apply to Shared Secret requests. Servers MAY challengetheclient for a long- term credential if one was not provided in a request. However, theySTUN server. The response MUSTNOT challenge the request forinclude ashort-term credential.NONCE, selected by the server. o If theShared Secret Request did not arrive overmessage contains aTLS connection,MESSAGE-INTEGRITY attribute, but is missing the USERNAME, REALM or NONCE attributes, the server MUST generatea Shared Secret Erroran error response with anERROR-CODE attribute that has a responseerror code of433.400. o If therequest is valid and authenticated (assuming the serverNONCE isperforming authentication),no longer valid, the server MUSTcreate a short term credential for the user. This credential consistsgenerate an error response with an error code ofa username and password. The credentials438 (Stale Nonce). This response MUSTbe valid forinclude aduration of at least nine minutes,NONCE andSHOULD NOT be valid for a duration of longer than thirty minutes. The username MUST be distinct, with extremely high probabilities, from all usernames that have been handed out across all servers that are returned from DNS SRV queries for the same domain name. Extremely high probability means thatREALM attribute. o Using thelikelihood of collision SHOULD be better than 1 in 2**64. Thepasswordfor each username MUST be cryptographically randomassociated withat least 128 bits of entropy. 12.3.9. Security Considerations for Short-Term Password The security considerations in Section 13 do not apply to the Shared Secret request and response, since these messages do not make use of mapped addresses, which istheprimary source of security consideration discussed there. Rather, shared secret requests are used to obtain short term credentials that are usedusername in theauthentication of other messages. BecauseUSERNAME attribute, compute theShared Secret response itself carries a credential, invalue for theform of a username and password, it must be sent encrypted. For this reason, STUN servers MUST reject any Shared Secret request that hasmessage-integrity as described in Section 14.4. If the resulting value does notarrived over a TLS connection. Malicious clients could generate a multiplicity of Shared Secret requests, eachmatch the contents ofwhich causesthe MESSAGE-INTEGRITY attribute, the serverto allocate shared secrets, eachMUST reject the request with an error response. This response MUST use an error code ofwhich might consume memory401. It MUST include a REALM andprocessing resources.NONCE attribute. Ifshared secret requests are not being authenticated, this leads to a possible denial-of-service attack. Indeed, even ifthese checks pass, therequestor is authenticated, attacks are still possible. To prevent being swamped with traffic, a STUNserverSHOULD limitcontinues to process thenumber of simultaneous TLS connections it will hold open by dropping an existing connection when a new connectionrequestarrives (based on an Least Recently Used (LRU) policy, for example). Similarly, servers SHOULD allocate only a small number of shared secretsor indication. Any response generated by the server MUST include the MESSAGE-INTEGRITY attribute, computed using the username and password utilized toa host with a particular source transport address. Requests fromauthenticate thesame transport address which exceed this limitrequest. The REALM, NONCE, and USERNAME attributes SHOULD NOT berejected withincluded. 10.2.3. Receiving a600 response. Servers SHOULD also limitResponse The processing here takes place prior to thetotal number of shared secrets they will provide at a time across all clients, based onprocessing in Section 7.3.3 or Section 7.3.4. If thenumberresponse is an error response, with an error code ofusers and expected loads during normal peak usage. If a Shared Secret request arrives and401 (Unauthorized), theserver has exceeded its limit, itclient SHOULDrejectretry the request with a500 response. Furthermore, for servers that are not authenticating shared secret requests, it is RECOMMENDED that short-term credentials be constructed in a way such that they do not require memory or disk to store. This can be donenew transaction. This request MUST contain a USERNAME, determined byintelligently computingtheusername and password. One approach is to constructclient as theUSERNAME as: USERNAME = <prefix,rounded-time,hmac> Where prefix is some random text string (differentappropriate username foreach shared secret request), rounded-time isthecurrent time modulo 20 minutes, and hmac is an HMAC [13] overREALM from theprefix and rounded-time, using a server private key.error response. Thepassword is then computed as: password = <hmac(USERNAME,anotherprivatekey)> With this structurerequest MUST contain theserver can verify thatREALM, copied from theusername was not tampered witherror response. The request MUST contain the NONCE, copied from the error response. The request MUST contain the MESSAGE-INTEGRITY attribute, computed using thehmac present inpassword associated with theusername. 13. Security Considerations Attacks on STUN systems vary depending onusername in theusage.USERNAME attribute. Theshort term password usageclient MUST NOT perform this retry if it isquite different fromnot changing theother usages defined here, andUSERNAME or REALM or itssecurity considerations are unique to it and discussed as part ofassociated password, from theusage definition. However, all ofprevious attempt. If theother usages are very similar and share a similar set of security considerations as a consequence of their usageresponse is an error response with an error code of 438, themapped address from STUN Binding Responses. Consequently, these security considerations apply to usage ofclient MUST retry themapped address. 13.1. Attacks on STUN Generally speaking, attacks on STUN can be classified into denial of service attacks and eavesdropping attacks. Denial of service attacks can be launched against a STUN server itself or against other elementsrequest, using theSTUN protocol.new NONCE supplied in the 438 response. This retry MUST also include the USERNAME, REALM and MESSAGE-INTEGRITY. Theattacks of greater interest are thoseclient looks for the MESSAGE-INTEGRITY attribute inwhichtheSTUN server and client are used to launch denial of service (DoS) attacks against other entities, includingresponse (either success or failure). If present, the clientitself. Many ofcomputes theattacks requiremessage integrity over theattacker to generate aresponseto a legitimate STUN request,as defined inorder to provide the client with a faked mapped address. The attacks that can be launchedSection 14.4, usingsuch a technique include: 13.1.1. Attack I: DDoS Against a Target In this case, the attacker provides a large number of clients withthe samefaked mapped address that points topassword it utilized for theintended target. This will trick allrequest. If theSTUN clients into thinking that their addresses are equal to that ofresulting value matches thetarget. The clients then hand out that address in order to receive traffic on it (for example, in SIP or H.323 messages). However, allcontents ofthat traffic becomes focused at the intended target. The attack can provide substantial amplification, especially when used with clients that are using STUN to enable multimedia applications. 13.1.2. Attack II: Silencing a Client In this attack,theattacker seeks to deny a client access to services enabled by STUN (for example, a client using STUN to enable SIP-based multimedia traffic). To do that,MESSAGE-INTEGRITY attribute, theattacker provides that client with a faked mapped address. The mapped address it providesresponse isa transport address that routes to nowhere. As a result,considered authenticated. If theclient won't receive any ofvalue does not match, or if MESSAGE-INTEGRITY was absent, thepacketsresponse MUST be discarded, as if itexpectswas never received. This means that retransmits, if applicable, will continue. 11. ALTERNATE-SERVER Mechanism This section describes a mechanism in STUN that allows a server toreceive when it hands out the mapped address.redirect a client to another server. Thisexploitationextension isnot very interesting for the attacker. It impactsoptional, and asingle client, whichusage must define if and when this extension isfrequently not the desired target. Moreover, any attacker that can mount the attack could also deny service toused. To prevent denial-of-service attacks, this extension MUST only be used in situations where the clientby other means, such as preventing theand server are using an authentication and message-integrity mechanism. A server using this extension redirects a clientfrom receiving any response from the STUN server, or evento another server by replying to aDHCP server. 13.1.3. Attack III: Assuming the Identityrequest message with an error response message with an error code of 300 (Try Alternate). The server MUST include aClient This attack is similar to attack II. However, the faked mapped address points to the attacker themself. This allowsALTERNATE-SERVER attribute in theattacker to receive trafficerror response. The error response message MUST be authenticated, whichwas destined for the client. 13.1.4. Attack IV: Eavesdropping In this attack,in practice means theattacker forcesrequest message must have passed the authentication checks. A clientto useusing this extension handles amapped address that routes to itself. It then forwards any packets it receives to300 (Try Alternate) error code as follows. If theclient. This attack would allowerror response has passed theattacker to observe all packets sent toauthentication checks, then theclient. However,client looks for a ALTERNATE-SERVER attribute inorder to launchtheattack, the attacker must have already been able to observe packets fromerror response. If one is found, then the clienttoconsiders theSTUN server. In most cases (suchcurrent transaction aswhenfailed, and re-attempts theattack is launchedrequest with the server specified in the attribute. The client SHOULD reuse any authentication credentials froman access network), this means thattheattacker could already observe packets sent toold request in theclient.new transaction. 12. Backwards Compatibility with RFC 3489 Thisattack is, assection define procedures that allow aresult, only useful for observing traffic by attackers on the path fromdegree of backwards compatible with the original protocol defined in RFC 3489 [RFC3489]. This mechanism is optional, meant to be utilized only in cases where a new client can connect tothe STUNan old server,but not generally onor vice-a-versa. A usage must define if and when this procedure is used. Section 18 lists all thepathchanges between this specification and RFC 3489 [RFC3489]. However, not all ofpackets being routed towards the client. 13.2. Launchingthese differences are important, because "classic STUN" was only used in a few specific ways. For theAttacks It is important to note that attackspurposes of thisnature (injecting responses with fake mapped addresses) require that the attacker be capable of eavesdropping requests sent fromextension, theclient toimportant changes are theserver (or to act as a man infollowing. In RFC 3489: o UDP was themiddle for such attacks). Thisonly supported transport; o The field that isbecause STUN requests containnow the Magic Cookie field was atransaction identifier, selected bypart of theclient, which is random with 96transaction id field, and transaction ids were 128 bitsof entropy.long; o Theserver echoes this value inXOR-MAPPED-ADDRESS attribute did not exist, and theresponse,Binding method used the MAPPED-ADDRESS attribute instead o There were two comprehension-required attributes, RESPONSE-ADDRESS and CHANGE-REQUEST, that have been removed from this specification. * These attributes are now part of the NAT Behavior Discovery usage. 12.1. Changes to Client Processing A clientignores any responsesthatdon't have a matching transaction ID. Therefore, in order for an attackerwants toprovideinteroperate with afaked response[RFC3489] server SHOULD send a request message thatis accepted byuses theclient,Binding method, contains no attributes, and uses UDP as theattacker needstransport protocol toknowthetransaction ID of the request. The large amount of randomness, combined withserver. If successful, theneed to know whensuccess response received from theclient sendsserver will contain arequest and the transport addresses used for that request, precludes attacks that involve guessingMAPPED-ADDRESS attribute rather than an XOR-MAPPED-ADDRESS attribute; other than this change, thetransaction ID. Since allprocessing of theabove attacks rely on this one primitive - injecting aresponsewith a faked mapped address - preventing the attacksisaccomplished by preventing this one operation. To prevent it, we needidentical toconsiderthevarious ways in which it can be accomplished. There are several: 13.2.1. Approach I: Compromise a Legitimate STUNprocedures described above. 12.2. Changes to ServerIn this attack, the attacker compromises a legitimateProcessing A STUN serverthroughcan detect when avirus or Trojan horse. Presumably, this would allowgiven Binding Request message was sent from an RFC 3489 [RFC3489] client by theattacker to take overabsence of theSTUN server, and controlcorrect value in the Magic Cookie field. When thetypes of responses it generates. Compromise of a STUNservercan also leaddetects an RFC 3489 client, it SHOULD copy the value seen in the Magic Cookie field in the Binding Request todiscovery of open ports. Knowledgethe Magic Cookie field in the Binding Response message, and insert a MAPPED-ADDRESS attribute instead of anopen port createsXOR- MAPPED-ADDRESS attribute. The client might, in rare situations, include either the RESPONSE- ADDRESS or CHANGE-REQUEST attributes. In these situations, the server will view these as unknown comprehension-required attributes and reply with anopportunity for DoS attacks on those ports (or DDoS attacks iferror response. Since thetraversed NATmechanisms utilizing those attributes are no longer supported, this behavior isa full cone NAT). Discovering open portsacceptable. 13. STUN Usages STUN by itself isalready fairly trivial using port probing, so this doesnotrepresent a major threat. 13.2.2. Approach II: DNS Attacks STUN servers are discovered using DNS SRV records. If an attacker can compromise the DNS, it can inject fake records which mapadomain namesolution to theIP addressNAT traversal problem. Rather, STUN defines a toolkit of functions that can be used inside a larger solution. The term "STUN Usage" is used for any solution that uses STUNserver run byas a component. At theattacker. This will allow it to inject fake responses to launch anytime ofthe attacks above. Clearly, this attack is only applicable forwriting, three STUN usageswhich discover servers through DNS. 13.2.3. Approach III: Rogue Router orare defined: Interactive Connectivity Establishment (ICE) [I-D.ietf-mmusic-ice], Client- initiated connections for SIP [I-D.ietf-sip-outbound], and NATRather than compromiseBehavior Discovery [I-D.ietf-behave-nat-behavior-discovery]. Other STUN usages may be defined in the future. A STUNserver, an attacker can cause ausage defines how STUNserveris actually utilized - when togenerate responsessend requests, what to do with thewrong mapped address by compromising a router or NAT on the path from the clientresponses, and which optional procedures defined here (or in an extension totheSTUN) are to be used. A usage would also define: o Which STUNserver.methods are used; o What authentication and message integrity mechanisms are used; o What mechanisms are used to distinguish STUN messages from other messages. WhentheSTUNrequest passes through the rogue router or NAT, it rewrites the source transport address of the packet to be that of the desired mapped address. This address cannot be arbitrary. If the attackerisonrun over TCP, a framing mechanism may be required; o How a STUN client determines thepublic Internet (that is, there are no NATs between itIP address and port of the STUNserver),server; o Whether backwards compatibility to RFC 3489 is required; o What optional attributes defined here (such as FINGERPRINT andthe attacker doesn't modify theALTERNATE-SERVER) or in other extensions are required. In addition, any STUNrequest, the address has to have the property that packets sent fromusage must consider the security implications of using STUNserver toin thataddress would route through the compromised router. This is becauseusage. A number of attacks against STUN are known (see the Security 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 STUNserver will sendis an example of theresponses backUnilateral Self-Address Fixing approach tothe source transportNAT traversal, and if so, addressoftherequest. Withquestions raised in RFC 3424. 14. STUN Attributes After the STUN header are zero or more attributes. Each attribute MUST be TLV encoded, with amodified source transport address,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 5: Format of STUN Attributes The value in theonly way they can reachLength field MUST contain theclient is iflength of thecompromised router directs them there. IfValue part of theattacker isattribute, prior to padding, measured in bytes. Since STUN aligns attributes on 32 bit boundaries, attributes whose content is not aprivate network (that is, theremultiple of 4 bytes areNATs between itpadded with 1, 2 or 3 bytes of padding so that its value contains a multiple of 4 bytes. The padding bits are ignored, andthe STUN server), the attacker will notmay beable to force the server to generate arbitrary mapped addressesany value. Any attribute type MAY appear more than once inresponses. They willa STUN message. Unless specified otherwise, the order of appearance is significant: onlybe able forcetheSTUN serverfirst occurance needs togenerate mapped addresses which routebe processed by a receiver, and any duplicates MAY be ignored by a receiver. To allow future revisions of this specification to add new attributes if needed, theprivate network. Thisattribute space isbecause the NATdivided into two ranges. Attributes with type values betweenthe attacker0x0000 and 0x7FFF are comprehension-required attributes, which means that the STUNserver will rewrite the source transport address ofagent cannot successfully process theSTUN request, mappingmessage unless itto a public addressunderstands the attribute. Attributes with type values between 0x8000 and 0xFFFF are comprehension-optional attributes, which means thatroutes tothose attributes can be ignored by theprivate network. BecauseSTUN agent if it does not understand them. The STUN Attribute types defined by this specification are: Comprehension-required range (0x0000-0x7FFF): 0x0000: (Reserved) 0x0001: MAPPED-ADDRESS 0x0006: USERNAME 0x0007: (Reserved; was PASSWORD) 0x0008: MESSAGE-INTEGRITY 0x0009: ERROR-CODE 0x000A: UNKNOWN-ATTRIBUTES 0x0014: REALM 0x0015: NONCE 0x0020: XOR-MAPPED-ADDRESS Comprehension-optional range (0x8000-0xFFFF) 0x8022: SERVER 0x8023: ALTERNATE-SERVER 0x8028: FINGERPRINT The rest ofthis, the attacker can only forcethis section describes theserver to generate faked mapped addresses that route toformat of theprivate network. Unfortunately, it is possible thatvarious attributes defined in this specification. 14.1. MAPPED-ADDRESS The MAPPED-ADDRESS attribute indicates alow quality NAT would be willing to mapreflexive transport address of the client. It consists of anallocated publiceight bit addressto another publicfamily, and a sixteen bit port, followed by a fixed length value representing the IP address. If the address(as opposed to an internal private address), in which casefamily is IPv4, theattacker could forgeaddress MUST be 32 bits. If thesourceaddressin a STUN request tofamily is IPv6, the address MUST bean arbitrary public address. This kind of behavior from NATs does appear to128 bits. All fields must berare. 13.2.4. Approach IV: Manin network byte order. The format of theMiddle As an alternative to approach III (Section 13.2.3), if the attackerMAPPED-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 7: Format of MAPPED-ADDRESS attribute The address family canplace an elementtake on thepath fromfollowing values: 0x01:IPv4 0x02:IPv6 The first 8 bits of theclientMAPPED-ADDRESS MUST be set tothe server, the element can act as a man-in-the-middle. In that case, it can intercept a STUN request,0 andgenerate a STUN response directlyMUST be ignored by receivers. These bits are present for aligning parameters on natural 32 bit boundaries. This attribute is used only by servers for achieving backwards compatibility withany desired value of the mapped address field. Alternatively, it can forward the STUN requestRFC 3489 [RFC3489] clients. 14.2. XOR-MAPPED-ADDRESS The XOR-MAPPED-ADDRESS attribute is identical to theserver (after potential modification), receiveMAPPED-ADDRESS attribute, except that theresponse, and forward it toreflexive transport address is obfuscated through theclient. When forwardingXOR function. The format of therequestXOR-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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |x x x x x x x x| Family | X-Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | X-Address (Variable) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Figure 9: Format of XOR-MAPPED-ADDRESS Attribute The Family represents the IP address family, andresponse, this attackissubjectencoded identically to thesame limitations onFamily in MAPPED-ADDRESS. X-Port is the mappedaddress described in Approach III (Section 13.2.3). 13.2.5. Approach V: Response Injection Plus DoS In this approach,port, exclusive or'd with most significant 16 bits of theattacker does not need to be a MitM (as in approaches III and IV). Rather, it only needs to be able to eavesdrop onto a network segment that carries STUN requests. Thismagic cookie. If the IP address family is IPv4, X-Address iseasily done in multiple access networks such as ethernet or unprotected 802.11. To injectthefake response,mapped IP address exclusive or'd with theattacker listens onmagic cookie. If thenetwork for a STUN request. When it sees one, it simultaneously launches a DoS attack onIP address family is IPv6, theSTUN server, and generates its own STUN response withX-Address is thedesiredmapped IP addressvalue. The STUN response generated by the attacker will reachexclusively or'ed with theclient,magic cookie and theDoS attack against the server is aimed at preventing the legitimate response from96- bit transaction ID. For example, using theserver from reaching"^" character to indicate exclusive or, if theclient. Arguably,IP address is 192.168.1.1 (0xc0a80101) and theattacker can do withoutport is 5555 (0x15B3), theDoS attack onX-Port would be 0x15B3 ^ 0x2112 = 0x34A1, and theserver, so long asX-Address would be 0xc0a80101 ^ 0x2112A442 = 0xe1baa543. The rules for encoding and processing thefaked response beatsfirst 8 bits of thereal response back toattribute's value, theclient,rules for handling multiple occurrences of the attribute, and theclient usesrules for processing addresses families are thefirst response,same as for MAPPED-ADDRESS. NOTE: XOR-MAPPED-ADDRESS andignoresMAPPED-ADDRESS differ only in their encoding of thesecond (even though it's different). 13.2.6. Approach VI: Duplication This approach is similar to approach V (Section 13.2.5).transport address. Theattacker listens onformer encodes thenetwork for a STUN request. Whentransport address by exclusive-or'ing itsees one,with the magic cookie. The latter encodes itgenerates its own STUN request towardsdirectly in binary. RFC 3489 originally specified only MAPPED-ADDRESS. However, deployment experience found that some NATs rewrite theserver. This STUN request is identical to32-bit binary payloads containing theone it saw,NAT's public IP address, such as STUN's MAPPED-ADDRESS attribute, in the well-meaning butwithmisguided attempt at providing aspoofed source IP address.generic ALG function. Such behavior interferes with the operation of STUN and also causes failure of STUN's message integrity checking. 14.3. USERNAME Thespoofed addressUSERNAME attribute isequal to the one thatused for message integrity. It identifies theattacker desires to have placedusername and password combination used in themapped addressmessage integrity check. The value ofthe STUN response. In fact, the attacker generatesUSERNAME is a variable length value. It MUST contain afloodUTF-8 encoded sequence ofsuch packets.less than 128 characters. 14.4. MESSAGE-INTEGRITY The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of the STUN message. The MESSAGE-INTEGRITY attribute can be present in any STUNserver will receive the one original request, plus a flood of duplicate fake ones. It generates responses to all of them. Ifmessage type. Since it uses theflood is sufficiently large forSHA1 hash, theresponsesHMAC will be 20 bytes. The text used as input tocongest routers or some other equipment, thereHMAC isa reasonable probability thattheone real response is lost (along with many ofSTUN message, including thefaked ones), butheader, up to and including thenet result is that onlyattribute preceding thefaked responses are received byMESSAGE-INTEGRITY attribute. With theSTUN client. These responses are all identical and all containexception of themapped addressFINGERPRINT attribute, which appears after MESSAGE-INTEGRITY, agents MUST ignore all other attributes thatthe attacker wanted the client to use.follow MESSAGE-INTEGRITY. Theflood of duplicate packets is not needed (that is, only one faked request is sent), so longkey used asthe faked response beats the real response backinput to HMAC is theclient, andpassword. Since theclient useshash is computed over thefirst response, and ignoresentire STUN message, it includes thesecond (even though it's different). Note that, in this approach, launching a DoS attack againstlength field from the STUNserver ormessage header. This length indicates theIP network, to preventlength of thevalid response from being sent or received, is problematic. The attacker needsentire message, including theSTUN server toMESSAGE-INTEGRITY attribute itself. Consequently, the MESSAGE-INTEGRITY attribute MUST beavailable to handle its own request. Dueinserted into the message (with dummy content) prior to theperiodic retransmissionscomputation of therequest fromintegrity check. Once theclient, this leaves a very tiny window of opportunity. The attacker must startcomputation is performed, theDoS attack immediately aftervalue of theactual request fromattribute can be filled in. This ensures theclient, causinglength has the correctresponse to be discarded, and then ceasevalue when theDoS attack in order to send its own request, all beforehash is performed. Similarly, when validating thenext retransmission fromMESSAGE-INTEGRITY, theclient. Duelength field should be adjusted to point to theclose spacingend of theretransmits (100msMESSAGE-INTEGRITY attribute prior toa few seconds), thiscalculating the HMAC. Such adjustment isvery difficult to do. Besides DoS attacks, therenecessary when attributes, such as FINTERPRINT, appear after MESSAGE- INTEGRITY. 14.5. FINGERPRINT The FINGERPRINT attribute may beother ways to preventpresent in all STUN messages. The value of theactual request fromattribute is computed as theclient from reachingCRC-32 of theserver. Layer 2 manipulations, for example, might be ableSTUN message up toaccomplish it. Fortunately, this approach(but excluding) the FINGERPRINT attribute itself, xor-d with the 32 bit value 0x5354554e (the XOR helps in cases where an application packet is also using CRC-32 in it). The 32 bit CRC issubject tothesame limitations documentedone defined inApproach III (Section 13.2.3),ITU V.42 [ITU.V42.1994], whichlimit the rangehas a generator polynomial ofmapped addressesx32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1. When present, theattacker can causeFINGERPRINT attribute MUST be theSTUN server to generate. 13.3. Countermeasures STUN provides mechanisms to counterlast attribute in theapproaches described above,message, andadditional, non-STUN techniquesthus will appear after MESSAGE-INTEGRITY. The FINGERPRINT attribute canbe used as well. First off, itaid in distinguishing STUN packets from packets of other protocols. See Section 8. When using the FINGERPRINT attribute in a message, the attribute isRECOMMENDED that networksfirst placed into the message withSTUN clients implement ingress source filtering [6]. Thisa dummy value, then the CRC is computed, and then the value of the attribute is updated. If the MESSAGE-INTEGRITY attribute is also present, then it must be present with the correct message-integrity value before the CRC is computed, since the CRC isparticularly important fordone over theNATs themselves. As Section 13.2.3 explains, NATs which do not perform this check can be usedvalue of the MESSAGE-INTEGRITY attribute as"reflectors"well. 14.6. ERROR-CODE The ERROR-CODE attribute is used inDDoS attacks. Most NATs do perform this check asError Response messages. It contains adefault modenumeric error code value in the range ofoperation. We strongly advise people who purchase NATs300 toensure that this capability is present699 plus a textual reason phrase encoded in UTF-8, andenabled. Secondly, for usages where the STUN serverisnot co-locatedconsistent in its code assignments and semantics withsome kind of application (such as the binding discovery usage), itSIP [RFC3261] and HTTP [RFC2616]. The reason phrase isRECOMMENDED that STUN servers be run on hosts dedicated to STUN, with all UDPmeant for user consumption, andTCP ports disabled exceptcan be anything appropriate for theSTUN ports. This is to prevent viruses and Trojan horses from infecting STUN servers, in order to prevent their compromise. This helps mitigate Approach I (Section 13.2.1). Thirdly, to preventerror code. Recommended reason phrases for theDNS attackdefined error codes are presented below. The reason phrase MUST be a UTF-8 encoded sequence ofSection 13.2.2, Section 8.2 recommends thatless than 128 characters. To facilitate processing, theclient verifyclass of thecredentials provided byerror code (the hundreds digit) is encoded separately from theserver withrest of thename used incode. 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, should be 0 |Class| Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reason Phrase (variable) .. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The Reserved bits SHOULD be 0, and are for alignment on 32-bit boundaries. Receivers MUST ignore these bits. The Class represents theDNS lookup. Finally, allhundreds digit of theattacks above rely on the client takingerror code. The value MUST be between 3 and 6. The number represents themapped address it learned from STUN,error code modulo 100, andusing it in application layer protocols. If encryptionits value MUST be between 0 andmessage integrity99. The following error codes, along with their recommended reason phrases (in brackets) areprovided within those protocols,defined: 300 Try Alternate: The client should contact an alternate server for this request. This error response MUST only be sent if theeavesdroppingrequest included a USERNAME attribute andidentity assumption attacks cana valid MESSAGE- INTEGRITY attribute; otherwise it MUST NOT beprevented. As such, applications that make use of STUN addresses in application protocols SHOULD use integritysent andencryption, even if a SHOULD level strengtherror code 400 isnot specified for that protocol. For example, multimedia applications using STUN addresses to receive RTP traffic would use secure RTP [23]. The above three techniques are non-STUN mechanisms. STUN itself provides several countermeasures. Approaches IV (Section 13.2.4), when generatingsuggested. This error response MUST be protected with the MESSAGE-INTEGRITY attribute, and receivers MUST validate the MESSAGE-INTEGRITY of this responselocally,before redirecting themselves to an alternate server. Note: failure to generate andV (Section 13.2.5) requirevalidate message-integrity for a 300 response allows an on-path attacker togeneratefalsify afaked response. A faked300 responsemust match the 96-bit transaction ID of the request.thus causing subsequent STUN messages to be sent to a victim. 400 Bad Request: Theattack is further prevented by using the message integrity mechanism provided in STUN, described in Section 11.4. Approaches III (Section 13.2.3), IV (Section 13.2.4), when using the relaying technique, and VI (Section 13.2.6), however, are not preventable through server signatures. These three approaches are functional when the attacker modifies nothing but the source address ofrequest was malformed. The client SHOULD NOT retry theSTUN request. Sadly, this isrequest without modification from theone thing that cannotprevious attempt. The server may not beprotected through cryptographic means, asable to generate a valid MESSAGE-INTEGRITY for thisiserror, so thechange that STUN itself is seeking to detect and report. It is therefore an inherent weakness in NAT, andclient MUST NOT expect a valid MESSAGE-INTEGRITY attribute on this response. 401 Unauthorized: The request did notfixable in STUN. 13.4. Residual Threats None ofcontain thecountermeasures listed above can preventexpected MESSAGE- INTEGRITY attribute. The server MAY include theattacks describedMESSAGE- INTEGRITY attribute inSection 13.2.3 if the attacker isits error response. 420 Unknown Attribute: The server received STUN packet containing a comprehension-required attribute which it did not understand. The server MUST put this unknown attribute in theappropriate network paths. Specifically, consider the case in whichUNKNOWN- ATTRIBUTE attribute of its error response. 438 Stale Nonce: The NONCE used by theattacker wishes to convinceclientC that it has address V.was no longer valid. Theattacker needs to have a network element onclient should retry, using thepath between A andNONCE provided in the response. 500 Server Error: The server(in order to modify the request)has suffered a temporary error. The client should try again. 14.7. REALM The REALM attribute may be present in requests andonresponses. It contains text which meets thepath betweengrammar for "realm-value" as described in RFC 3261 [RFC3261] but without theserverdouble quotes andV so thattheir surrounding whitespace. That is, itcan forward the response to C. Furthermore, if thereis an unquoted realm-value. It MUST be aNAT betweenUTF-8 encoded sequence of less than 128 characters. Presence of the REALM attribute in a request indicates that long-term credentials are being used for authentication. Presence in certain error responses indicates that theattacker andserver wishes theserver, V must alsoclient to use a long-term credential for authentication. 14.8. NONCE The NONCE attribute may bebehind the same NAT. In suchpresent in requests and responses. It contains asituation, the attacker can either gain access to all the application-layer trafficsequence of qdtext ormount the DDOS attack describedquoted-pair, which are defined in RFC 3261 [RFC3261]. See RFC 2617 [RFC2617], Section13.1.1. Note that any host which exists4.3, for guidance on selection of nonce values inthe correct topological relationship can be DDOSed.a server. Itneed notMUST beusing STUN. 14. IAB Considerationsless than 128 characters. 14.9. UNKNOWN-ATTRIBUTES TheIAB has studied the problem of "Unilateral Self Address Fixing" (UNSAF), whichUNKNOWN-ATTRIBUTES attribute is present only in an error response when thegeneral process by which a client attempts to determine its addressresponse code inanother realm ontheother side of a NAT through a collaborative protocol reflection mechanism (RFC3424 [24]). STUNERROR-CODE attribute is 420. The attribute contains a list of 16 bit values, each of which represents anexampleattribute type that was not understood by the server. 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 11: Format of UNKNOWN-ATTRIBUTES attribute Note: In [RFC3489], this field was padded to 32 by duplicating the last attribute. In this version of the specification, the normal padding rules for attributes are used instead. 14.10. SERVER The server attribute contains aprotocol that performs this typetextual description offunction forthebinding discovery usage.software being used by the server, including manufacturer and version number. TheIABattribute hasmandated that any protocols developed for this purpose document a specific setno impact on operation ofconsiderations. This section meets those requirements forthebinding discovery usage. 14.1. Problem Definition From RFC3424 [24], any UNSAF proposal must provide: Precise definition ofprotocol, and serves only as aspecific, limited-scope problem thattool for diagnostic and debugging purposes. The value of SERVER isto be solved with the UNSAF proposal. A short term fix should notvariable length. It MUST begeneralized to solve other problems; this is why "short term fixes usually aren't".a UTF-8 encoded sequence of less than 128 characters 14.11. ALTERNATE-SERVER Thespecific problem being solved byalternate server represents an alternate transport address identifying a different STUN server which the STUN client should try. It isto provideencoded in thefunctionality necessarysame way as MAPPED-ADDRESS, and thus refers todescribe howa single server by IP address. The IP address family MUST be identical toconnect two endpoints regardlessthat of thelocation of typesource IP address ofNATs inthetopology. 14.2. Exit Strategy From RFC3424 [24], any UNSAF proposal must provide: Description ofrequest. This attribute MUST only appear in anexit strategy/transition plan. The better short term fixeserror response that contains a MESSAGE-INTEGRITY attribute. This prevents it from being used in denial-of-service attacks. 15. Security Considerations 15.1. Attacks against the Protocol 15.1.1. Outside Attacks An attacker can try to modify STUN messages in transit, in order to cause a failure in STUN operation. These attacks are prevented for both requests and responses through theonesmessage integrity mechanism, using either a short term or long term credential. An attacker thatwill naturallycan observe, but not modify STUN messages in-transit (for example, an attacker present on a shared access medium, such as Wi-Fi), can seelessa STUN request, andless use as the appropriate technology is deployed.then immediately send a STUNby itself does not provideresponse, typically anexit strategy.error response, in order to disrupt STUN processing. This attack isprovided by techniques, such as Interactive Connectivity Establishment (ICE [13]),also prevented for messages thatallow a clientutilize MESSAGE-INTEGRITY. However, some error responses, those related todetermine whether addresses learned fromauthentication in particular, cannot be protected by MESSAGE- INTEGRITY. When STUN itself is run over a secure transport protocol (e.g., TLS), these attacks areneeded, or whether other addresses, such as the one on the local interface, will work when communicating with another host. With suchcompletely mitigated. 15.1.2. Inside Attacks A rogue client may try to launch adetection technique, asDoS attack against aclient finds that the addresses providedserver by sending it a large number of STUNare never used,requests. Fortunately, STUNqueriesrequests cancease tobemade, thus allowing them to phase out. 14.3. Brittleness Introducedprocessed statelessly bySTUN From RFC3424 [24], any UNSAF proposal must provide: Discussion of specific issues that may render systems more "brittle". For example, approaches that involve using data at multiple network layers create more dependencies, increase debugging challenges, and make it hardera server, making such attacks hard totransition. STUN introduces brittleness into the system in several ways: o Transport addresses discovered by STUN inlaunch. 15.2. Attacks Affecting theBinding Discovery usage will onlyUsage This section lists attacks that might beuseful for receiving packets fromlaunched against apeer if the NAT does not have address or address and port dependent mapping properties. When thisusageis used in isolation, this makesof STUN. Each STUNbrittle, since its effectiveness depends on the typeusage must consider whether these attacks are applicable to it, and if so, discuss counter-measures. Most ofNAT. This brittleness is eliminated whentheBinding Discovery usage is usedattacks inconcert with mechanisms which can verifythis section revolve around an attacker modifying thetransportreflexive addressand use others if it doesn't work. ICE is an example of such a mechanism. o Transport addresses discoveredlearned by a STUNin the Binding Discovery usage will only be useful for receiving packets fromclient through apeer ifBinding Request/Binding Response transaction. Since theSTUN server subtendsusage of the reflexive addressrealmis a function of thepeer. For example, consider client Ausage, the applicability andB, bothremediation ofwhich have residential NAT devices. Both devices connect them to their cable operators, but both clients have different providers. Each provider has a NAT in frontthese attacks is usage-specific. In common situations, modification oftheir entire network, connecting it tothepublic Internet. Ifreflexive address by an on-path attacker is easy to do. Consider, for example, the common situation where STUNserver used by Aisin A's cable operator's network,run directly over UDP. In this case, an on-path attacker can modify the source IP addressobtained byof the Binding Request before itwill not be usable by B.arrives at the STUN server. The STUN server will then return this IP address in the XOR-MAPPED-ADDRESS attribute to 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, since the intervening NAT must beinable to modify this value. Instead, one solution to preventing thenetwork whichattacks listed below is for the client to verify the reflexive address learned, as is done in ICE [I-D.ietf-mmusic-ice]. Other usages may use other means to prevent these attacks. 15.2.1. Attack I: DDoS Against acommon ancestorTarget 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 toboth - in this case,that of thepublic Internet. When this usage is usedtarget. If the clients hand out that reflexive address inisolation, this makes STUN brittle, since its effectiveness dependsorder to receive traffic on it (for example, in SIP messages), thetopological placement oftraffic will instead be sent to theSTUN server.target. Thisbrittleness is eliminatedattack can provide substantial amplification, especially whenthe Binding Discovery usage isusedin concertwithmechanisms which can verifyclients that are using STUN to enable multimedia applications. 15.2.2. Attack II: Silencing a Client In this attack, thetransportattacker provides a STUN client with a faked reflexive address. The reflexive addressand use others ifitdoesn't work. ICEprovides isan example of suchamechanism. o The bindings allocated from the NAT needtransport address that routes tobe continuously refreshed. Sincenowhere. As a result, thetimeouts for these bindings is very implementation specific,client won't receive any of therefresh interval cannot easily be determined. Whenpackets it expects to receive when it hands out thebindingreflexive address. This exploitation is notbeing actively used to receive traffic, but to waitvery interesting foran incoming message, the binding refresh will needlessly consume network bandwidth. o The use of the STUN server in the Binding Discovery usage as an additional network element introduces another point of potential security attack. These attacks are largely prevented bythesecurity measures provided by STUN, butattacker. It impacts a single client, which is frequently notentirely. o The use of the STUN server as an additional network element introduces another point of failure. Iftheclient cannot locate a STUN server, or ifdesired target. Moreover, any attacker that can mount theserver should be unavailable dueattack could also deny service tofailure,theapplication cannot function. o The use of STUN to discover address bindings may result in an increase in latency for applications. o Transport addresses discoveredclient bySTUN inother means, such as preventing theBinding Discovery usage will only be useful forclient from receivingpacketsany response froma peer behind the same NAT ifthe STUNserver supports hairpinning [14]. When this usage is used in isolation, this makes STUN brittle, since its effectiveness depends onserver, or even a DHCP server. 15.2.3. Attack III: Assuming thetopological placementIdentity ofthe STUN server.a Client Thisbrittleness is eliminated when the Binding Discovery usageattack isused in concert with mechanisms which can verifysimilar to attack III. However, thetransportfaked reflexive addressand use others if it doesn't work. ICE is an example of such a mechanism. o Most significantly, STUN introduces potential security threatspoints to the attacker itself. This allows the attacker to receive traffic whichcannot be eliminated through cryptographic means. These security problems are described fully in Section 13. 14.4. Requirementswas destined for the client. 15.2.4. Attack IV: Eavesdropping In this attack, the attacker forces the client to use aLong Term Solution From RFC3424 [24],reflexive address that routes to itself. It then forwards anyUNSAF proposal must provide: Identify requirements for longer term, sound technical solutions -- contributepackets it receives to theprocess of findingclient. This attack would allow theright longer term solution. Our experience with STUN has ledattacker tothe following requirements for a long term solutionobserve all packets sent to theNAT problem: o Requests for bindings and control of other resourcesclient. However, ina NAT needorder to launch the attack, the attacker must have already been able to observe packets from the client tobe explicit. Much ofthebrittleness inSTUNderivesserver. In most cases (such as when the attack is launched fromits guessing atan access network), this means that theparameters ofattacker could already observe packets sent to theNAT, rather than tellingclient. This attack is, as a result, only useful for observing traffic by attackers on theNAT what parameters to use, or knowing what parameterspath from theNAT will use. o Control needsclient tobe in-band. There are far too many scenarios in whichtheclient willSTUN server, but notknow aboutgenerally on thelocation of middleboxes aheadpath oftime. Instead, controlpackets being routed towards the client. 15.3. Hash Agility Plan This specification uses SHA-1 for computation ofsuch boxes needsthe message integrity. If, at a later time, SHA-1 is found tooccur in- band, traveling alongbe compromised, thesame path asfollowing is thedata will itself travel. This guaranteesremedy thatthe right set of middleboxes are controlled. o Control needs towill belimited. Usersapplied. We willneed to communicate through NATsdefine a STUN extension whichare outside of their administrative control. In order for providers tointroduces a new message integrity attribute, computed using a new hash. Clients would bewillingrequired todeploy NATs which can be controlled by usersinclude both the new and old message integrity attributes indifferent domains,their requests or indications. A new server will utilize thescope of such controls needs to be extremely limited - typically, allocating a binding to reachnew message integrity attribute, and an old one, theaddressold. After a transition period wherethe control packetsmixed implementations arecoming from. o Simplicity is Paramount. The control protocol will need to be implementedinvery simple clients. The servers will need to support extremely high loads. The protocoldeployment, the old message-integrity attribute willneed tobeextremely robust, being the precursor to a host of application protocols. As such, simplicity is key. 14.5. Issues with Existing NAPT Boxes From RFC3424 [24], any UNSAF proposal must provide: Discussion of the impact of the noted practical issues with existing, deployed NA[P]Tsdeprecated by another specification, andexperience reports. Originally, RFC 3489 was developed as a standalone solution for NAT traversal for several types of applications, including VoIP. However, practical experience found thatclients will cease including it in requests. 16. IAB Considerations The IAB has studied thelimitationsproblem ofits usage in isolation made it impractical as a complete solution. There were too many NATs"Unilateral Self Address Fixing" (UNSAF), whichdidn't support hairpinning oris the general process by whichhada client attempts to determine its addressand port dependent mapping properties. Consequently,in another realm on the other side of a NAT through a collaborative protocol reflection mechanism (RFC3424 [RFC3424]). STUNwas revisedcan be used toproduceperform thisspecification, which turns STUN intofunction using atool thatBindingRequest/BindingResponse transaction if one agent isused as part ofbehind abroader solution. For multimedia communications protocols, this broader solutionNAT and the other isICE. ICE useson thebinding discovery usage and defines its own connectivity check usage, and then utilizes them together. When done this way, ICE eliminates almost allpublic side of thebrittlenessNAT. The IAB has mandated that protocols developed for this purpose document a specific set of considerations. Because some STUN usages provide UNSAF functions (such as ICE [I-D.ietf-mmusic-ice] ), andissues found with RFC 3489 alone. 15.others do not (such as SIP Outbound [I-D.ietf-sip-outbound]), answers to these considerations need to be addressed by the usages themselves. 17. IANA Considerations IANA is hereby requested to createtwothree newregistries -registries: a STUN methods registry, a STUN Attributes registry, and a STUNAttributes. IANA must assignError Codes registry. 17.1. STUN Methods Registry A STUN method is a hex number in thefollowing values to both registries before publicationrange 0x000 - 0x3FF. The encoding ofthis document as an RFC. New values for bothSTUN method into a STUN message is described in Section 6. The initial STUN methodsandare: 0x000: (Reserved) 0x001: Binding 0x002: (Reserved; was SharedSecret) STUNattributesmethods in the range 0x000 - 0x1FF are assignedthrough the IETF consensus process via RFCs approvedby IETF Consensus [RFC2434]. STUN methods in theIESG [25]. 15.1.range 0x200 - 0x3FF are assigned on a First Come First Served basis [RFC2434] 17.2. STUNMethodsAttribute RegistryThe initial STUN methods are: 0x001:Binding 0x002:Shared Secret 15.2.A STUN AttributeRegistrytype is a hex number in the range 0x0000 - 0xFFFF. STUNattributes values aboveattribute types in the range 0x0000 - 0x7FFF are consideredoptional attributes; attributes equal to 0x7FFF or belowcomprehension-required; STUN attribute types in the range 0x8000 - 0xFFFF are consideredmandatory attributes. The STUN client andcomprehension-optional. A STUNserver process optionalagent handles unknown comprehension-required andmandatorycomprehension-optional attributes differently.IANA should assign values based on the RFC consensus process.The initial STUN Attributes types are: Comprehension-required range (0x0000-0x7FFF): 0x0000: (Reserved) 0x0001: MAPPED-ADDRESS 0x0006: USERNAME 0x0007:PASSWORD(Reserved; was PASSWORD) 0x0008: MESSAGE-INTEGRITY 0x0009: ERROR-CODE 0x000A: UNKNOWN-ATTRIBUTES 0x0014: REALM 0x0015: NONCE 0x0020: XOR-MAPPED-ADDRESS0x8023: FINGERPRINTComprehension-optional range (0x8000-0xFFFF) 0x8022: SERVER 0x8023: ALTERNATE-SERVER0x8024: REFRESH-INTERVAL 16.0x8028: FINGERPRINT STUN Attribute types in the first half of the comprehension-required range (0x0000 - 0x3FFF) and in the first half of the comprehension- optional range (0x8000 - 0xBFFF) are assigned by IETF Consensus [RFC2434]. STUN Attribute types in the second half of the comprehension-required range (0x4000 - 0x7FFF) and in the second half of the comprehension-optional range (0xC000 - 0xFFFF) are assigned on a First Come First Served basis [RFC2434]. 17.3. STUN Error Code 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 which is intended only for human consumption and can be anything appropriate; this document proposes only suggested values. STUN error codes are consistent in codepoint assignments and semantics with SIP [RFC3261] and HTTP [RFC2616]. The initial values in this registry are given in Section 14.6. New STUN error codes are assigned on a Specification-Required basis [RFC2434]. 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 7.3.4. 18. Changes Since RFC 3489 This specificationupdatesobsoletes RFC3489[15].[RFC3489]. This specification differs from RFC3489 in thefollowing ways:following ways: o Removed the notion that STUN is a complete NAT traversal solution. STUN is now a toolkit that can be used to produce a NAT traversal solution. As a consequence, changed the name of the protocol to Session Traversal Utilities for NAT. o Introduced the concept of STUN usages, and described what a usage of STUN must document. o Removed the usage of STUN for NAT type detection and binding lifetime discovery. These techniques have proven overly brittle due to wider variations in the types of NAT devices than described in this document. Removed the RESPONSE-ADDRESS, CHANGED-ADDRESS, CHANGE-REQUEST, SOURCE-ADDRESS, and REFLECTED-FROM attributes. o Added a fixed 32-bit magic cookie and reduced length of transaction ID by 32 bits. The magic cookie begins at the same offset as the original transaction ID. o Added the XOR-MAPPED-ADDRESS attribute, which is included in Binding Responses if the magic cookie is present in the request. Otherwise the RFC3489 behavior is retained (that is, Binding Response includes MAPPED-ADDRESS). See discussion in XOR-MAPPED- ADDRESS regarding this change. o Introduced formal structure into the Message Type header field, with an explicit pair of bits for indication of request, response, error response or indication. Consequently, the message type field is split into the class (one of the previous four) and method. o Explicitly point out that the most significant two bits of STUN are 0b00, allowing easy differentiation with RTP packets when used with ICE. o Added the FINGERPRINT attribute to provide a method of definitely detecting the difference between STUN and another protocol when the two protocols are multiplexed together. o Added support for IPv6. Made it clear that an IPv4 client could get a v6 mapped address, and vice-a-versa. o Added long-term credential-based authentication. o Added the SERVER, REALM, NONCE, and ALTERNATE-SERVER attributes. o Removed the SharedSecret method, and thus the PASSWORD attribute. This method was almost never implemented and is not needed with current usages. o Removed recommendation to continue listening for STUN Responses for 10 seconds in an attempt to recognize an attack. oIntroduced the concept of STUN usages and defined three usages - Binding Discovery, NAT Keepalive, and Short term password. oChanged transaction timers to be more TCP friendly. o Removed the STUN example that centered around the separation of the control and media planes. Instead, provided more information on using STUN with protocols.17.o Defined a generic padding mechanism that changes the interpretation of the length attribute. This would, in theory, break backwards compatibility. However, the mechanism in RFC 3489 never worked for the few attributes that weren't aligned naturally on 32 bit boundaries. o REALM, USERNAME, SERVER, reason phrases and NONCE limited to 127 characters. 19. Acknowledgements The authors would like to thank Cedric Aoun, Pete Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, 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.18.20. References18.1.20.1. Normative References[1][RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.[2][RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, September 1981.[3][RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for specifying the location of services (DNS SRV)", RFC 2782, February 2000.[4][RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000.[5] Dierks, T. and C. Allen, "The TLS Protocol Version 1.0", RFC 2246, January 1999. [6] Ferguson, P. and D. Senie, "Network Ingress Filtering: Defeating Denial of Service Attacks which employ IP Source Address Spoofing", BCP 38, RFC 2827, May 2000. [7][RFC2617] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., Leach, P., Luotonen, A., and L. Stewart, "HTTP Authentication: Basic and Digest Access Authentication", RFC 2617, June 1999.[8][RFC2988] Paxson, V. and M. Allman, "Computing TCP's Retransmission Timer", RFC 2988, November 2000.[9][ITU.V42.1994] International Telecommunications Union, "Error-correcting Procedures for DCEs Using Asynchronous-to-Synchronous Conversion", ITU-T Recommendation V.42, 1994.18.2.20.2. Informational References[10][RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC:Keyed-HashingKeyed- Hashing for Message Authentication", RFC 2104, February 1997.[11][RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, A., Peterson, J., Sparks, R., Handley, M., and E. Schooler, "SIP: Session Initiation Protocol", RFC 3261, June 2002.[12][RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.[13][I-D.ietf-mmusic-ice] Rosenberg, J., "Interactive Connectivity Establishment (ICE): AMethodologyProtocol for Network Address Translator (NAT) Traversal for Offer/Answer Protocols",draft-ietf-mmusic-ice-13draft-ietf-mmusic-ice-16 (work in progress),JanuaryJune 2007.[14] Audet, F. and C. Jennings, "NAT Behavioral Requirements for Unicast UDP", draft-ietf-behave-nat-udp-08 (work in progress), October 2006. [15][RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, "STUN - Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translators (NATs)", RFC 3489, March 2003.[16][I-D.ietf-behave-turn] Rosenberg, J., "Obtaining Relay Addresses from Simple Traversal Underneath NAT (STUN)",draft-ietf-behave-turn-02draft-ietf-behave-turn-03 (work in progress),October 2006. [17] Schulzrinne, H., Casner, S., Frederick, R., and V. Jacobson, "RTP: A Transport Protocol for Real-Time Applications", RFC 3550, July 2003. [18]March 2007. [I-D.ietf-sip-outbound] Jennings, C. and R. Mahy, "Managing Client Initiated Connections in the Session Initiation Protocol (SIP)",draft-ietf-sip-outbound-07draft-ietf-sip-outbound-09 (work in progress),JanuaryJune 2007.[19] Handley, M., Jacobson, V., and C. Perkins, "SDP: Session Description Protocol", RFC 4566, July 2006. [20] Senie, D., "Network Address Translator (NAT)-Friendly Application Design Guidelines", RFC 3235, January 2002. [21] Holdrege, M.[I-D.ietf-behave-nat-behavior-discovery] MacDonald, D. andP. Srisuresh, "Protocol ComplicationsB. Lowekamp, "NAT Behavior Discovery Using STUN", draft-ietf-behave-nat-behavior-discovery-00 (work in progress), February 2007. [I-D.ietf-mmusic-ice-tcp] Rosenberg, J., "TCP Candidates withthe IP Network Address Translator", RFC 3027, January 2001. [22]Interactive Connectivity Establishment (ICE", draft-ietf-mmusic-ice-tcp-03 (work in progress), March 2007. [RFC3264] Rosenberg, J. and H. Schulzrinne, "An Offer/Answer Model with Session Description Protocol (SDP)", RFC 3264, June 2002.[23] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, "The Secure Real-time Transport Protocol (SRTP)", RFC 3711, March 2004. [24][RFC3424] Daigle, L. and IAB, "IAB Considerations for UNilateralSelf- AddressSelf-Address Fixing (UNSAF) Across Network Address Translation", RFC 3424, November 2002.[25][RFC2434] Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 2434, October 1998. Appendix A. C Snippet to Determine STUN Message Types Given an 16-bit STUN message type value in host byte order in msg_type parameter, below are C macros to determine the STUN message types: #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) Authors' Addresses Jonathan Rosenberg Cisco Edison, NJ US Email: jdrosen@cisco.com URI: http://www.jdrosen.net Christian Huitema Microsoft One Microsoft Way Redmond, WA 98052 US Email: huitema@microsoft.com Rohan Mahy Plantronics 345 Encinal Street Santa Cruz, CA 95060 US Email: rohan@ekabal.com Philip Matthews Avaya 1135 Innovation Drive Ottawa, Ontario K2K 3G7 Canada Phone: +1 613 592 4343 x224 Fax: Email: philip_matthews@magma.ca URI: Dan Wing CiscoSystems771 Alder Drive San Jose, CA 95035 US Email: dwing@cisco.com Full Copyright Statement Copyright (C) The IETF Trust (2007). This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights. This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Intellectual Property The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79. Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr. The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org. Acknowledgment Funding for the RFC Editor function is provided by the IETF Administrative Support Activity (IASA).