idnits 2.17.1 draft-ietf-tram-stunbis-00.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). -- The document date (November 13, 2014) is 3444 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'RFC3264' is defined on line 2194, but no explicit reference was found in the text ** Obsolete normative reference: RFC 2818 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 2460 (Obsoleted by RFC 8200) ** Obsolete normative reference: RFC 2617 (Obsoleted by RFC 7235, RFC 7615, RFC 7616, RFC 7617) ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Downref: Normative reference to an Informational RFC: RFC 1321 ** Obsolete normative reference: RFC 4013 (Obsoleted by RFC 7613) -- Possible downref: Non-RFC (?) normative reference: ref. 'ITU.V42.2002' -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) -- Obsolete informational reference (is this intentional?): RFC 5245 (Obsoleted by RFC 8445, RFC 8839) -- Obsolete informational reference (is this intentional?): RFC 3489 (Obsoleted by RFC 5389) -- Obsolete informational reference (is this intentional?): RFC 5766 (Obsoleted by RFC 8656) -- Obsolete informational reference (is this intentional?): RFC 5226 (Obsoleted by RFC 8126) -- Obsolete informational reference (is this intentional?): RFC 5389 (Obsoleted by RFC 8489) Summary: 6 errors (**), 0 flaws (~~), 3 warnings (==), 9 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 TRAM M. Petit-Huguenin 3 Internet-Draft Impedance Mismatch 4 Obsoletes: 5389 (if approved) G. Salgueiro 5 Intended status: Standards Track J. Rosenberg 6 Expires: May 17, 2015 D. Wing 7 Cisco 8 R. Mahy 9 Plantronics 10 P. Matthews 11 Avaya 12 November 13, 2014 14 Session Traversal Utilities for NAT (STUN) 15 draft-ietf-tram-stunbis-00 17 Abstract 19 Session Traversal Utilities for NAT (STUN) is a protocol that serves 20 as a tool for other protocols in dealing with Network Address 21 Translator (NAT) traversal. It can be used by an endpoint to 22 determine the IP address and port allocated to it by a NAT. It can 23 also be used to check connectivity between two endpoints, and as a 24 keep-alive protocol to maintain NAT bindings. STUN works with many 25 existing NATs, and does not require any special behavior from them. 27 STUN is not a NAT traversal solution by itself. Rather, it is a tool 28 to be used in the context of a NAT traversal solution. 30 This document obsoletes RFC 5389. 32 Status of This Memo 34 This Internet-Draft is submitted in full conformance with the 35 provisions of BCP 78 and BCP 79. 37 Internet-Drafts are working documents of the Internet Engineering 38 Task Force (IETF). Note that other groups may also distribute 39 working documents as Internet-Drafts. The list of current Internet- 40 Drafts is at http://datatracker.ietf.org/drafts/current/. 42 Internet-Drafts are draft documents valid for a maximum of six months 43 and may be updated, replaced, or obsoleted by other documents at any 44 time. It is inappropriate to use Internet-Drafts as reference 45 material or to cite them other than as "work in progress." 47 This Internet-Draft will expire on May 17, 2015. 49 Copyright Notice 51 Copyright (c) 2014 IETF Trust and the persons identified as the 52 document authors. All rights reserved. 54 This document is subject to BCP 78 and the IETF Trust's Legal 55 Provisions Relating to IETF Documents 56 (http://trustee.ietf.org/license-info) in effect on the date of 57 publication of this document. Please review these documents 58 carefully, as they describe your rights and restrictions with respect 59 to this document. Code Components extracted from this document must 60 include Simplified BSD License text as described in Section 4.e of 61 the Trust Legal Provisions and are provided without warranty as 62 described in the Simplified BSD License. 64 Table of Contents 66 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 67 2. Overview of Operation . . . . . . . . . . . . . . . . . . . . 4 68 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 7 69 4. Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 7 70 5. STUN Message Structure . . . . . . . . . . . . . . . . . . . 9 71 6. Base Protocol Procedures . . . . . . . . . . . . . . . . . . 11 72 6.1. Forming a Request or an Indication . . . . . . . . . . . 11 73 6.2. Sending the Request or Indication . . . . . . . . . . . . 12 74 6.2.1. Sending over UDP . . . . . . . . . . . . . . . . . . 12 75 6.2.2. Sending over TCP or TLS-over-TCP . . . . . . . . . . 13 76 6.3. Receiving a STUN Message . . . . . . . . . . . . . . . . 15 77 6.3.1. Processing a Request . . . . . . . . . . . . . . . . 16 78 6.3.1.1. Forming a Success or Error Response . . . . . . . 17 79 6.3.1.2. Sending the Success or Error Response . . . . . . 18 80 6.3.2. Processing an Indication . . . . . . . . . . . . . . 18 81 6.3.3. Processing a Success Response . . . . . . . . . . . . 18 82 6.3.4. Processing an Error Response . . . . . . . . . . . . 19 83 7. FINGERPRINT Mechanism . . . . . . . . . . . . . . . . . . . . 19 84 8. DNS Discovery of a Server . . . . . . . . . . . . . . . . . 20 85 9. Authentication and Message-Integrity Mechanisms . . . . . . . 21 86 9.1. Short-Term Credential Mechanism . . . . . . . . . . . . . 21 87 9.1.1. Forming a Request or Indication . . . . . . . . . . . 22 88 9.1.2. Receiving a Request or Indication . . . . . . . . . . 22 89 9.1.3. Receiving a Response . . . . . . . . . . . . . . . . 23 90 9.2. Long-Term Credential Mechanism . . . . . . . . . . . . . 23 91 9.2.1. Forming a Request . . . . . . . . . . . . . . . . . . 24 92 9.2.1.1. First Request . . . . . . . . . . . . . . . . . . 24 93 9.2.1.2. Subsequent Requests . . . . . . . . . . . . . . . 25 94 9.2.2. Receiving a Request . . . . . . . . . . . . . . . . . 25 95 9.2.3. Receiving a Response . . . . . . . . . . . . . . . . 26 96 10. ALTERNATE-SERVER Mechanism . . . . . . . . . . . . . . . . . 26 97 11. Backwards Compatibility with RFC 3489 . . . . . . . . . . . . 27 98 11.1. Changes to Client Processing . . . . . . . . . . . . . . 28 99 11.2. Changes to Server Processing . . . . . . . . . . . . . . 28 100 12. Basic Server Behavior . . . . . . . . . . . . . . . . . . . . 29 101 13. STUN Usages . . . . . . . . . . . . . . . . . . . . . . . . . 29 102 14. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . . 30 103 14.1. MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . . . 31 104 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . 32 105 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . . . . 33 106 14.4. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . . . . 33 107 14.5. MESSAGE-INTEGRITY2 . . . . . . . . . . . . . . . . . . . 34 108 14.6. FINGERPRINT . . . . . . . . . . . . . . . . . . . . . . 35 109 14.7. ERROR-CODE . . . . . . . . . . . . . . . . . . . . . . . 36 110 14.8. REALM . . . . . . . . . . . . . . . . . . . . . . . . . 37 111 14.9. NONCE . . . . . . . . . . . . . . . . . . . . . . . . . 38 112 14.10. UNKNOWN-ATTRIBUTES . . . . . . . . . . . . . . . . . . . 38 113 14.11. SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . 38 114 14.12. ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . 39 115 15. Security Considerations . . . . . . . . . . . . . . . . . . . 39 116 15.1. Attacks against the Protocol . . . . . . . . . . . . . . 39 117 15.1.1. Outside Attacks . . . . . . . . . . . . . . . . . . 39 118 15.1.2. Inside Attacks . . . . . . . . . . . . . . . . . . . 40 119 15.2. Attacks Affecting the Usage . . . . . . . . . . . . . . 40 120 15.2.1. Attack I: Distributed DoS (DDoS) against a Target . 41 121 15.2.2. Attack II: Silencing a Client . . . . . . . . . . . 41 122 15.2.3. Attack III: Assuming the Identity of a Client . . . 41 123 15.2.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . 42 124 15.3. Hash Agility Plan . . . . . . . . . . . . . . . . . . . 42 125 16. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 42 126 17. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 43 127 17.1. STUN Methods Registry . . . . . . . . . . . . . . . . . 43 128 17.2. STUN Attribute Registry . . . . . . . . . . . . . . . . 43 129 17.3. STUN Error Code Registry . . . . . . . . . . . . . . . . 44 130 17.4. STUN UDP and TCP Port Numbers . . . . . . . . . . . . . 45 131 18. Changes since RFC 5389 . . . . . . . . . . . . . . . . . . . 45 132 19. Contributors . . . . . . . . . . . . . . . . . . . . . . . . 45 133 20. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 45 134 21. References . . . . . . . . . . . . . . . . . . . . . . . . . 46 135 21.1. Normative References . . . . . . . . . . . . . . . . . . 46 136 21.2. Informational References . . . . . . . . . . . . . . . . 47 137 Appendix A. C Snippet to Determine STUN Message Types . . . . . 48 138 Appendix B. Release notes . . . . . . . . . . . . . . . . . . . 48 139 B.1. Open Issues . . . . . . . . . . . . . . . . . . . . . . . 48 140 B.2. Modifications between draft-salgueiro-tram-stunbis-02 and 141 draft-salgueiro-tram-stunbis-01 . . . . . . . . . . . . . 49 142 B.3. Modifications between draft-salgueiro-tram-stunbis-01 and 143 draft-salgueiro-tram-stunbis-00 . . . . . . . . . . . . . 49 144 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 50 146 1. Introduction 148 The protocol defined in this specification, Session Traversal 149 Utilities for NAT, provides a tool for dealing with NATs. It 150 provides a means for an endpoint to determine the IP address and port 151 allocated by a NAT that corresponds to its private IP address and 152 port. It also provides a way for an endpoint to keep a NAT binding 153 alive. With some extensions, the protocol can be used to do 154 connectivity checks between two endpoints [RFC5245], or to relay 155 packets between two endpoints [RFC5766]. 157 In keeping with its tool nature, this specification defines an 158 extensible packet format, defines operation over several transport 159 protocols, and provides for two forms of authentication. 161 STUN is intended to be used in context of one or more NAT traversal 162 solutions. These solutions are known as STUN usages. Each usage 163 describes how STUN is utilized to achieve the NAT traversal solution. 164 Typically, a usage indicates when STUN messages get sent, which 165 optional attributes to include, what server is used, and what 166 authentication mechanism is to be used. Interactive Connectivity 167 Establishment (ICE) [RFC5245] is one usage of STUN. SIP Outbound 168 [RFC5626] is another usage of STUN. In some cases, a usage will 169 require extensions to STUN. A STUN extension can be in the form of 170 new methods, attributes, or error response codes. More information 171 on STUN usages can be found in Section 13. 173 2. Overview of Operation 175 This section is descriptive only. 177 /-----\ 178 // STUN \\ 179 | Server | 180 \\ // 181 \-----/ 183 +--------------+ Public Internet 184 ................| NAT 2 |....................... 185 +--------------+ 187 +--------------+ Private NET 2 188 ................| NAT 1 |....................... 189 +--------------+ 191 /-----\ 192 // STUN \\ 193 | Client | 194 \\ // Private NET 1 195 \-----/ 197 Figure 1: One Possible STUN Configuration 199 One possible STUN configuration is shown in Figure 1. In this 200 configuration, there are two entities (called STUN agents) that 201 implement the STUN protocol. The lower agent in the figure is the 202 client, and is connected to private network 1. This network connects 203 to private network 2 through NAT 1. Private network 2 connects to 204 the public Internet through NAT 2. The upper agent in the figure is 205 the server, and resides on the public Internet. 207 STUN is a client-server protocol. It supports two types of 208 transactions. One is a request/response transaction in which a 209 client sends a request to a server, and the server returns a 210 response. The second is an indication transaction in which either 211 agent -- client or server -- sends an indication that generates no 212 response. Both types of transactions include a transaction ID, which 213 is a randomly selected 96-bit number. For request/response 214 transactions, this transaction ID allows the client to associate the 215 response with the request that generated it; for indications, the 216 transaction ID serves as a debugging aid. 218 All STUN messages start with a fixed header that includes a method, a 219 class, and the transaction ID. The method indicates which of the 220 various requests or indications this is; this specification defines 221 just one method, Binding, but other methods are expected to be 222 defined in other documents. The class indicates whether this is a 223 request, a success response, an error response, or an indication. 224 Following the fixed header comes zero or more attributes, which are 225 Type-Length-Value extensions that convey additional information for 226 the specific message. 228 This document defines a single method called Binding. The Binding 229 method can be used either in request/response transactions or in 230 indication transactions. When used in request/response transactions, 231 the Binding method can be used to determine the particular "binding" 232 a NAT has allocated to a STUN client. When used in either request/ 233 response or in indication transactions, the Binding method can also 234 be used to keep these "bindings" alive. 236 In the Binding request/response transaction, a Binding request is 237 sent from a STUN client to a STUN server. When the Binding request 238 arrives at the STUN server, it may have passed through one or more 239 NATs between the STUN client and the STUN server (in Figure 1, there 240 were two such NATs). As the Binding request message passes through a 241 NAT, the NAT will modify the source transport address (that is, the 242 source IP address and the source port) of the packet. As a result, 243 the source transport address of the request received by the server 244 will be the public IP address and port created by the NAT closest to 245 the server. This is called a reflexive transport address. The STUN 246 server copies that source transport address into an XOR-MAPPED- 247 ADDRESS attribute in the STUN Binding response and sends the Binding 248 response back to the STUN client. As this packet passes back through 249 a NAT, the NAT will modify the destination transport address in the 250 IP header, but the transport address in the XOR-MAPPED-ADDRESS 251 attribute within the body of the STUN response will remain untouched. 252 In this way, the client can learn its reflexive transport address 253 allocated by the outermost NAT with respect to the STUN server. 255 In some usages, STUN must be multiplexed with other protocols (e.g., 256 [RFC5245], [RFC5626]). In these usages, there must be a way to 257 inspect a packet and determine if it is a STUN packet or not. STUN 258 provides three fields in the STUN header with fixed values that can 259 be used for this purpose. If this is not sufficient, then STUN 260 packets can also contain a FINGERPRINT value, which can further be 261 used to distinguish the packets. 263 STUN defines a set of optional procedures that a usage can decide to 264 use, called mechanisms. These mechanisms include DNS discovery, a 265 redirection technique to an alternate server, a fingerprint attribute 266 for demultiplexing, and two authentication and message-integrity 267 exchanges. The authentication mechanisms revolve around the use of a 268 username, password, and message-integrity value. Two authentication 269 mechanisms, the long-term credential mechanism and the short-term 270 credential mechanism, are defined in this specification. Each usage 271 specifies the mechanisms allowed with that usage. 273 In the long-term credential mechanism, the client and server share a 274 pre-provisioned username and password and perform a digest challenge/ 275 response exchange inspired by (but differing in details) to the one 276 defined for HTTP [RFC2617]. In the short-term credential mechanism, 277 the client and the server exchange a username and password through 278 some out-of-band method prior to the STUN exchange. For example, in 279 the ICE usage [RFC5245] the two endpoints use out-of-band signaling 280 to exchange a username and password. These are used to integrity 281 protect and authenticate the request and response. There is no 282 challenge or nonce used. 284 3. Terminology 286 In this document, the key words "MUST", "MUST NOT", "REQUIRED", 287 "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", 288 and "OPTIONAL" are to be interpreted as described in BCP 14, RFC 2119 289 [RFC2119] and indicate requirement levels for compliant STUN 290 implementations. 292 4. Definitions 294 STUN Agent: A STUN agent is an entity that implements the STUN 295 protocol. The entity can be either a STUN client or a STUN 296 server. 298 STUN Client: A STUN client is an entity that sends STUN requests and 299 receives STUN responses. A STUN client can also send indications. 300 In this specification, the terms STUN client and client are 301 synonymous. 303 STUN Server: A STUN server is an entity that receives STUN requests 304 and sends STUN responses. A STUN server can also send 305 indications. In this specification, the terms STUN server and 306 server are synonymous. 308 Transport Address: The combination of an IP address and port number 309 (such as a UDP or TCP port number). 311 Reflexive Transport Address: A transport address learned by a client 312 that identifies that client as seen by another host on an IP 313 network, typically a STUN server. When there is an intervening 314 NAT between the client and the other host, the reflexive transport 315 address represents the mapped address allocated to the client on 316 the public side of the NAT. Reflexive transport addresses are 317 learned from the mapped address attribute (MAPPED-ADDRESS or XOR- 318 MAPPED-ADDRESS) in STUN responses. 320 Mapped Address: Same meaning as reflexive address. This term is 321 retained only for historic reasons and due to the naming of the 322 MAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. 324 Long-Term Credential: A username and associated password that 325 represent a shared secret between client and server. Long-term 326 credentials are generally granted to the client when a subscriber 327 enrolls in a service and persist until the subscriber leaves the 328 service or explicitly changes the credential. 330 Long-Term Password: The password from a long-term credential. 332 Short-Term Credential: A temporary username and associated password 333 that represent a shared secret between client and server. Short- 334 term credentials are obtained through some kind of protocol 335 mechanism between the client and server, preceding the STUN 336 exchange. A short-term credential has an explicit temporal scope, 337 which may be based on a specific amount of time (such as 5 338 minutes) or on an event (such as termination of a SIP dialog). 339 The specific scope of a short-term credential is defined by the 340 application usage. 342 Short-Term Password: The password component of a short-term 343 credential. 345 STUN Indication: A STUN message that does not receive a response. 347 Attribute: The STUN term for a Type-Length-Value (TLV) object that 348 can be added to a STUN message. Attributes are divided into two 349 types: comprehension-required and comprehension-optional. STUN 350 agents can safely ignore comprehension-optional attributes they 351 don't understand, but cannot successfully process a message if it 352 contains comprehension-required attributes that are not 353 understood. 355 RTO: Retransmission TimeOut, which defines the initial period of 356 time between transmission of a request and the first retransmit of 357 that request. 359 5. STUN Message Structure 361 STUN messages are encoded in binary using network-oriented format 362 (most significant byte or octet first, also commonly known as big- 363 endian). The transmission order is described in detail in Appendix B 364 of RFC791 [RFC0791]. Unless otherwise noted, numeric constants are 365 in decimal (base 10). 367 All STUN messages MUST start with a 20-byte header followed by zero 368 or more Attributes. The STUN header contains a STUN message type, 369 magic cookie, transaction ID, and message length. 371 0 1 2 3 372 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 373 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 374 |0 0| STUN Message Type | Message Length | 375 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 376 | Magic Cookie | 377 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 378 | | 379 | Transaction ID (96 bits) | 380 | | 381 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 383 Figure 2: Format of STUN Message Header 385 The most significant 2 bits of every STUN message MUST be zeroes. 386 This can be used to differentiate STUN packets from other protocols 387 when STUN is multiplexed with other protocols on the same port. 389 The message type defines the message class (request, success 390 response, failure response, or indication) and the message method 391 (the primary function) of the STUN message. Although there are four 392 message classes, there are only two types of transactions in STUN: 393 request/response transactions (which consist of a request message and 394 a response message) and indication transactions (which consist of a 395 single indication message). Response classes are split into error 396 and success responses to aid in quickly processing the STUN message. 398 The message type field is decomposed further into the following 399 structure: 401 0 1 402 2 3 4 5 6 7 8 9 0 1 2 3 4 5 404 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 405 |M |M |M|M|M|C|M|M|M|C|M|M|M|M| 406 |11|10|9|8|7|1|6|5|4|0|3|2|1|0| 407 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 409 Figure 3: Format of STUN Message Type Field 411 Here the bits in the message type field are shown as most significant 412 (M11) through least significant (M0). M11 through M0 represent a 413 12-bit encoding of the method. C1 and C0 represent a 2-bit encoding 414 of the class. A class of 0b00 is a request, a class of 0b01 is an 415 indication, a class of 0b10 is a success response, and a class of 416 0b11 is an error response. This specification defines a single 417 method, Binding. The method and class are orthogonal, so that for 418 each method, a request, success response, error response, and 419 indication are possible for that method. Extensions defining new 420 methods MUST indicate which classes are permitted for that method. 422 For example, a Binding request has class=0b00 (request) and 423 method=0b000000000001 (Binding) and is encoded into the first 16 bits 424 as 0x0001. A Binding response has class=0b10 (success response) and 425 method=0b000000000001, and is encoded into the first 16 bits as 426 0x0101. 428 Note: This unfortunate encoding is due to assignment of values in 429 [RFC3489] that did not consider encoding Indications, Success, and 430 Errors using bit fields. 432 The magic cookie field MUST contain the fixed value 0x2112A442 in 433 network byte order. In RFC 3489 [RFC3489], this field was part of 434 the transaction ID; placing the magic cookie in this location allows 435 a server to detect if the client will understand certain attributes 436 that were added in this revised specification. In addition, it aids 437 in distinguishing STUN packets from packets of other protocols when 438 STUN is multiplexed with those other protocols on the same port. 440 The transaction ID is a 96-bit identifier, used to uniquely identify 441 STUN transactions. For request/response transactions, the 442 transaction ID is chosen by the STUN client for the request and 443 echoed by the server in the response. For indications, it is chosen 444 by the agent sending the indication. It primarily serves to 445 correlate requests with responses, though it also plays a small role 446 in helping to prevent certain types of attacks. The server also uses 447 the transaction ID as a key to identify each transaction uniquely 448 across all clients. As such, the transaction ID MUST be uniformly 449 and randomly chosen from the interval 0 .. 2**96-1, and SHOULD be 450 cryptographically random. Resends of the same request reuse the same 451 transaction ID, but the client MUST choose a new transaction ID for 452 new transactions unless the new request is bit-wise identical to the 453 previous request and sent from the same transport address to the same 454 IP address. Success and error responses MUST carry the same 455 transaction ID as their corresponding request. When an agent is 456 acting as a STUN server and STUN client on the same port, the 457 transaction IDs in requests sent by the agent have no relationship to 458 the transaction IDs in requests received by the agent. 460 The message length MUST contain the size, in bytes, of the message 461 not including the 20-byte STUN header. Since all STUN attributes are 462 padded to a multiple of 4 bytes, the last 2 bits of this field are 463 always zero. This provides another way to distinguish STUN packets 464 from packets of other protocols. 466 Following the STUN fixed portion of the header are zero or more 467 attributes. Each attribute is TLV (Type-Length-Value) encoded. The 468 details of the encoding, and of the attributes themselves are given 469 in Section 14. 471 6. Base Protocol Procedures 473 This section defines the base procedures of the STUN protocol. It 474 describes how messages are formed, how they are sent, and how they 475 are processed when they are received. It also defines the detailed 476 processing of the Binding method. Other sections in this document 477 describe optional procedures that a usage may elect to use in certain 478 situations. Other documents may define other extensions to STUN, by 479 adding new methods, new attributes, or new error response codes. 481 6.1. Forming a Request or an Indication 483 When formulating a request or indication message, the agent MUST 484 follow the rules in Section 5 when creating the header. In addition, 485 the message class MUST be either "Request" or "Indication" (as 486 appropriate), and the method must be either Binding or some method 487 defined in another document. 489 The agent then adds any attributes specified by the method or the 490 usage. For example, some usages may specify that the agent use an 491 authentication method (Section 9) or the FINGERPRINT attribute 492 (Section 7). 494 If the agent is sending a request, it SHOULD add a SOFTWARE attribute 495 to the request. Agents MAY include a SOFTWARE attribute in 496 indications, depending on the method. Extensions to STUN should 497 discuss whether SOFTWARE is useful in new indications. 499 For the Binding method with no authentication, no attributes are 500 required unless the usage specifies otherwise. 502 All STUN messages sent over UDP SHOULD be less than the path MTU, if 503 known. If the path MTU is unknown, messages SHOULD be the smaller of 504 576 bytes and the first-hop MTU for IPv4 [RFC1122] and 1280 bytes for 505 IPv6 [RFC2460]. This value corresponds to the overall size of the IP 506 packet. Consequently, for IPv4, the actual STUN message would need 507 to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte 508 UDP header, assuming no IP options are used). STUN provides no 509 ability to handle the case where the request is under the MTU but the 510 response would be larger than the MTU. It is not envisioned that 511 this limitation will be an issue for STUN. The MTU limitation is a 512 SHOULD, and not a MUST, to account for cases where STUN itself is 513 being used to probe for MTU characteristics [RFC5780]. Outside of 514 this or similar applications, the MTU constraint MUST be followed. 516 6.2. Sending the Request or Indication 518 The agent then sends the request or indication. This document 519 specifies how to send STUN messages over UDP, TCP, or TLS-over-TCP; 520 other transport protocols may be added in the future. The STUN usage 521 must specify which transport protocol is used, and how the agent 522 determines the IP address and port of the recipient. Section 8 523 describes a DNS-based method of determining the IP address and port 524 of a server that a usage may elect to use. STUN may be used with 525 anycast addresses, but only with UDP and in usages where 526 authentication is not used. 528 At any time, a client MAY have multiple outstanding STUN requests 529 with the same STUN server (that is, multiple transactions in 530 progress, with different transaction IDs). Absent other limits to 531 the rate of new transactions (such as those specified by ICE for 532 connectivity checks or when STUN is run over TCP), a client SHOULD 533 space new transactions to a server by RTO and SHOULD limit itself to 534 ten outstanding transactions to the same server. 536 6.2.1. Sending over UDP 538 When running STUN over UDP, it is possible that the STUN message 539 might be dropped by the network. Reliability of STUN request/ 540 response transactions is accomplished through retransmissions of the 541 request message by the client application itself. STUN indications 542 are not retransmitted; thus, indication transactions over UDP are not 543 reliable. 545 A client SHOULD retransmit a STUN request message starting with an 546 interval of RTO ("Retransmission TimeOut"), doubling after each 547 retransmission. The RTO is an estimate of the round-trip time (RTT), 548 and is computed as described in RFC 6298 [RFC6298], with two 549 exceptions. First, the initial value for RTO SHOULD be greater than 550 500 ms. The exception cases for this "SHOULD" are when other 551 mechanisms are used to derive congestion thresholds (such as the ones 552 defined in ICE for fixed rate streams), or when STUN is used in non- 553 Internet environments with known network capacities. In fixed-line 554 access links, a value of 500 ms is RECOMMENDED. Second, the value of 555 RTO SHOULD NOT be rounded up to the nearest second. Rather, a 1 ms 556 accuracy SHOULD be maintained. As with TCP, the usage of Karn's 557 algorithm is RECOMMENDED [KARN87]. When applied to STUN, it means 558 that RTT estimates SHOULD NOT be computed from STUN transactions that 559 result in the retransmission of a request. 561 The value for RTO SHOULD be cached by a client after the completion 562 of the transaction, and used as the starting value for RTO for the 563 next transaction to the same server (based on equality of IP 564 address). The value SHOULD be considered stale and discarded after 565 10 minutes. 567 Retransmissions continue until a response is received, or until a 568 total of Rc requests have been sent. Rc SHOULD be configurable and 569 SHOULD have a default of 7. If, after the last request, a duration 570 equal to Rm times the RTO has passed without a response (providing 571 ample time to get a response if only this final request actually 572 succeeds), the client SHOULD consider the transaction to have failed. 573 Rm SHOULD be configurable and SHOULD have a default of 16. A STUN 574 transaction over UDP is also considered failed if there has been a 575 hard ICMP error [RFC1122]. For example, assuming an RTO of 500ms, 576 requests would be sent at times 0 ms, 500 ms, 1500 ms, 3500 ms, 7500 577 ms, 15500 ms, and 31500 ms. If the client has not received a 578 response after 39500 ms, the client will consider the transaction to 579 have timed out. 581 6.2.2. Sending over TCP or TLS-over-TCP 583 For TCP and TLS-over-TCP, the client opens a TCP connection to the 584 server. 586 In some usages of STUN, STUN is sent as the only protocol over the 587 TCP connection. In this case, it can be sent without the aid of any 588 additional framing or demultiplexing. In other usages, or with other 589 extensions, it may be multiplexed with other data over a TCP 590 connection. In that case, STUN MUST be run on top of some kind of 591 framing protocol, specified by the usage or extension, which allows 592 for the agent to extract complete STUN messages and complete 593 application layer messages. The STUN service running on the well- 594 known port or ports discovered through the DNS procedures in 595 Section 8 is for STUN alone, and not for STUN multiplexed with other 596 data. Consequently, no framing protocols are used in connections to 597 those servers. When additional framing is utilized, the usage will 598 specify how the client knows to apply it and what port to connect to. 599 For example, in the case of ICE connectivity checks, this information 600 is learned through out-of-band negotiation between client and server. 602 When STUN is run by itself over TLS-over-TCP, the 603 TLS_RSA_WITH_AES_128_CBC_SHA ciphersuite MUST be implemented at a 604 minimum. Implementations MAY also support any other ciphersuite. 605 When it receives the TLS Certificate message, the client SHOULD 606 verify the certificate and inspect the site identified by the 607 certificate. If the certificate is invalid or revoked, or if it does 608 not identify the appropriate party, the client MUST NOT send the STUN 609 message or otherwise proceed with the STUN transaction. The client 610 MUST verify the identity of the server. To do that, it follows the 611 identification procedures defined in Section 3.1 of RFC 2818 612 [RFC2818]. Those procedures assume the client is dereferencing a 613 URI. For purposes of usage with this specification, the client 614 treats the original domain name or IP address used in Section 8 as 615 the host portion of the URI that has been dereferenced. 616 Alternatively, a client MAY be configured with a set of domains or IP 617 addresses that are trusted; if a certificate is received that 618 identifies one of those domains or IP addresses, the client considers 619 the identity of the server to be verified. 621 When STUN is run multiplexed with other protocols over a TLS-over-TCP 622 connection, the mandatory ciphersuites and TLS handling procedures 623 operate as defined by those protocols. 625 Reliability of STUN over TCP and TLS-over-TCP is handled by TCP 626 itself, and there are no retransmissions at the STUN protocol level. 627 However, for a request/response transaction, if the client has not 628 received a response by Ti seconds after it sent the SYN to establish 629 the connection, it considers the transaction to have timed out. Ti 630 SHOULD be configurable and SHOULD have a default of 39.5s. This 631 value has been chosen to equalize the TCP and UDP timeouts for the 632 default initial RTO. 634 In addition, if the client is unable to establish the TCP connection, 635 or the TCP connection is reset or fails before a response is 636 received, any request/response transaction in progress is considered 637 to have failed. 639 The client MAY send multiple transactions over a single TCP (or TLS- 640 over-TCP) connection, and it MAY send another request before 641 receiving a response to the previous. The client SHOULD keep the 642 connection open until it: 644 o has no further STUN requests or indications to send over that 645 connection, and 647 o has no plans to use any resources (such as a mapped address 648 (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address 649 [RFC5766]) that were learned though STUN requests sent over that 650 connection, and 652 o if multiplexing other application protocols over that port, has 653 finished using that other application, and 655 o if using that learned port with a remote peer, has established 656 communications with that remote peer, as is required by some TCP 657 NAT traversal techniques (e.g., [RFC6544]). 659 At the server end, the server SHOULD keep the connection open, and 660 let the client close it, unless the server has determined that the 661 connection has timed out (for example, due to the client 662 disconnecting from the network). Bindings learned by the client will 663 remain valid in intervening NATs only while the connection remains 664 open. Only the client knows how long it needs the binding. The 665 server SHOULD NOT close a connection if a request was received over 666 that connection for which a response was not sent. A server MUST NOT 667 ever open a connection back towards the client in order to send a 668 response. Servers SHOULD follow best practices regarding connection 669 management in cases of overload. 671 6.3. Receiving a STUN Message 673 This section specifies the processing of a STUN message. The 674 processing specified here is for STUN messages as defined in this 675 specification; additional rules for backwards compatibility are 676 defined in Section 11. Those additional procedures are optional, and 677 usages can elect to utilize them. First, a set of processing 678 operations is applied that is independent of the class. This is 679 followed by class-specific processing, described in the subsections 680 that follow. 682 When a STUN agent receives a STUN message, it first checks that the 683 message obeys the rules of Section 5. It checks that the first two 684 bits are 0, that the magic cookie field has the correct value, that 685 the message length is sensible, and that the method value is a 686 supported method. It checks that the message class is allowed for 687 the particular method. If the message class is "Success Response" or 688 "Error Response", the agent checks that the transaction ID matches a 689 transaction that is still in progress. If the FINGERPRINT extension 690 is being used, the agent checks that the FINGERPRINT attribute is 691 present and contains the correct value. If any errors are detected, 692 the message is silently discarded. In the case when STUN is being 693 multiplexed with another protocol, an error may indicate that this is 694 not really a STUN message; in this case, the agent should try to 695 parse the message as a different protocol. 697 The STUN agent then does any checks that are required by a 698 authentication mechanism that the usage has specified (see 699 Section 9). 701 Once the authentication checks are done, the STUN agent checks for 702 unknown attributes and known-but-unexpected attributes in the 703 message. Unknown comprehension-optional attributes MUST be ignored 704 by the agent. Known-but-unexpected attributes SHOULD be ignored by 705 the agent. Unknown comprehension-required attributes cause 706 processing that depends on the message class and is described below. 708 At this point, further processing depends on the message class of the 709 request. 711 6.3.1. Processing a Request 713 If the request contains one or more unknown comprehension-required 714 attributes, the server replies with an error response with an error 715 code of 420 (Unknown Attribute), and includes an UNKNOWN-ATTRIBUTES 716 attribute in the response that lists the unknown comprehension- 717 required attributes. 719 The server then does any additional checking that the method or the 720 specific usage requires. If all the checks succeed, the server 721 formulates a success response as described below. 723 When run over UDP, a request received by the server could be the 724 first request of a transaction, or a retransmission. The server MUST 725 respond to retransmissions such that the following property is 726 preserved: if the client receives the response to the retransmission 727 and not the response that was sent to the original request, the 728 overall state on the client and server is identical to the case where 729 only the response to the original retransmission is received, or 730 where both responses are received (in which case the client will use 731 the first). The easiest way to meet this requirement is for the 732 server to remember all transaction IDs received over UDP and their 733 corresponding responses in the last 40 seconds. However, this 734 requires the server to hold state, and will be inappropriate for any 735 requests which are not authenticated. Another way is to reprocess 736 the request and recompute the response. The latter technique MUST 737 only be applied to requests that are idempotent (a request is 738 considered idempotent when the same request can be safely repeated 739 without impacting the overall state of the system) and result in the 740 same success response for the same request. The Binding method is 741 considered to be idempotent. Note that there are certain rare 742 network events that could cause the reflexive transport address value 743 to change, resulting in a different mapped address in different 744 success responses. Extensions to STUN MUST discuss the implications 745 of request retransmissions on servers that do not store transaction 746 state. 748 6.3.1.1. Forming a Success or Error Response 750 When forming the response (success or error), the server follows the 751 rules of Section 6. The method of the response is the same as that 752 of the request, and the message class is either "Success Response" or 753 "Error Response". 755 For an error response, the server MUST add an ERROR-CODE attribute 756 containing the error code specified in the processing above. The 757 reason phrase is not fixed, but SHOULD be something suitable for the 758 error code. For certain errors, additional attributes are added to 759 the message. These attributes are spelled out in the description 760 where the error code is specified. For example, for an error code of 761 420 (Unknown Attribute), the server MUST include an UNKNOWN- 762 ATTRIBUTES attribute. Certain authentication errors also cause 763 attributes to be added (see Section 9). Extensions may define other 764 errors and/or additional attributes to add in error cases. 766 If the server authenticated the request using an authentication 767 mechanism, then the server SHOULD add the appropriate authentication 768 attributes to the response (see Section 9). 770 The server also adds any attributes required by the specific method 771 or usage. In addition, the server SHOULD add a SOFTWARE attribute to 772 the message. 774 For the Binding method, no additional checking is required unless the 775 usage specifies otherwise. When forming the success response, the 776 server adds a XOR-MAPPED-ADDRESS attribute to the response, where the 777 contents of the attribute are the source transport address of the 778 request message. For UDP, this is the source IP address and source 779 UDP port of the request message. For TCP and TLS-over-TCP, this is 780 the source IP address and source TCP port of the TCP connection as 781 seen by the server. 783 6.3.1.2. Sending the Success or Error Response 785 The response (success or error) is sent over the same transport as 786 the request was received on. If the request was received over UDP, 787 the destination IP address and port of the response are the source IP 788 address and port of the received request message, and the source IP 789 address and port of the response are equal to the destination IP 790 address and port of the received request message. If the request was 791 received over TCP or TLS-over-TCP, the response is sent back on the 792 same TCP connection as the request was received on. 794 6.3.2. Processing an Indication 796 If the indication contains unknown comprehension-required attributes, 797 the indication is discarded and processing ceases. 799 The agent then does any additional checking that the method or the 800 specific usage requires. If all the checks succeed, the agent then 801 processes the indication. No response is generated for an 802 indication. 804 For the Binding method, no additional checking or processing is 805 required, unless the usage specifies otherwise. The mere receipt of 806 the message by the agent has refreshed the "bindings" in the 807 intervening NATs. 809 Since indications are not re-transmitted over UDP (unlike requests), 810 there is no need to handle re-transmissions of indications at the 811 sending agent. 813 6.3.3. Processing a Success Response 815 If the success response contains unknown comprehension-required 816 attributes, the response is discarded and the transaction is 817 considered to have failed. 819 The client then does any additional checking that the method or the 820 specific usage requires. If all the checks succeed, the client then 821 processes the success response. 823 For the Binding method, the client checks that the XOR-MAPPED-ADDRESS 824 attribute is present in the response. The client checks the address 825 family specified. If it is an unsupported address family, the 826 attribute SHOULD be ignored. If it is an unexpected but supported 827 address family (for example, the Binding transaction was sent over 828 IPv4, but the address family specified is IPv6), then the client MAY 829 accept and use the value. 831 6.3.4. Processing an Error Response 833 If the error response contains unknown comprehension-required 834 attributes, or if the error response does not contain an ERROR-CODE 835 attribute, then the transaction is simply considered to have failed. 837 The client then does any processing specified by the authentication 838 mechanism (see Section 9). This may result in a new transaction 839 attempt. 841 The processing at this point depends on the error code, the method, 842 and the usage; the following are the default rules: 844 o If the error code is 300 through 399, the client SHOULD consider 845 the transaction as failed unless the ALTERNATE-SERVER extension is 846 being used. See Section 10. 848 o If the error code is 400 through 499, the client declares the 849 transaction failed; in the case of 420 (Unknown Attribute), the 850 response should contain a UNKNOWN-ATTRIBUTES attribute that gives 851 additional information. 853 o If the error code is 500 through 599, the client MAY resend the 854 request; clients that do so MUST limit the number of times they do 855 this. 857 Any other error code causes the client to consider the transaction 858 failed. 860 7. FINGERPRINT Mechanism 862 This section describes an optional mechanism for STUN that aids in 863 distinguishing STUN messages from packets of other protocols when the 864 two are multiplexed on the same transport address. This mechanism is 865 optional, and a STUN usage must describe if and when it is used. The 866 FINGERPRINT mechanism is not backwards compatible with RFC3489, and 867 cannot be used in environments where such compatibility is required. 869 In some usages, STUN messages are multiplexed on the same transport 870 address as other protocols, such as the Real Time Transport Protocol 871 (RTP). In order to apply the processing described in Section 6, STUN 872 messages must first be separated from the application packets. 874 Section 5 describes three fixed fields in the STUN header that can be 875 used for this purpose. However, in some cases, these three fixed 876 fields may not be sufficient. 878 When the FINGERPRINT extension is used, an agent includes the 879 FINGERPRINT attribute in messages it sends to another agent. 880 Section 14.6 describes the placement and value of this attribute. 882 When the agent receives what it believes is a STUN message, then, in 883 addition to other basic checks, the agent also checks that the 884 message contains a FINGERPRINT attribute and that the attribute 885 contains the correct value. Section 6.3 describes when in the 886 overall processing of a STUN message the FINGERPRINT check is 887 performed. This additional check helps the agent detect messages of 888 other protocols that might otherwise seem to be STUN messages. 890 8. DNS Discovery of a Server 892 This section describes an optional procedure for STUN that allows a 893 client to use DNS to determine the IP address and port of a server. 894 A STUN usage must describe if and when this extension is used. To 895 use this procedure, the client must know a server's domain name and a 896 service name; the usage must also describe how the client obtains 897 these. Hard-coding the domain name of the server into software is 898 NOT RECOMMENDED in case the domain name is lost or needs to change 899 for legal or other reasons. 901 When a client wishes to locate a STUN server in the public Internet 902 that accepts Binding request/response transactions, the SRV service 903 name is "stun". When it wishes to locate a STUN server that accepts 904 Binding request/response transactions over a TLS session, the SRV 905 service name is "stuns". STUN usages MAY define additional DNS SRV 906 service names. 908 The domain name is resolved to a transport address using the SRV 909 procedures specified in [RFC2782]. The DNS SRV service name is the 910 service name provided as input to this procedure. The protocol in 911 the SRV lookup is the transport protocol the client will run STUN 912 over: "udp" for UDP and "tcp" for TCP. Note that only "tcp" is 913 defined with "stuns" at this time. 915 The procedures of RFC 2782 are followed to determine the server to 916 contact. RFC 2782 spells out the details of how a set of SRV records 917 is sorted and then tried. However, RFC 2782 only states that the 918 client should "try to connect to the (protocol, address, service)" 919 without giving any details on what happens in the event of failure. 920 When following these procedures, if the STUN transaction times out 921 without receipt of a response, the client SHOULD retry the request to 922 the next server in the ordered defined by RFC 2782. Such a retry is 923 only possible for request/response transmissions, since indication 924 transactions generate no response or timeout. 926 The default port for STUN requests is 3478, for both TCP and UDP. 928 Administrators of STUN servers SHOULD use this port in their SRV 929 records for UDP and TCP. In all cases, the port in DNS MUST reflect 930 the one on which the server is listening. The default port for STUN 931 over TLS is 5349. Servers can run STUN over TLS on the same port as 932 STUN over TCP if the server software supports determining whether the 933 initial message is a TLS or STUN message. 935 If no SRV records were found, the client performs an A or AAAA record 936 lookup of the domain name. The result will be a list of IP 937 addresses, each of which can be contacted at the default port using 938 UDP or TCP, independent of the STUN usage. For usages that require 939 TLS, the client connects to one of the IP addresses using the default 940 STUN over TLS port. 942 9. Authentication and Message-Integrity Mechanisms 944 This section defines two mechanisms for STUN that a client and server 945 can use to provide authentication and message integrity; these two 946 mechanisms are known as the short-term credential mechanism and the 947 long-term credential mechanism. These two mechanisms are optional, 948 and each usage must specify if and when these mechanisms are used. 949 Consequently, both clients and servers will know which mechanism (if 950 any) to follow based on knowledge of which usage applies. For 951 example, a STUN server on the public Internet supporting ICE would 952 have no authentication, whereas the STUN server functionality in an 953 agent supporting connectivity checks would utilize short-term 954 credentials. An overview of these two mechanisms is given in 955 Section 2. 957 Each mechanism specifies the additional processing required to use 958 that mechanism, extending the processing specified in Section 6. The 959 additional processing occurs in three different places: when forming 960 a message, when receiving a message immediately after the basic 961 checks have been performed, and when doing the detailed processing of 962 error responses. 964 9.1. Short-Term Credential Mechanism 966 The short-term credential mechanism assumes that, prior to the STUN 967 transaction, the client and server have used some other protocol to 968 exchange a credential in the form of a username and password. This 969 credential is time-limited. The time limit is defined by the usage. 970 As an example, in the ICE usage [RFC5245], the two endpoints use out- 971 of-band signaling to agree on a username and password, and this 972 username and password are applicable for the duration of the media 973 session. 975 This credential is used to form a message-integrity check in each 976 request and in many responses. There is no challenge and response as 977 in the long-term mechanism; consequently, replay is prevented by 978 virtue of the time-limited nature of the credential. 980 9.1.1. Forming a Request or Indication 982 For a request or indication message, the agent MUST include the 983 USERNAME and MESSAGE-INTEGRITY attributes in the message. The HMAC 984 for the MESSAGE-INTEGRITY attribute is computed as described in 985 Section 14.4. Note that the password is never included in the 986 request or indication. 988 9.1.2. Receiving a Request or Indication 990 After the agent has done the basic processing of a message, the agent 991 performs the checks listed below in order specified: 993 o If the message does not contain both a MESSAGE-INTEGRITY and a 994 USERNAME attribute: 996 * If the message is a request, the server MUST reject the request 997 with an error response. This response MUST use an error code 998 of 400 (Bad Request). 1000 * If the message is an indication, the agent MUST silently 1001 discard the indication. 1003 o If the USERNAME does not contain a username value currently valid 1004 within the server: 1006 * If the message is a request, the server MUST reject the request 1007 with an error response. This response MUST use an error code 1008 of 401 (Unauthorized). 1010 * If the message is an indication, the agent MUST silently 1011 discard the indication. 1013 o Using the password associated with the username, compute the value 1014 for the message integrity as described in Section 14.4. If the 1015 resulting value does not match the contents of the MESSAGE- 1016 INTEGRITY attribute: 1018 * If the message is a request, the server MUST reject the request 1019 with an error response. This response MUST use an error code 1020 of 401 (Unauthorized). 1022 * If the message is an indication, the agent MUST silently 1023 discard the indication. 1025 If these checks pass, the agent continues to process the request or 1026 indication. Any response generated by a server MUST include the 1027 MESSAGE-INTEGRITY attribute, computed using the password utilized to 1028 authenticate the request. The response MUST NOT contain the USERNAME 1029 attribute. 1031 If any of the checks fail, a server MUST NOT include a MESSAGE- 1032 INTEGRITY or USERNAME attribute in the error response. This is 1033 because, in these failure cases, the server cannot determine the 1034 shared secret necessary to compute MESSAGE-INTEGRITY. 1036 9.1.3. Receiving a Response 1038 The client looks for the MESSAGE-INTEGRITY attribute in the response. 1039 If present, the client computes the message integrity over the 1040 response as defined in Section 14.4, using the same password it 1041 utilized for the request. If the resulting value matches the 1042 contents of the MESSAGE-INTEGRITY attribute, the response is 1043 considered authenticated. If the value does not match, or if 1044 MESSAGE-INTEGRITY was absent, the response MUST be discarded, as if 1045 it was never received. This means that retransmits, if applicable, 1046 will continue. 1048 9.2. Long-Term Credential Mechanism 1050 The long-term credential mechanism relies on a long-term credential, 1051 in the form of a username and password that are shared between client 1052 and server. The credential is considered long-term since it is 1053 assumed that it is provisioned for a user, and remains in effect 1054 until the user is no longer a subscriber of the system, or is 1055 changed. This is basically a traditional "log-in" username and 1056 password given to users. 1058 Because these usernames and passwords are expected to be valid for 1059 extended periods of time, replay prevention is provided in the form 1060 of a digest challenge. In this mechanism, the client initially sends 1061 a request, without offering any credentials or any integrity checks. 1062 The server rejects this request, providing the user a realm (used to 1063 guide the user or agent in selection of a username and password) and 1064 a nonce. The nonce provides the replay protection. It is a cookie, 1065 selected by the server, and encoded in such a way as to indicate a 1066 duration of validity or client identity from which it is valid. The 1067 client retries the request, this time including its username and the 1068 realm, and echoing the nonce provided by the server. The client also 1069 includes a message-integrity, which provides an HMAC over the entire 1070 request, including the nonce. The server validates the nonce and 1071 checks the message integrity. If they match, the request is 1072 authenticated. If the nonce is no longer valid, it is considered 1073 "stale", and the server rejects the request, providing a new nonce. 1075 In subsequent requests to the same server, the client reuses the 1076 nonce, username, realm, and password it used previously. In this 1077 way, subsequent requests are not rejected until the nonce becomes 1078 invalid by the server, in which case the rejection provides a new 1079 nonce to the client. 1081 Note that the long-term credential mechanism cannot be used to 1082 protect indications, since indications cannot be challenged. Usages 1083 utilizing indications must either use a short-term credential or omit 1084 authentication and message integrity for them. 1086 Since the long-term credential mechanism is susceptible to offline 1087 dictionary attacks, deployments SHOULD utilize passwords that are 1088 difficult to guess. In cases where the credentials are not entered 1089 by the user, but are rather placed on a client device during device 1090 provisioning, the password SHOULD have at least 128 bits of 1091 randomness. In cases where the credentials are entered by the user, 1092 they should follow best current practices around password structure. 1094 9.2.1. Forming a Request 1096 There are two cases when forming a request. In the first case, this 1097 is the first request from the client to the server (as identified by 1098 its IP address and port). In the second case, the client is 1099 submitting a subsequent request once a previous request/response 1100 transaction has completed successfully. Forming a request as a 1101 consequence of a 401 or 438 error response is covered in 1102 Section 9.2.3 and is not considered a "subsequent request" and thus 1103 does not utilize the rules described in Section 9.2.1.2. 1105 9.2.1.1. First Request 1107 If the client has not completed a successful request/response 1108 transaction with the server (as identified by hostname, if the DNS 1109 procedures of Section 8 are used, else IP address if not), it SHOULD 1110 omit the USERNAME, MESSAGE-INTEGRITY, REALM, and NONCE attributes. 1111 In other words, the very first request is sent as if there were no 1112 authentication or message integrity applied. 1114 9.2.1.2. Subsequent Requests 1116 Once a request/response transaction has completed successfully, the 1117 client will have been presented a realm and nonce by the server, and 1118 selected a username and password with which it authenticated. The 1119 client SHOULD cache the username, password, realm, and nonce for 1120 subsequent communications with the server. When the client sends a 1121 subsequent request, it SHOULD include the USERNAME, REALM, and NONCE 1122 attributes with these cached values. It SHOULD include a MESSAGE- 1123 INTEGRITY attribute, computed as described in Section 14.4 using the 1124 cached password. 1126 9.2.2. Receiving a Request 1128 After the server has done the basic processing of a request, it 1129 performs the checks listed below in the order specified: 1131 o If the message does not contain a MESSAGE-INTEGRITY attribute, the 1132 server MUST generate an error response with an error code of 401 1133 (Unauthorized). This response MUST include a REALM value. It is 1134 RECOMMENDED that the REALM value be the domain name of the 1135 provider of the STUN server. The response MUST include a NONCE, 1136 selected by the server. The response SHOULD NOT contain a 1137 USERNAME or MESSAGE-INTEGRITY attribute. 1139 o If the message contains a MESSAGE-INTEGRITY attribute, but is 1140 missing the USERNAME, REALM, or NONCE attribute, the server MUST 1141 generate an error response with an error code of 400 (Bad 1142 Request). This response SHOULD NOT include a USERNAME, NONCE, 1143 REALM, or MESSAGE-INTEGRITY attribute. 1145 o If the NONCE is no longer valid, the server MUST generate an error 1146 response with an error code of 438 (Stale Nonce). This response 1147 MUST include NONCE and REALM attributes and SHOULD NOT include the 1148 USERNAME or MESSAGE-INTEGRITY attribute. Servers can invalidate 1149 nonces in order to provide additional security. See Section 4.3 1150 of [RFC2617] for guidelines. 1152 o If the username in the USERNAME attribute is not valid, the server 1153 MUST generate an error response with an error code of 401 1154 (Unauthorized). This response MUST include a REALM value. It is 1155 RECOMMENDED that the REALM value be the domain name of the 1156 provider of the STUN server. The response MUST include a NONCE, 1157 selected by the server. The response SHOULD NOT contain a 1158 USERNAME or MESSAGE-INTEGRITY attribute. 1160 o Using the password associated with the username in the USERNAME 1161 attribute, compute the value for the message integrity as 1162 described in Section 14.4. If the resulting value does not match 1163 the contents of the MESSAGE-INTEGRITY attribute, the server MUST 1164 reject the request with an error response. This response MUST use 1165 an error code of 401 (Unauthorized). It MUST include REALM and 1166 NONCE attributes and SHOULD NOT include the USERNAME or MESSAGE- 1167 INTEGRITY attribute. 1169 If these checks pass, the server continues to process the request. 1170 Any response generated by the server (excepting the cases described 1171 above) MUST include the MESSAGE-INTEGRITY attribute, computed using 1172 the username and password utilized to authenticate the request. The 1173 REALM, NONCE, and USERNAME attributes SHOULD NOT be included. 1175 9.2.3. Receiving a Response 1177 If the response is an error response with an error code of 401 1178 (Unauthorized), the client SHOULD retry the request with a new 1179 transaction. This request MUST contain a USERNAME, determined by the 1180 client as the appropriate username for the REALM from the error 1181 response. The request MUST contain the REALM, copied from the error 1182 response. The request MUST contain the NONCE, copied from the error 1183 response. The request MUST contain the MESSAGE-INTEGRITY attribute, 1184 computed using the password associated with the username in the 1185 USERNAME attribute. The client MUST NOT perform this retry if it is 1186 not changing the USERNAME or REALM or its associated password, from 1187 the previous attempt. 1189 If the response is an error response with an error code of 438 (Stale 1190 Nonce), the client MUST retry the request, using the new NONCE 1191 supplied in the 438 (Stale Nonce) response. This retry MUST also 1192 include the USERNAME, REALM, and MESSAGE-INTEGRITY. 1194 The client looks for the MESSAGE-INTEGRITY attribute in the response 1195 (either success or failure). If present, the client computes the 1196 message integrity over the response as defined in Section 14.4, using 1197 the same password it utilized for the request. If the resulting 1198 value matches the contents of the MESSAGE-INTEGRITY attribute, the 1199 response is considered authenticated. If the value does not match, 1200 or if MESSAGE-INTEGRITY was absent, the response MUST be discarded, 1201 as if it was never received. This means that retransmits, if 1202 applicable, will continue. 1204 10. ALTERNATE-SERVER Mechanism 1206 This section describes a mechanism in STUN that allows a server to 1207 redirect a client to another server. This extension is optional, and 1208 a usage must define if and when this extension is used. 1210 A server using this extension redirects a client to another server by 1211 replying to a request message with an error response message with an 1212 error code of 300 (Try Alternate). The server MUST include an 1213 ALTERNATE-SERVER attribute in the error response. The error response 1214 message MAY be authenticated; however, there are uses cases for 1215 ALTERNATE-SERVER where authentication of the response is not possible 1216 or practical. 1218 A client using this extension handles a 300 (Try Alternate) error 1219 code as follows. The client looks for an ALTERNATE-SERVER attribute 1220 in the error response. If one is found, then the client considers 1221 the current transaction as failed, and reattempts the request with 1222 the server specified in the attribute, using the same transport 1223 protocol used for the previous request. That request, if 1224 authenticated, MUST utilize the same credentials that the client 1225 would have used in the request to the server that performed the 1226 redirection. If the client has been redirected to a server on which 1227 it has already tried this request within the last five minutes, it 1228 MUST ignore the redirection and consider the transaction to have 1229 failed. This prevents infinite ping-ponging between servers in case 1230 of redirection loops. 1232 11. Backwards Compatibility with RFC 3489 1234 This section defines procedures that allow a degree of backwards 1235 compatibility with the original protocol defined in RFC 3489 1236 [RFC3489]. This mechanism is optional, meant to be utilized only in 1237 cases where a new client can connect to an old server, or vice versa. 1238 A usage must define if and when this procedure is used. 1240 Section 19 of [RFC5389] lists all the changes between this 1241 specification and RFC 3489 [RFC3489]. However, not all of these 1242 differences are important, because "classic STUN" was only used in a 1243 few specific ways. For the purposes of this extension, the important 1244 changes are the following. In RFC 3489: 1246 o UDP was the only supported transport. 1248 o The field that is now the magic cookie field was a part of the 1249 transaction ID field, and transaction IDs were 128 bits long. 1251 o The XOR-MAPPED-ADDRESS attribute did not exist, and the Binding 1252 method used the MAPPED-ADDRESS attribute instead. 1254 o There were three comprehension-required attributes, RESPONSE- 1255 ADDRESS, CHANGE-REQUEST, and CHANGED-ADDRESS, that have been 1256 removed from this specification. 1258 * CHANGE-REQUEST and CHANGED-ADDRESS are now part of the NAT 1259 Behavior Discovery usage [RFC5780], and the other is 1260 deprecated. 1262 11.1. Changes to Client Processing 1264 A client that wants to interoperate with an [RFC3489] server SHOULD 1265 send a request message that uses the Binding method, contains no 1266 attributes, and uses UDP as the transport protocol to the server. If 1267 successful, the success response received from the server will 1268 contain a MAPPED-ADDRESS attribute rather than an XOR-MAPPED-ADDRESS 1269 attribute. A client seeking to interoperate with an older server 1270 MUST be prepared to receive either. Furthermore, the client MUST 1271 ignore any Reserved comprehension-required attributes that might 1272 appear in the response. Of the Reserved attributes in Section 17.2, 1273 0x0002, 0x0004, 0x0005, and 0x000B may appear in Binding responses 1274 from a server compliant to RFC 3489. Other than this change, the 1275 processing of the response is identical to the procedures described 1276 above. 1278 11.2. Changes to Server Processing 1280 A STUN server can detect when a given Binding request message was 1281 sent from an RFC 3489 [RFC3489] client by the absence of the correct 1282 value in the magic cookie field. When the server detects an RFC 3489 1283 client, it SHOULD copy the value seen in the magic cookie field in 1284 the Binding request to the magic cookie field in the Binding response 1285 message, and insert a MAPPED-ADDRESS attribute instead of an XOR- 1286 MAPPED-ADDRESS attribute. 1288 The client might, in rare situations, include either the RESPONSE- 1289 ADDRESS or CHANGE-REQUEST attributes. In these situations, the 1290 server will view these as unknown comprehension-required attributes 1291 and reply with an error response. Since the mechanisms utilizing 1292 those attributes are no longer supported, this behavior is 1293 acceptable. 1295 The RFC 3489 version of STUN lacks both the magic cookie and the 1296 FINGERPRINT attribute that allows for a very high probability of 1297 correctly identifying STUN messages when multiplexed with other 1298 protocols. Therefore, STUN implementations that are backwards 1299 compatible with RFC 3489 SHOULD NOT be used in cases where STUN will 1300 be multiplexed with another protocol. However, that should not be an 1301 issue as such multiplexing was not available in RFC 3489. 1303 12. Basic Server Behavior 1305 This section defines the behavior of a basic, stand-alone STUN 1306 server. A basic STUN server provides clients with server reflexive 1307 transport addresses by receiving and replying to STUN Binding 1308 requests. 1310 The STUN server MUST support the Binding method. It SHOULD NOT 1311 utilize the short-term or long-term credential mechanism. This is 1312 because the work involved in authenticating the request is more than 1313 the work in simply processing it. It SHOULD NOT utilize the 1314 ALTERNATE-SERVER mechanism for the same reason. It MUST support UDP 1315 and TCP. It MAY support STUN over TCP/TLS; however, TLS provides 1316 minimal security benefits in this basic mode of operation. It MAY 1317 utilize the FINGERPRINT mechanism but MUST NOT require it. Since the 1318 stand-alone server only runs STUN, FINGERPRINT provides no benefit. 1319 Requiring it would break compatibility with RFC 3489, and such 1320 compatibility is desirable in a stand-alone server. Stand-alone STUN 1321 servers SHOULD support backwards compatibility with [RFC3489] 1322 clients, as described in Section 11. 1324 It is RECOMMENDED that administrators of STUN servers provide DNS 1325 entries for those servers as described in Section 8. 1327 A basic STUN server is not a solution for NAT traversal by itself. 1328 However, it can be utilized as part of a solution through STUN 1329 usages. This is discussed further in Section 13. 1331 13. STUN Usages 1333 STUN by itself is not a solution to the NAT traversal problem. 1334 Rather, STUN defines a tool that can be used inside a larger 1335 solution. The term "STUN usage" is used for any solution that uses 1336 STUN as a component. 1338 At the time of writing, three STUN usages are defined: Interactive 1339 Connectivity Establishment (ICE) [RFC5245], Client-initiated 1340 connections for SIP [RFC5626], and NAT Behavior Discovery [RFC5780]. 1341 Other STUN usages may be defined in the future. 1343 A STUN usage defines how STUN is actually utilized -- when to send 1344 requests, what to do with the responses, and which optional 1345 procedures defined here (or in an extension to STUN) are to be used. 1346 A usage would also define: 1348 o Which STUN methods are used. 1350 o What authentication and message-integrity mechanisms are used. 1352 o The considerations around manual vs. automatic key derivation for 1353 the integrity mechanism, as discussed in [RFC4107]. 1355 o What mechanisms are used to distinguish STUN messages from other 1356 messages. When STUN is run over TCP, a framing mechanism may be 1357 required. 1359 o How a STUN client determines the IP address and port of the STUN 1360 server. 1362 o Whether backwards compatibility to RFC 3489 is required. 1364 o What optional attributes defined here (such as FINGERPRINT and 1365 ALTERNATE-SERVER) or in other extensions are required. 1367 In addition, any STUN usage must consider the security implications 1368 of using STUN in that usage. A number of attacks against STUN are 1369 known (see the Security Considerations section in this document), and 1370 any usage must consider how these attacks can be thwarted or 1371 mitigated. 1373 Finally, a usage must consider whether its usage of STUN is an 1374 example of the Unilateral Self-Address Fixing approach to NAT 1375 traversal, and if so, address the questions raised in RFC 3424 1376 [RFC3424]. 1378 14. STUN Attributes 1380 After the STUN header are zero or more attributes. Each attribute 1381 MUST be TLV encoded, with a 16-bit type, 16-bit length, and value. 1382 Each STUN attribute MUST end on a 32-bit boundary. As mentioned 1383 above, all fields in an attribute are transmitted most significant 1384 bit first. 1386 0 1 2 3 1387 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 1388 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1389 | Type | Length | 1390 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1391 | Value (variable) .... 1392 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1394 Figure 4: Format of STUN Attributes 1396 The value in the length field MUST contain the length of the Value 1397 part of the attribute, prior to padding, measured in bytes. Since 1398 STUN aligns attributes on 32-bit boundaries, attributes whose content 1399 is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of 1400 padding so that its value contains a multiple of 4 bytes. The 1401 padding bits are ignored, and may be any value. 1403 Any attribute type MAY appear more than once in a STUN message. 1404 Unless specified otherwise, the order of appearance is significant: 1405 only the first occurrence needs to be processed by a receiver, and 1406 any duplicates MAY be ignored by a receiver. 1408 To allow future revisions of this specification to add new attributes 1409 if needed, the attribute space is divided into two ranges. 1410 Attributes with type values between 0x0000 and 0x7FFF are 1411 comprehension-required attributes, which means that the STUN agent 1412 cannot successfully process the message unless it understands the 1413 attribute. Attributes with type values between 0x8000 and 0xFFFF are 1414 comprehension-optional attributes, which means that those attributes 1415 can be ignored by the STUN agent if it does not understand them. 1417 The set of STUN attribute types is maintained by IANA. The initial 1418 set defined by this specification is found in Section 17.2. 1420 The rest of this section describes the format of the various 1421 attributes defined in this specification. 1423 14.1. MAPPED-ADDRESS 1425 The MAPPED-ADDRESS attribute indicates a reflexive transport address 1426 of the client. It consists of an 8-bit address family and a 16-bit 1427 port, followed by a fixed-length value representing the IP address. 1428 If the address family is IPv4, the address MUST be 32 bits. If the 1429 address family is IPv6, the address MUST be 128 bits. All fields 1430 must be in network byte order. 1432 The format of the MAPPED-ADDRESS attribute is: 1434 0 1 2 3 1435 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 1436 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1437 |0 0 0 0 0 0 0 0| Family | Port | 1438 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1439 | | 1440 | Address (32 bits or 128 bits) | 1441 | | 1442 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1444 Figure 5: Format of MAPPED-ADDRESS Attribute 1446 The address family can take on the following values: 1448 0x01:IPv4 1449 0x02:IPv6 1451 The first 8 bits of the MAPPED-ADDRESS MUST be set to 0 and MUST be 1452 ignored by receivers. These bits are present for aligning parameters 1453 on natural 32-bit boundaries. 1455 This attribute is used only by servers for achieving backwards 1456 compatibility with RFC 3489 [RFC3489] clients. 1458 14.2. XOR-MAPPED-ADDRESS 1460 The XOR-MAPPED-ADDRESS attribute is identical to the MAPPED-ADDRESS 1461 attribute, except that the reflexive transport address is obfuscated 1462 through the XOR function. 1464 The format of the XOR-MAPPED-ADDRESS is: 1466 0 1 2 3 1467 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 1468 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1469 |x x x x x x x x| Family | X-Port | 1470 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1471 | X-Address (Variable) 1472 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1474 Figure 6: Format of XOR-MAPPED-ADDRESS Attribute 1476 The Family represents the IP address family, and is encoded 1477 identically to the Family in MAPPED-ADDRESS. 1479 X-Port is computed by taking the mapped port in host byte order, 1480 XOR'ing it with the most significant 16 bits of the magic cookie, and 1481 then the converting the result to network byte order. If the IP 1482 address family is IPv4, X-Address is computed by taking the mapped IP 1483 address in host byte order, XOR'ing it with the magic cookie, and 1484 converting the result to network byte order. If the IP address 1485 family is IPv6, X-Address is computed by taking the mapped IP address 1486 in host byte order, XOR'ing it with the concatenation of the magic 1487 cookie and the 96-bit transaction ID, and converting the result to 1488 network byte order. 1490 The rules for encoding and processing the first 8 bits of the 1491 attribute's value, the rules for handling multiple occurrences of the 1492 attribute, and the rules for processing address families are the same 1493 as for MAPPED-ADDRESS. 1495 Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only in their 1496 encoding of the transport address. The former encodes the transport 1497 address by exclusive-or'ing it with the magic cookie. The latter 1498 encodes it directly in binary. RFC 3489 originally specified only 1499 MAPPED-ADDRESS. However, deployment experience found that some NATs 1500 rewrite the 32-bit binary payloads containing the NAT's public IP 1501 address, such as STUN's MAPPED-ADDRESS attribute, in the well-meaning 1502 but misguided attempt at providing a generic ALG function. Such 1503 behavior interferes with the operation of STUN and also causes 1504 failure of STUN's message-integrity checking. 1506 14.3. USERNAME 1508 The USERNAME attribute is used for message integrity. It identifies 1509 the username and password combination used in the message-integrity 1510 check. 1512 The value of USERNAME is a variable-length value. It MUST contain a 1513 UTF-8 [RFC3629] encoded sequence of less than 513 bytes, and MUST 1514 have been processed using SASLprep [RFC4013]. 1516 14.4. MESSAGE-INTEGRITY 1518 The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of 1519 the STUN message. The MESSAGE-INTEGRITY attribute can be present in 1520 any STUN message type. Since it uses the SHA1 hash, the HMAC will be 1521 20 bytes. The text used as input to HMAC is the STUN message, 1522 including the header, up to and including the attribute preceding the 1523 MESSAGE-INTEGRITY attribute. With the exception of the MESSAGE- 1524 INTEGRITY2 and FINGERPRINT attributes, which appear after MESSAGE- 1525 INTEGRITY, agents MUST ignore all other attributes that follow 1526 MESSAGE-INTEGRITY. 1528 The key for the HMAC depends on whether long-term or short-term 1529 credentials are in use. For long-term credentials, the key is 16 1530 bytes: 1532 key = MD5(username ":" realm ":" SASLprep(password)) 1534 That is, the 16-byte key is formed by taking the MD5 hash of the 1535 result of concatenating the following five fields: (1) the username, 1536 with any quotes and trailing nulls removed, as taken from the 1537 USERNAME attribute (in which case SASLprep has already been applied); 1538 (2) a single colon; (3) the realm, with any quotes and trailing nulls 1539 removed; (4) a single colon; and (5) the password, with any trailing 1540 nulls removed and after processing using SASLprep. For example, if 1541 the username was 'user', the realm was 'realm', and the password was 1542 'pass', then the 16-byte HMAC key would be the result of performing 1543 an MD5 hash on the string 'user:realm:pass', the resulting hash being 1544 0x8493fbc53ba582fb4c044c456bdc40eb. 1546 For short-term credentials: 1548 key = SASLprep(password) 1550 where MD5 is defined in RFC 1321 [RFC1321] and SASLprep() is defined 1551 in RFC 4013 [RFC4013]. 1553 The structure of the key when used with long-term credentials 1554 facilitates deployment in systems that also utilize SIP. Typically, 1555 SIP systems utilizing SIP's digest authentication mechanism do not 1556 actually store the password in the database. Rather, they store a 1557 value called H(A1), which is equal to the key defined above. 1559 Based on the rules above, the hash used to construct MESSAGE- 1560 INTEGRITY includes the length field from the STUN message header. 1561 Prior to performing the hash, the MESSAGE-INTEGRITY attribute MUST be 1562 inserted into the message (with dummy content). The length MUST then 1563 be set to point to the length of the message up to, and including, 1564 the MESSAGE-INTEGRITY attribute itself, but excluding any attributes 1565 after it. Once the computation is performed, the value of the 1566 MESSAGE-INTEGRITY attribute can be filled in, and the value of the 1567 length in the STUN header can be set to its correct value -- the 1568 length of the entire message. Similarly, when validating the 1569 MESSAGE-INTEGRITY, the length field should be adjusted to point to 1570 the end of the MESSAGE-INTEGRITY attribute prior to calculating the 1571 HMAC. Such adjustment is necessary when attributes, such as 1572 FINGERPRINT, appear after MESSAGE-INTEGRITY. 1574 14.5. MESSAGE-INTEGRITY2 1576 The MESSAGE-INTEGRITY2 attribute contains an HMAC-SHA-256 [RFC2104] 1577 of the STUN message. The MESSAGE-INTEGRITY attribute can be present 1578 in any STUN message type. Since it uses the SHA-256 hash, the HMAC 1579 will be 32 bytes. The text used as input to HMAC is the STUN 1580 message, including the header, up to and including the attribute 1581 preceding the MESSAGE-INTEGRITY2 attribute. With the exception of 1582 the FINGERPRINT attribute, which appears after MESSAGE-INTEGRITY2, 1583 agents MUST ignore all other attributes that follow MESSAGE- 1584 INTEGRITY2. 1586 The key for the HMAC depends on whether long-term or short-term 1587 credentials are in use. For long-term credentials, the key is 16 1588 bytes: 1590 key = MD5(username ":" realm ":" SASLprep(password)) 1592 That is, the 16-byte key is formed by taking the MD5 hash of the 1593 result of concatenating the following five fields: (1) the username, 1594 with any quotes and trailing nulls removed, as taken from the 1595 USERNAME attribute (in which case SASLprep has already been applied); 1596 (2) a single colon; (3) the realm, with any quotes and trailing nulls 1597 removed; (4) a single colon; and (5) the password, with any trailing 1598 nulls removed and after processing using SASLprep. For example, if 1599 the username was 'user', the realm was 'realm', and the password was 1600 'pass', then the 16-byte HMAC key would be the result of performing 1601 an MD5 hash on the string 'user:realm:pass', the resulting hash being 1602 0x8493fbc53ba582fb4c044c456bdc40eb. 1604 For short-term credentials: 1606 +key = SASLprep(password) 1608 where MD5 is defined in RFC 1321 [RFC1321] and SASLprep() is defined 1609 in RFC 4013 [RFC4013]. 1611 The structure of the key when used with long-term credentials 1612 facilitates deployment in systems that also utilize SIP. Typically, 1613 SIP systems utilizing SIP's digest authentication mechanism do not 1614 actually store the password in the database. Rather, they store a 1615 value called H(A1), which is equal to the key defined above. 1617 Based on the rules above, the hash used to construct MESSAGE- 1618 INTEGRITY2 includes the length field from the STUN message header. 1619 Prior to performing the hash, the MESSAGE-INTEGRITY2 attribute MUST 1620 be inserted into the message (with dummy content). The length MUST 1621 then be set to point to the length of the message up to, and 1622 including, the MESSAGE-INTEGRITY2 attribute itself, but excluding any 1623 attributes after it. Once the computation is performed, the value of 1624 the MESSAGE-INTEGRITY2 attribute can be filled in, and the value of 1625 the length in the STUN header can be set to its correct value -- the 1626 length of the entire message. Similarly, when validating the 1627 MESSAGE-INTEGRITY2, the length field should be adjusted to point to 1628 the end of the MESSAGE-INTEGRITY2 attribute prior to calculating the 1629 HMAC. Such adjustment is necessary when attributes, such as 1630 FINGERPRINT, appear after MESSAGE-INTEGRITY2. 1632 14.6. FINGERPRINT 1634 The FINGERPRINT attribute MAY be present in all STUN messages. The 1635 value of the attribute is computed as the CRC-32 of the STUN message 1636 up to (but excluding) the FINGERPRINT attribute itself, XOR'ed with 1637 the 32-bit value 0x5354554e (the XOR helps in cases where an 1638 application packet is also using CRC-32 in it). The 32-bit CRC is 1639 the one defined in ITU V.42 [ITU.V42.2002], which has a generator 1640 polynomial of x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1. 1641 When present, the FINGERPRINT attribute MUST be the last attribute in 1642 the message, and thus will appear after MESSAGE-INTEGRITY. 1644 The FINGERPRINT attribute can aid in distinguishing STUN packets from 1645 packets of other protocols. See Section 7. 1647 As with MESSAGE-INTEGRITY, the CRC used in the FINGERPRINT attribute 1648 covers the length field from the STUN message header. Therefore, 1649 this value must be correct and include the CRC attribute as part of 1650 the message length, prior to computation of the CRC. When using the 1651 FINGERPRINT attribute in a message, the attribute is first placed 1652 into the message with a dummy value, then the CRC is computed, and 1653 then the value of the attribute is updated. If the MESSAGE-INTEGRITY 1654 attribute is also present, then it must be present with the correct 1655 message-integrity value before the CRC is computed, since the CRC is 1656 done over the value of the MESSAGE-INTEGRITY attribute as well. 1658 14.7. ERROR-CODE 1660 The ERROR-CODE attribute is used in error response messages. It 1661 contains a numeric error code value in the range of 300 to 699 plus a 1662 textual reason phrase encoded in UTF-8 [RFC3629], and is consistent 1663 in its code assignments and semantics with SIP [RFC3261] and HTTP 1664 [RFC2616]. The reason phrase is meant for user consumption, and can 1665 be anything appropriate for the error code. Recommended reason 1666 phrases for the defined error codes are included in the IANA registry 1667 for error codes. The reason phrase MUST be a UTF-8 [RFC3629] encoded 1668 sequence of less than 128 characters (which can be as long as 763 1669 bytes). 1671 0 1 2 3 1672 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 1673 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1674 | Reserved, should be 0 |Class| Number | 1675 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1676 | Reason Phrase (variable) .. 1677 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1679 Figure 7: ERROR-CODE Attribute 1681 To facilitate processing, the class of the error code (the hundreds 1682 digit) is encoded separately from the rest of the code, as shown in 1683 Figure 7. 1685 The Reserved bits SHOULD be 0, and are for alignment on 32-bit 1686 boundaries. Receivers MUST ignore these bits. The Class represents 1687 the hundreds digit of the error code. The value MUST be between 3 1688 and 6. The Number represents the error code modulo 100, and its 1689 value MUST be between 0 and 99. 1691 The following error codes, along with their recommended reason 1692 phrases, are defined: 1694 300 Try Alternate: The client should contact an alternate server for 1695 this request. This error response MUST only be sent if the 1696 request included a USERNAME attribute and a valid MESSAGE- 1697 INTEGRITY attribute; otherwise, it MUST NOT be sent and error 1698 code 400 (Bad Request) is suggested. This error response MUST 1699 be protected with the MESSAGE-INTEGRITY attribute, and receivers 1700 MUST validate the MESSAGE-INTEGRITY of this response before 1701 redirecting themselves to an alternate server. 1703 Note: Failure to generate and validate message integrity for 1704 a 300 response allows an on-path attacker to falsify a 300 1705 response thus causing subsequent STUN messages to be sent to 1706 a victim. 1708 400 Bad Request: The request was malformed. The client SHOULD NOT 1709 retry the request without modification from the previous 1710 attempt. The server may not be able to generate a valid 1711 MESSAGE-INTEGRITY for this error, so the client MUST NOT expect 1712 a valid MESSAGE-INTEGRITY attribute on this response. 1714 401 Unauthorized: The request did not contain the correct 1715 credentials to proceed. The client should retry the request 1716 with proper credentials. 1718 420 Unknown Attribute: The server received a STUN packet containing 1719 a comprehension-required attribute that it did not understand. 1720 The server MUST put this unknown attribute in the UNKNOWN- 1721 ATTRIBUTE attribute of its error response. 1723 438 Stale Nonce: The NONCE used by the client was no longer valid. 1724 The client should retry, using the NONCE provided in the 1725 response. 1727 500 Server Error: The server has suffered a temporary error. The 1728 client should try again. 1730 14.8. REALM 1732 The REALM attribute may be present in requests and responses. It 1733 contains text that meets the grammar for "realm-value" as described 1734 in RFC 3261 [RFC3261] but without the double quotes and their 1735 surrounding whitespace. That is, it is an unquoted realm-value (and 1736 is therefore a sequence of qdtext or quoted-pair). It MUST be a 1737 UTF-8 [RFC3629] encoded sequence of less than 128 characters (which 1738 can be as long as 763 bytes), and MUST have been processed using 1739 SASLprep [RFC4013]. 1741 Presence of the REALM attribute in a request indicates that long-term 1742 credentials are being used for authentication. Presence in certain 1743 error responses indicates that the server wishes the client to use a 1744 long-term credential for authentication. 1746 14.9. NONCE 1748 The NONCE attribute may be present in requests and responses. It 1749 contains a sequence of qdtext or quoted-pair, which are defined in 1750 RFC 3261 [RFC3261]. Note that this means that the NONCE attribute 1751 will not contain actual quote characters. See RFC 2617 [RFC2617], 1752 Section 4.3, for guidance on selection of nonce values in a server. 1753 It MUST be less than 128 characters (which can be as long as 763 1754 bytes). 1756 14.10. UNKNOWN-ATTRIBUTES 1758 The UNKNOWN-ATTRIBUTES attribute is present only in an error response 1759 when the response code in the ERROR-CODE attribute is 420. 1761 The attribute contains a list of 16-bit values, each of which 1762 represents an attribute type that was not understood by the server. 1764 0 1 2 3 1765 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 1766 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1767 | Attribute 1 Type | Attribute 2 Type | 1768 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1769 | Attribute 3 Type | Attribute 4 Type ... 1770 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1772 Figure 8: Format of UNKNOWN-ATTRIBUTES Attribute 1774 Note: In [RFC3489], this field was padded to 32 by duplicating the 1775 last attribute. In this version of the specification, the normal 1776 padding rules for attributes are used instead. 1778 14.11. SOFTWARE 1780 The SOFTWARE attribute contains a textual description of the software 1781 being used by the agent sending the message. It is used by clients 1782 and servers. Its value SHOULD include manufacturer and version 1783 number. The attribute has no impact on operation of the protocol, 1784 and serves only as a tool for diagnostic and debugging purposes. The 1785 value of SOFTWARE is variable length. It MUST be a UTF-8 [RFC3629] 1786 encoded sequence of less than 128 characters (which can be as long as 1787 763 bytes). 1789 14.12. ALTERNATE-SERVER 1791 The alternate server represents an alternate transport address 1792 identifying a different STUN server that the STUN client should try. 1794 It is encoded in the same way as MAPPED-ADDRESS, and thus refers to a 1795 single server by IP address. The IP address family MUST be identical 1796 to that of the source IP address of the request. 1798 15. Security Considerations 1800 15.1. Attacks against the Protocol 1802 15.1.1. Outside Attacks 1804 An attacker can try to modify STUN messages in transit, in order to 1805 cause a failure in STUN operation. These attacks are detected for 1806 both requests and responses through the message-integrity mechanism, 1807 using either a short-term or long-term credential. Of course, once 1808 detected, the manipulated packets will be dropped, causing the STUN 1809 transaction to effectively fail. This attack is possible only by an 1810 on-path attacker. 1812 An attacker that can observe, but not modify, STUN messages in- 1813 transit (for example, an attacker present on a shared access medium, 1814 such as Wi-Fi), can see a STUN request, and then immediately send a 1815 STUN response, typically an error response, in order to disrupt STUN 1816 processing. This attack is also prevented for messages that utilize 1817 MESSAGE-INTEGRITY. However, some error responses, those related to 1818 authentication in particular, cannot be protected by MESSAGE- 1819 INTEGRITY. When STUN itself is run over a secure transport protocol 1820 (e.g., TLS), these attacks are completely mitigated. 1822 Depending on the STUN usage, these attacks may be of minimal 1823 consequence and thus do not require message integrity to mitigate. 1824 For example, when STUN is used to a basic STUN server to discover a 1825 server reflexive candidate for usage with ICE, authentication and 1826 message integrity are not required since these attacks are detected 1827 during the connectivity check phase. The connectivity checks 1828 themselves, however, require protection for proper operation of ICE 1829 overall. As described in Section 13, STUN usages describe when 1830 authentication and message integrity are needed. 1832 Since STUN uses the HMAC of a shared secret for authentication and 1833 integrity protection, it is subject to offline dictionary attacks. 1834 When authentication is utilized, it SHOULD be with a strong password 1835 that is not readily subject to offline dictionary attacks. 1836 Protection of the channel itself, using TLS, mitigates these attacks. 1837 However, STUN is most often run over UDP and in those cases, strong 1838 passwords are the only way to protect against these attacks. 1840 15.1.2. Inside Attacks 1842 A rogue client may try to launch a DoS attack against a server by 1843 sending it a large number of STUN requests. Fortunately, STUN 1844 requests can be processed statelessly by a server, making such 1845 attacks hard to launch. 1847 A rogue client may use a STUN server as a reflector, sending it 1848 requests with a falsified source IP address and port. In such a 1849 case, the response would be delivered to that source IP and port. 1850 There is no amplification of the number of packets with this attack 1851 (the STUN server sends one packet for each packet sent by the 1852 client), though there is a small increase in the amount of data, 1853 since STUN responses are typically larger than requests. This attack 1854 is mitigated by ingress source address filtering. 1856 Revealing the specific software version of the agent through the 1857 SOFTWARE attribute might allow them to become more vulnerable to 1858 attacks against software that is known to contain security holes. 1859 Implementers SHOULD make usage of the SOFTWARE attribute a 1860 configurable option. 1862 15.2. Attacks Affecting the Usage 1864 This section lists attacks that might be launched against a usage of 1865 STUN. Each STUN usage must consider whether these attacks are 1866 applicable to it, and if so, discuss counter-measures. 1868 Most of the attacks in this section revolve around an attacker 1869 modifying the reflexive address learned by a STUN client through a 1870 Binding request/response transaction. Since the usage of the 1871 reflexive address is a function of the usage, the applicability and 1872 remediation of these attacks are usage-specific. In common 1873 situations, modification of the reflexive address by an on-path 1874 attacker is easy to do. Consider, for example, the common situation 1875 where STUN is run directly over UDP. In this case, an on-path 1876 attacker can modify the source IP address of the Binding request 1877 before it arrives at the STUN server. The STUN server will then 1878 return this IP address in the XOR-MAPPED-ADDRESS attribute to the 1879 client, and send the response back to that (falsified) IP address and 1880 port. If the attacker can also intercept this response, it can 1881 direct it back towards the client. Protecting against this attack by 1882 using a message-integrity check is impossible, since a message- 1883 integrity value cannot cover the source IP address, since the 1884 intervening NAT must be able to modify this value. Instead, one 1885 solution to preventing the attacks listed below is for the client to 1886 verify the reflexive address learned, as is done in ICE [RFC5245]. 1887 Other usages may use other means to prevent these attacks. 1889 15.2.1. Attack I: Distributed DoS (DDoS) against a Target 1891 In this attack, the attacker provides one or more clients with the 1892 same faked reflexive address that points to the intended target. 1893 This will trick the STUN clients into thinking that their reflexive 1894 addresses are equal to that of the target. If the clients hand out 1895 that reflexive address in order to receive traffic on it (for 1896 example, in SIP messages), the traffic will instead be sent to the 1897 target. This attack can provide substantial amplification, 1898 especially when used with clients that are using STUN to enable 1899 multimedia applications. However, it can only be launched against 1900 targets for which packets from the STUN server to the target pass 1901 through the attacker, limiting the cases in which it is possible. 1903 15.2.2. Attack II: Silencing a Client 1905 In this attack, the attacker provides a STUN client with a faked 1906 reflexive address. The reflexive address it provides is a transport 1907 address that routes to nowhere. As a result, the client won't 1908 receive any of the packets it expects to receive when it hands out 1909 the reflexive address. This exploitation is not very interesting for 1910 the attacker. It impacts a single client, which is frequently not 1911 the desired target. Moreover, any attacker that can mount the attack 1912 could also deny service to the client by other means, such as 1913 preventing the client from receiving any response from the STUN 1914 server, or even a DHCP server. As with the attack in Section 15.2.1, 1915 this attack is only possible when the attacker is on path for packets 1916 sent from the STUN server towards this unused IP address. 1918 15.2.3. Attack III: Assuming the Identity of a Client 1920 This attack is similar to attack II. However, the faked reflexive 1921 address points to the attacker itself. This allows the attacker to 1922 receive traffic that was destined for the client. 1924 15.2.4. Attack IV: Eavesdropping 1926 In this attack, the attacker forces the client to use a reflexive 1927 address that routes to itself. It then forwards any packets it 1928 receives to the client. This attack would allow the attacker to 1929 observe all packets sent to the client. However, in order to launch 1930 the attack, the attacker must have already been able to observe 1931 packets from the client to the STUN server. In most cases (such as 1932 when the attack is launched from an access network), this means that 1933 the attacker could already observe packets sent to the client. This 1934 attack is, as a result, only useful for observing traffic by 1935 attackers on the path from the client to the STUN server, but not 1936 generally on the path of packets being routed towards the client. 1938 15.3. Hash Agility Plan 1940 This specification uses HMAC-SHA-1 for computation of the message 1941 integrity. If, at a later time, HMAC-SHA-1 is found to be 1942 compromised, the following is the remedy that will be applied. 1944 We will define a STUN extension that introduces a new message- 1945 integrity attribute, computed using a new hash. Clients would be 1946 required to include both the new and old message-integrity attributes 1947 in their requests or indications. A new server will utilize the new 1948 message-integrity attribute, and an old one, the old. After a 1949 transition period where mixed implementations are in deployment, the 1950 old message-integrity attribute will be deprecated by another 1951 specification, and clients will cease including it in requests. 1953 It is also important to note that the HMAC is done using a key that 1954 is itself computed using an MD5 of the user's password. The choice 1955 of the MD5 hash was made because of the existence of legacy databases 1956 that store passwords in that form. If future work finds that an HMAC 1957 of an MD5 input is not secure, and a different hash is needed, it can 1958 also be changed using this plan. However, this would require 1959 administrators to repopulate their databases. 1961 16. IAB Considerations 1963 The IAB has studied the problem of Unilateral Self-Address Fixing 1964 (UNSAF), which is the general process by which a client attempts to 1965 determine its address in another realm on the other side of a NAT 1966 through a collaborative protocol reflection mechanism (RFC3424 1967 [RFC3424]). STUN can be used to perform this function using a 1968 Binding request/response transaction if one agent is behind a NAT and 1969 the other is on the public side of the NAT. 1971 The IAB has suggested that protocols developed for this purpose 1972 document a specific set of considerations. Because some STUN usages 1973 provide UNSAF functions (such as ICE [RFC5245] ), and others do not 1974 (such as SIP Outbound [RFC5626]), answers to these considerations 1975 need to be addressed by the usages themselves. 1977 17. IANA Considerations 1979 IANA has created three new registries: a "STUN Methods Registry", a 1980 "STUN Attributes Registry", and a "STUN Error Codes Registry". IANA 1981 has also changed the name of the assigned IANA port for STUN from 1982 "nat-stun-port" to "stun". 1984 17.1. STUN Methods Registry 1986 A STUN method is a hex number in the range 0x000 - 0xFFF. The 1987 encoding of STUN method into a STUN message is described in 1988 Section 5. 1990 The initial STUN methods are: 1992 0x000: (Reserved) 1993 0x001: Binding 1994 0x002: (Reserved; was SharedSecret) 1996 STUN methods in the range 0x000 - 0x7FF are assigned by IETF Review 1997 [RFC5226]. STUN methods in the range 0x800 - 0xFFF are assigned by 1998 Designated Expert [RFC5226]. The responsibility of the expert is to 1999 verify that the selected codepoint(s) are not in use and that the 2000 request is not for an abnormally large number of codepoints. 2001 Technical review of the extension itself is outside the scope of the 2002 designated expert responsibility. 2004 17.2. STUN Attribute Registry 2006 A STUN Attribute type is a hex number in the range 0x0000 - 0xFFFF. 2007 STUN attribute types in the range 0x0000 - 0x7FFF are considered 2008 comprehension-required; STUN attribute types in the range 0x8000 - 2009 0xFFFF are considered comprehension-optional. A STUN agent handles 2010 unknown comprehension-required and comprehension-optional attributes 2011 differently. 2013 The initial STUN Attributes types are: 2015 Comprehension-required range (0x0000-0x7FFF): 2016 0x0000: (Reserved) 2017 0x0001: MAPPED-ADDRESS 2018 0x0002: (Reserved; was RESPONSE-ADDRESS) 2019 0x0003: (Reserved; was CHANGE-ADDRESS) 2020 0x0004: (Reserved; was SOURCE-ADDRESS) 2021 0x0005: (Reserved; was CHANGED-ADDRESS) 2022 0x0006: USERNAME 2023 0x0007: (Reserved; was PASSWORD) 2024 0x0008: MESSAGE-INTEGRITY 2025 0x0009: ERROR-CODE 2026 0x000A: UNKNOWN-ATTRIBUTES 2027 0x000B: (Reserved; was REFLECTED-FROM) 2028 0x0014: REALM 2029 0x0015: NONCE 2030 0x0020: XOR-MAPPED-ADDRESS 2032 Comprehension-optional range (0x8000-0xFFFF) 2033 0x8022: SOFTWARE 2034 0x8023: ALTERNATE-SERVER 2035 0x8028: FINGERPRINT 2037 STUN Attribute types in the first half of the comprehension-required 2038 range (0x0000 - 0x3FFF) and in the first half of the comprehension- 2039 optional range (0x8000 - 0xBFFF) are assigned by IETF Review 2040 [RFC5226]. STUN Attribute types in the second half of the 2041 comprehension-required range (0x4000 - 0x7FFF) and in the second half 2042 of the comprehension-optional range (0xC000 - 0xFFFF) are assigned by 2043 Designated Expert [RFC5226]. The responsibility of the expert is to 2044 verify that the selected codepoint(s) are not in use, and that the 2045 request is not for an abnormally large number of codepoints. 2046 Technical review of the extension itself is outside the scope of the 2047 designated expert responsibility. 2049 17.3. STUN Error Code Registry 2051 A STUN error code is a number in the range 0 - 699. STUN error codes 2052 are accompanied by a textual reason phrase in UTF-8 [RFC3629] that is 2053 intended only for human consumption and can be anything appropriate; 2054 this document proposes only suggested values. 2056 STUN error codes are consistent in codepoint assignments and 2057 semantics with SIP [RFC3261] and HTTP [RFC2616]. 2059 The initial values in this registry are given in Section 14.7. 2061 New STUN error codes are assigned based on IETF Review [RFC5226]. 2062 The specification must carefully consider how clients that do not 2063 understand this error code will process it before granting the 2064 request. See the rules in Section 6.3.4. 2066 17.4. STUN UDP and TCP Port Numbers 2068 IANA has previously assigned port 3478 for STUN. This port appears 2069 in the IANA registry under the moniker "nat-stun-port". In order to 2070 align the DNS SRV procedures with the registered protocol service, 2071 IANA is requested to change the name of protocol assigned to port 2072 3478 from "nat-stun-port" to "stun", and the textual name from 2073 "Simple Traversal of UDP Through NAT (STUN)" to "Session Traversal 2074 Utilities for NAT", so that the IANA port registry would read: 2076 stun 3478/tcp Session Traversal Utilities for NAT (STUN) port 2077 stun 3478/udp Session Traversal Utilities for NAT (STUN) port 2079 In addition, IANA has assigned port number 5349 for the "stuns" 2080 service, defined over TCP and UDP. The UDP port is not currently 2081 defined; however, it is reserved for future use. 2083 18. Changes since RFC 5389 2085 This specification obsoletes RFC 5389 [RFC5389]. This specification 2086 differs from RFC 5389 in the following ways: 2088 o 2090 19. Contributors 2092 Christian Huitema and Joel Weinberger were original co-authors of RFC 2093 3489. 2095 20. Acknowledgements 2097 The authors of RFC 5389 would like to thank Cedric Aoun, Pete 2098 Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, Magnus 2099 Westerlund, Miguel Garcia, Bruce Lowekamp, and Chris Sullivan for 2100 their comments, and Baruch Sterman and Alan Hawrylyshen for initial 2101 implementations. Thanks for Leslie Daigle, Allison Mankin, Eric 2102 Rescorla, and Henning Schulzrinne for IESG and IAB input on this 2103 work. 2105 21. References 2107 21.1. Normative References 2109 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2110 Requirement Levels", BCP 14, RFC 2119, March 1997. 2112 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, September 2113 1981. 2115 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2116 specifying the location of services (DNS SRV)", RFC 2782, 2117 February 2000. 2119 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 2121 [RFC1122] Braden, R., "Requirements for Internet Hosts - 2122 Communication Layers", STD 3, RFC 1122, October 1989. 2124 [RFC2460] Deering, S. and R. Hinden, "Internet Protocol, Version 6 2125 (IPv6) Specification", RFC 2460, December 1998. 2127 [RFC2617] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., 2128 Leach, P., Luotonen, A., and L. Stewart, "HTTP 2129 Authentication: Basic and Digest Access Authentication", 2130 RFC 2617, June 1999. 2132 [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, 2133 "Computing TCP's Retransmission Timer", RFC 6298, June 2134 2011. 2136 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 2137 Hashing for Message Authentication", RFC 2104, February 2138 1997. 2140 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2141 10646", STD 63, RFC 3629, November 2003. 2143 [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, 2144 April 1992. 2146 [RFC4013] Zeilenga, K., "SASLprep: Stringprep Profile for User Names 2147 and Passwords", RFC 4013, February 2005. 2149 [ITU.V42.2002] 2150 International Telecommunications Union, "Error-correcting 2151 Procedures for DCEs Using Asynchronous-to-Synchronous 2152 Conversion", ITU-T Recommendation V.42, 2002. 2154 21.2. Informational References 2156 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 2157 A., Peterson, J., Sparks, R., Handley, M., and E. 2158 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 2159 June 2002. 2161 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 2162 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 2163 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 2165 [RFC4107] Bellovin, S. and R. Housley, "Guidelines for Cryptographic 2166 Key Management", BCP 107, RFC 4107, June 2005. 2168 [RFC5245] Rosenberg, J., "Interactive Connectivity Establishment 2169 (ICE): A Protocol for Network Address Translator (NAT) 2170 Traversal for Offer/Answer Protocols", RFC 5245, April 2171 2010. 2173 [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, 2174 "STUN - Simple Traversal of User Datagram Protocol (UDP) 2175 Through Network Address Translators (NATs)", RFC 3489, 2176 March 2003. 2178 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 2179 Relays around NAT (TURN): Relay Extensions to Session 2180 Traversal Utilities for NAT (STUN)", RFC 5766, April 2010. 2182 [RFC5626] Jennings, C., Mahy, R., and F. Audet, "Managing Client- 2183 Initiated Connections in the Session Initiation Protocol 2184 (SIP)", RFC 5626, October 2009. 2186 [RFC5780] MacDonald, D. and B. Lowekamp, "NAT Behavior Discovery 2187 Using Session Traversal Utilities for NAT (STUN)", RFC 2188 5780, May 2010. 2190 [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B., and A. Roach, 2191 "TCP Candidates with Interactive Connectivity 2192 Establishment (ICE)", RFC 6544, March 2012. 2194 [RFC3264] Rosenberg, J. and H. Schulzrinne, "An Offer/Answer Model 2195 with Session Description Protocol (SDP)", RFC 3264, June 2196 2002. 2198 [RFC3424] Daigle, L. and IAB, "IAB Considerations for UNilateral 2199 Self-Address Fixing (UNSAF) Across Network Address 2200 Translation", RFC 3424, November 2002. 2202 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 2203 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 2204 May 2008. 2206 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 2207 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 2208 October 2008. 2210 [KARN87] Karn, P. and C. Partridge, "Improving Round-Trip Time 2211 Estimates in Reliable Transport Protocols", SIGCOMM 1987, 2212 August 1987. 2214 Appendix A. C Snippet to Determine STUN Message Types 2216 Given a 16-bit STUN message type value in host byte order in msg_type 2217 parameter, below are C macros to determine the STUN message types: 2219 #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) 2220 #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) 2221 #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) 2222 #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) 2224 Appendix B. Release notes 2226 This section must be removed before publication as an RFC. 2228 B.1. Open Issues 2230 1. Clean the IANA section. 2232 2. Fix bug on retransmission RTO in section 7.2. 2234 3. Fix unclear text about RTO caching in section 7.2.1. 2236 4. Integrate RFC 5769 (stun vectors) as examples 2238 5. Integrate RFC 7350 (dtls) 2240 6. Integrate RFC 7064 (URI). 2242 7. STUN hash algorithm agility (currently only SHA-1 is allowed). 2244 8. Clarify terminology, text and guidance for STUN fragmentation. 2246 9. Clarify whether it's valid to share nonces across TURN 2247 allocations. 2249 10. Clarify nonce behavior for both invalid and expired nonces. 2250 Right now only expired nonces are described. Define a new 2251 "invalid nonce" error code (presumably 438) 2253 11. This question was raised: If a STUN (TURN) client receives a 2254 "300 Try Alternate" response to a STUN request sent over TLS, it 2255 should then connect to a different STUN server over TLS. What 2256 subjectAltName should it expect in the redirected-to server's 2257 certificate? 2259 12. Normatively reference the new ORIGIN RFC 2261 B.2. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 2262 salgueiro-tram-stunbis-01 2264 o Add definition of MESSAGE-INTEGRITY2. 2266 o Update text and reference from RFC 2988 to RFC 6298. 2268 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 2270 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 2272 o Fix section number and make clear that the original domain name is 2273 used for the server certificate verification. This is consistent 2274 with what RFC 5922 (section 4) is doing. (Errata #2010) 2276 o Remove text transitioning from RFC 3489. 2278 o Add definition of MESSAGE-INTEGRITY2. 2280 o Update text and reference from RFC 2988 to RFC 6298. 2282 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 2284 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 2286 o Fix section number and make clear that the original domain name is 2287 used for the server certificate verification. This is consistent 2288 with what RFC 5922 (section 4) is doing. (Errata #2010) 2290 B.3. Modifications between draft-salgueiro-tram-stunbis-01 and draft- 2291 salgueiro-tram-stunbis-00 2293 o Restore the RFC 5389 text. 2295 o Add list of open issues. 2297 Authors' Addresses 2299 Marc Petit-Huguenin 2300 Impedance Mismatch 2302 Email: marc@petit-huguenin.org 2304 Gonzalo Salgueiro 2305 Cisco 2306 7200-12 Kit Creek Road 2307 Research Triangle Park, NC 27709 2308 US 2310 Email: gsalguei@cisco.com 2312 Jonathan Rosenberg 2313 Cisco 2314 Edison, NJ 2315 US 2317 Email: jdrosen@cisco.com 2318 URI: http://www.jdrosen.net 2320 Dan Wing 2321 Cisco 2322 771 Alder Drive 2323 San Jose, CA 95035 2324 US 2326 Email: dwing@cisco.com 2328 Rohan Mahy 2329 Plantronics 2330 345 Encinal Street 2331 Santa Cruz, CA 95060 2332 US 2334 Email: rohan@ekabal.com 2335 Philip Matthews 2336 Avaya 2337 1135 Innovation Drive 2338 Ottawa, Ontario K2K 3G7 2339 Canada 2341 Phone: +1 613 592 4343 x224 2342 Email: philip_matthews@magma.ca