idnits 2.17.1 draft-ietf-tram-stunbis-10.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 (February 16, 2017) is 2597 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. 'ITU.V42.2002' ** Downref: Normative reference to an Informational RFC: RFC 1321 ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Obsolete normative reference: RFC 2460 (Obsoleted by RFC 8200) ** Obsolete normative reference: RFC 2617 (Obsoleted by RFC 7235, RFC 7615, RFC 7616, RFC 7617) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 6125 (Obsoleted by RFC 9525) ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) ** Obsolete normative reference: RFC 7613 (Obsoleted by RFC 8265) == Outdated reference: A later version (-20) exists of draft-ietf-ice-rfc5245bis-01 -- 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 3489 (Obsoleted by RFC 5389) -- Obsolete informational reference (is this intentional?): RFC 5226 (Obsoleted by RFC 8126) -- Obsolete informational reference (is this intentional?): RFC 5389 (Obsoleted by RFC 8489) -- Obsolete informational reference (is this intentional?): RFC 5766 (Obsoleted by RFC 8656) -- Obsolete informational reference (is this intentional?): RFC 7525 (Obsoleted by RFC 9325) Summary: 8 errors (**), 0 flaws (~~), 3 warnings (==), 8 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: August 20, 2017 D. Wing 7 Cisco 8 R. Mahy 9 Plantronics 10 P. Matthews 11 Avaya 12 February 16, 2017 14 Session Traversal Utilities for NAT (STUN) 15 draft-ietf-tram-stunbis-10 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 August 20, 2017. 49 Copyright Notice 51 Copyright (c) 2017 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 . . . . . . . . . . . . . . . . . . . . 5 68 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 8 69 4. Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 8 70 5. STUN Message Structure . . . . . . . . . . . . . . . . . . . 10 71 6. Base Protocol Procedures . . . . . . . . . . . . . . . . . . 12 72 6.1. Forming a Request or an Indication . . . . . . . . . . . 12 73 6.2. Sending the Request or Indication . . . . . . . . . . . . 13 74 6.2.1. Sending over UDP or DTLS-over-UDP . . . . . . . . . . 14 75 6.2.2. Sending over TCP or TLS-over-TCP . . . . . . . . . . 15 76 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP . . . . . 16 77 6.3. Receiving a STUN Message . . . . . . . . . . . . . . . . 17 78 6.3.1. Processing a Request . . . . . . . . . . . . . . . . 17 79 6.3.1.1. Forming a Success or Error Response . . . . . . . 18 80 6.3.1.2. Sending the Success or Error Response . . . . . . 19 81 6.3.2. Processing an Indication . . . . . . . . . . . . . . 19 82 6.3.3. Processing a Success Response . . . . . . . . . . . . 20 83 6.3.4. Processing an Error Response . . . . . . . . . . . . 20 84 7. FINGERPRINT Mechanism . . . . . . . . . . . . . . . . . . . . 21 85 8. DNS Discovery of a Server . . . . . . . . . . . . . . . . . . 21 86 8.1. STUN URI Scheme Semantics . . . . . . . . . . . . . . . . 22 87 9. Authentication and Message-Integrity Mechanisms . . . . . . . 23 88 9.1. Short-Term Credential Mechanism . . . . . . . . . . . . . 23 89 9.1.1. HMAC Key . . . . . . . . . . . . . . . . . . . . . . 23 90 9.1.2. Forming a Request or Indication . . . . . . . . . . . 24 91 9.1.3. Receiving a Request or Indication . . . . . . . . . . 24 92 9.1.4. Receiving a Response . . . . . . . . . . . . . . . . 25 93 9.1.5. Sending Subsequent Requests . . . . . . . . . . . . . 26 94 9.2. Long-Term Credential Mechanism . . . . . . . . . . . . . 26 95 9.2.1. Bid Down Attack Prevention . . . . . . . . . . . . . 27 96 9.2.2. HMAC Key . . . . . . . . . . . . . . . . . . . . . . 27 97 9.2.3. Forming a Request . . . . . . . . . . . . . . . . . . 28 98 9.2.3.1. First Request . . . . . . . . . . . . . . . . . . 28 99 9.2.3.2. Subsequent Requests . . . . . . . . . . . . . . . 29 100 9.2.4. Receiving a Request . . . . . . . . . . . . . . . . . 29 101 9.2.5. Receiving a Response . . . . . . . . . . . . . . . . 31 102 10. ALTERNATE-SERVER Mechanism . . . . . . . . . . . . . . . . . 33 103 11. Backwards Compatibility with RFC 3489 . . . . . . . . . . . . 34 104 12. Basic Server Behavior . . . . . . . . . . . . . . . . . . . . 34 105 13. STUN Usages . . . . . . . . . . . . . . . . . . . . . . . . . 35 106 14. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . . 36 107 14.1. MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . . . 37 108 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . 37 109 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . . . . 38 110 14.4. USERHASH . . . . . . . . . . . . . . . . . . . . . . . . 39 111 14.5. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . . . . 39 112 14.6. MESSAGE-INTEGRITY-SHA256 . . . . . . . . . . . . . . . . 40 113 14.7. FINGERPRINT . . . . . . . . . . . . . . . . . . . . . . 41 114 14.8. ERROR-CODE . . . . . . . . . . . . . . . . . . . . . . . 41 115 14.9. REALM . . . . . . . . . . . . . . . . . . . . . . . . . 43 116 14.10. NONCE . . . . . . . . . . . . . . . . . . . . . . . . . 43 117 14.11. PASSWORD-ALGORITHMS . . . . . . . . . . . . . . . . . . 43 118 14.12. PASSWORD-ALGORITHM . . . . . . . . . . . . . . . . . . . 44 119 14.13. UNKNOWN-ATTRIBUTES . . . . . . . . . . . . . . . . . . . 45 120 14.14. SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . 45 121 14.15. ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . 45 122 14.16. ALTERNATE-DOMAIN . . . . . . . . . . . . . . . . . . . . 45 123 15. Security Considerations . . . . . . . . . . . . . . . . . . . 46 124 15.1. Attacks against the Protocol . . . . . . . . . . . . . . 46 125 15.1.1. Outside Attacks . . . . . . . . . . . . . . . . . . 46 126 15.1.2. Inside Attacks . . . . . . . . . . . . . . . . . . . 47 127 15.2. Attacks Affecting the Usage . . . . . . . . . . . . . . 47 128 15.2.1. Attack I: Distributed DoS (DDoS) against a Target . 48 129 15.2.2. Attack II: Silencing a Client . . . . . . . . . . . 48 130 15.2.3. Attack III: Assuming the Identity of a Client . . . 48 131 15.2.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . 48 132 15.3. Hash Agility Plan . . . . . . . . . . . . . . . . . . . 49 133 16. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 49 134 17. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 49 135 17.1. STUN Security Features Registry . . . . . . . . . . . . 50 136 17.2. STUN Methods Registry . . . . . . . . . . . . . . . . . 50 137 17.3. STUN Attribute Registry . . . . . . . . . . . . . . . . 50 138 17.3.1. Updated Attributes . . . . . . . . . . . . . . . . . 50 139 17.3.2. New Attributes . . . . . . . . . . . . . . . . . . . 51 140 17.4. STUN Error Code Registry . . . . . . . . . . . . . . . . 51 141 17.5. Password Algorithm Registry . . . . . . . . . . . . . . 51 142 17.5.1. Password Algorithms . . . . . . . . . . . . . . . . 52 143 17.5.1.1. MD5 . . . . . . . . . . . . . . . . . . . . . . 52 144 17.5.1.2. SHA256 . . . . . . . . . . . . . . . . . . . . . 52 146 17.6. STUN UDP and TCP Port Numbers . . . . . . . . . . . . . 52 147 18. Changes since RFC 5389 . . . . . . . . . . . . . . . . . . . 52 148 19. References . . . . . . . . . . . . . . . . . . . . . . . . . 53 149 19.1. Normative References . . . . . . . . . . . . . . . . . . 53 150 19.2. Informative References . . . . . . . . . . . . . . . . . 55 151 Appendix A. C Snippet to Determine STUN Message Types . . . . . 57 152 Appendix B. Test Vectors . . . . . . . . . . . . . . . . . . . . 58 153 B.1. Sample Request with Long-Term Authentication with 154 MESSAGE-INTEGRITY-SHA256 and USERHASH . . . . . . . . . . 58 155 Appendix C. Release notes . . . . . . . . . . . . . . . . . . . 60 156 C.1. Modifications between draft-ietf-tram-stunbis-09 and 157 draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 60 158 C.2. Modifications between draft-ietf-tram-stunbis-09 and 159 draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 60 160 C.3. Modifications between draft-ietf-tram-stunbis-08 and 161 draft-ietf-tram-stunbis-07 . . . . . . . . . . . . . . . 61 162 C.4. Modifications between draft-ietf-tram-stunbis-07 and 163 draft-ietf-tram-stunbis-06 . . . . . . . . . . . . . . . 61 164 C.5. Modifications between draft-ietf-tram-stunbis-06 and 165 draft-ietf-tram-stunbis-05 . . . . . . . . . . . . . . . 61 166 C.6. Modifications between draft-ietf-tram-stunbis-05 and 167 draft-ietf-tram-stunbis-04 . . . . . . . . . . . . . . . 62 168 C.7. Modifications between draft-ietf-tram-stunbis-04 and 169 draft-ietf-tram-stunbis-03 . . . . . . . . . . . . . . . 62 170 C.8. Modifications between draft-ietf-tram-stunbis-03 and 171 draft-ietf-tram-stunbis-02 . . . . . . . . . . . . . . . 62 172 C.9. Modifications between draft-ietf-tram-stunbis-02 and 173 draft-ietf-tram-stunbis-01 . . . . . . . . . . . . . . . 62 174 C.10. Modifications between draft-ietf-tram-stunbis-01 and 175 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 63 176 C.11. Modifications between draft-salgueiro-tram-stunbis-02 and 177 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 64 178 C.12. Modifications between draft-salgueiro-tram-stunbis-02 and 179 draft-salgueiro-tram-stunbis-01 . . . . . . . . . . . . . 64 180 C.13. Modifications between draft-salgueiro-tram-stunbis-01 and 181 draft-salgueiro-tram-stunbis-00 . . . . . . . . . . . . . 64 182 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 64 183 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 65 184 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 65 186 1. Introduction 188 The protocol defined in this specification, Session Traversal 189 Utilities for NAT, provides a tool for dealing with NATs. It 190 provides a means for an endpoint to determine the IP address and port 191 allocated by a NAT that corresponds to its private IP address and 192 port. It also provides a way for an endpoint to keep a NAT binding 193 alive. With some extensions, the protocol can be used to do 194 connectivity checks between two endpoints [I-D.ietf-ice-rfc5245bis], 195 or to relay packets between two endpoints [RFC5766]. 197 In keeping with its tool nature, this specification defines an 198 extensible packet format, defines operation over several transport 199 protocols, and provides for two forms of authentication. 201 STUN is intended to be used in context of one or more NAT traversal 202 solutions. These solutions are known as STUN usages. Each usage 203 describes how STUN is utilized to achieve the NAT traversal solution. 204 Typically, a usage indicates when STUN messages get sent, which 205 optional attributes to include, what server is used, and what 206 authentication mechanism is to be used. Interactive Connectivity 207 Establishment (ICE) [I-D.ietf-ice-rfc5245bis] is one usage of STUN. 208 SIP Outbound [RFC5626] is another usage of STUN. In some cases, a 209 usage will require extensions to STUN. A STUN extension can be in 210 the form of new methods, attributes, or error response codes. More 211 information on STUN usages can be found in Section 13. 213 Implementations and deployments of a STUN usage using TLS or DTLS 214 should follow the recommendations in [RFC7525]. 216 2. Overview of Operation 218 This section is descriptive only. 220 /-----\ 221 // STUN \\ 222 | Server | 223 \\ // 224 \-----/ 226 +--------------+ Public Internet 227 ................| NAT 2 |....................... 228 +--------------+ 230 +--------------+ Private NET 2 231 ................| NAT 1 |....................... 232 +--------------+ 234 /-----\ 235 // STUN \\ 236 | Client | 237 \\ // Private NET 1 238 \-----/ 240 Figure 1: One Possible STUN Configuration 242 One possible STUN configuration is shown in Figure 1. In this 243 configuration, there are two entities (called STUN agents) that 244 implement the STUN protocol. The lower agent in the figure is the 245 client, and is connected to private network 1. This network connects 246 to private network 2 through NAT 1. Private network 2 connects to 247 the public Internet through NAT 2. The upper agent in the figure is 248 the server, and resides on the public Internet. 250 STUN is a client-server protocol. It supports two types of 251 transactions. One is a request/response transaction in which a 252 client sends a request to a server, and the server returns a 253 response. The second is an indication transaction in which either 254 agent -- client or server -- sends an indication that generates no 255 response. Both types of transactions include a transaction ID, which 256 is a randomly selected 96-bit number. For request/response 257 transactions, this transaction ID allows the client to associate the 258 response with the request that generated it; for indications, the 259 transaction ID serves as a debugging aid. 261 All STUN messages start with a fixed header that includes a method, a 262 class, and the transaction ID. The method indicates which of the 263 various requests or indications this is; this specification defines 264 just one method, Binding, but other methods are expected to be 265 defined in other documents. The class indicates whether this is a 266 request, a success response, an error response, or an indication. 267 Following the fixed header comes zero or more attributes, which are 268 Type-Length-Value extensions that convey additional information for 269 the specific message. 271 This document defines a single method called Binding. The Binding 272 method can be used either in request/response transactions or in 273 indication transactions. When used in request/response transactions, 274 the Binding method can be used to determine the particular "binding" 275 a NAT has allocated to a STUN client. When used in either request/ 276 response or in indication transactions, the Binding method can also 277 be used to keep these "bindings" alive. 279 In the Binding request/response transaction, a Binding request is 280 sent from a STUN client to a STUN server. When the Binding request 281 arrives at the STUN server, it may have passed through one or more 282 NATs between the STUN client and the STUN server (in Figure 1, there 283 were two such NATs). As the Binding request message passes through a 284 NAT, the NAT will modify the source transport address (that is, the 285 source IP address and the source port) of the packet. As a result, 286 the source transport address of the request received by the server 287 will be the public IP address and port created by the NAT closest to 288 the server. This is called a reflexive transport address. The STUN 289 server copies that source transport address into an XOR-MAPPED- 290 ADDRESS attribute in the STUN Binding response and sends the Binding 291 response back to the STUN client. As this packet passes back through 292 a NAT, the NAT will modify the destination transport address in the 293 IP header, but the transport address in the XOR-MAPPED-ADDRESS 294 attribute within the body of the STUN response will remain untouched. 295 In this way, the client can learn its reflexive transport address 296 allocated by the outermost NAT with respect to the STUN server. 298 In some usages, STUN must be multiplexed with other protocols (e.g., 299 [I-D.ietf-ice-rfc5245bis], [RFC5626]). In these usages, there must 300 be a way to inspect a packet and determine if it is a STUN packet or 301 not. STUN provides three fields in the STUN header with fixed values 302 that can be used for this purpose. If this is not sufficient, then 303 STUN packets can also contain a FINGERPRINT value, which can further 304 be used to distinguish the packets. 306 STUN defines a set of optional procedures that a usage can decide to 307 use, called mechanisms. These mechanisms include DNS discovery, a 308 redirection technique to an alternate server, a fingerprint attribute 309 for demultiplexing, and two authentication and message-integrity 310 exchanges. The authentication mechanisms revolve around the use of a 311 username, password, and message-integrity value. Two authentication 312 mechanisms, the long-term credential mechanism and the short-term 313 credential mechanism, are defined in this specification. Each usage 314 specifies the mechanisms allowed with that usage. 316 In the long-term credential mechanism, the client and server share a 317 pre-provisioned username and password and perform a digest challenge/ 318 response exchange inspired by (but differing in details) to the one 319 defined for HTTP [RFC2617]. In the short-term credential mechanism, 320 the client and the server exchange a username and password through 321 some out-of-band method prior to the STUN exchange. For example, in 322 the ICE usage [I-D.ietf-ice-rfc5245bis] the two endpoints use out-of- 323 band signaling to exchange a username and password. These are used 324 to integrity protect and authenticate the request and response. 325 There is no challenge or nonce used. 327 3. Terminology 329 In this document, the key words "MUST", "MUST NOT", "REQUIRED", 330 "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", 331 and "OPTIONAL" are to be interpreted as described in [RFC2119] and 332 indicate requirement levels for compliant STUN implementations. 334 4. Definitions 336 STUN Agent: A STUN agent is an entity that implements the STUN 337 protocol. The entity can be either a STUN client or a STUN 338 server. 340 STUN Client: A STUN client is an entity that sends STUN requests and 341 receives STUN responses. A STUN client can also send indications. 342 In this specification, the terms STUN client and client are 343 synonymous. 345 STUN Server: A STUN server is an entity that receives STUN requests 346 and sends STUN responses. A STUN server can also send 347 indications. In this specification, the terms STUN server and 348 server are synonymous. 350 Transport Address: The combination of an IP address and port number 351 (such as a UDP or TCP port number). 353 Reflexive Transport Address: A transport address learned by a client 354 that identifies that client as seen by another host on an IP 355 network, typically a STUN server. When there is an intervening 356 NAT between the client and the other host, the reflexive transport 357 address represents the mapped address allocated to the client on 358 the public side of the NAT. Reflexive transport addresses are 359 learned from the mapped address attribute (MAPPED-ADDRESS or XOR- 360 MAPPED-ADDRESS) in STUN responses. 362 Mapped Address: Same meaning as reflexive address. This term is 363 retained only for historic reasons and due to the naming of the 364 MAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. 366 Long-Term Credential: A username and associated password that 367 represent a shared secret between client and server. Long-term 368 credentials are generally granted to the client when a subscriber 369 enrolls in a service and persist until the subscriber leaves the 370 service or explicitly changes the credential. 372 Long-Term Password: The password from a long-term credential. 374 Short-Term Credential: A temporary username and associated password 375 that represent a shared secret between client and server. Short- 376 term credentials are obtained through some kind of protocol 377 mechanism between the client and server, preceding the STUN 378 exchange. A short-term credential has an explicit temporal scope, 379 which may be based on a specific amount of time (such as 5 380 minutes) or on an event (such as termination of a SIP dialog). 381 The specific scope of a short-term credential is defined by the 382 application usage. 384 Short-Term Password: The password component of a short-term 385 credential. 387 STUN Indication: A STUN message that does not receive a response. 389 Attribute: The STUN term for a Type-Length-Value (TLV) object that 390 can be added to a STUN message. Attributes are divided into two 391 types: comprehension-required and comprehension-optional. STUN 392 agents can safely ignore comprehension-optional attributes they 393 don't understand, but cannot successfully process a message if it 394 contains comprehension-required attributes that are not 395 understood. 397 RTO: Retransmission TimeOut, which defines the initial period of 398 time between transmission of a request and the first retransmit of 399 that request. 401 5. STUN Message Structure 403 STUN messages are encoded in binary using network-oriented format 404 (most significant byte or octet first, also commonly known as big- 405 endian). The transmission order is described in detail in Appendix B 406 of [RFC0791]. Unless otherwise noted, numeric constants are in 407 decimal (base 10). 409 All STUN messages MUST start with a 20-byte header followed by zero 410 or more Attributes. The STUN header contains a STUN message type, 411 magic cookie, transaction ID, and message length. 413 0 1 2 3 414 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 415 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 416 |0 0| STUN Message Type | Message Length | 417 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 418 | Magic Cookie | 419 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 420 | | 421 | Transaction ID (96 bits) | 422 | | 423 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 425 Figure 2: Format of STUN Message Header 427 The most significant 2 bits of every STUN message MUST be zeroes. 428 This can be used to differentiate STUN packets from other protocols 429 when STUN is multiplexed with other protocols on the same port. 431 The message type defines the message class (request, success 432 response, failure response, or indication) and the message method 433 (the primary function) of the STUN message. Although there are four 434 message classes, there are only two types of transactions in STUN: 435 request/response transactions (which consist of a request message and 436 a response message) and indication transactions (which consist of a 437 single indication message). Response classes are split into error 438 and success responses to aid in quickly processing the STUN message. 440 The message type field is decomposed further into the following 441 structure: 443 0 1 444 2 3 4 5 6 7 8 9 0 1 2 3 4 5 445 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 446 |M |M |M|M|M|C|M|M|M|C|M|M|M|M| 447 |11|10|9|8|7|1|6|5|4|0|3|2|1|0| 448 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 450 Figure 3: Format of STUN Message Type Field 452 Here the bits in the message type field are shown as most significant 453 (M11) through least significant (M0). M11 through M0 represent a 454 12-bit encoding of the method. C1 and C0 represent a 2-bit encoding 455 of the class. A class of 0b00 is a request, a class of 0b01 is an 456 indication, a class of 0b10 is a success response, and a class of 457 0b11 is an error response. This specification defines a single 458 method, Binding. The method and class are orthogonal, so that for 459 each method, a request, success response, error response, and 460 indication are possible for that method. Extensions defining new 461 methods MUST indicate which classes are permitted for that method. 463 For example, a Binding request has class=0b00 (request) and 464 method=0b000000000001 (Binding) and is encoded into the first 16 bits 465 as 0x0001. A Binding response has class=0b10 (success response) and 466 method=0b000000000001, and is encoded into the first 16 bits as 467 0x0101. 469 Note: This unfortunate encoding is due to assignment of values in 470 [RFC3489] that did not consider encoding Indications, Success, and 471 Errors using bit fields. 473 The magic cookie field MUST contain the fixed value 0x2112A442 in 474 network byte order. In [RFC3489], this field was part of the 475 transaction ID; placing the magic cookie in this location allows a 476 server to detect if the client will understand certain attributes 477 that were added in this revised specification. In addition, it aids 478 in distinguishing STUN packets from packets of other protocols when 479 STUN is multiplexed with those other protocols on the same port. 481 The transaction ID is a 96-bit identifier, used to uniquely identify 482 STUN transactions. For request/response transactions, the 483 transaction ID is chosen by the STUN client for the request and 484 echoed by the server in the response. For indications, it is chosen 485 by the agent sending the indication. It primarily serves to 486 correlate requests with responses, though it also plays a small role 487 in helping to prevent certain types of attacks. The server also uses 488 the transaction ID as a key to identify each transaction uniquely 489 across all clients. As such, the transaction ID MUST be uniformly 490 and randomly chosen from the interval 0 .. 2**96-1, and SHOULD be 491 cryptographically random. Resends of the same request reuse the same 492 transaction ID, but the client MUST choose a new transaction ID for 493 new transactions unless the new request is bit-wise identical to the 494 previous request and sent from the same transport address to the same 495 IP address. Success and error responses MUST carry the same 496 transaction ID as their corresponding request. When an agent is 497 acting as a STUN server and STUN client on the same port, the 498 transaction IDs in requests sent by the agent have no relationship to 499 the transaction IDs in requests received by the agent. 501 The message length MUST contain the size, in bytes, of the message 502 not including the 20-byte STUN header. Since all STUN attributes are 503 padded to a multiple of 4 bytes, the last 2 bits of this field are 504 always zero. This provides another way to distinguish STUN packets 505 from packets of other protocols. 507 Following the STUN fixed portion of the header are zero or more 508 attributes. Each attribute is TLV (Type-Length-Value) encoded. The 509 details of the encoding, and of the attributes themselves are given 510 in Section 14. 512 6. Base Protocol Procedures 514 This section defines the base procedures of the STUN protocol. It 515 describes how messages are formed, how they are sent, and how they 516 are processed when they are received. It also defines the detailed 517 processing of the Binding method. Other sections in this document 518 describe optional procedures that a usage may elect to use in certain 519 situations. Other documents may define other extensions to STUN, by 520 adding new methods, new attributes, or new error response codes. 522 6.1. Forming a Request or an Indication 524 When formulating a request or indication message, the agent MUST 525 follow the rules in Section 5 when creating the header. In addition, 526 the message class MUST be either "Request" or "Indication" (as 527 appropriate), and the method must be either Binding or some method 528 defined in another document. 530 The agent then adds any attributes specified by the method or the 531 usage. For example, some usages may specify that the agent use an 532 authentication method (Section 9) or the FINGERPRINT attribute 533 (Section 7). 535 If the agent is sending a request, it SHOULD add a SOFTWARE attribute 536 to the request. Agents MAY include a SOFTWARE attribute in 537 indications, depending on the method. Extensions to STUN should 538 discuss whether SOFTWARE is useful in new indications. 540 For the Binding method with no authentication, no attributes are 541 required unless the usage specifies otherwise. 543 All STUN messages sent over UDP or DTLS-over-UDP [RFC6347] SHOULD be 544 less than the path MTU, if known. 546 If the path MTU is unknown for UDP, messages SHOULD be the smaller of 547 576 bytes and the first-hop MTU for IPv4 [RFC1122] and 1280 bytes for 548 IPv6 [RFC2460]. This value corresponds to the overall size of the IP 549 packet. Consequently, for IPv4, the actual STUN message would need 550 to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte 551 UDP header, assuming no IP options are used). 553 If the path MTU is unknown for DTLS-over-UDP, the rules described in 554 the previous paragraph need to be adjusted to take into account the 555 size of the (13-byte) DTLS Record header, the MAC size, and the 556 padding size. 558 STUN provides no ability to handle the case where the request is 559 under the MTU but the response would be larger than the MTU. It is 560 not envisioned that this limitation will be an issue for STUN. The 561 MTU limitation is a SHOULD, and not a MUST, to account for cases 562 where STUN itself is being used to probe for MTU characteristics 563 [RFC5780]. Outside of this or similar applications, the MTU 564 constraint MUST be followed. 566 6.2. Sending the Request or Indication 568 The agent then sends the request or indication. This document 569 specifies how to send STUN messages over UDP, TCP, TLS-over-TCP, or 570 DTLS-over-UDP; other transport protocols may be added in the future. 571 The STUN usage must specify which transport protocol is used, and how 572 the agent determines the IP address and port of the recipient. 573 Section 8 describes a DNS-based method of determining the IP address 574 and port of a server that a usage may elect to use. STUN may be used 575 with anycast addresses, but only with UDP and in usages where 576 authentication is not used. 578 At any time, a client MAY have multiple outstanding STUN requests 579 with the same STUN server (that is, multiple transactions in 580 progress, with different transaction IDs). Absent other limits to 581 the rate of new transactions (such as those specified by ICE for 582 connectivity checks or when STUN is run over TCP), a client SHOULD 583 limit itself to ten outstanding transactions to the same server. 585 6.2.1. Sending over UDP or DTLS-over-UDP 587 When running STUN over UDP or STUN over DTLS-over-UDP [RFC7350], it 588 is possible that the STUN message might be dropped by the network. 589 Reliability of STUN request/response transactions is accomplished 590 through retransmissions of the request message by the client 591 application itself. STUN indications are not retransmitted; thus, 592 indication transactions over UDP or DTLS-over-UDP are not reliable. 594 A client SHOULD retransmit a STUN request message starting with an 595 interval of RTO ("Retransmission TimeOut"), doubling after each 596 retransmission. The RTO is an estimate of the round-trip time (RTT), 597 and is computed as described in [RFC6298], with two exceptions. 598 First, the initial value for RTO SHOULD be greater than 500 ms. The 599 exception cases for this "SHOULD" are when other mechanisms are used 600 to derive congestion thresholds (such as the ones defined in ICE for 601 fixed rate streams), or when STUN is used in non-Internet 602 environments with known network capacities. In fixed-line access 603 links, a value of 500 ms is RECOMMENDED. Second, the value of RTO 604 SHOULD NOT be rounded up to the nearest second. Rather, a 1 ms 605 accuracy SHOULD be maintained. As with TCP, the usage of Karn's 606 algorithm is RECOMMENDED [KARN87]. When applied to STUN, it means 607 that RTT estimates SHOULD NOT be computed from STUN transactions that 608 result in the retransmission of a request. 610 The value for RTO SHOULD be cached by a client after the completion 611 of the transaction, and used as the starting value for RTO for the 612 next transaction to the same server (based on equality of IP 613 address). The value SHOULD be considered stale and discarded after 614 10 minutes without any transactions to the same server. 616 Retransmissions continue until a response is received, or until a 617 total of Rc requests have been sent. Rc SHOULD be configurable and 618 SHOULD have a default of 7. If, after the last request, a duration 619 equal to Rm times the RTO has passed without a response (providing 620 ample time to get a response if only this final request actually 621 succeeds), the client SHOULD consider the transaction to have failed. 622 Rm SHOULD be configurable and SHOULD have a default of 16. A STUN 623 transaction over UDP or DTLS-over-UDP is also considered failed if 624 there has been a hard ICMP error [RFC1122]. For example, assuming an 625 RTO of 500ms, requests would be sent at times 0 ms, 500 ms, 1500 ms, 626 3500 ms, 7500 ms, 15500 ms, and 31500 ms. If the client has not 627 received a response after 39500 ms, the client will consider the 628 transaction to have timed out. 630 6.2.2. Sending over TCP or TLS-over-TCP 632 For TCP and TLS-over-TCP [RFC5246], the client opens a TCP connection 633 to the server. 635 In some usages of STUN, STUN is sent as the only protocol over the 636 TCP connection. In this case, it can be sent without the aid of any 637 additional framing or demultiplexing. In other usages, or with other 638 extensions, it may be multiplexed with other data over a TCP 639 connection. In that case, STUN MUST be run on top of some kind of 640 framing protocol, specified by the usage or extension, which allows 641 for the agent to extract complete STUN messages and complete 642 application layer messages. The STUN service running on the well- 643 known port or ports discovered through the DNS procedures in 644 Section 8 is for STUN alone, and not for STUN multiplexed with other 645 data. Consequently, no framing protocols are used in connections to 646 those servers. When additional framing is utilized, the usage will 647 specify how the client knows to apply it and what port to connect to. 648 For example, in the case of ICE connectivity checks, this information 649 is learned through out-of-band negotiation between client and server. 651 Reliability of STUN over TCP and TLS-over-TCP is handled by TCP 652 itself, and there are no retransmissions at the STUN protocol level. 653 However, for a request/response transaction, if the client has not 654 received a response by Ti seconds after it sent the SYN to establish 655 the connection, it considers the transaction to have timed out. Ti 656 SHOULD be configurable and SHOULD have a default of 39.5s. This 657 value has been chosen to equalize the TCP and UDP timeouts for the 658 default initial RTO. 660 In addition, if the client is unable to establish the TCP connection, 661 or the TCP connection is reset or fails before a response is 662 received, any request/response transaction in progress is considered 663 to have failed. 665 The client MAY send multiple transactions over a single TCP (or TLS- 666 over-TCP) connection, and it MAY send another request before 667 receiving a response to the previous. The client SHOULD keep the 668 connection open until it: 670 o has no further STUN requests or indications to send over that 671 connection, and 673 o has no plans to use any resources (such as a mapped address 674 (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address 675 [RFC5766]) that were learned though STUN requests sent over that 676 connection, and 678 o if multiplexing other application protocols over that port, has 679 finished using that other application, and 681 o if using that learned port with a remote peer, has established 682 communications with that remote peer, as is required by some TCP 683 NAT traversal techniques (e.g., [RFC6544]). 685 At the server end, the server SHOULD keep the connection open, and 686 let the client close it, unless the server has determined that the 687 connection has timed out (for example, due to the client 688 disconnecting from the network). Bindings learned by the client will 689 remain valid in intervening NATs only while the connection remains 690 open. Only the client knows how long it needs the binding. The 691 server SHOULD NOT close a connection if a request was received over 692 that connection for which a response was not sent. A server MUST NOT 693 ever open a connection back towards the client in order to send a 694 response. Servers SHOULD follow best practices regarding connection 695 management in cases of overload. 697 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP 699 When STUN is run by itself over TLS-over-TCP or DTLS-over-UDP, the 700 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 and 701 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suites MUST be 702 implemented and other cipher suites MAY be implemented. Perfect 703 Forward Secrecy (PFS) cipher suites MUST be preferred over non-PFS 704 cipher suites. Cipher suites with known weaknesses, such as those 705 based on (single) DES and RC4, MUST NOT be used. Implementations 706 MUST disable TLS-level compression. 708 When it receives the TLS Certificate message, the client SHOULD 709 verify the certificate and inspect the site identified by the 710 certificate. If the certificate is invalid or revoked, or if it does 711 not identify the appropriate party, the client MUST NOT send the STUN 712 message or otherwise proceed with the STUN transaction. The client 713 MUST verify the identity of the server. To do that, it follows the 714 identification procedures defined in [RFC6125]. Alternatively, a 715 client MAY be configured with a set of domains or IP addresses that 716 are trusted; if a certificate is received that identifies one of 717 those domains or IP addresses, the client considers the identity of 718 the server to be verified. 720 When STUN is run multiplexed with other protocols over a TLS-over-TCP 721 connection or a DTLS-over-UDP association, the mandatory ciphersuites 722 and TLS handling procedures operate as defined by those protocols. 724 6.3. Receiving a STUN Message 726 This section specifies the processing of a STUN message. The 727 processing specified here is for STUN messages as defined in this 728 specification; additional rules for backwards compatibility are 729 defined in Section 11. Those additional procedures are optional, and 730 usages can elect to utilize them. First, a set of processing 731 operations is applied that is independent of the class. This is 732 followed by class-specific processing, described in the subsections 733 that follow. 735 When a STUN agent receives a STUN message, it first checks that the 736 message obeys the rules of Section 5. It checks that the first two 737 bits are 0, that the magic cookie field has the correct value, that 738 the message length is sensible, and that the method value is a 739 supported method. It checks that the message class is allowed for 740 the particular method. If the message class is "Success Response" or 741 "Error Response", the agent checks that the transaction ID matches a 742 transaction that is still in progress. If the FINGERPRINT extension 743 is being used, the agent checks that the FINGERPRINT attribute is 744 present and contains the correct value. If any errors are detected, 745 the message is silently discarded. In the case when STUN is being 746 multiplexed with another protocol, an error may indicate that this is 747 not really a STUN message; in this case, the agent should try to 748 parse the message as a different protocol. 750 The STUN agent then does any checks that are required by a 751 authentication mechanism that the usage has specified (see 752 Section 9). 754 Once the authentication checks are done, the STUN agent checks for 755 unknown attributes and known-but-unexpected attributes in the 756 message. Unknown comprehension-optional attributes MUST be ignored 757 by the agent. Known-but-unexpected attributes SHOULD be ignored by 758 the agent. Unknown comprehension-required attributes cause 759 processing that depends on the message class and is described below. 761 At this point, further processing depends on the message class of the 762 request. 764 6.3.1. Processing a Request 766 If the request contains one or more unknown comprehension-required 767 attributes, the server replies with an error response with an error 768 code of 420 (Unknown Attribute), and includes an UNKNOWN-ATTRIBUTES 769 attribute in the response that lists the unknown comprehension- 770 required attributes. 772 The server then does any additional checking that the method or the 773 specific usage requires. If all the checks succeed, the server 774 formulates a success response as described below. 776 When run over UDP or DTLS-over-UDP, a request received by the server 777 could be the first request of a transaction, or a retransmission. 778 The server MUST respond to retransmissions such that the following 779 property is preserved: if the client receives the response to the 780 retransmission and not the response that was sent to the original 781 request, the overall state on the client and server is identical to 782 the case where only the response to the original retransmission is 783 received, or where both responses are received (in which case the 784 client will use the first). The easiest way to meet this requirement 785 is for the server to remember all transaction IDs received over UDP 786 or DTLS-over-UDP and their corresponding responses in the last 40 787 seconds. However, this requires the server to hold state, and will 788 be inappropriate for any requests which are not authenticated. 789 Another way is to reprocess the request and recompute the response. 790 The latter technique MUST only be applied to requests that are 791 idempotent (a request is considered idempotent when the same request 792 can be safely repeated without impacting the overall state of the 793 system) and result in the same success response for the same request. 794 The Binding method is considered to be idempotent. Note that there 795 are certain rare network events that could cause the reflexive 796 transport address value to change, resulting in a different mapped 797 address in different success responses. Extensions to STUN MUST 798 discuss the implications of request retransmissions on servers that 799 do not store transaction state. 801 6.3.1.1. Forming a Success or Error Response 803 When forming the response (success or error), the server follows the 804 rules of Section 6. The method of the response is the same as that 805 of the request, and the message class is either "Success Response" or 806 "Error Response". 808 For an error response, the server MUST add an ERROR-CODE attribute 809 containing the error code specified in the processing above. The 810 reason phrase is not fixed, but SHOULD be something suitable for the 811 error code. For certain errors, additional attributes are added to 812 the message. These attributes are spelled out in the description 813 where the error code is specified. For example, for an error code of 814 420 (Unknown Attribute), the server MUST include an UNKNOWN- 815 ATTRIBUTES attribute. Certain authentication errors also cause 816 attributes to be added (see Section 9). Extensions may define other 817 errors and/or additional attributes to add in error cases. 819 If the server authenticated the request using an authentication 820 mechanism, then the server SHOULD add the appropriate authentication 821 attributes to the response (see Section 9). 823 The server also adds any attributes required by the specific method 824 or usage. In addition, the server SHOULD add a SOFTWARE attribute to 825 the message. 827 For the Binding method, no additional checking is required unless the 828 usage specifies otherwise. When forming the success response, the 829 server adds a XOR-MAPPED-ADDRESS attribute to the response, where the 830 contents of the attribute are the source transport address of the 831 request message. For UDP or DTLS-over-UDP this is the source IP 832 address and source UDP port of the request message. For TCP and TLS- 833 over-TCP, this is the source IP address and source TCP port of the 834 TCP connection as seen by the server. 836 6.3.1.2. Sending the Success or Error Response 838 The response (success or error) is sent over the same transport as 839 the request was received on. If the request was received over UDP or 840 DTLS-over-UDP the destination IP address and port of the response are 841 the source IP address and port of the received request message, and 842 the source IP address and port of the response are equal to the 843 destination IP address and port of the received request message. If 844 the request was received over TCP or TLS-over-TCP, the response is 845 sent back on the same TCP connection as the request was received on. 847 6.3.2. Processing an Indication 849 If the indication contains unknown comprehension-required attributes, 850 the indication is discarded and processing ceases. 852 The agent then does any additional checking that the method or the 853 specific usage requires. If all the checks succeed, the agent then 854 processes the indication. No response is generated for an 855 indication. 857 For the Binding method, no additional checking or processing is 858 required, unless the usage specifies otherwise. The mere receipt of 859 the message by the agent has refreshed the "bindings" in the 860 intervening NATs. 862 Since indications are not re-transmitted over UDP or DTLS-over-UDP 863 (unlike requests), there is no need to handle re-transmissions of 864 indications at the sending agent. 866 6.3.3. Processing a Success Response 868 If the success response contains unknown comprehension-required 869 attributes, the response is discarded and the transaction is 870 considered to have failed. 872 The client then does any additional checking that the method or the 873 specific usage requires. If all the checks succeed, the client then 874 processes the success response. 876 For the Binding method, the client checks that the XOR-MAPPED-ADDRESS 877 attribute is present in the response. The client checks the address 878 family specified. If it is an unsupported address family, the 879 attribute SHOULD be ignored. If it is an unexpected but supported 880 address family (for example, the Binding transaction was sent over 881 IPv4, but the address family specified is IPv6), then the client MAY 882 accept and use the value. 884 6.3.4. Processing an Error Response 886 If the error response contains unknown comprehension-required 887 attributes, or if the error response does not contain an ERROR-CODE 888 attribute, then the transaction is simply considered to have failed. 890 The client then does any processing specified by the authentication 891 mechanism (see Section 9). This may result in a new transaction 892 attempt. 894 The processing at this point depends on the error code, the method, 895 and the usage; the following are the default rules: 897 o If the error code is 300 through 399, the client SHOULD consider 898 the transaction as failed unless the ALTERNATE-SERVER extension is 899 being used. See Section 10. 901 o If the error code is 400 through 499, the client declares the 902 transaction failed; in the case of 420 (Unknown Attribute), the 903 response should contain a UNKNOWN-ATTRIBUTES attribute that gives 904 additional information. 906 o If the error code is 500 through 599, the client MAY resend the 907 request; clients that do so MUST limit the number of times they do 908 this. 910 Any other error code causes the client to consider the transaction 911 failed. 913 7. FINGERPRINT Mechanism 915 This section describes an optional mechanism for STUN that aids in 916 distinguishing STUN messages from packets of other protocols when the 917 two are multiplexed on the same transport address. This mechanism is 918 optional, and a STUN usage must describe if and when it is used. The 919 FINGERPRINT mechanism is not backwards compatible with RFC3489, and 920 cannot be used in environments where such compatibility is required. 922 In some usages, STUN messages are multiplexed on the same transport 923 address as other protocols, such as the Real Time Transport Protocol 924 (RTP). In order to apply the processing described in Section 6, STUN 925 messages must first be separated from the application packets. 927 Section 5 describes three fixed fields in the STUN header that can be 928 used for this purpose. However, in some cases, these three fixed 929 fields may not be sufficient. 931 When the FINGERPRINT extension is used, an agent includes the 932 FINGERPRINT attribute in messages it sends to another agent. 933 Section 14.7 describes the placement and value of this attribute. 935 When the agent receives what it believes is a STUN message, then, in 936 addition to other basic checks, the agent also checks that the 937 message contains a FINGERPRINT attribute and that the attribute 938 contains the correct value. Section 6.3 describes when in the 939 overall processing of a STUN message the FINGERPRINT check is 940 performed. This additional check helps the agent detect messages of 941 other protocols that might otherwise seem to be STUN messages. 943 8. DNS Discovery of a Server 945 This section describes an optional procedure for STUN that allows a 946 client to use DNS to determine the IP address and port of a server. 947 A STUN usage must describe if and when this extension is used. To 948 use this procedure, the client must know a STUN URI [RFC7064]; the 949 usage must also describe how the client obtains this URI. Hard- 950 coding a STUN URI into software is NOT RECOMMENDED in case the domain 951 name is lost or needs to change for legal or other reasons. 953 When a client wishes to locate a STUN server on the public Internet 954 that accepts Binding request/response transactions, the STUN URI 955 scheme is "stun". When it wishes to locate a STUN server that 956 accepts Binding request/response transactions over a TLS, or DTLS 957 session, the URI scheme is "stuns". 959 The syntax of the "stun" and "stuns" URIs are defined in Section 3.1 960 of [RFC7064]. STUN usages MAY define additional URI schemes. 962 8.1. STUN URI Scheme Semantics 964 If the part contains an IP address, then this IP address is 965 used directly to contact the server. A "stuns" URI containing an IP 966 address MUST be rejected, unless the domain name is provided by the 967 same mechanism that provided the STUN URI, and that domain name can 968 be passed to the verification code. 970 If the URI does not contain an IP address, the domain name contained 971 in the part is resolved to a transport address using the SRV 972 procedures specified in [RFC2782]. The DNS SRV service name is the 973 content of the part. The protocol in the SRV lookup is the 974 transport protocol the client will run STUN over: "udp" for UDP and 975 "tcp" for TCP. 977 The procedures of RFC 2782 are followed to determine the server to 978 contact. RFC 2782 spells out the details of how a set of SRV records 979 is sorted and then tried. However, RFC 2782 only states that the 980 client should "try to connect to the (protocol, address, service)" 981 without giving any details on what happens in the event of failure. 982 When following these procedures, if the STUN transaction times out 983 without receipt of a response, the client SHOULD retry the request to 984 the next server in the ordered defined by RFC 2782. Such a retry is 985 only possible for request/response transmissions, since indication 986 transactions generate no response or timeout. 988 The default port for STUN requests is 3478, for both TCP and UDP. 989 The default port for STUN over TLS and STUN over DTLS requests is 990 5349. Servers can run STUN over DTLS on the same port as STUN over 991 UDP if the server software supports determining whether the initial 992 message is a DTLS or STUN message. Servers can run STUN over TLS on 993 the same port as STUN over TCP if the server software supports 994 determining whether the initial message is a TLS or STUN message. 996 Administrators of STUN servers SHOULD use these ports in their SRV 997 records for UDP and TCP. In all cases, the port in DNS MUST reflect 998 the one on which the server is listening. 1000 If no SRV records were found, the client performs an A or AAAA record 1001 lookup of the domain name. The result will be a list of IP 1002 addresses, each of which can be contacted at the default port using 1003 UDP or TCP, independent of the STUN usage. For usages that require 1004 TLS, the client connects to one of the IP addresses using the default 1005 STUN over TLS port. For usages that require DTLS, the client 1006 connects to one of the IP addresses using the default STUN over DTLS 1007 port. 1009 9. Authentication and Message-Integrity Mechanisms 1011 This section defines two mechanisms for STUN that a client and server 1012 can use to provide authentication and message integrity; these two 1013 mechanisms are known as the short-term credential mechanism and the 1014 long-term credential mechanism. These two mechanisms are optional, 1015 and each usage must specify if and when these mechanisms are used. 1016 Consequently, both clients and servers will know which mechanism (if 1017 any) to follow based on knowledge of which usage applies. For 1018 example, a STUN server on the public Internet supporting ICE would 1019 have no authentication, whereas the STUN server functionality in an 1020 agent supporting connectivity checks would utilize short-term 1021 credentials. An overview of these two mechanisms is given in 1022 Section 2. 1024 Each mechanism specifies the additional processing required to use 1025 that mechanism, extending the processing specified in Section 6. The 1026 additional processing occurs in three different places: when forming 1027 a message, when receiving a message immediately after the basic 1028 checks have been performed, and when doing the detailed processing of 1029 error responses. 1031 9.1. Short-Term Credential Mechanism 1033 The short-term credential mechanism assumes that, prior to the STUN 1034 transaction, the client and server have used some other protocol to 1035 exchange a credential in the form of a username and password. This 1036 credential is time-limited. The time limit is defined by the usage. 1037 As an example, in the ICE usage [I-D.ietf-ice-rfc5245bis], the two 1038 endpoints use out-of-band signaling to agree on a username and 1039 password, and this username and password are applicable for the 1040 duration of the media session. 1042 This credential is used to form a message-integrity check in each 1043 request and in many responses. There is no challenge and response as 1044 in the long-term mechanism; consequently, replay is prevented by 1045 virtue of the time-limited nature of the credential. 1047 9.1.1. HMAC Key 1049 For short-term credentials the HMAC key is defined as follow: 1051 key = OpaqueString(password) 1053 where the OpaqueString profile is defined in [RFC7613]. 1055 9.1.2. Forming a Request or Indication 1057 For a request or indication message, the agent MUST include the 1058 USERNAME, MESSAGE-INTEGRITY-SHA256, and MESSAGE-INTEGRITY attributes 1059 in the message unless the agent knows from an external indication 1060 which message integrity algorithm is supported by both agents. In 1061 this case either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 MUST 1062 be included in addition to USERNAME. The HMAC for the MESSAGE- 1063 INTEGRITY attribute is computed as described in Section 14.5 and the 1064 HMAC for the MESSAGE-INTEGRITY-SHA256 attributes is computed as 1065 described in Section 14.6. Note that the password is never included 1066 in the request or indication. 1068 9.1.3. Receiving a Request or Indication 1070 After the agent has done the basic processing of a message, the agent 1071 performs the checks listed below in order specified: 1073 o If the message does not contain 1) a MESSAGE-INTEGRITY or a 1074 MESSAGE-INTEGRITY-SHA256 attribute and 2) a USERNAME attribute: 1076 * If the message is a request, the server MUST reject the request 1077 with an error response. This response MUST use an error code 1078 of 400 (Bad Request). 1080 * If the message is an indication, the agent MUST silently 1081 discard the indication. 1083 o If the USERNAME does not contain a username value currently valid 1084 within the server: 1086 * If the message is a request, the server MUST reject the request 1087 with an error response. This response MUST use an error code 1088 of 401 (Unauthenticated). 1090 * If the message is an indication, the agent MUST silently 1091 discard the indication. 1093 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1094 value for the message integrity as described in Section 14.6, 1095 using the password associated with the username. If the MESSAGE- 1096 INTEGRITY-SHA256 attribute is not present, and using the same 1097 password, compute the value for the message integrity as described 1098 in Section 14.5. If the resulting value does not match the 1099 contents of the corresponding attribute (MESSAGE-INTEGRITY-SHA256 1100 or MESSAGE-INTEGRITY): 1102 * If the message is a request, the server MUST reject the request 1103 with an error response. This response MUST use an error code 1104 of 401 (Unauthenticated). 1106 * If the message is an indication, the agent MUST silently 1107 discard the indication. 1109 If these checks pass, the agent continues to process the request or 1110 indication. Any response generated by a server to a request that 1111 contains a MESSAGE-INTEGRITY-SHA256 attribute MUST include the 1112 MESSAGE-INTEGRITY-SHA256 attribute, computed using the password 1113 utilized to authenticate the request. Any response generated by a 1114 server to a request that contains only a MESSAGE-INTEGRITY attribute 1115 MUST include the MESSAGE-INTEGRITY attribute, computed using the 1116 password utilized to authenticate the request. This means that only 1117 one of these attributes can appear in a response. The response MUST 1118 NOT contain the USERNAME attribute. 1120 If any of the checks fail, a server MUST NOT include a MESSAGE- 1121 INTEGRITY-SHA256, MESSAGE-INTEGRITY, or USERNAME attribute in the 1122 error response. This is because, in these failure cases, the server 1123 cannot determine the shared secret necessary to compute the MESSAGE- 1124 INTEGRITY-SHA256 or MESSAGE-INTEGRITY attributes. 1126 9.1.4. Receiving a Response 1128 The client looks for the MESSAGE-INTEGRITY or the MESSAGE-INTEGRITY- 1129 SHA256 attribute in the response. If present, the client computes 1130 the message integrity over the response as defined in Section 14.5 or 1131 Section 14.6, respectively, using the same password it utilized for 1132 the request. If the resulting value matches the contents of the 1133 MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, 1134 respectively, the response is considered authenticated. If the value 1135 does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 1136 SHA256 were absent, the processing depends on the request been sent 1137 over a reliable or an unreliable transport. 1139 If the request was sent over an unreliable transport, the response 1140 MUST be discarded, as if it was never received. This means that 1141 retransmits, if applicable, will continue. If all the reponses 1142 received are discarded then instead of signalling a timeout after 1143 ending the transaction the layer MUST signal that an attack took 1144 place. 1146 If the request was sent over a reliable transport, the response MUST 1147 be discarded and the layer MUST immediately end the transaction and 1148 signal that an attack took place. 1150 If the client only sent one algorithm in the request (because of the 1151 external indication in section Section 9.2.3, or this being a 1152 subsequent request as defined in Section 9.1.5) the algorithm in the 1153 response has to match otherwise the response MUST be discarded. 1155 9.1.5. Sending Subsequent Requests 1157 A client sending subsequent requests to the same server MAY choose to 1158 send only the MESSAGE-INTEGRITY-SHA256 or the MESSAGE-INTEGRITY 1159 attribute depending upon the attribute that was received in the 1160 response to the initial request. Here same server means same IP 1161 address and port number, not just the same URL or SRV lookup result. 1163 9.2. Long-Term Credential Mechanism 1165 The long-term credential mechanism relies on a long-term credential, 1166 in the form of a username and password that are shared between client 1167 and server. The credential is considered long-term since it is 1168 assumed that it is provisioned for a user, and remains in effect 1169 until the user is no longer a subscriber of the system, or is 1170 changed. This is basically a traditional "log-in" username and 1171 password given to users. 1173 Because these usernames and passwords are expected to be valid for 1174 extended periods of time, replay prevention is provided in the form 1175 of a digest challenge. In this mechanism, the client initially sends 1176 a request, without offering any credentials or any integrity checks. 1177 The server rejects this request, providing the user a realm (used to 1178 guide the user or agent in selection of a username and password) and 1179 a nonce. The nonce provides the replay protection. It is a cookie, 1180 selected by the server, and encoded in such a way as to indicate a 1181 duration of validity or client identity from which it is valid. The 1182 client retries the request, this time including its username and the 1183 realm, and echoing the nonce provided by the server. The client also 1184 includes a message-integrity, which provides an HMAC over the entire 1185 request, including the nonce. The server validates the nonce and 1186 checks the message integrity. If they match, the request is 1187 authenticated. If the nonce is no longer valid, it is considered 1188 "stale", and the server rejects the request, providing a new nonce. 1190 In subsequent requests to the same server, the client reuses the 1191 nonce, username, realm, and password it used previously. In this 1192 way, subsequent requests are not rejected until the nonce becomes 1193 invalid by the server, in which case the rejection provides a new 1194 nonce to the client. 1196 Note that the long-term credential mechanism cannot be used to 1197 protect indications, since indications cannot be challenged. Usages 1198 utilizing indications must either use a short-term credential or omit 1199 authentication and message integrity for them. 1201 Since the long-term credential mechanism is susceptible to offline 1202 dictionary attacks, deployments SHOULD utilize passwords that are 1203 difficult to guess. In cases where the credentials are not entered 1204 by the user, but are rather placed on a client device during device 1205 provisioning, the password SHOULD have at least 128 bits of 1206 randomness. In cases where the credentials are entered by the user, 1207 they should follow best current practices around password structure. 1209 9.2.1. Bid Down Attack Prevention 1211 This document introduces two new security features that provide the 1212 ability to choose the algorithm used for password protection as well 1213 as the ability to use an anonymous username. Both of these 1214 capabilities are optional in order to remain backwards compatible 1215 with previous versions of the STUN protocol. 1217 These new capabilities are subject to bid down attacks whereby an 1218 attacker in the message path can remove these capabilities and force 1219 weaker security properties. To prevent these kinds of attacks from 1220 going undetected, the nonce is enhanced with additional information. 1222 If the server uses one of the security features subject to bid down 1223 attack protection it MUST prepend the NONCE attribute value with the 1224 character string composed of "obMatJos2" concatenated with the Base64 1225 encoding of the 24 bit STUN Security Features as defined in 1226 Section 17.1. The 24 bit Security Feature set is encoded as a 24 bit 1227 integer in network order. For the remainder of this document the 1228 term "nonce cookie" will refer to the complete 13 character string 1229 prepended to the NONCE attribute value. 1231 The value of the "nonce cookie" will vary based on the specific STUN 1232 Security Features bit values selected. When this document makes 1233 reference to the "nonce cookie" in a section discussing a specific 1234 STUN Security Feature it is understood that the corresponding STUN 1235 Security Feature bit in the "nonce cookie" is set to 1. 1237 For example, in Section 9.2.4 discussing the PASSWORD-ALGORITHMS 1238 security feature, it is implied that the "Password algorithms" bit, 1239 as defined in Section 17.1, is set to 1 in the "nonce cookie". 1241 9.2.2. HMAC Key 1243 For long-term credentials that do not use a different algorithm, as 1244 specified by the PASSWORD-ALGORITHM attribute, the key is 16 bytes: 1246 key = MD5(username ":" realm ":" OpaqueString(password)) 1248 Where MD5 is defined in [RFC1321] and the OpaqueString profile is 1249 defined in [RFC7613]. 1251 The 16-byte key is formed by taking the MD5 hash of the result of 1252 concatenating the following five fields: (1) the username, with any 1253 quotes and trailing nulls removed, as taken from the USERNAME 1254 attribute (in which case OpaqueString has already been applied); (2) 1255 a single colon; (3) the realm, with any quotes and trailing nulls 1256 removed; (4) a single colon; and (5) the password, with any trailing 1257 nulls removed and after processing using OpaqueString. For example, 1258 if the username was 'user', the realm was 'realm', and the password 1259 was 'pass', then the 16-byte HMAC key would be the result of 1260 performing an MD5 hash on the string 'user:realm:pass', the resulting 1261 hash being 0x8493fbc53ba582fb4c044c456bdc40eb. 1263 The structure of the key when used with long-term credentials 1264 facilitates deployment in systems that also utilize SIP. Typically, 1265 SIP systems utilizing SIP's digest authentication mechanism do not 1266 actually store the password in the database. Rather, they store a 1267 value called H(A1), which is equal to the key defined above. 1269 When a PASSWORD-ALGORITHM is used, the key length and algorithm to 1270 use are described in Section 17.5.1. 1272 9.2.3. Forming a Request 1274 There are two cases when forming a request. In the first case, this 1275 is the first request from the client to the server (as identified by 1276 its IP address and port). In the second case, the client is 1277 submitting a subsequent request once a previous request/response 1278 transaction has completed successfully. Forming a request as a 1279 consequence of a 401 or 438 error response is covered in 1280 Section 9.2.5 and is not considered a "subsequent request" and thus 1281 does not utilize the rules described in Section 9.2.3.2. 1283 The difference between a first request and a subsequent request is 1284 the presence or absence of some attributes, so omitting or including 1285 them is a MUST. 1287 9.2.3.1. First Request 1289 If the client has not completed a successful request/response 1290 transaction with the server (as identified by hostname, if the DNS 1291 procedures of Section 8 are used, else IP address if not), it MUST 1292 omit the USERNAME, USERHASH, MESSAGE-INTEGRITY, MESSAGE-INTEGRITY- 1293 SHA256, REALM, NONCE, PASSWORD-ALGORITHMS, and PASSWORD-ALGORITHM 1294 attributes. In other words, the very first request is sent as if 1295 there were no authentication or message integrity applied. 1297 9.2.3.2. Subsequent Requests 1299 Once a request/response transaction has completed successfully, the 1300 client will have been presented a realm and nonce by the server, and 1301 selected a username and password with which it authenticated. The 1302 client SHOULD cache the username, password, realm, and nonce for 1303 subsequent communications with the server. When the client sends a 1304 subsequent request, it MUST include either the USERNAME or USERHASH, 1305 REALM, NONCE, and PASSWORD-ALGORITHM attributes with these cached 1306 values. It MUST include a MESSAGE-INTEGRITY attribute or a MESSAGE- 1307 INTEGRITY-SHA256 attribute, computed as described in Section 14.5 and 1308 Section 14.6 using the cached password. The choice between the two 1309 attributes depends on the attribute received in the response to the 1310 first request. 1312 9.2.4. Receiving a Request 1314 After the server has done the basic processing of a request, it 1315 performs the checks listed below in the order specified: 1317 o If the message does not contain a MESSAGE-INTEGRITY or MESSAGE- 1318 INTEGRITY-SHA256 attribute, the server MUST generate an error 1319 response with an error code of 401 (Unauthenticated). This 1320 response MUST include a REALM value. It is RECOMMENDED that the 1321 REALM value be the domain name of the provider of the STUN server. 1322 The response MUST include a NONCE, selected by the server. The 1323 server MUST ensure that the same NONCE cannot be selected for 1324 clients that use different IP addresses and/or different ports. 1325 The server MAY support alternate password algorithms, in which 1326 case it can list them in preferential order in a PASSWORD- 1327 ALGORITHMS attribute. If the server adds a PASSWORD-ALGORITHMS 1328 attribute it MUST prepend the NONCE attribute value with the 1329 "nonce cookie" that has the STUN Security Feature "Password 1330 algorithms" bit set to 1. The server MAY support anonymous 1331 username, in which case it can prepend the NONCE attribute value 1332 with the "nonce cookie" that has the STUN Security Feature 1333 "Anonymous username" bit set to 1. The response SHOULD NOT 1334 contain a USERNAME, USERHASH, MESSAGE-INTEGRITY or MESSAGE- 1335 INTEGRITY-SHA256 attribute. 1337 Note: Sharing a NONCE is no longer permitted, so trying to share one 1338 will result in a wasted transaction. 1340 o If the message contains a MESSAGE-INTEGRITY or a MESSAGE- 1341 INTEGRITY-SHA256 attribute, but is missing either the USERNAME or 1342 USERHASH, REALM, or NONCE attribute, the server MUST generate an 1343 error response with an error code of 400 (Bad Request). This 1344 response SHOULD NOT include a USERNAME, USERHASH, NONCE, or REALM. 1345 The response cannot contain a MESSAGE-INTEGRITY or MESSAGE- 1346 INTEGRITY-SHA256 attribute, as the attributes required to generate 1347 them are missing. 1349 o If the NONCE attribute starts with the "nonce cookie" with the 1350 STUN Security Feature "Password algorithm" bit set to 1 but 1351 PASSWORD-ALGORITHMS does not match the value sent in the response 1352 that sent this NONCE, then the server MUST generate an error 1353 response with an error code of 400 (Bad Request). 1355 o If the NONCE attribute starts with the "nonce cookie" with the 1356 STUN Security Feature "Password algorithm" bit set to 1 but the 1357 request contains neither PASSWORD-ALGORITHMS nor PASSWORD- 1358 ALGORITHM, then the request is processed as though PASSWORD- 1359 ALGORITHM were MD5 (Note that if the original PASSWORD-ALGORITHMS 1360 attribute did not contain MD5, this will result in a 400 Bad 1361 Request in a later step below). 1363 o If the NONCE attribute starts with the "nonce cookie" with the 1364 STUN Security Feature "Password algorithm" bit set to 1 but only 1365 one of PASSWORD-ALGORITHM or PASSWORD-ALGORITHMS is present, then 1366 the server MUST generate an error response with an error code of 1367 400 (Bad Request). 1369 o If the NONCE attribute starts with the "nonce cookie" with the 1370 STUN Security Feature "Password algorithm" bit set to 1 but 1371 PASSWORD-ALGORITHM does not match one of the entries in PASSWORD- 1372 ALGORITHMS, then the server MUST generate an error response with 1373 an error code of 400 (Bad Request). 1375 o If the NONCE is no longer valid and at the same time the MESSAGE- 1376 INTEGRITY or a MESSAGE-INTEGRITY-SHA256 attribute is invalid, the 1377 server MUST generate an error response with an error code of 401. 1378 This response MUST include NONCE, REALM, and PASSWORD-ALGORITHMS 1379 attributes and SHOULD NOT include the USERNAME or USERHASH 1380 attribute. The response MAY include a MESSAGE-INTEGRITY or 1381 MESSAGE-INTEGRITY-SHA256 attribute, using the previous NONCE to 1382 calculate it. 1384 o If the NONCE is no longer valid, the server MUST generate an error 1385 response with an error code of 438 (Stale Nonce). This response 1386 MUST include NONCE, REALM, and PASSWORD-ALGORITHMS attributes and 1387 SHOULD NOT include the USERNAME, USERHASH attribute, The response 1388 MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1389 attribute, using the previous NONCE to calculate it. Servers can 1390 invalidate nonces in order to provide additional security. See 1391 Section 4.3 of [RFC2617] for guidelines. 1393 o If the username in the USERNAME or USERHASH attribute is not 1394 valid, the server MUST generate an error response with an error 1395 code of 401 (Unauthenticated). This response MUST include a REALM 1396 value. It is RECOMMENDED that the REALM value be the domain name 1397 of the provider of the STUN server. The response MUST include a 1398 NONCE, selected by the server. The response MUST include a 1399 PASSWORD-ALGORITHMS attribute. The response SHOULD NOT contain a 1400 USERNAME, USERHASH attribute. The response MAY include a MESSAGE- 1401 INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, using the 1402 previous password to calculate it. 1404 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1405 value for the message integrity as described in Section 14.6, 1406 using the password associated with the username. Else, using the 1407 same password, compute the value for the message integrity as 1408 described in Section 14.5. If the resulting value does not match 1409 the contents of the MESSAGE-INTEGRITY attribute or the MESSAGE- 1410 INTEGRITY-SHA256 attribute, the server MUST reject the request 1411 with an error response. This response MUST use an error code of 1412 401 (Unauthenticated). It MUST include REALM and NONCE attributes 1413 and SHOULD NOT include the USERNAME, USERHASH, MESSAGE-INTEGRITY, 1414 or MESSAGE-INTEGRITY-SHA256 attribute. 1416 For the responses sent by the steps above, the MESSAGE-INTEGRITY- 1417 SHA256 attribute cannot be added. 1419 If these checks pass, the server continues to process the request. 1420 Any response generated by the server MUST include MESSAGE-INTEGRITY- 1421 SHA256 attribute, computed using the username and password utilized 1422 to authenticate the request, unless the request was processed as 1423 though PASSWORD-ALGORITHM was MD5 (because the request contained 1424 neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM). In that case 1425 the MESSAGE-INTEGRITY attribute MUST be used instead of the MESSAGE- 1426 INTEGRITY-SHA256 attribute. The REALM, NONCE, USERNAME and USERHASH 1427 attributes SHOULD NOT be included. 1429 9.2.5. Receiving a Response 1431 If the response is an error response with an error code of 401 1432 (Unauthenticated) or 438 (Stale Nonce), the client MUST test if the 1433 NONCE attribute value starts with the "nonce cookie". If the test 1434 succeeds and the "nonce cookie" has the STUN Security Feature 1435 "Password algorithm" bit set to 1 but no PASSWORD-ALGORITHMS 1436 attribute is present, then the client MUST NOT retry the request with 1437 a new transaction. If the test succeeds and the "nonce cookie" has 1438 the STUN Security Feature "Username anonymity" bit set to 1 but no 1439 USERHASH attribute is present, then the client MUST NOT retry the 1440 request with a new transaction. 1442 If the response is an error response with an error code of 401 1443 (Unauthenticated), the client SHOULD retry the request with a new 1444 transaction. This request MUST contain a USERNAME or a USERHASH, 1445 determined by the client as the appropriate username for the REALM 1446 from the error response. If the "nonce cookie" was present and had 1447 the STUN Security Feature "Username anonymity" bit set to 1 then the 1448 USERHASH attribute MUST be used, else the USERNAME attribute MUST be 1449 used. The request MUST contain the REALM, copied from the error 1450 response. The request MUST contain the NONCE, copied from the error 1451 response. If the response contains a PASSWORD-ALGORITHMS attribute, 1452 the request MUST contain the PASSWORD-ALGORITHMS attribute with the 1453 same content. If the response contains a PASSWORD-ALGORITHMS 1454 attribute, and this attribute contains at least one algorithm that is 1455 supported by the client then the request MUST contain a PASSWORD- 1456 ALGORITHM attribute with the first algorithm supported on the list. 1457 If the response contains a PASSWORD-ALGORITHMS attribute, and this 1458 attribute does not contain any algorithm that is supported by the 1459 client, then the client MUST NOT retry the request with a new 1460 transaction. The client MUST NOT perform this retry if it is not 1461 changing the USERNAME or USERHASH or REALM or its associated 1462 password, from the previous attempt. 1464 If the response is an error response with an error code of 438 (Stale 1465 Nonce), the client MUST retry the request, using the new NONCE 1466 attribute supplied in the 438 (Stale Nonce) response. This retry 1467 MUST also include either the USERNAME or USERHASH, REALM and either 1468 the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attributes. 1470 For all other responses, if the NONCE attribute starts with the 1471 "nonce cookie" with the STUN Security Feature "Password algorithm" 1472 bit set to 1 but PASSWORD-ALGORITHMS is not present, the response 1473 MUST be ignored. For all other responses, if the NONCE attribute 1474 starts with the "nonce cookie" with the STUN Security Feature "User 1475 anonymity" bit set to 1 but USERHASH is not present, the response 1476 MUST be ignored. 1478 If the response is an error response with an error code of 400, and 1479 does not contains either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1480 SHA256 attribute then the response MUST be discarded, as if it was 1481 never received. This means that retransmits, if applicable, will 1482 continue. 1484 The client looks for the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1485 SHA256 attribute in the response (either success or failure). If 1486 present, the client computes the message integrity over the response 1487 as defined in Section 14.5 or Section 14.6, using the same password 1488 it utilized for the request. If the resulting value matches the 1489 contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1490 attribute, the response is considered authenticated. If the value 1491 does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 1492 SHA256 were absent, the processing depends on the request been sent 1493 over a reliable or an unreliable transport. 1495 If the request was sent over an unreliable transport, the response 1496 MUST be discarded, as if it was never received. This means that 1497 retransmits, if applicable, will continue. If all the reponses 1498 received are discarded then instead of signalling a timeout after 1499 ending the transaction the layer MUST signal that an attack took 1500 place. 1502 If the request was sent over a reliable transport, the response MUST 1503 be discarded and the layer MUST immediately end the transaction and 1504 signal that an attack took place. 1506 If the response contains a PASSWORD-ALGORITHMS attribute, the 1507 subsequent request MUST be authenticated using MESSAGE-INTEGRITY- 1508 SHA256 only. 1510 10. ALTERNATE-SERVER Mechanism 1512 This section describes a mechanism in STUN that allows a server to 1513 redirect a client to another server. This extension is optional, and 1514 a usage must define if and when this extension is used. 1516 A server using this extension redirects a client to another server by 1517 replying to a request message with an error response message with an 1518 error code of 300 (Try Alternate). The server MUST include an 1519 ALTERNATE-SERVER attribute in the error response. The error response 1520 message MAY be authenticated; however, there are uses cases for 1521 ALTERNATE-SERVER where authentication of the response is not possible 1522 or practical. If the transaction uses TLS or DTLS and if the 1523 transaction is authenticated by a MESSAGE-INTEGRITY-SHA256 attribute 1524 and if the server wants to redirect to a server that uses a different 1525 certificate, then it MUST include an ALTERNATE-DOMAIN attribute 1526 containing the subjectAltName of that certificate. 1528 A client using this extension handles a 300 (Try Alternate) error 1529 code as follows. The client looks for an ALTERNATE-SERVER attribute 1530 in the error response. If one is found, then the client considers 1531 the current transaction as failed, and reattempts the request with 1532 the server specified in the attribute, using the same transport 1533 protocol used for the previous request. That request, if 1534 authenticated, MUST utilize the same credentials that the client 1535 would have used in the request to the server that performed the 1536 redirection. If the transport protocol uses TLS or DTLS, then the 1537 client looks for an ALTERNATE-DOMAIN attribute. If the attribute is 1538 found, the domain MUST be used to validate the certificate using the 1539 recommendations in [RFC6125]. If the attribute is not found, the 1540 same domain that was used for the original request MUST be used to 1541 validate the certificate. If the client has been redirected to a 1542 server on which it has already tried this request within the last 1543 five minutes, it MUST ignore the redirection and consider the 1544 transaction to have failed. This prevents infinite ping-ponging 1545 between servers in case of redirection loops. 1547 11. Backwards Compatibility with RFC 3489 1549 In addition to the backward compatibility already described in 1550 Section 12 of [RFC5389], DTLS MUST NOT be used with STUN [RFC3489] 1551 (also referred to as "classic STUN"). Any STUN request or indication 1552 without the magic cookie (see Section 6 of [RFC5389]) over DTLS MUST 1553 always result in an error. 1555 12. Basic Server Behavior 1557 This section defines the behavior of a basic, stand-alone STUN 1558 server. A basic STUN server provides clients with server reflexive 1559 transport addresses by receiving and replying to STUN Binding 1560 requests. 1562 The STUN server MUST support the Binding method. It SHOULD NOT 1563 utilize the short-term or long-term credential mechanism. This is 1564 because the work involved in authenticating the request is more than 1565 the work in simply processing it. It SHOULD NOT utilize the 1566 ALTERNATE-SERVER mechanism for the same reason. It MUST support UDP 1567 and TCP. It MAY support STUN over TCP/TLS or STUN over UDP/DTLS; 1568 however, DTLS and TLS provide minimal security benefits in this basic 1569 mode of operation. It MAY utilize the FINGERPRINT mechanism but MUST 1570 NOT require it. Since the stand-alone server only runs STUN, 1571 FINGERPRINT provides no benefit. Requiring it would break 1572 compatibility with RFC 3489, and such compatibility is desirable in a 1573 stand-alone server. Stand-alone STUN servers SHOULD support 1574 backwards compatibility with [RFC3489] clients, as described in 1575 Section 11. 1577 It is RECOMMENDED that administrators of STUN servers provide DNS 1578 entries for those servers as described in Section 8. 1580 A basic STUN server is not a solution for NAT traversal by itself. 1581 However, it can be utilized as part of a solution through STUN 1582 usages. This is discussed further in Section 13. 1584 13. STUN Usages 1586 STUN by itself is not a solution to the NAT traversal problem. 1587 Rather, STUN defines a tool that can be used inside a larger 1588 solution. The term "STUN usage" is used for any solution that uses 1589 STUN as a component. 1591 A STUN usage defines how STUN is actually utilized -- when to send 1592 requests, what to do with the responses, and which optional 1593 procedures defined here (or in an extension to STUN) are to be used. 1594 A usage would also define: 1596 o Which STUN methods are used. 1598 o What transports are used. If DTLS-over-UDP is used then 1599 implementing the denial-of-service countermeasure described in 1600 Section 4.2.1 of [RFC6347] is mandatory. 1602 o What authentication and message-integrity mechanisms are used. 1604 o The considerations around manual vs. automatic key derivation for 1605 the integrity mechanism, as discussed in [RFC4107]. 1607 o What mechanisms are used to distinguish STUN messages from other 1608 messages. When STUN is run over TCP, a framing mechanism may be 1609 required. 1611 o How a STUN client determines the IP address and port of the STUN 1612 server. 1614 o Whether backwards compatibility to RFC 3489 is required. 1616 o What optional attributes defined here (such as FINGERPRINT and 1617 ALTERNATE-SERVER) or in other extensions are required. 1619 o If MESSAGE-INTEGRITY-256 truncation is permitted, and the limits 1620 permitted for truncation. 1622 In addition, any STUN usage must consider the security implications 1623 of using STUN in that usage. A number of attacks against STUN are 1624 known (see the Security Considerations section in this document), and 1625 any usage must consider how these attacks can be thwarted or 1626 mitigated. 1628 Finally, a usage must consider whether its usage of STUN is an 1629 example of the Unilateral Self-Address Fixing approach to NAT 1630 traversal, and if so, address the questions raised in RFC 3424 1631 [RFC3424]. 1633 14. STUN Attributes 1635 After the STUN header are zero or more attributes. Each attribute 1636 MUST be TLV encoded, with a 16-bit type, 16-bit length, and value. 1637 Each STUN attribute MUST end on a 32-bit boundary. As mentioned 1638 above, all fields in an attribute are transmitted most significant 1639 bit first. 1641 0 1 2 3 1642 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 1643 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1644 | Type | Length | 1645 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1646 | Value (variable) .... 1647 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1649 Figure 4: Format of STUN Attributes 1651 The value in the length field MUST contain the length of the Value 1652 part of the attribute, prior to padding, measured in bytes. Since 1653 STUN aligns attributes on 32-bit boundaries, attributes whose content 1654 is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of 1655 padding so that its value contains a multiple of 4 bytes. The 1656 padding bits are ignored, and may be any value. 1658 Any attribute type MAY appear more than once in a STUN message. 1659 Unless specified otherwise, the order of appearance is significant: 1660 only the first occurrence needs to be processed by a receiver, and 1661 any duplicates MAY be ignored by a receiver. 1663 To allow future revisions of this specification to add new attributes 1664 if needed, the attribute space is divided into two ranges. 1665 Attributes with type values between 0x0000 and 0x7FFF are 1666 comprehension-required attributes, which means that the STUN agent 1667 cannot successfully process the message unless it understands the 1668 attribute. Attributes with type values between 0x8000 and 0xFFFF are 1669 comprehension-optional attributes, which means that those attributes 1670 can be ignored by the STUN agent if it does not understand them. 1672 The set of STUN attribute types is maintained by IANA. The initial 1673 set defined by this specification is found in Section 17.3. 1675 The rest of this section describes the format of the various 1676 attributes defined in this specification. 1678 14.1. MAPPED-ADDRESS 1680 The MAPPED-ADDRESS attribute indicates a reflexive transport address 1681 of the client. It consists of an 8-bit address family and a 16-bit 1682 port, followed by a fixed-length value representing the IP address. 1683 If the address family is IPv4, the address MUST be 32 bits. If the 1684 address family is IPv6, the address MUST be 128 bits. All fields 1685 must be in network byte order. 1687 The format of the MAPPED-ADDRESS attribute is: 1689 0 1 2 3 1690 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 1691 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1692 |0 0 0 0 0 0 0 0| Family | Port | 1693 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1694 | | 1695 | Address (32 bits or 128 bits) | 1696 | | 1697 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1699 Figure 5: Format of MAPPED-ADDRESS Attribute 1701 The address family can take on the following values: 1703 0x01:IPv4 1704 0x02:IPv6 1706 The first 8 bits of the MAPPED-ADDRESS MUST be set to 0 and MUST be 1707 ignored by receivers. These bits are present for aligning parameters 1708 on natural 32-bit boundaries. 1710 This attribute is used only by servers for achieving backwards 1711 compatibility with [RFC3489] clients. 1713 14.2. XOR-MAPPED-ADDRESS 1715 The XOR-MAPPED-ADDRESS attribute is identical to the MAPPED-ADDRESS 1716 attribute, except that the reflexive transport address is obfuscated 1717 through the XOR function. 1719 The format of the XOR-MAPPED-ADDRESS is: 1721 0 1 2 3 1722 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 1723 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1724 |0 0 0 0 0 0 0 0| Family | X-Port | 1725 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1726 | X-Address (Variable) 1727 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1729 Figure 6: Format of XOR-MAPPED-ADDRESS Attribute 1731 The Family represents the IP address family, and is encoded 1732 identically to the Family in MAPPED-ADDRESS. 1734 X-Port is computed by taking the mapped port in host byte order, 1735 XOR'ing it with the most significant 16 bits of the magic cookie, and 1736 then the converting the result to network byte order. If the IP 1737 address family is IPv4, X-Address is computed by taking the mapped IP 1738 address in host byte order, XOR'ing it with the magic cookie, and 1739 converting the result to network byte order. If the IP address 1740 family is IPv6, X-Address is computed by taking the mapped IP address 1741 in host byte order, XOR'ing it with the concatenation of the magic 1742 cookie and the 96-bit transaction ID, and converting the result to 1743 network byte order. 1745 The rules for encoding and processing the first 8 bits of the 1746 attribute's value, the rules for handling multiple occurrences of the 1747 attribute, and the rules for processing address families are the same 1748 as for MAPPED-ADDRESS. 1750 Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only in their 1751 encoding of the transport address. The former encodes the transport 1752 address by exclusive-or'ing it with the magic cookie. The latter 1753 encodes it directly in binary. RFC 3489 originally specified only 1754 MAPPED-ADDRESS. However, deployment experience found that some NATs 1755 rewrite the 32-bit binary payloads containing the NAT's public IP 1756 address, such as STUN's MAPPED-ADDRESS attribute, in the well-meaning 1757 but misguided attempt at providing a generic ALG function. Such 1758 behavior interferes with the operation of STUN and also causes 1759 failure of STUN's message-integrity checking. 1761 14.3. USERNAME 1763 The USERNAME attribute is used for message integrity. It identifies 1764 the username and password combination used in the message-integrity 1765 check. 1767 The value of USERNAME is a variable-length value. It MUST contain a 1768 UTF-8 [RFC3629] encoded sequence of less than 513 bytes, and MUST 1769 have been processed using the OpaqueString profile [RFC7613]. 1771 14.4. USERHASH 1773 The USERHASH attribute is used as a replacement for the USERNAME 1774 attribute when username anonymity is supported. 1776 The value of USERHASH has a fixed length of 32 bytes. The username 1777 MUST have been processed using the OpaqueString profile [RFC7613] 1778 before hashing. 1780 The following is the operation that the client will perform to hash 1781 the username: 1783 userhash = SHA256(username ":" realm) 1785 14.5. MESSAGE-INTEGRITY 1787 The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of 1788 the STUN message. The MESSAGE-INTEGRITY attribute can be present in 1789 any STUN message type. Since it uses the SHA1 hash, the HMAC will be 1790 at 20 bytes. 1792 The text used as input to HMAC is the STUN message, including the 1793 header, up to and including the attribute preceding the MESSAGE- 1794 INTEGRITY attribute. With the exception of the MESSAGE-INTEGRITY- 1795 SHA256 and FINGERPRINT attributes, which appear after MESSAGE- 1796 INTEGRITY, agents MUST ignore all other attributes that follow 1797 MESSAGE-INTEGRITY. 1799 The key for the HMAC depends on which credential mechanism is in use. 1800 Section 9.1.1 defines the key for the short-term credential mechanism 1801 and Section 9.2.2 defines the key for the long-term credential 1802 mechanism. Other credential mechanisms MUST define the key that is 1803 used for the HMAC. 1805 Based on the rules above, the hash used to construct MESSAGE- 1806 INTEGRITY includes the length field from the STUN message header. 1807 Prior to performing the hash, the MESSAGE-INTEGRITY attribute MUST be 1808 inserted into the message (with dummy content). The length MUST then 1809 be set to point to the length of the message up to, and including, 1810 the MESSAGE-INTEGRITY attribute itself, but excluding any attributes 1811 after it. Once the computation is performed, the value of the 1812 MESSAGE-INTEGRITY attribute can be filled in, and the value of the 1813 length in the STUN header can be set to its correct value -- the 1814 length of the entire message. Similarly, when validating the 1815 MESSAGE-INTEGRITY, the length field should be adjusted to point to 1816 the end of the MESSAGE-INTEGRITY attribute prior to calculating the 1817 HMAC. Such adjustment is necessary when attributes, such as 1818 FINGERPRINT, appear after MESSAGE-INTEGRITY. 1820 14.6. MESSAGE-INTEGRITY-SHA256 1822 The MESSAGE-INTEGRITY-SHA256 attribute contains an HMAC-SHA-256 1823 [RFC2104] of the STUN message. The MESSAGE-INTEGRITY-SHA256 1824 attribute can be present in any STUN message type. Since it uses the 1825 SHA1 hash, the HMAC will be at most 32 bytes. The HMAC MUST NOT be 1826 truncated below a minimum size of 16 bytes. If truncation is 1827 employed then the HMAC size MUST be a multiple of 4. Truncation MUST 1828 be done by stripping off the final bytes. STUN Usages can define 1829 their own truncation limits, as long as they adhere to the guidelines 1830 specificed above. STUN Usages that do not define truncation limits 1831 MUST NOT use truncation at all. 1833 The text used as input to HMAC is the STUN message, including the 1834 header, up to and including the attribute preceding the MESSAGE- 1835 INTEGRITY-SHA256 attribute. With the exception of the FINGERPRINT 1836 attribute, which appears after MESSAGE-INTEGRITY-SHA256, agents MUST 1837 ignore all other attributes that follow MESSAGE-INTEGRITY-SHA256. 1839 The key for the HMAC depends on which credential mechanism is in use. 1840 Section 9.1.1 defines the key for the short-term credential mechanism 1841 and Section 9.2.2 defines the key for the long-term credential 1842 mechanism. Other credential mechanism MUST define the key that is 1843 used for the HMAC. 1845 Based on the rules above, the hash used to construct MESSAGE- 1846 INTEGRITY-SHA256 includes the length field from the STUN message 1847 header. Prior to performing the hash, the MESSAGE-INTEGRITY-SHA256 1848 attribute MUST be inserted into the message (with dummy content). 1849 The length MUST then be set to point to the length of the message up 1850 to, and including, the MESSAGE-INTEGRITY-SHA256 attribute itself, but 1851 excluding any attributes after it. Once the computation is 1852 performed, the value of the MESSAGE-INTEGRITY-SHA256 attribute can be 1853 filled in, and the value of the length in the STUN header can be set 1854 to its correct value -- the length of the entire message. Similarly, 1855 when validating the MESSAGE-INTEGRITY-SHA256, the length field should 1856 be adjusted to point to the end of the MESSAGE-INTEGRITY-SHA256 1857 attribute prior to calculating the HMAC. Such adjustment is 1858 necessary when attributes, such as FINGERPRINT, appear after MESSAGE- 1859 INTEGRITY-SHA256. 1861 14.7. FINGERPRINT 1863 The FINGERPRINT attribute MAY be present in all STUN messages. The 1864 value of the attribute is computed as the CRC-32 of the STUN message 1865 up to (but excluding) the FINGERPRINT attribute itself, XOR'ed with 1866 the 32-bit value 0x5354554e (the XOR helps in cases where an 1867 application packet is also using CRC-32 in it). The 32-bit CRC is 1868 the one defined in ITU V.42 [ITU.V42.2002], which has a generator 1869 polynomial of x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1. 1870 See the sample code for the CRC-32 in Section 8 of [RFC1952]. 1872 When present, the FINGERPRINT attribute MUST be the last attribute in 1873 the message, and thus will appear after MESSAGE-INTEGRITY. 1875 The FINGERPRINT attribute can aid in distinguishing STUN packets from 1876 packets of other protocols. See Section 7. 1878 As with MESSAGE-INTEGRITY, the CRC used in the FINGERPRINT attribute 1879 covers the length field from the STUN message header. Therefore, 1880 this value must be correct and include the CRC attribute as part of 1881 the message length, prior to computation of the CRC. When using the 1882 FINGERPRINT attribute in a message, the attribute is first placed 1883 into the message with a dummy value, then the CRC is computed, and 1884 then the value of the attribute is updated. If the MESSAGE-INTEGRITY 1885 attribute is also present, then it must be present with the correct 1886 message-integrity value before the CRC is computed, since the CRC is 1887 done over the value of the MESSAGE-INTEGRITY attribute as well. 1889 14.8. ERROR-CODE 1891 The ERROR-CODE attribute is used in error response messages. It 1892 contains a numeric error code value in the range of 300 to 699 plus a 1893 textual reason phrase encoded in UTF-8 [RFC3629], and is consistent 1894 in its code assignments and semantics with SIP [RFC3261] and HTTP 1895 [RFC2616]. The reason phrase is meant for user consumption, and can 1896 be anything appropriate for the error code. Recommended reason 1897 phrases for the defined error codes are included in the IANA registry 1898 for error codes. The reason phrase MUST be a UTF-8 [RFC3629] encoded 1899 sequence of less than 128 characters (which can be as long as 763 1900 bytes). 1902 0 1 2 3 1903 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 1904 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1905 | Reserved, should be 0 |Class| Number | 1906 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1907 | Reason Phrase (variable) .. 1908 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1910 Figure 7: ERROR-CODE Attribute 1912 To facilitate processing, the class of the error code (the hundreds 1913 digit) is encoded separately from the rest of the code, as shown in 1914 Figure 7. 1916 The Reserved bits SHOULD be 0, and are for alignment on 32-bit 1917 boundaries. Receivers MUST ignore these bits. The Class represents 1918 the hundreds digit of the error code. The value MUST be between 3 1919 and 6. The Number represents the error code modulo 100, and its 1920 value MUST be between 0 and 99. 1922 The following error codes, along with their recommended reason 1923 phrases, are defined: 1925 300 Try Alternate: The client should contact an alternate server for 1926 this request. This error response MUST only be sent if the 1927 request included either a USERNAME or USERHASH attribute and a 1928 valid MESSAGE-INTEGRITY attribute; otherwise, it MUST NOT be sent 1929 and error code 400 (Bad Request) is suggested. This error 1930 response MUST be protected with the MESSAGE-INTEGRITY attribute, 1931 and receivers MUST validate the MESSAGE-INTEGRITY of this response 1932 before redirecting themselves to an alternate server. 1934 Note: Failure to generate and validate message integrity for a 300 1935 response allows an on-path attacker to falsify a 300 response thus 1936 causing subsequent STUN messages to be sent to a victim. 1938 400 Bad Request: The request was malformed. The client SHOULD NOT 1939 retry the request without modification from the previous attempt. 1940 The server may not be able to generate a valid MESSAGE-INTEGRITY 1941 for this error, so the client MUST NOT expect a valid MESSAGE- 1942 INTEGRITY attribute on this response. 1944 401 Unauthenticated: The request did not contain the correct 1945 credentials to proceed. The client should retry the request with 1946 proper credentials. 1948 420 Unknown Attribute: The server received a STUN packet containing 1949 a comprehension-required attribute that it did not understand. 1951 The server MUST put this unknown attribute in the UNKNOWN- 1952 ATTRIBUTE attribute of its error response. 1954 438 Stale Nonce: The NONCE used by the client was no longer valid. 1955 The client should retry, using the NONCE provided in the response. 1957 500 Server Error: The server has suffered a temporary error. The 1958 client should try again. 1960 14.9. REALM 1962 The REALM attribute may be present in requests and responses. It 1963 contains text that meets the grammar for "realm-value" as described 1964 in [RFC3261] but without the double quotes and their surrounding 1965 whitespace. That is, it is an unquoted realm-value (and is therefore 1966 a sequence of qdtext or quoted-pair). It MUST be a UTF-8 [RFC3629] 1967 encoded sequence of less than 128 characters (which can be as long as 1968 763 bytes), and MUST have been processed using the OpaqueString 1969 profile [RFC7613]. 1971 Presence of the REALM attribute in a request indicates that long-term 1972 credentials are being used for authentication. Presence in certain 1973 error responses indicates that the server wishes the client to use a 1974 long-term credential for authentication. 1976 14.10. NONCE 1978 The NONCE attribute may be present in requests and responses. It 1979 contains a sequence of qdtext or quoted-pair, which are defined in 1980 RFC 3261 [RFC3261]. Note that this means that the NONCE attribute 1981 will not contain actual quote characters. See [RFC2617], 1982 Section 4.3, for guidance on selection of nonce values in a server. 1983 It MUST be less than 128 characters (which can be as long as 763 1984 bytes). 1986 14.11. PASSWORD-ALGORITHMS 1988 The PASSWORD-ALGORITHMS attribute may be present in requests and 1989 responses. It contains the list of algorithms that the server can 1990 use to derive the long-term password. 1992 The set of known algorithms is maintained by IANA. The initial set 1993 defined by this specification is found in Section 17.5. 1995 The attribute contains a list of algorithm numbers and variable 1996 length parameters. The algorithm number is a 16-bit value as defined 1997 in Section 17.5. The parameters start with the actual length of the 1998 parameters as a 16-bit value, followed by the parameters that are 1999 specific to each algorithm. The parameters are padded to a 32-bit 2000 boundary, in the same manner as an attribute. 2002 0 1 2 3 2003 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 2004 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2005 | Algorithm 1 | Algorithm 1 Parameters Length | 2006 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2007 | Algorithm 1 Parameters (variable) 2008 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2009 | Algorithm 2 | Algorithm 2 Parameters Length | 2010 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2011 | Algorithm 2 Parameter (variable) 2012 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2013 | ... 2015 Figure 8: Format of PASSWORD-ALGORITHMS Attribute 2017 14.12. PASSWORD-ALGORITHM 2019 The PASSWORD-ALGORITHM attribute is present only in requests. It 2020 contains the algorithms that the server must use to derive the long- 2021 term password. 2023 The set of known algorithms is maintained by IANA. The initial set 2024 defined by this specification is found in Section 17.5. 2026 The attribute contains an algorithm number and variable length 2027 parameters. The algorithm number is a 16-bit value as defined in 2028 Section 17.5. The parameters starts with the actual length of the 2029 parameters as a 16-bit value, followed by the parameters that are 2030 specific to the algorithm. The parameters are padded to a 32-bit 2031 boundary, in the same manner as an attribute. 2033 0 1 2 3 2034 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 2035 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2036 | Algorithm | Algorithm Parameters Length | 2037 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2038 | Algorithm Parameters (variable) 2039 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2041 Figure 9: Format of PASSWORD-ALGORITHM Attribute 2043 14.13. UNKNOWN-ATTRIBUTES 2045 The UNKNOWN-ATTRIBUTES attribute is present only in an error response 2046 when the response code in the ERROR-CODE attribute is 420. 2048 The attribute contains a list of 16-bit values, each of which 2049 represents an attribute type that was not understood by the server. 2051 0 1 2 3 2052 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 2053 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2054 | Attribute 1 Type | Attribute 2 Type | 2055 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2056 | Attribute 3 Type | Attribute 4 Type ... 2057 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2059 Figure 10: Format of UNKNOWN-ATTRIBUTES Attribute 2061 Note: In [RFC3489], this field was padded to 32 by duplicating the 2062 last attribute. In this version of the specification, the normal 2063 padding rules for attributes are used instead. 2065 14.14. SOFTWARE 2067 The SOFTWARE attribute contains a textual description of the software 2068 being used by the agent sending the message. It is used by clients 2069 and servers. Its value SHOULD include manufacturer and version 2070 number. The attribute has no impact on operation of the protocol, 2071 and serves only as a tool for diagnostic and debugging purposes. The 2072 value of SOFTWARE is variable length. It MUST be a UTF-8 [RFC3629] 2073 encoded sequence of less than 128 characters (which can be as long as 2074 763 bytes). 2076 14.15. ALTERNATE-SERVER 2078 The alternate server represents an alternate transport address 2079 identifying a different STUN server that the STUN client should try. 2081 It is encoded in the same way as MAPPED-ADDRESS, and thus refers to a 2082 single server by IP address. The IP address family MUST be identical 2083 to that of the source IP address of the request. 2085 14.16. ALTERNATE-DOMAIN 2087 The alternate domain represents the domain name that is used to 2088 verify the IP address in the ALTERNATE-SERVER attribute when the 2089 transport protocol uses TLS or DTLS. 2091 The value of ALTERNATE-DOMAIN is variable length. It MUST be a UTF-8 2092 [RFC3629] encoded sequence of less than 128 characters (which can be 2093 as long as 763 bytes). 2095 15. Security Considerations 2097 15.1. Attacks against the Protocol 2099 15.1.1. Outside Attacks 2101 An attacker can try to modify STUN messages in transit, in order to 2102 cause a failure in STUN operation. These attacks are detected for 2103 both requests and responses through the message-integrity mechanism, 2104 using either a short-term or long-term credential. Of course, once 2105 detected, the manipulated packets will be dropped, causing the STUN 2106 transaction to effectively fail. This attack is possible only by an 2107 on-path attacker. 2109 An attacker that can observe, but not modify, STUN messages in- 2110 transit (for example, an attacker present on a shared access medium, 2111 such as Wi-Fi), can see a STUN request, and then immediately send a 2112 STUN response, typically an error response, in order to disrupt STUN 2113 processing. This attack is also prevented for messages that utilize 2114 MESSAGE-INTEGRITY. However, some error responses, those related to 2115 authentication in particular, cannot be protected by MESSAGE- 2116 INTEGRITY. When STUN itself is run over a secure transport protocol 2117 (e.g., TLS), these attacks are completely mitigated. 2119 Depending on the STUN usage, these attacks may be of minimal 2120 consequence and thus do not require message integrity to mitigate. 2121 For example, when STUN is used to a basic STUN server to discover a 2122 server reflexive candidate for usage with ICE, authentication and 2123 message integrity are not required since these attacks are detected 2124 during the connectivity check phase. The connectivity checks 2125 themselves, however, require protection for proper operation of ICE 2126 overall. As described in Section 13, STUN usages describe when 2127 authentication and message integrity are needed. 2129 Since STUN uses the HMAC of a shared secret for authentication and 2130 integrity protection, it is subject to offline dictionary attacks. 2131 When authentication is utilized, it SHOULD be with a strong password 2132 that is not readily subject to offline dictionary attacks. 2133 Protection of the channel itself, using TLS or DTLS, mitigates these 2134 attacks. 2136 STUN supports both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, 2137 which is subject to bid down attacks by an on-path attacker. 2138 Protection of the channel itself, using TLS or DTLS, mitigates these 2139 attacks. Timely removal of the support of MESSAGE-INTEGRITY in a 2140 future version of STUN is necessary. 2142 15.1.2. Inside Attacks 2144 A rogue client may try to launch a DoS attack against a server by 2145 sending it a large number of STUN requests. Fortunately, STUN 2146 requests can be processed statelessly by a server, making such 2147 attacks hard to launch. 2149 A rogue client may use a STUN server as a reflector, sending it 2150 requests with a falsified source IP address and port. In such a 2151 case, the response would be delivered to that source IP and port. 2152 There is no amplification of the number of packets with this attack 2153 (the STUN server sends one packet for each packet sent by the 2154 client), though there is a small increase in the amount of data, 2155 since STUN responses are typically larger than requests. This attack 2156 is mitigated by ingress source address filtering. 2158 Revealing the specific software version of the agent through the 2159 SOFTWARE attribute might allow them to become more vulnerable to 2160 attacks against software that is known to contain security holes. 2161 Implementers SHOULD make usage of the SOFTWARE attribute a 2162 configurable option. 2164 15.2. Attacks Affecting the Usage 2166 This section lists attacks that might be launched against a usage of 2167 STUN. Each STUN usage must consider whether these attacks are 2168 applicable to it, and if so, discuss counter-measures. 2170 Most of the attacks in this section revolve around an attacker 2171 modifying the reflexive address learned by a STUN client through a 2172 Binding request/response transaction. Since the usage of the 2173 reflexive address is a function of the usage, the applicability and 2174 remediation of these attacks are usage-specific. In common 2175 situations, modification of the reflexive address by an on-path 2176 attacker is easy to do. Consider, for example, the common situation 2177 where STUN is run directly over UDP. In this case, an on-path 2178 attacker can modify the source IP address of the Binding request 2179 before it arrives at the STUN server. The STUN server will then 2180 return this IP address in the XOR-MAPPED-ADDRESS attribute to the 2181 client, and send the response back to that (falsified) IP address and 2182 port. If the attacker can also intercept this response, it can 2183 direct it back towards the client. Protecting against this attack by 2184 using a message-integrity check is impossible, since a message- 2185 integrity value cannot cover the source IP address, since the 2186 intervening NAT must be able to modify this value. Instead, one 2187 solution to preventing the attacks listed below is for the client to 2188 verify the reflexive address learned, as is done in ICE 2189 [I-D.ietf-ice-rfc5245bis]. Other usages may use other means to 2190 prevent these attacks. 2192 15.2.1. Attack I: Distributed DoS (DDoS) against a Target 2194 In this attack, the attacker provides one or more clients with the 2195 same faked reflexive address that points to the intended target. 2196 This will trick the STUN clients into thinking that their reflexive 2197 addresses are equal to that of the target. If the clients hand out 2198 that reflexive address in order to receive traffic on it (for 2199 example, in SIP messages), the traffic will instead be sent to the 2200 target. This attack can provide substantial amplification, 2201 especially when used with clients that are using STUN to enable 2202 multimedia applications. However, it can only be launched against 2203 targets for which packets from the STUN server to the target pass 2204 through the attacker, limiting the cases in which it is possible. 2206 15.2.2. Attack II: Silencing a Client 2208 In this attack, the attacker provides a STUN client with a faked 2209 reflexive address. The reflexive address it provides is a transport 2210 address that routes to nowhere. As a result, the client won't 2211 receive any of the packets it expects to receive when it hands out 2212 the reflexive address. This exploitation is not very interesting for 2213 the attacker. It impacts a single client, which is frequently not 2214 the desired target. Moreover, any attacker that can mount the attack 2215 could also deny service to the client by other means, such as 2216 preventing the client from receiving any response from the STUN 2217 server, or even a DHCP server. As with the attack in Section 15.2.1, 2218 this attack is only possible when the attacker is on path for packets 2219 sent from the STUN server towards this unused IP address. 2221 15.2.3. Attack III: Assuming the Identity of a Client 2223 This attack is similar to attack II. However, the faked reflexive 2224 address points to the attacker itself. This allows the attacker to 2225 receive traffic that was destined for the client. 2227 15.2.4. Attack IV: Eavesdropping 2229 In this attack, the attacker forces the client to use a reflexive 2230 address that routes to itself. It then forwards any packets it 2231 receives to the client. This attack would allow the attacker to 2232 observe all packets sent to the client. However, in order to launch 2233 the attack, the attacker must have already been able to observe 2234 packets from the client to the STUN server. In most cases (such as 2235 when the attack is launched from an access network), this means that 2236 the attacker could already observe packets sent to the client. This 2237 attack is, as a result, only useful for observing traffic by 2238 attackers on the path from the client to the STUN server, but not 2239 generally on the path of packets being routed towards the client. 2241 15.3. Hash Agility Plan 2243 This specification uses both HMAC-SHA-1 and HMAC-SHA-256 for 2244 computation of the message integrity. If, at a later time, HMAC- 2245 SHA-256 is found to be compromised, the following is the remedy that 2246 will be applied. 2248 We will define a STUN extension that introduces a new message- 2249 integrity attribute, computed using a new hash. Clients would be 2250 required to include both the new and old message-integrity attributes 2251 in their requests or indications. A new server will utilize the new 2252 message-integrity attribute, and an old one, the old. After a 2253 transition period where mixed implementations are in deployment, the 2254 old message-integrity attribute will be deprecated by another 2255 specification, and clients will cease including it in requests. 2257 After a transition period, a new document updating this document will 2258 remove the usage of HMAC-SHA-1 for computation of the message- 2259 integrity. 2261 16. IAB Considerations 2263 The IAB has studied the problem of Unilateral Self-Address Fixing 2264 (UNSAF), which is the general process by which a client attempts to 2265 determine its address in another realm on the other side of a NAT 2266 through a collaborative protocol reflection mechanism ([RFC3424]). 2267 STUN can be used to perform this function using a Binding request/ 2268 response transaction if one agent is behind a NAT and the other is on 2269 the public side of the NAT. 2271 The IAB has suggested that protocols developed for this purpose 2272 document a specific set of considerations. Because some STUN usages 2273 provide UNSAF functions (such as ICE [I-D.ietf-ice-rfc5245bis] ), and 2274 others do not (such as SIP Outbound [RFC5626]), answers to these 2275 considerations need to be addressed by the usages themselves. 2277 17. IANA Considerations 2278 17.1. STUN Security Features Registry 2280 A STUN Security Feature set is a 24 bit value. 2282 IANA is requested to create a new registry containing the STUN 2283 Security Features that are protected by the bid down attack 2284 prevention mechanism described in section Section 9.2.1. 2286 The initial STUN Security Features are: 2288 0x000001: Password algorithms 2289 0x000002: Username anonymity 2291 New Security Features are assigned by a Standard Action [RFC5226]. 2293 17.2. STUN Methods Registry 2295 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2296 for the following STUN methods: 2298 0x000: (Reserved) 2299 0x001: Binding 2300 0x002: (Reserved; was SharedSecret) 2302 17.3. STUN Attribute Registry 2304 17.3.1. Updated Attributes 2306 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2307 for the following STUN methods: 2309 Comprehension-required range (0x0000-0x7FFF): 2310 0x0000: (Reserved) 2311 0x0001: MAPPED-ADDRESS 2312 0x0002: (Reserved; was RESPONSE-ADDRESS) 2313 0x0003: (Reserved; was CHANGE-REQUEST) 2314 0x0004: (Reserved; was SOURCE-ADDRESS) 2315 0x0005: (Reserved; was CHANGED-ADDRESS) 2316 0x0006: USERNAME 2317 0x0007: (Reserved; was PASSWORD) 2318 0x0008: MESSAGE-INTEGRITY 2319 0x0009: ERROR-CODE 2320 0x000A: UNKNOWN-ATTRIBUTES 2321 0x000B: (Reserved; was REFLECTED-FROM) 2322 0x0014: REALM 2323 0x0015: NONCE 2324 0x0020: XOR-MAPPED-ADDRESS 2326 Comprehension-optional range (0x8000-0xFFFF) 2327 0x8022: SOFTWARE 2328 0x8023: ALTERNATE-SERVER 2329 0x8028: FINGERPRINT 2331 17.3.2. New Attributes 2333 IANA is requested to add the following attribute to the STUN 2334 Attribute Registry: 2336 Comprehension-required range (0x0000-0x7FFF): 2337 0xXXXX: MESSAGE-INTEGRITY-SHA256 2338 0xXXXX: PASSWORD-ALGORITHM 2339 0xXXXX: USERHASH 2341 Comprehension-optional range (0x8000-0xFFFF) 2342 0xXXXX: PASSSORD-ALGORITHMS 2343 0xXXXX: ALTERNATE-DOMAIN 2345 17.4. STUN Error Code Registry 2347 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2348 for the Error Codes given in Section 14.8. 2350 17.5. Password Algorithm Registry 2352 IANA is requested to create a new registry for Password Algorithm. 2354 A Password Algorithm is a hex number in the range 0x0000 - 0xFFFF. 2356 The initial Password Algorithms are: 2358 0x0001: MD5 2359 0x0002: SHA256 2361 Password Algorithms in the first half of the range (0x0000 - 0x7FFF) 2362 are assigned by IETF Review [RFC5226]. Password Algorithms in the 2363 second half of the range (0x8000 - 0xFFFF) are assigned by Designated 2364 Expert [RFC5226]. 2366 17.5.1. Password Algorithms 2368 17.5.1.1. MD5 2370 This password algorithm is taken from [RFC1321]. 2372 The key length is 20 bytes and the parameters value is empty. 2374 Note: This algorithm MUST only be used for compatibility with legacy 2375 systems. 2377 key = MD5(username ":" realm ":" OpaqueString(password)) 2379 17.5.1.2. SHA256 2381 This password algorithm is taken from [RFC7616]. 2383 The key length is 32 bytes and the parameters value is empty. 2385 key = SHA256(username ":" realm ":" OpaqueString(password)) 2387 17.6. STUN UDP and TCP Port Numbers 2389 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2390 for the following ports: 2392 stun 3478/tcp Session Traversal Utilities for NAT (STUN) port 2393 stun 3478/udp Session Traversal Utilities for NAT (STUN) port 2394 stuns 5349/tcp Session Traversal Utilities for NAT (STUN) port 2396 18. Changes since RFC 5389 2398 This specification obsoletes [RFC5389]. This specification differs 2399 from RFC 5389 in the following ways: 2401 o Added support for DTLS-over-UDP (RFC 6347). 2403 o Made clear that the RTO is considered stale if there is no 2404 transactions with the server. 2406 o Aligned the RTO calculation with RFC 6298. 2408 o Updated the cipher suites for TLS. 2410 o Added support for STUN URI (RFC 7064). 2412 o Added support for SHA256 message integrity. 2414 o Updated the PRECIS support to RFC 7613. 2416 o Added protocol and registry to choose the password encryption 2417 algorithm. 2419 o Added support for anonymous username. 2421 o Added protocol and registry for preventing biddown attacks. 2423 o Sharing a NONCE is no longer permitted. 2425 o Added the possibility of using a domain name in the alternate 2426 server mechanism. 2428 o Added more C snippets. 2430 o Added test vector. 2432 19. References 2434 19.1. Normative References 2436 [ITU.V42.2002] 2437 International Telecommunications Union, "Error-correcting 2438 Procedures for DCEs Using Asynchronous-to-Synchronous 2439 Conversion", ITU-T Recommendation V.42, 2002. 2441 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 2442 DOI 10.17487/RFC0791, September 1981, 2443 . 2445 [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - 2446 Communication Layers", STD 3, RFC 1122, 2447 DOI 10.17487/RFC1122, October 1989, 2448 . 2450 [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, 2451 DOI 10.17487/RFC1321, April 1992, 2452 . 2454 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 2455 Hashing for Message Authentication", RFC 2104, 2456 DOI 10.17487/RFC2104, February 1997, 2457 . 2459 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2460 Requirement Levels", BCP 14, RFC 2119, 2461 DOI 10.17487/RFC2119, March 1997, 2462 . 2464 [RFC2460] Deering, S. and R. Hinden, "Internet Protocol, Version 6 2465 (IPv6) Specification", RFC 2460, DOI 10.17487/RFC2460, 2466 December 1998, . 2468 [RFC2617] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., 2469 Leach, P., Luotonen, A., and L. Stewart, "HTTP 2470 Authentication: Basic and Digest Access Authentication", 2471 RFC 2617, DOI 10.17487/RFC2617, June 1999, 2472 . 2474 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2475 specifying the location of services (DNS SRV)", RFC 2782, 2476 DOI 10.17487/RFC2782, February 2000, 2477 . 2479 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2480 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2481 2003, . 2483 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 2484 (TLS) Protocol Version 1.2", RFC 5246, 2485 DOI 10.17487/RFC5246, August 2008, 2486 . 2488 [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and 2489 Verification of Domain-Based Application Service Identity 2490 within Internet Public Key Infrastructure Using X.509 2491 (PKIX) Certificates in the Context of Transport Layer 2492 Security (TLS)", RFC 6125, DOI 10.17487/RFC6125, March 2493 2011, . 2495 [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, 2496 "Computing TCP's Retransmission Timer", RFC 6298, 2497 DOI 10.17487/RFC6298, June 2011, 2498 . 2500 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 2501 Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, 2502 January 2012, . 2504 [RFC7064] Nandakumar, S., Salgueiro, G., Jones, P., and M. Petit- 2505 Huguenin, "URI Scheme for the Session Traversal Utilities 2506 for NAT (STUN) Protocol", RFC 7064, DOI 10.17487/RFC7064, 2507 November 2013, . 2509 [RFC7350] Petit-Huguenin, M. and G. Salgueiro, "Datagram Transport 2510 Layer Security (DTLS) as Transport for Session Traversal 2511 Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, 2512 August 2014, . 2514 [RFC7613] Saint-Andre, P. and A. Melnikov, "Preparation, 2515 Enforcement, and Comparison of Internationalized Strings 2516 Representing Usernames and Passwords", RFC 7613, 2517 DOI 10.17487/RFC7613, August 2015, 2518 . 2520 19.2. Informative References 2522 [I-D.ietf-ice-rfc5245bis] 2523 Keranen, A. and J. Rosenberg, "Interactive Connectivity 2524 Establishment (ICE): A Protocol for Network Address 2525 Translator (NAT) Traversal", draft-ietf-ice-rfc5245bis-01 2526 (work in progress), December 2015. 2528 [KARN87] Karn, P. and C. Partridge, "Improving Round-Trip Time 2529 Estimates in Reliable Transport Protocols", SIGCOMM 1987, 2530 August 1987. 2532 [RFC1952] Deutsch, P., "GZIP file format specification version 4.3", 2533 RFC 1952, DOI 10.17487/RFC1952, May 1996, 2534 . 2536 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 2537 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 2538 Transfer Protocol -- HTTP/1.1", RFC 2616, 2539 DOI 10.17487/RFC2616, June 1999, 2540 . 2542 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 2543 A., Peterson, J., Sparks, R., Handley, M., and E. 2544 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 2545 DOI 10.17487/RFC3261, June 2002, 2546 . 2548 [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations for 2549 UNilateral Self-Address Fixing (UNSAF) Across Network 2550 Address Translation", RFC 3424, DOI 10.17487/RFC3424, 2551 November 2002, . 2553 [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, 2554 "STUN - Simple Traversal of User Datagram Protocol (UDP) 2555 Through Network Address Translators (NATs)", RFC 3489, 2556 DOI 10.17487/RFC3489, March 2003, 2557 . 2559 [RFC4107] Bellovin, S. and R. Housley, "Guidelines for Cryptographic 2560 Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, 2561 June 2005, . 2563 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 2564 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 2565 DOI 10.17487/RFC5226, May 2008, 2566 . 2568 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 2569 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 2570 DOI 10.17487/RFC5389, October 2008, 2571 . 2573 [RFC5626] Jennings, C., Ed., Mahy, R., Ed., and F. Audet, Ed., 2574 "Managing Client-Initiated Connections in the Session 2575 Initiation Protocol (SIP)", RFC 5626, 2576 DOI 10.17487/RFC5626, October 2009, 2577 . 2579 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 2580 Relays around NAT (TURN): Relay Extensions to Session 2581 Traversal Utilities for NAT (STUN)", RFC 5766, 2582 DOI 10.17487/RFC5766, April 2010, 2583 . 2585 [RFC5769] Denis-Courmont, R., "Test Vectors for Session Traversal 2586 Utilities for NAT (STUN)", RFC 5769, DOI 10.17487/RFC5769, 2587 April 2010, . 2589 [RFC5780] MacDonald, D. and B. Lowekamp, "NAT Behavior Discovery 2590 Using Session Traversal Utilities for NAT (STUN)", 2591 RFC 5780, DOI 10.17487/RFC5780, May 2010, 2592 . 2594 [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B., and A. Roach, 2595 "TCP Candidates with Interactive Connectivity 2596 Establishment (ICE)", RFC 6544, DOI 10.17487/RFC6544, 2597 March 2012, . 2599 [RFC7525] Sheffer, Y., Holz, R., and P. Saint-Andre, 2600 "Recommendations for Secure Use of Transport Layer 2601 Security (TLS) and Datagram Transport Layer Security 2602 (DTLS)", BCP 195, RFC 7525, DOI 10.17487/RFC7525, May 2603 2015, . 2605 [RFC7616] Shekh-Yusef, R., Ed., Ahrens, D., and S. Bremer, "HTTP 2606 Digest Access Authentication", RFC 7616, 2607 DOI 10.17487/RFC7616, September 2015, 2608 . 2610 Appendix A. C Snippet to Determine STUN Message Types 2612 Given a 16-bit STUN message type value in host byte order in msg_type 2613 parameter, below are C macros to determine the STUN message types: 2615 2616 #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) 2617 #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) 2618 #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) 2619 #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) 2620 2622 A function to convert method and class into a message type: 2624 2625 int type(int method, int cls) { 2626 return (method & 0x0F80) << 9 | (method & 0x0070) << 5 2627 | (method & 0x000F) | (cls & 0x0002) << 8 2628 | (cls & 0x0001) << 4; 2629 } 2630 2632 A function to extract the method from the message type: 2634 2635 int method(int type) { 2636 return (type & 0x3E00) >> 2 | (type & 0x00E0) >> 1 2637 | (type & 0x000F); 2638 } 2639 2641 A function to extract the class from the message type: 2643 2644 int cls(int type) { 2645 return (type & 0x0100) >> 7 | (type & 0x0010) >> 4; 2646 } 2647 2649 Appendix B. Test Vectors 2651 This section augments the list of test vectors defined in [RFC5769] 2652 with MESSAGE-INTEGRITY-SHA256. All the formats and definitions 2653 listed in Section 2 of [RFC5769] apply here. 2655 B.1. Sample Request with Long-Term Authentication with MESSAGE- 2656 INTEGRITY-SHA256 and USERHASH 2658 This request uses the following parameters: 2660 Username: "" (without 2661 quotes) unaffected by OpaqueString [RFC7613] processing 2663 Password: "TheMtr" and "TheMatrIX" (without 2664 quotes) respectively before and after OpaqueString processing 2666 Nonce: "obMatJos2AAACf//499k954d6OL34oL9FSTvy64sA" (without quotes) 2668 Realm: "example.org" (without quotes) 2669 00 01 00 9c Request type and message length 2670 21 12 a4 42 Magic cookie 2671 78 ad 34 33 } 2672 c6 ad 72 c0 } Transaction ID 2673 29 da 41 2e } 2674 XX XX 00 20 USERHASH attribute header 2675 4a 3c f3 8f } 2676 ef 69 92 bd } 2677 a9 52 c6 78 } 2678 04 17 da 0f } Userhash value (32 bytes) 2679 24 81 94 15 } 2680 56 9e 60 b2 } 2681 05 c4 6e 41 } 2682 40 7f 17 04 } 2683 00 15 00 29 NONCE attribute header 2684 6f 62 4d 61 } 2685 74 4a 6f 73 } 2686 32 41 41 41 } 2687 43 66 2f 2f } 2688 34 39 39 6b } Nonce value and padding (3 bytes) 2689 39 35 34 64 } 2690 36 4f 4c 33 } 2691 34 6f 4c 39 } 2692 46 53 54 76 } 2693 79 36 34 73 } 2694 41 00 00 00 } 2695 00 14 00 0b REALM attribute header 2696 65 78 61 6d } 2697 70 6c 65 2e } Realm value (11 bytes) and padding (1 byte) 2698 6f 72 67 00 } 2699 XX XX 00 20 MESSAGE-INTEGRITY-SHA256 attribute header 2700 c4 ec a2 b6 } 2701 24 6f 26 be } 2702 bc 2f 77 49 } 2703 07 c2 00 a3 } HMAC-SHA256 value 2704 76 c7 c2 8e } 2705 b4 d1 26 60 } 2706 bb fe 9f 28 } 2707 0e 85 71 f2 } 2709 Note: Before publication, the XX XX placeholder must be replaced by 2710 the value assigned to MESSAGE-INTEGRITY-SHA256 and USERHASH by 2711 IANA. The MESSAGE-INTEGRITY-SHA256 attribute value will need to 2712 be updated after this. 2714 Appendix C. Release notes 2716 This section must be removed before publication as an RFC. 2718 C.1. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf- 2719 tram-stunbis-08 2721 o Removed the reserved value in the security registry, as it does 2722 not make sense in a bitset. 2724 o Updated change list. 2726 o Updated the minimum trancation size for M-I-256 to 16 bytes. 2728 o Changed the truncation order to match RFC 7518. 2730 o Fixed bugs in truncation boundary text. 2732 o Stated that STUN Usages have to explicitly state that they can use 2733 truncation. 2735 o Removed truncation from the MESSAGE-INTEGRITY attrbute. 2737 o Add reference to C code in RFC 1952. 2739 o Replaced RFC 2818 reference to RFC 6125. 2741 C.2. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf- 2742 tram-stunbis-08 2744 o Packets discarded in a reliable or unreliable transaction triggers 2745 an attack error instead of a timeout error. An attack error on a 2746 reliable transport is signaled immediately instead of waiting for 2747 the timeout. 2749 o Explicitly state that a received 400 response without 2750 authentication will be dropped until timeout. 2752 o Clarify the SHOULD omit/include rules in LTCM. 2754 o If the nonce and the hmac are both invalid, then a 401 is sent 2755 instead of a 438. 2757 o The 401 and 438 error response to subsequent requests may use the 2758 previous NONCE/password to authenticate, if they are still 2759 available. 2761 o Change "401 Unauthorized" to "401 Unauthenticated" 2762 o Make clear that in some cases it is impossible to add a MI or MI2 2763 even if the text says SHOULD NOT. 2765 C.3. Modifications between draft-ietf-tram-stunbis-08 and draft-ietf- 2766 tram-stunbis-07 2768 o Updated list of changes since RFC 5389. 2770 o More examples are automatically generated. 2772 o Message integrity truncation is fixed at a multiple of 4 bytes, 2773 because the padding will not decrease by more than this. 2775 o USERHASH contains the 32 bytes of the hash, not a character 2776 string. 2778 o Updated the example to use the USERHASH attribuet and the modified 2779 NONCE attribute. 2781 o Updated ICEbis reference. 2783 C.4. Modifications between draft-ietf-tram-stunbis-07 and draft-ietf- 2784 tram-stunbis-06 2786 o Add USERHASH attribute to carry the hashed version of the 2787 username. 2789 o Add IANA registry and nonce encoding for Security Features that 2790 need to be protected from bid down attacks. 2792 o Modified MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 to support 2793 truncation limits (pending cryptographic review), 2795 C.5. Modifications between draft-ietf-tram-stunbis-06 and draft-ietf- 2796 tram-stunbis-05 2798 o Changed I-D references to RFC references. 2800 o Changed CHANGE-ADDRESS to CHANGE-REQUEST (Errata #4233). 2802 o Added test vector for MESSAGE-INTEGRITY-SHA256. 2804 o Address additional review comments from Jonathan Lennox and 2805 Brandon Williams. 2807 C.6. Modifications between draft-ietf-tram-stunbis-05 and draft-ietf- 2808 tram-stunbis-04 2810 o Address review comments from Jonathan Lennox and Brandon Williams. 2812 C.7. Modifications between draft-ietf-tram-stunbis-04 and draft-ietf- 2813 tram-stunbis-03 2815 o Remove SCTP. 2817 o Remove DANE. 2819 o s/MESSAGE-INTEGRITY2/MESSAGE-INTEGRITY-SHA256/ 2821 o Remove Salted SHA256 password hash. 2823 o The RTO delay between transactions is removed. 2825 o Make clear that reusing NONCE will trigger a wasted round trip. 2827 C.8. Modifications between draft-ietf-tram-stunbis-03 and draft-ietf- 2828 tram-stunbis-02 2830 o SCTP prefix is now 0b00000101 instead of 0x11. 2832 o Add SCTP at various places it was needed. 2834 o Update the hash agility plan to take in account HMAC-SHA-256. 2836 o Adds the bid down attack on message-integrity in the security 2837 section. 2839 C.9. Modifications between draft-ietf-tram-stunbis-02 and draft-ietf- 2840 tram-stunbis-01 2842 o STUN hash algorithm agility (currently only SHA-1 is allowed). 2844 o Clarify terminology, text and guidance for STUN fragmentation. 2846 o Clarify whether it's valid to share nonces across TURN 2847 allocations. 2849 o Prevent the server to allocate the same NONCE to clients with 2850 different IP address and/or different port. This prevent sharing 2851 the nonce between TURN allocations in TURN. 2853 o Add reference to draft-ietf-uta-tls-bcp 2854 o Add a new attribute ALTERNATE-DOMAIN to verify the certificate of 2855 the ALTERNATE-SERVER after a 300 over (D)TLS. 2857 o The RTP delay between transactions applies only to parallel 2858 transactions, not to serial transactions. That prevents a 3RTT 2859 delay between the first transaction and the second transaction 2860 with long term authentication. 2862 o Add text saying ORIGIN can increase a request size beyond the MTU 2863 and so require an SCTPoUDP transport. 2865 o Move the Acknowledgments and Contributor sections to the end of 2866 the document, in accordance with RFC 7322 section 4. 2868 C.10. Modifications between draft-ietf-tram-stunbis-01 and draft-ietf- 2869 tram-stunbis-00 2871 o Add negotiation mechanism for new password algorithms. 2873 o Describe the MESSAGE-INTEGRITY/MESSAGE-INTEGRITY2 protocol. 2875 o Add support for SCTP to solve the fragmentation problem. 2877 o Merge RFC 7350: 2879 * Split the "Sending over..." sections in 3. 2881 * Add DTLS-over-UDP as transport. 2883 * Update the cipher suites and cipher/compression restrictions. 2885 * A stuns uri with an IP address is rejected. 2887 * Replace most of the RFC 3489 compatibility by a reference to 2888 the section in RFC 5389. 2890 * Update the STUN Usages list with transport applicability. 2892 o Merge RFC 7064: 2894 * DNS discovery is done from the URI. 2896 * Reorganized the text about default ports. 2898 o Add more C snippets. 2900 o Make clear that the cached RTO is discarded only if there is no 2901 new transations for 10 minutes. 2903 C.11. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 2904 ietf-tram-stunbis-00 2906 o Draft adopted as WG item. 2908 C.12. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 2909 salgueiro-tram-stunbis-01 2911 o Add definition of MESSAGE-INTEGRITY2. 2913 o Update text and reference from RFC 2988 to RFC 6298. 2915 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 2917 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 2919 o Fix section number and make clear that the original domain name is 2920 used for the server certificate verification. This is consistent 2921 with what RFC 5922 (section 4) is doing. (Errata #2010) 2923 o Remove text transitioning from RFC 3489. 2925 o Add definition of MESSAGE-INTEGRITY2. 2927 o Update text and reference from RFC 2988 to RFC 6298. 2929 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 2931 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 2933 o Fix section number and make clear that the original domain name is 2934 used for the server certificate verification. This is consistent 2935 with what RFC 5922 (section 4) is doing. (Errata #2010) 2937 C.13. Modifications between draft-salgueiro-tram-stunbis-01 and draft- 2938 salgueiro-tram-stunbis-00 2940 o Restore the RFC 5389 text. 2942 o Add list of open issues. 2944 Acknowledgements 2946 Thanks to Michael Tuexen, Tirumaleswar Reddy, Oleg Moskalenko, Simon 2947 Perreault, Benjamin Schwartz, Rifaat Shekh-Yusef, Alan Johnston, 2948 Jonathan Lennox, Brandon Williams, Olle Johansson, and Martin Thomson 2949 for the comments, suggestions, and questions that helped improve this 2950 document. 2952 The authors of RFC 5389 would like to thank Cedric Aoun, Pete 2953 Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, Magnus 2954 Westerlund, Miguel Garcia, Bruce Lowekamp, and Chris Sullivan for 2955 their comments, and Baruch Sterman and Alan Hawrylyshen for initial 2956 implementations. Thanks for Leslie Daigle, Allison Mankin, Eric 2957 Rescorla, and Henning Schulzrinne for IESG and IAB input on this 2958 work. 2960 Contributors 2962 Christian Huitema and Joel Weinberger were original co-authors of RFC 2963 3489. 2965 Authors' Addresses 2967 Marc Petit-Huguenin 2968 Impedance Mismatch 2970 Email: marc@petit-huguenin.org 2972 Gonzalo Salgueiro 2973 Cisco 2974 7200-12 Kit Creek Road 2975 Research Triangle Park, NC 27709 2976 US 2978 Email: gsalguei@cisco.com 2980 Jonathan Rosenberg 2981 Cisco 2982 Edison, NJ 2983 US 2985 Email: jdrosen@cisco.com 2986 URI: http://www.jdrosen.net 2988 Dan Wing 2989 Cisco 2990 771 Alder Drive 2991 San Jose, CA 95035 2992 US 2994 Email: dwing@cisco.com 2995 Rohan Mahy 2996 Plantronics 2997 345 Encinal Street 2998 Santa Cruz, CA 95060 2999 US 3001 Email: rohan@ekabal.com 3003 Philip Matthews 3004 Avaya 3005 1135 Innovation Drive 3006 Ottawa, Ontario K2K 3G7 3007 Canada 3009 Phone: +1 613 592 4343 x224 3010 Email: philip_matthews@magma.ca