idnits 2.17.1 draft-ietf-tram-stunbis-21.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 date (March 21, 2019) is 1857 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' -- Possible downref: Non-RFC (?) normative reference: ref. 'KARN87' ** Downref: Normative reference to an Informational RFC: RFC 1321 ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 6125 (Obsoleted by RFC 9525) ** Downref: Normative reference to an Informational RFC: RFC 6151 ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) -- Obsolete informational reference (is this intentional?): RFC 7525 (ref. 'BCP195') (Obsoleted by RFC 9325) == Outdated reference: A later version (-20) exists of draft-ietf-tram-stun-pmtud-10 == Outdated reference: A later version (-13) exists of draft-irtf-cfrg-argon2-04 -- Obsolete informational reference (is this intentional?): RFC 3489 (Obsoleted by RFC 5389) -- 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 7231 (Obsoleted by RFC 9110) Summary: 6 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 Cisco 6 Expires: September 22, 2019 J. Rosenberg 7 Five9 8 D. Wing 10 R. Mahy 11 Unaffiliated 12 P. Matthews 13 Nokia 14 March 21, 2019 16 Session Traversal Utilities for NAT (STUN) 17 draft-ietf-tram-stunbis-21 19 Abstract 21 Session Traversal Utilities for NAT (STUN) is a protocol that serves 22 as a tool for other protocols in dealing with Network Address 23 Translator (NAT) traversal. It can be used by an endpoint to 24 determine the IP address and port allocated to it by a NAT. It can 25 also be used to check connectivity between two endpoints, and as a 26 keep-alive protocol to maintain NAT bindings. STUN works with many 27 existing NATs, and does not require any special behavior from them. 29 STUN is not a NAT traversal solution by itself. Rather, it is a tool 30 to be used in the context of a NAT traversal solution. 32 This document obsoletes RFC 5389. 34 Status of This Memo 36 This Internet-Draft is submitted in full conformance with the 37 provisions of BCP 78 and BCP 79. 39 Internet-Drafts are working documents of the Internet Engineering 40 Task Force (IETF). Note that other groups may also distribute 41 working documents as Internet-Drafts. The list of current Internet- 42 Drafts is at https://datatracker.ietf.org/drafts/current/. 44 Internet-Drafts are draft documents valid for a maximum of six months 45 and may be updated, replaced, or obsoleted by other documents at any 46 time. It is inappropriate to use Internet-Drafts as reference 47 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on September 22, 2019. 50 Copyright Notice 52 Copyright (c) 2019 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (https://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 5 68 2. Overview of Operation . . . . . . . . . . . . . . . . . . . . 6 69 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 8 70 4. Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 8 71 5. STUN Message Structure . . . . . . . . . . . . . . . . . . . 10 72 6. Base Protocol Procedures . . . . . . . . . . . . . . . . . . 12 73 6.1. Forming a Request or an Indication . . . . . . . . . . . 12 74 6.2. Sending the Request or Indication . . . . . . . . . . . . 13 75 6.2.1. Sending over UDP or DTLS-over-UDP . . . . . . . . . . 14 76 6.2.2. Sending over TCP or TLS-over-TCP . . . . . . . . . . 15 77 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP . . . . . 16 78 6.3. Receiving a STUN Message . . . . . . . . . . . . . . . . 17 79 6.3.1. Processing a Request . . . . . . . . . . . . . . . . 18 80 6.3.1.1. Forming a Success or Error Response . . . . . . . 18 81 6.3.1.2. Sending the Success or Error Response . . . . . . 19 82 6.3.2. Processing an Indication . . . . . . . . . . . . . . 19 83 6.3.3. Processing a Success Response . . . . . . . . . . . . 20 84 6.3.4. Processing an Error Response . . . . . . . . . . . . 20 85 7. FINGERPRINT Mechanism . . . . . . . . . . . . . . . . . . . . 21 86 8. DNS Discovery of a Server . . . . . . . . . . . . . . . . . . 21 87 8.1. STUN URI Scheme Semantics . . . . . . . . . . . . . . . . 22 88 9. Authentication and Message-Integrity Mechanisms . . . . . . . 23 89 9.1. Short-Term Credential Mechanism . . . . . . . . . . . . . 23 90 9.1.1. HMAC Key . . . . . . . . . . . . . . . . . . . . . . 24 91 9.1.2. Forming a Request or Indication . . . . . . . . . . . 24 92 9.1.3. Receiving a Request or Indication . . . . . . . . . . 24 93 9.1.4. Receiving a Response . . . . . . . . . . . . . . . . 25 94 9.1.5. Sending Subsequent Requests . . . . . . . . . . . . . 26 95 9.2. Long-Term Credential Mechanism . . . . . . . . . . . . . 26 96 9.2.1. Bid Down Attack Prevention . . . . . . . . . . . . . 28 97 9.2.2. HMAC Key . . . . . . . . . . . . . . . . . . . . . . 28 98 9.2.3. Forming a Request . . . . . . . . . . . . . . . . . . 29 99 9.2.3.1. First Request . . . . . . . . . . . . . . . . . . 29 100 9.2.3.2. Subsequent Requests . . . . . . . . . . . . . . . 29 101 9.2.4. Receiving a Request . . . . . . . . . . . . . . . . . 30 102 9.2.5. Receiving a Response . . . . . . . . . . . . . . . . 32 103 10. ALTERNATE-SERVER Mechanism . . . . . . . . . . . . . . . . . 33 104 11. Backwards Compatibility with RFC 3489 . . . . . . . . . . . . 34 105 12. Basic Server Behavior . . . . . . . . . . . . . . . . . . . . 35 106 13. STUN Usages . . . . . . . . . . . . . . . . . . . . . . . . . 36 107 14. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . . 37 108 14.1. MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . . . 38 109 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . 39 110 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . . . . 40 111 14.4. USERHASH . . . . . . . . . . . . . . . . . . . . . . . . 40 112 14.5. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . . . . 40 113 14.6. MESSAGE-INTEGRITY-SHA256 . . . . . . . . . . . . . . . . 41 114 14.7. FINGERPRINT . . . . . . . . . . . . . . . . . . . . . . 42 115 14.8. ERROR-CODE . . . . . . . . . . . . . . . . . . . . . . . 42 116 14.9. REALM . . . . . . . . . . . . . . . . . . . . . . . . . 44 117 14.10. NONCE . . . . . . . . . . . . . . . . . . . . . . . . . 44 118 14.11. PASSWORD-ALGORITHMS . . . . . . . . . . . . . . . . . . 44 119 14.12. PASSWORD-ALGORITHM . . . . . . . . . . . . . . . . . . . 45 120 14.13. UNKNOWN-ATTRIBUTES . . . . . . . . . . . . . . . . . . . 46 121 14.14. SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . 46 122 14.15. ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . 46 123 14.16. ALTERNATE-DOMAIN . . . . . . . . . . . . . . . . . . . . 47 124 15. Operational Considerations . . . . . . . . . . . . . . . . . 47 125 16. Security Considerations . . . . . . . . . . . . . . . . . . . 47 126 16.1. Attacks against the Protocol . . . . . . . . . . . . . . 47 127 16.1.1. Outside Attacks . . . . . . . . . . . . . . . . . . 47 128 16.1.2. Inside Attacks . . . . . . . . . . . . . . . . . . . 48 129 16.1.3. Bid-Down Attacks . . . . . . . . . . . . . . . . . . 49 130 16.2. Attacks Affecting the Usage . . . . . . . . . . . . . . 51 131 16.2.1. Attack I: Distributed DoS (DDoS) against a Target . 51 132 16.2.2. Attack II: Silencing a Client . . . . . . . . . . . 52 133 16.2.3. Attack III: Assuming the Identity of a Client . . . 52 134 16.2.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . 52 135 16.3. Hash Agility Plan . . . . . . . . . . . . . . . . . . . 52 136 17. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 53 137 18. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 54 138 18.1. STUN Security Features Registry . . . . . . . . . . . . 54 139 18.2. STUN Methods Registry . . . . . . . . . . . . . . . . . 54 140 18.3. STUN Attribute Registry . . . . . . . . . . . . . . . . 54 141 18.3.1. Updated Attributes . . . . . . . . . . . . . . . . . 54 142 18.3.2. New Attributes . . . . . . . . . . . . . . . . . . . 55 143 18.4. STUN Error Code Registry . . . . . . . . . . . . . . . . 55 144 18.5. STUN Password Algorithm Registry . . . . . . . . . . . . 55 145 18.5.1. Password Algorithms . . . . . . . . . . . . . . . . 56 146 18.5.1.1. MD5 . . . . . . . . . . . . . . . . . . . . . . 56 147 18.5.1.2. SHA-256 . . . . . . . . . . . . . . . . . . . . 56 148 18.6. STUN UDP and TCP Port Numbers . . . . . . . . . . . . . 56 149 19. Changes Since RFC 5389 . . . . . . . . . . . . . . . . . . . 57 150 20. References . . . . . . . . . . . . . . . . . . . . . . . . . 57 151 20.1. Normative References . . . . . . . . . . . . . . . . . . 57 152 20.2. Informative References . . . . . . . . . . . . . . . . . 60 153 Appendix A. C Snippet to Determine STUN Message Types . . . . . 62 154 Appendix B. Test Vectors . . . . . . . . . . . . . . . . . . . . 63 155 B.1. Sample Request with Long-Term Authentication with 156 MESSAGE-INTEGRITY-SHA256 and USERHASH . . . . . . . . . . 63 157 Appendix C. Release notes . . . . . . . . . . . . . . . . . . . 65 158 C.1. Modifications between draft-ietf-tram-stunbis-21 and 159 draft-ietf-tram-stunbis-20 . . . . . . . . . . . . . . . 65 160 C.2. Modifications between draft-ietf-tram-stunbis-20 and 161 draft-ietf-tram-stunbis-19 . . . . . . . . . . . . . . . 65 162 C.3. Modifications between draft-ietf-tram-stunbis-19 and 163 draft-ietf-tram-stunbis-18 . . . . . . . . . . . . . . . 65 164 C.4. Modifications between draft-ietf-tram-stunbis-18 and 165 draft-ietf-tram-stunbis-17 . . . . . . . . . . . . . . . 65 166 C.5. Modifications between draft-ietf-tram-stunbis-17 and 167 draft-ietf-tram-stunbis-16 . . . . . . . . . . . . . . . 65 168 C.6. Modifications between draft-ietf-tram-stunbis-16 and 169 draft-ietf-tram-stunbis-15 . . . . . . . . . . . . . . . 65 170 C.7. Modifications between draft-ietf-tram-stunbis-15 and 171 draft-ietf-tram-stunbis-14 . . . . . . . . . . . . . . . 66 172 C.8. Modifications between draft-ietf-tram-stunbis-14 and 173 draft-ietf-tram-stunbis-13 . . . . . . . . . . . . . . . 66 174 C.9. Modifications between draft-ietf-tram-stunbis-13 and 175 draft-ietf-tram-stunbis-12 . . . . . . . . . . . . . . . 67 176 C.10. Modifications between draft-ietf-tram-stunbis-12 and 177 draft-ietf-tram-stunbis-11 . . . . . . . . . . . . . . . 67 178 C.11. Modifications between draft-ietf-tram-stunbis-11 and 179 draft-ietf-tram-stunbis-10 . . . . . . . . . . . . . . . 67 180 C.12. Modifications between draft-ietf-tram-stunbis-10 and 181 draft-ietf-tram-stunbis-09 . . . . . . . . . . . . . . . 68 182 C.13. Modifications between draft-ietf-tram-stunbis-09 and 183 draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 68 184 C.14. Modifications between draft-ietf-tram-stunbis-08 and 185 draft-ietf-tram-stunbis-07 . . . . . . . . . . . . . . . 69 186 C.15. Modifications between draft-ietf-tram-stunbis-07 and 187 draft-ietf-tram-stunbis-06 . . . . . . . . . . . . . . . 69 188 C.16. Modifications between draft-ietf-tram-stunbis-06 and 189 draft-ietf-tram-stunbis-05 . . . . . . . . . . . . . . . 69 190 C.17. Modifications between draft-ietf-tram-stunbis-05 and 191 draft-ietf-tram-stunbis-04 . . . . . . . . . . . . . . . 69 193 C.18. Modifications between draft-ietf-tram-stunbis-04 and 194 draft-ietf-tram-stunbis-03 . . . . . . . . . . . . . . . 70 195 C.19. Modifications between draft-ietf-tram-stunbis-03 and 196 draft-ietf-tram-stunbis-02 . . . . . . . . . . . . . . . 70 197 C.20. Modifications between draft-ietf-tram-stunbis-02 and 198 draft-ietf-tram-stunbis-01 . . . . . . . . . . . . . . . 70 199 C.21. Modifications between draft-ietf-tram-stunbis-01 and 200 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 71 201 C.22. Modifications between draft-salgueiro-tram-stunbis-02 and 202 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 72 203 C.23. Modifications between draft-salgueiro-tram-stunbis-02 and 204 draft-salgueiro-tram-stunbis-01 . . . . . . . . . . . . . 72 205 C.24. Modifications between draft-salgueiro-tram-stunbis-01 and 206 draft-salgueiro-tram-stunbis-00 . . . . . . . . . . . . . 72 207 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 72 208 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 73 209 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 73 211 1. Introduction 213 The protocol defined in this specification, Session Traversal 214 Utilities for NAT, provides a tool for dealing with NATs. It 215 provides a means for an endpoint to determine the IP address and port 216 allocated by a NAT that corresponds to its private IP address and 217 port. It also provides a way for an endpoint to keep a NAT binding 218 alive. With some extensions, the protocol can be used to do 219 connectivity checks between two endpoints [RFC8445], or to relay 220 packets between two endpoints [RFC5766]. 222 In keeping with its tool nature, this specification defines an 223 extensible packet format, defines operation over several transport 224 protocols, and provides for two forms of authentication. 226 STUN is intended to be used in the context of one or more NAT 227 traversal solutions. These solutions are known as STUN usages. Each 228 usage describes how STUN is utilized to achieve the NAT traversal 229 solution. Typically, a usage indicates when STUN messages get sent, 230 which optional attributes to include, what server is used, and what 231 authentication mechanism is to be used. Interactive Connectivity 232 Establishment (ICE) [RFC8445] is one usage of STUN. SIP Outbound 233 [RFC5626] is another usage of STUN. In some cases, a usage will 234 require extensions to STUN. A STUN extension can be in the form of 235 new methods, attributes, or error response codes. More information 236 on STUN usages can be found in Section 13. 238 2. Overview of Operation 240 This section is descriptive only. 242 /-----\ 243 // STUN \\ 244 | Server | 245 \\ // 246 \-----/ 248 +--------------+ Public Internet 249 ................| NAT 2 |....................... 250 +--------------+ 252 +--------------+ Private NET 2 253 ................| NAT 1 |....................... 254 +--------------+ 256 /-----\ 257 // STUN \\ 258 | Client | 259 \\ // Private NET 1 260 \-----/ 262 Figure 1: One Possible STUN Configuration 264 One possible STUN configuration is shown in Figure 1. In this 265 configuration, there are two entities (called STUN agents) that 266 implement the STUN protocol. The lower agent in the figure is the 267 client, and is connected to private network 1. This network connects 268 to private network 2 through NAT 1. Private network 2 connects to 269 the public Internet through NAT 2. The upper agent in the figure is 270 the server, and resides on the public Internet. 272 STUN is a client-server protocol. It supports two types of 273 transactions. One is a request/response transaction in which a 274 client sends a request to a server, and the server returns a 275 response. The second is an indication transaction in which either 276 agent -- client or server -- sends an indication that generates no 277 response. Both types of transactions include a transaction ID, which 278 is a randomly selected 96-bit number. For request/response 279 transactions, this transaction ID allows the client to associate the 280 response with the request that generated it; for indications, the 281 transaction ID serves as a debugging aid. 283 All STUN messages start with a fixed header that includes a method, a 284 class, and the transaction ID. The method indicates which of the 285 various requests or indications this is; this specification defines 286 just one method, Binding, but other methods are expected to be 287 defined in other documents. The class indicates whether this is a 288 request, a success response, an error response, or an indication. 289 Following the fixed header comes zero or more attributes, which are 290 Type-Length-Value extensions that convey additional information for 291 the specific message. 293 This document defines a single method called Binding. The Binding 294 method can be used either in request/response transactions or in 295 indication transactions. When used in request/response transactions, 296 the Binding method can be used to determine the particular "binding" 297 a NAT has allocated to a STUN client. When used in either request/ 298 response or in indication transactions, the Binding method can also 299 be used to keep these "bindings" alive. 301 In the Binding request/response transaction, a Binding request is 302 sent from a STUN client to a STUN server. When the Binding request 303 arrives at the STUN server, it may have passed through one or more 304 NATs between the STUN client and the STUN server (in Figure 1, there 305 were two such NATs). As the Binding request message passes through a 306 NAT, the NAT will modify the source transport address (that is, the 307 source IP address and the source port) of the packet. As a result, 308 the source transport address of the request received by the server 309 will be the public IP address and port created by the NAT closest to 310 the server. This is called a reflexive transport address. The STUN 311 server copies that source transport address into an XOR-MAPPED- 312 ADDRESS attribute in the STUN Binding response and sends the Binding 313 response back to the STUN client. As this packet passes back through 314 a NAT, the NAT will modify the destination transport address in the 315 IP header, but the transport address in the XOR-MAPPED-ADDRESS 316 attribute within the body of the STUN response will remain untouched. 317 In this way, the client can learn its reflexive transport address 318 allocated by the outermost NAT with respect to the STUN server. 320 In some usages, STUN must be multiplexed with other protocols (e.g., 321 [RFC8445], [RFC5626]). In these usages, there must be a way to 322 inspect a packet and determine if it is a STUN packet or not. STUN 323 provides three fields in the STUN header with fixed values that can 324 be used for this purpose. If this is not sufficient, then STUN 325 packets can also contain a FINGERPRINT value, which can further be 326 used to distinguish the packets. 328 STUN defines a set of optional procedures that a usage can decide to 329 use, called mechanisms. These mechanisms include DNS discovery, a 330 redirection technique to an alternate server, a fingerprint attribute 331 for demultiplexing, and two authentication and message-integrity 332 exchanges. The authentication mechanisms revolve around the use of a 333 username, password, and message-integrity value. Two authentication 334 mechanisms, the long-term credential mechanism and the short-term 335 credential mechanism, are defined in this specification. Each usage 336 specifies the mechanisms allowed with that usage. 338 In the long-term credential mechanism, the client and server share a 339 pre-provisioned username and password and perform a digest challenge/ 340 response exchange inspired by (but differing in details) to the one 341 defined for HTTP [RFC7616]. In the short-term credential mechanism, 342 the client and the server exchange a username and password through 343 some out-of-band method prior to the STUN exchange. For example, in 344 the ICE usage [RFC8445] the two endpoints use out-of-band signaling 345 to exchange a username and password. These are used to integrity 346 protect and authenticate the request and response. There is no 347 challenge or nonce used. 349 3. Terminology 351 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 352 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 353 "OPTIONAL" in this document are to be interpreted as described in BCP 354 14 [RFC2119][RFC8174] when, and only when, they appear in all 355 capitals, as shown here. 357 4. Definitions 359 STUN Agent: A STUN agent is an entity that implements the STUN 360 protocol. The entity can be either a STUN client or a STUN 361 server. 363 STUN Client: A STUN client is an entity that sends STUN requests and 364 receives STUN responses and STUN indications. A STUN client can 365 also send indications. In this specification, the terms STUN 366 client and client are synonymous. 368 STUN Server: A STUN server is an entity that receives STUN requests 369 and STUN indications, and sends STUN responses. A STUN server can 370 also send indications. In this specification, the terms STUN 371 server and server are synonymous. 373 Transport Address: The combination of an IP address and port number 374 (such as a UDP or TCP port number). 376 Reflexive Transport Address: A transport address learned by a client 377 that identifies that client as seen by another host on an IP 378 network, typically a STUN server. When there is an intervening 379 NAT between the client and the other host, the reflexive transport 380 address represents the mapped address allocated to the client on 381 the public side of the NAT. Reflexive transport addresses are 382 learned from the mapped address attribute (MAPPED-ADDRESS or XOR- 383 MAPPED-ADDRESS) in STUN responses. 385 Mapped Address: Same meaning as reflexive address. This term is 386 retained only for historic reasons and due to the naming of the 387 MAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. 389 Long-Term Credential: A username and associated password that 390 represent a shared secret between client and server. Long-term 391 credentials are generally granted to the client when a subscriber 392 enrolls in a service and persist until the subscriber leaves the 393 service or explicitly changes the credential. 395 Long-Term Password: The password from a long-term credential. 397 Short-Term Credential: A temporary username and associated password 398 that represent a shared secret between client and server. Short- 399 term credentials are obtained through some kind of protocol 400 mechanism between the client and server, preceding the STUN 401 exchange. A short-term credential has an explicit temporal scope, 402 which may be based on a specific amount of time (such as 5 403 minutes) or on an event (such as termination of a Session 404 Initiation Protocol (SIP [RFC3261]) dialog). The specific scope 405 of a short-term credential is defined by the application usage. 407 Short-Term Password: The password component of a short-term 408 credential. 410 STUN Indication: A STUN message that does not receive a response. 412 Attribute: The STUN term for a Type-Length-Value (TLV) object that 413 can be added to a STUN message. Attributes are divided into two 414 types: comprehension-required and comprehension-optional. STUN 415 agents can safely ignore comprehension-optional attributes they 416 don't understand, but cannot successfully process a message if it 417 contains comprehension-required attributes that are not 418 understood. 420 RTO: Retransmission TimeOut, which defines the initial period of 421 time between transmission of a request and the first retransmit of 422 that request. 424 5. STUN Message Structure 426 STUN messages are encoded in binary using network-oriented format 427 (most significant byte or octet first, also commonly known as big- 428 endian). The transmission order is described in detail in Appendix B 429 of [RFC0791]. Unless otherwise noted, numeric constants are in 430 decimal (base 10). 432 All STUN messages comprise a 20-byte header followed by zero or more 433 Attributes. The STUN header contains a STUN message type, message 434 length, magic cookie, and transaction ID. 436 0 1 2 3 437 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 438 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 439 |0 0| STUN Message Type | Message Length | 440 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 441 | Magic Cookie | 442 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 443 | | 444 | Transaction ID (96 bits) | 445 | | 446 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 448 Figure 2: Format of STUN Message Header 450 The most significant 2 bits of every STUN message MUST be zeroes. 451 This can be used to differentiate STUN packets from other protocols 452 when STUN is multiplexed with other protocols on the same port. 454 The message type defines the message class (request, success 455 response, error response, or indication) and the message method (the 456 primary function) of the STUN message. Although there are four 457 message classes, there are only two types of transactions in STUN: 458 request/response transactions (which consist of a request message and 459 a response message) and indication transactions (which consist of a 460 single indication message). Response classes are split into error 461 and success responses to aid in quickly processing the STUN message. 463 The message type field is decomposed further into the following 464 structure: 466 0 1 467 2 3 4 5 6 7 8 9 0 1 2 3 4 5 468 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 469 |M |M |M|M|M|C|M|M|M|C|M|M|M|M| 470 |11|10|9|8|7|1|6|5|4|0|3|2|1|0| 471 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 473 Figure 3: Format of STUN Message Type Field 475 Here the bits in the message type field are shown as most significant 476 (M11) through least significant (M0). M11 through M0 represent a 477 12-bit encoding of the method. C1 and C0 represent a 2-bit encoding 478 of the class. A class of 0b00 is a request, a class of 0b01 is an 479 indication, a class of 0b10 is a success response, and a class of 480 0b11 is an error response. This specification defines a single 481 method, Binding. The method and class are orthogonal, so that for 482 each method, a request, success response, error response, and 483 indication are possible for that method. Extensions defining new 484 methods MUST indicate which classes are permitted for that method. 486 For example, a Binding request has class=0b00 (request) and 487 method=0b000000000001 (Binding) and is encoded into the first 16 bits 488 as 0x0001. A Binding response has class=0b10 (success response) and 489 method=0b000000000001, and is encoded into the first 16 bits as 490 0x0101. 492 Note: This unfortunate encoding is due to assignment of values in 493 [RFC3489] that did not consider encoding Indications, Success, and 494 Errors using bit fields. 496 The magic cookie field MUST contain the fixed value 0x2112A442 in 497 network byte order. In [RFC3489], this field was part of the 498 transaction ID; placing the magic cookie in this location allows a 499 server to detect if the client will understand certain attributes 500 that were added to STUN by [RFC5389]. In addition, it aids in 501 distinguishing STUN packets from packets of other protocols when STUN 502 is multiplexed with those other protocols on the same port. 504 The transaction ID is a 96-bit identifier, used to uniquely identify 505 STUN transactions. For request/response transactions, the 506 transaction ID is chosen by the STUN client for the request and 507 echoed by the server in the response. For indications, it is chosen 508 by the agent sending the indication. It primarily serves to 509 correlate requests with responses, though it also plays a small role 510 in helping to prevent certain types of attacks. The server also uses 511 the transaction ID as a key to identify each transaction uniquely 512 across all clients. As such, the transaction ID MUST be uniformly 513 and randomly chosen from the interval 0 .. 2**96-1, and MUST be 514 cryptographically random. Resends of the same request reuse the same 515 transaction ID, but the client MUST choose a new transaction ID for 516 new transactions unless the new request is bit-wise identical to the 517 previous request and sent from the same transport address to the same 518 IP address. Success and error responses MUST carry the same 519 transaction ID as their corresponding request. When an agent is 520 acting as a STUN server and STUN client on the same port, the 521 transaction IDs in requests sent by the agent have no relationship to 522 the transaction IDs in requests received by the agent. 524 The message length MUST contain the size, in bytes, of the message 525 not including the 20-byte STUN header. Since all STUN attributes are 526 padded to a multiple of 4 bytes, the last 2 bits of this field are 527 always zero. This provides another way to distinguish STUN packets 528 from packets of other protocols. 530 Following the STUN fixed portion of the header are zero or more 531 attributes. Each attribute is TLV (Type-Length-Value) encoded. The 532 details of the encoding, and of the attributes themselves are given 533 in Section 14. 535 6. Base Protocol Procedures 537 This section defines the base procedures of the STUN protocol. It 538 describes how messages are formed, how they are sent, and how they 539 are processed when they are received. It also defines the detailed 540 processing of the Binding method. Other sections in this document 541 describe optional procedures that a usage may elect to use in certain 542 situations. Other documents may define other extensions to STUN, by 543 adding new methods, new attributes, or new error response codes. 545 6.1. Forming a Request or an Indication 547 When formulating a request or indication message, the agent MUST 548 follow the rules in Section 5 when creating the header. In addition, 549 the message class MUST be either "Request" or "Indication" (as 550 appropriate), and the method must be either Binding or some method 551 defined in another document. 553 The agent then adds any attributes specified by the method or the 554 usage. For example, some usages may specify that the agent use an 555 authentication method (Section 9) or the FINGERPRINT attribute 556 (Section 7). 558 If the agent is sending a request, it SHOULD add a SOFTWARE attribute 559 to the request. Agents MAY include a SOFTWARE attribute in 560 indications, depending on the method. Extensions to STUN should 561 discuss whether SOFTWARE is useful in new indications. Note that the 562 inclusion of a SOFTWARE attribute may have security implications; see 563 Section 16.1.2 for details. 565 For the Binding method with no authentication, no attributes are 566 required unless the usage specifies otherwise. 568 All STUN messages sent over UDP or DTLS-over-UDP [RFC6347] SHOULD be 569 less than the path MTU, if known. 571 If the path MTU is unknown for UDP, messages SHOULD be the smaller of 572 576 bytes and the first-hop MTU for IPv4 [RFC1122] and 1280 bytes for 573 IPv6 [RFC8200]. This value corresponds to the overall size of the IP 574 packet. Consequently, for IPv4, the actual STUN message would need 575 to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte 576 UDP header, assuming no IP options are used). 578 If the path MTU is unknown for DTLS-over-UDP, the rules described in 579 the previous paragraph need to be adjusted to take into account the 580 size of the (13-byte) DTLS Record header, the MAC size, and the 581 padding size. 583 STUN provides no ability to handle the case where the request is 584 under the MTU but the response would be larger than the MTU. It is 585 not envisioned that this limitation will be an issue for STUN. The 586 MTU limitation is a SHOULD, and not a MUST, to account for cases 587 where STUN itself is being used to probe for MTU characteristics 588 [RFC5780]. See also [I-D.ietf-tram-stun-pmtud] for a framework that 589 uses STUN to add Path MTU Discovery to protocols that lack one. 590 Outside of this or similar applications, the MTU constraint MUST be 591 followed. 593 6.2. Sending the Request or Indication 595 The agent then sends the request or indication. This document 596 specifies how to send STUN messages over UDP, TCP, TLS-over-TCP, or 597 DTLS-over-UDP; other transport protocols may be added in the future. 598 The STUN usage must specify which transport protocol is used, and how 599 the agent determines the IP address and port of the recipient. 600 Section 8 describes a DNS-based method of determining the IP address 601 and port of a server that a usage may elect to use. 603 At any time, a client MAY have multiple outstanding STUN requests 604 with the same STUN server (that is, multiple transactions in 605 progress, with different transaction IDs). Absent other limits to 606 the rate of new transactions (such as those specified by ICE for 607 connectivity checks or when STUN is run over TCP), a client SHOULD 608 limit itself to ten outstanding transactions to the same server. 610 6.2.1. Sending over UDP or DTLS-over-UDP 612 When running STUN over UDP or STUN over DTLS-over-UDP [RFC7350], it 613 is possible that the STUN message might be dropped by the network. 614 Reliability of STUN request/response transactions is accomplished 615 through retransmissions of the request message by the client 616 application itself. STUN indications are not retransmitted; thus, 617 indication transactions over UDP or DTLS-over-UDP are not reliable. 619 A client SHOULD retransmit a STUN request message starting with an 620 interval of RTO ("Retransmission TimeOut"), doubling after each 621 retransmission. The RTO is an estimate of the round-trip time (RTT), 622 and is computed as described in [RFC6298], with two exceptions. 623 First, the initial value for RTO SHOULD be greater or equal to 500 624 ms. The exception cases for this "SHOULD" are when other mechanisms 625 are used to derive congestion thresholds (such as the ones defined in 626 ICE for fixed rate streams), or when STUN is used in non-Internet 627 environments with known network capacities. In fixed-line access 628 links, a value of 500 ms is RECOMMENDED. Second, the value of RTO 629 SHOULD NOT be rounded up to the nearest second. Rather, a 1 ms 630 accuracy SHOULD be maintained. As with TCP, the usage of Karn's 631 algorithm is RECOMMENDED [KARN87]. When applied to STUN, it means 632 that RTT estimates SHOULD NOT be computed from STUN transactions that 633 result in the retransmission of a request. 635 The value for RTO SHOULD be cached by a client after the completion 636 of the transaction, and used as the starting value for RTO for the 637 next transaction to the same server (based on equality of IP 638 address). The value SHOULD be considered stale and discarded if no 639 transactions have occurred to the same server in the last 10 minutes. 641 Retransmissions continue until a response is received, or until a 642 total of Rc requests have been sent. Rc SHOULD be configurable and 643 SHOULD have a default of 7. If, after the last request, a duration 644 equal to Rm times the RTO has passed without a response (providing 645 ample time to get a response if only this final request actually 646 succeeds), the client SHOULD consider the transaction to have failed. 647 Rm SHOULD be configurable and SHOULD have a default of 16. A STUN 648 transaction over UDP or DTLS-over-UDP is also considered failed if 649 there has been a hard ICMP error [RFC1122]. For example, assuming an 650 RTO of 500ms, requests would be sent at times 0 ms, 500 ms, 1500 ms, 651 3500 ms, 7500 ms, 15500 ms, and 31500 ms. If the client has not 652 received a response after 39500 ms, the client will consider the 653 transaction to have timed out. 655 6.2.2. Sending over TCP or TLS-over-TCP 657 For TCP and TLS-over-TCP [RFC5246], the client opens a TCP connection 658 to the server. 660 In some usages of STUN, STUN is sent as the only protocol over the 661 TCP connection. In this case, it can be sent without the aid of any 662 additional framing or demultiplexing. In other usages, or with other 663 extensions, it may be multiplexed with other data over a TCP 664 connection. In that case, STUN MUST be run on top of some kind of 665 framing protocol, specified by the usage or extension, which allows 666 for the agent to extract complete STUN messages and complete 667 application layer messages. The STUN service running on the well- 668 known port or ports discovered through the DNS procedures in 669 Section 8 is for STUN alone, and not for STUN multiplexed with other 670 data. Consequently, no framing protocols are used in connections to 671 those servers. When additional framing is utilized, the usage will 672 specify how the client knows to apply it and what port to connect to. 673 For example, in the case of ICE connectivity checks, this information 674 is learned through out-of-band negotiation between client and server. 676 Reliability of STUN over TCP and TLS-over-TCP is handled by TCP 677 itself, and there are no retransmissions at the STUN protocol level. 678 However, for a request/response transaction, if the client has not 679 received a response by Ti seconds after it sent the request message, 680 it considers the transaction to have timed out. Ti SHOULD be 681 configurable and SHOULD have a default of 39.5s. This value has been 682 chosen to equalize the TCP and UDP timeouts for the default initial 683 RTO. 685 In addition, if the client is unable to establish the TCP connection, 686 or the TCP connection is reset or fails before a response is 687 received, any request/response transaction in progress is considered 688 to have failed. 690 The client MAY send multiple transactions over a single TCP (or TLS- 691 over-TCP) connection, and it MAY send another request before 692 receiving a response to the previous request. The client SHOULD keep 693 the connection open until it: 695 o has no further STUN requests or indications to send over that 696 connection, and 698 o has no plans to use any resources (such as a mapped address 699 (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address 700 [RFC5766]) that were learned though STUN requests sent over that 701 connection, and 703 o if multiplexing other application protocols over that port, has 704 finished using those other protocols, and 706 o if using that learned port with a remote peer, has established 707 communications with that remote peer, as is required by some TCP 708 NAT traversal techniques (e.g., [RFC6544]). 710 The details of an eventual keep-alive mechanism are left to each STUN 711 Usage. In any case if a transaction fails because an idle TCP 712 connection doesn't work anymore the client SHOULD send an RST and try 713 to open a new TCP connection. 715 At the server end, the server SHOULD keep the connection open, and 716 let the client close it, unless the server has determined that the 717 connection has timed out (for example, due to the client 718 disconnecting from the network). Bindings learned by the client will 719 remain valid in intervening NATs only while the connection remains 720 open. Only the client knows how long it needs the binding. The 721 server SHOULD NOT close a connection if a request was received over 722 that connection for which a response was not sent. A server MUST NOT 723 ever open a connection back towards the client in order to send a 724 response. Servers SHOULD follow best practices regarding connection 725 management in cases of overload. 727 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP 729 When STUN is run by itself over TLS-over-TCP or DTLS-over-UDP, the 730 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 and 731 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suites MUST be 732 implemented and other cipher suites MAY be implemented. Perfect 733 Forward Secrecy (PFS) cipher suites MUST be preferred over non-PFS 734 cipher suites. Cipher suites with known weaknesses, such as those 735 based on (single) DES and RC4, MUST NOT be used. Implementations 736 MUST disable TLS-level compression. 738 These recommendations are just a part of the recommendations in 739 [BCP195] that implementations and deployments of a STUN Usage using 740 TLS or DTLS MUST follow. 742 When it receives the TLS Certificate message, the client MUST verify 743 the certificate and inspect the site identified by the certificate. 744 If the certificate is invalid or revoked, or if it does not identify 745 the appropriate party, the client MUST NOT send the STUN message or 746 otherwise proceed with the STUN transaction. The client MUST verify 747 the identity of the server. To do that, it follows the 748 identification procedures defined in [RFC6125], with a certificate 749 containing an identifier of type DNS-ID or CN-ID, optionally with a 750 wildcard character as leftmost label, but not of type SRV-ID or URI- 751 ID. 753 When STUN is run multiplexed with other protocols over a TLS-over-TCP 754 connection or a DTLS-over-UDP association, the mandatory ciphersuites 755 and TLS handling procedures operate as defined by those protocols. 757 6.3. Receiving a STUN Message 759 This section specifies the processing of a STUN message. The 760 processing specified here is for STUN messages as defined in this 761 specification; additional rules for backwards compatibility are 762 defined in Section 11. Those additional procedures are optional, and 763 usages can elect to utilize them. First, a set of processing 764 operations is applied that is independent of the class. This is 765 followed by class-specific processing, described in the subsections 766 that follow. 768 When a STUN agent receives a STUN message, it first checks that the 769 message obeys the rules of Section 5. It checks that the first two 770 bits are 0, that the magic cookie field has the correct value, that 771 the message length is sensible, and that the method value is a 772 supported method. It checks that the message class is allowed for 773 the particular method. If the message class is "Success Response" or 774 "Error Response", the agent checks that the transaction ID matches a 775 transaction that is still in progress. If the FINGERPRINT extension 776 is being used, the agent checks that the FINGERPRINT attribute is 777 present and contains the correct value. If any errors are detected, 778 the message is silently discarded. In the case when STUN is being 779 multiplexed with another protocol, an error may indicate that this is 780 not really a STUN message; in this case, the agent should try to 781 parse the message as a different protocol. 783 The STUN agent then does any checks that are required by a 784 authentication mechanism that the usage has specified (see 785 Section 9). 787 Once the authentication checks are done, the STUN agent checks for 788 unknown attributes and known-but-unexpected attributes in the 789 message. Unknown comprehension-optional attributes MUST be ignored 790 by the agent. Known-but-unexpected attributes SHOULD be ignored by 791 the agent. Unknown comprehension-required attributes cause 792 processing that depends on the message class and is described below. 794 At this point, further processing depends on the message class of the 795 request. 797 6.3.1. Processing a Request 799 If the request contains one or more unknown comprehension-required 800 attributes, the server replies with an error response with an error 801 code of 420 (Unknown Attribute), and includes an UNKNOWN-ATTRIBUTES 802 attribute in the response that lists the unknown comprehension- 803 required attributes. 805 Otherwise the server then does any additional checking that the 806 method or the specific usage requires. If all the checks succeed, 807 the server formulates a success response as described below. 809 When run over UDP or DTLS-over-UDP, a request received by the server 810 could be the first request of a transaction, or a retransmission. 811 The server MUST respond to retransmissions such that the following 812 property is preserved: if the client receives the response to the 813 retransmission and not the response that was sent to the original 814 request, the overall state on the client and server is identical to 815 the case where only the response to the original retransmission is 816 received, or where both responses are received (in which case the 817 client will use the first). The easiest way to meet this requirement 818 is for the server to remember all transaction IDs received over UDP 819 or DTLS-over-UDP and their corresponding responses in the last 40 820 seconds. However, this requires the server to hold state, and will 821 be inappropriate for any requests which are not authenticated. 822 Another way is to reprocess the request and recompute the response. 823 The latter technique MUST only be applied to requests that are 824 idempotent (a request is considered idempotent when the same request 825 can be safely repeated without impacting the overall state of the 826 system) and result in the same success response for the same request. 827 The Binding method is considered to be idempotent. Note that there 828 are certain rare network events that could cause the reflexive 829 transport address value to change, resulting in a different mapped 830 address in different success responses. Extensions to STUN MUST 831 discuss the implications of request retransmissions on servers that 832 do not store transaction state. 834 6.3.1.1. Forming a Success or Error Response 836 When forming the response (success or error), the server follows the 837 rules of Section 6. The method of the response is the same as that 838 of the request, and the message class is either "Success Response" or 839 "Error Response". 841 For an error response, the server MUST add an ERROR-CODE attribute 842 containing the error code specified in the processing above. The 843 reason phrase is not fixed, but SHOULD be something suitable for the 844 error code. For certain errors, additional attributes are added to 845 the message. These attributes are spelled out in the description 846 where the error code is specified. For example, for an error code of 847 420 (Unknown Attribute), the server MUST include an UNKNOWN- 848 ATTRIBUTES attribute. Certain authentication errors also cause 849 attributes to be added (see Section 9). Extensions may define other 850 errors and/or additional attributes to add in error cases. 852 If the server authenticated the request using an authentication 853 mechanism, then the server SHOULD add the appropriate authentication 854 attributes to the response (see Section 9). 856 The server also adds any attributes required by the specific method 857 or usage. In addition, the server SHOULD add a SOFTWARE attribute to 858 the message. 860 For the Binding method, no additional checking is required unless the 861 usage specifies otherwise. When forming the success response, the 862 server adds a XOR-MAPPED-ADDRESS attribute to the response, where the 863 contents of the attribute are the source transport address of the 864 request message. For UDP or DTLS-over-UDP this is the source IP 865 address and source UDP port of the request message. For TCP and TLS- 866 over-TCP, this is the source IP address and source TCP port of the 867 TCP connection as seen by the server. 869 6.3.1.2. Sending the Success or Error Response 871 The response (success or error) is sent over the same transport as 872 the request was received on. If the request was received over UDP or 873 DTLS-over-UDP the destination IP address and port of the response are 874 the source IP address and port of the received request message, and 875 the source IP address and port of the response are equal to the 876 destination IP address and port of the received request message. If 877 the request was received over TCP or TLS-over-TCP, the response is 878 sent back on the same TCP connection as the request was received on. 880 The server is allowed to send responses in a different order than it 881 received the requests. 883 6.3.2. Processing an Indication 885 If the indication contains unknown comprehension-required attributes, 886 the indication is discarded and processing ceases. 888 Otherwise the agent then does any additional checking that the method 889 or the specific usage requires. If all the checks succeed, the agent 890 then processes the indication. No response is generated for an 891 indication. 893 For the Binding method, no additional checking or processing is 894 required, unless the usage specifies otherwise. The mere receipt of 895 the message by the agent has refreshed the "bindings" in the 896 intervening NATs. 898 Since indications are not re-transmitted over UDP or DTLS-over-UDP 899 (unlike requests), there is no need to handle re-transmissions of 900 indications at the sending agent. 902 6.3.3. Processing a Success Response 904 If the success response contains unknown comprehension-required 905 attributes, the response is discarded and the transaction is 906 considered to have failed. 908 Otherwise the client then does any additional checking that the 909 method or the specific usage requires. If all the checks succeed, 910 the client then processes the success response. 912 For the Binding method, the client checks that the XOR-MAPPED-ADDRESS 913 attribute is present in the response. The client checks the address 914 family specified. If it is an unsupported address family, the 915 attribute SHOULD be ignored. If it is an unexpected but supported 916 address family (for example, the Binding transaction was sent over 917 IPv4, but the address family specified is IPv6), then the client MAY 918 accept and use the value. 920 6.3.4. Processing an Error Response 922 If the error response contains unknown comprehension-required 923 attributes, or if the error response does not contain an ERROR-CODE 924 attribute, then the transaction is simply considered to have failed. 926 Otherwise the client then does any processing specified by the 927 authentication mechanism (see Section 9). This may result in a new 928 transaction attempt. 930 The processing at this point depends on the error code, the method, 931 and the usage; the following are the default rules: 933 o If the error code is 300 through 399, the client SHOULD consider 934 the transaction as failed unless the ALTERNATE-SERVER extension 935 (Section 10) is being used. 937 o If the error code is 400 through 499, the client declares the 938 transaction failed; in the case of 420 (Unknown Attribute), the 939 response should contain a UNKNOWN-ATTRIBUTES attribute that gives 940 additional information. 942 o If the error code is 500 through 599, the client MAY resend the 943 request; clients that do so MUST limit the number of times they do 944 this. Unless a specific error code specifies a different value, 945 the number of retransmissions SHOULD be limited to 4. 947 Any other error code causes the client to consider the transaction 948 failed. 950 7. FINGERPRINT Mechanism 952 This section describes an optional mechanism for STUN that aids in 953 distinguishing STUN messages from packets of other protocols when the 954 two are multiplexed on the same transport address. This mechanism is 955 optional, and a STUN usage must describe if and when it is used. The 956 FINGERPRINT mechanism is not backwards compatible with RFC3489, and 957 cannot be used in environments where such compatibility is required. 959 In some usages, STUN messages are multiplexed on the same transport 960 address as other protocols, such as the Real Time Transport Protocol 961 (RTP). In order to apply the processing described in Section 6, STUN 962 messages must first be separated from the application packets. 964 Section 5 describes three fixed fields in the STUN header that can be 965 used for this purpose. However, in some cases, these three fixed 966 fields may not be sufficient. 968 When the FINGERPRINT extension is used, an agent includes the 969 FINGERPRINT attribute in messages it sends to another agent. 970 Section 14.7 describes the placement and value of this attribute. 972 When the agent receives what it believes is a STUN message, then, in 973 addition to other basic checks, the agent also checks that the 974 message contains a FINGERPRINT attribute and that the attribute 975 contains the correct value. Section 6.3 describes when in the 976 overall processing of a STUN message the FINGERPRINT check is 977 performed. This additional check helps the agent detect messages of 978 other protocols that might otherwise seem to be STUN messages. 980 8. DNS Discovery of a Server 982 This section describes an optional procedure for STUN that allows a 983 client to use DNS to determine the IP address and port of a server. 984 A STUN usage must describe if and when this extension is used. To 985 use this procedure, the client must know a STUN URI [RFC7064]; the 986 usage must also describe how the client obtains this URI. Hard- 987 coding a STUN URI into software is NOT RECOMMENDED in case the domain 988 name is lost or needs to change for legal or other reasons. 990 When a client wishes to locate a STUN server on the public Internet 991 that accepts Binding request/response transactions, the STUN URI 992 scheme is "stun". When it wishes to locate a STUN server that 993 accepts Binding request/response transactions over a TLS, or DTLS 994 session, the URI scheme is "stuns". 996 The syntax of the "stun" and "stuns" URIs are defined in Section 3.1 997 of [RFC7064]. STUN usages MAY define additional URI schemes. 999 8.1. STUN URI Scheme Semantics 1001 If the part of a "stun" URI contains an IP address, then this 1002 IP address is used directly to contact the server. A "stuns" URI 1003 containing an IP address MUST be rejected. A future STUN extension 1004 or usage may relax this requirement provided it demonstrates how to 1005 authenticate the STUN server and prevent man in the middle attacks. 1007 If the URI does not contain an IP address, the domain name contained 1008 in the part is resolved to a transport address using the SRV 1009 procedures specified in [RFC2782]. The DNS SRV service name is the 1010 content of the part. The protocol in the SRV lookup is the 1011 transport protocol the client will run STUN over: "udp" for UDP and 1012 "tcp" for TCP. 1014 The procedures of RFC 2782 are followed to determine the server to 1015 contact. RFC 2782 spells out the details of how a set of SRV records 1016 is sorted and then tried. However, RFC 2782 only states that the 1017 client should "try to connect to the (protocol, address, service)" 1018 without giving any details on what happens in the event of failure. 1019 When following these procedures, if the STUN transaction times out 1020 without receipt of a response, the client SHOULD retry the request to 1021 the next server in the ordered defined by RFC 2782. Such a retry is 1022 only possible for request/response transmissions, since indication 1023 transactions generate no response or timeout. 1025 In addition, instead of querying either the A or the AAAA resource 1026 records for a domain name, a dual-stack IPv4/IPv6 client MUST query 1027 both and try the requests with all the IP addresses received, as 1028 specified in [RFC8305]. 1030 The default port for STUN requests is 3478, for both TCP and UDP. 1031 The default port for STUN over TLS and STUN over DTLS requests is 1032 5349. Servers can run STUN over DTLS on the same port as STUN over 1033 UDP if the server software supports determining whether the initial 1034 message is a DTLS or STUN message. Servers can run STUN over TLS on 1035 the same port as STUN over TCP if the server software supports 1036 determining whether the initial message is a TLS or STUN message. 1038 Administrators of STUN servers SHOULD use these ports in their SRV 1039 records for UDP and TCP. In all cases, the port in DNS MUST reflect 1040 the one on which the server is listening. 1042 If no SRV records were found, the client performs both an A and AAAA 1043 record lookup of the domain name, as described in [RFC8305]. The 1044 result will be a list of IP addresses, each of which can be 1045 simultaneously contacted at the default port using UDP or TCP, 1046 independent of the STUN usage. For usages that require TLS, the 1047 client connects to the IP addresses using the default STUN over TLS 1048 port. For usages that require DTLS, the client connects to the IP 1049 addresses using the default STUN over DTLS port. 1051 9. Authentication and Message-Integrity Mechanisms 1053 This section defines two mechanisms for STUN that a client and server 1054 can use to provide authentication and message integrity; these two 1055 mechanisms are known as the short-term credential mechanism and the 1056 long-term credential mechanism. These two mechanisms are optional, 1057 and each usage must specify if and when these mechanisms are used. 1058 Consequently, both clients and servers will know which mechanism (if 1059 any) to follow based on knowledge of which usage applies. For 1060 example, a STUN server on the public Internet supporting ICE would 1061 have no authentication, whereas the STUN server functionality in an 1062 agent supporting connectivity checks would utilize short-term 1063 credentials. An overview of these two mechanisms is given in 1064 Section 2. 1066 Each mechanism specifies the additional processing required to use 1067 that mechanism, extending the processing specified in Section 6. The 1068 additional processing occurs in three different places: when forming 1069 a message, when receiving a message immediately after the basic 1070 checks have been performed, and when doing the detailed processing of 1071 error responses. 1073 Note that agents MUST ignore all attributes that follow MESSAGE- 1074 INTEGRITY, with the exception of the MESSAGE-INTEGRITY-SHA256 and 1075 FINGERPRINT attributes. Similarly agents MUST ignore all attributes 1076 that follow the MESSAGE-INTEGRITY-SHA256 attribute if the MESSAGE- 1077 INTEGRITY attribute is not present, with the exception of the 1078 FINGERPRINT attribute. 1080 9.1. Short-Term Credential Mechanism 1082 The short-term credential mechanism assumes that, prior to the STUN 1083 transaction, the client and server have used some other protocol to 1084 exchange a credential in the form of a username and password. This 1085 credential is time-limited. The time limit is defined by the usage. 1087 As an example, in the ICE usage [RFC8445], the two endpoints use out- 1088 of-band signaling to agree on a username and password, and this 1089 username and password are applicable for the duration of the media 1090 session. 1092 This credential is used to form a message-integrity check in each 1093 request and in many responses. There is no challenge and response as 1094 in the long-term mechanism; consequently, replay is limited by virtue 1095 of the time-limited nature of the credential. 1097 9.1.1. HMAC Key 1099 For short-term credentials the HMAC key is defined as follow: 1101 key = OpaqueString(password) 1103 where the OpaqueString profile is defined in [RFC8265]. The encoding 1104 used is UTF-8 [RFC3629]. 1106 9.1.2. Forming a Request or Indication 1108 For a request or indication message, the agent MUST include the 1109 USERNAME, MESSAGE-INTEGRITY-SHA256, and MESSAGE-INTEGRITY attributes 1110 in the message unless the agent knows from an external indication 1111 which message integrity algorithm is supported by both agents. In 1112 this case either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 MUST 1113 be included in addition to USERNAME. The HMAC for the MESSAGE- 1114 INTEGRITY attribute is computed as described in Section 14.5 and the 1115 HMAC for the MESSAGE-INTEGRITY-SHA256 attributes is computed as 1116 described in Section 14.6. Note that the password is never included 1117 in the request or indication. 1119 9.1.3. Receiving a Request or Indication 1121 After the agent has done the basic processing of a message, the agent 1122 performs the checks listed below in order specified: 1124 o If the message does not contain 1) a MESSAGE-INTEGRITY or a 1125 MESSAGE-INTEGRITY-SHA256 attribute and 2) a USERNAME attribute: 1127 * If the message is a request, the server MUST reject the request 1128 with an error response. This response MUST use an error code 1129 of 400 (Bad Request). 1131 * If the message is an indication, the agent MUST silently 1132 discard the indication. 1134 o If the USERNAME does not contain a username value currently valid 1135 within the server: 1137 * If the message is a request, the server MUST reject the request 1138 with an error response. This response MUST use an error code 1139 of 401 (Unauthenticated). 1141 * If the message is an indication, the agent MUST silently 1142 discard the indication. 1144 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1145 value for the message integrity as described in Section 14.6, 1146 using the password associated with the username. If the MESSAGE- 1147 INTEGRITY-SHA256 attribute is not present, then use the same 1148 password to compute the value for the message integrity as 1149 described in Section 14.5. If the resulting value does not match 1150 the contents of the corresponding attribute (MESSAGE-INTEGRITY- 1151 SHA256 or MESSAGE-INTEGRITY): 1153 * If the message is a request, the server MUST reject the request 1154 with an error response. This response MUST use an error code 1155 of 401 (Unauthenticated). 1157 * If the message is an indication, the agent MUST silently 1158 discard the indication. 1160 If these checks pass, the agent continues to process the request or 1161 indication. Any response generated by a server to a request that 1162 contains a MESSAGE-INTEGRITY-SHA256 attribute MUST include the 1163 MESSAGE-INTEGRITY-SHA256 attribute, computed using the password 1164 utilized to authenticate the request. Any response generated by a 1165 server to a request that contains only a MESSAGE-INTEGRITY attribute 1166 MUST include the MESSAGE-INTEGRITY attribute, computed using the 1167 password utilized to authenticate the request. This means that only 1168 one of these attributes can appear in a response. The response MUST 1169 NOT contain the USERNAME attribute. 1171 If any of the checks fail, a server MUST NOT include a MESSAGE- 1172 INTEGRITY-SHA256, MESSAGE-INTEGRITY, or USERNAME attribute in the 1173 error response. This is because, in these failure cases, the server 1174 cannot determine the shared secret necessary to compute the MESSAGE- 1175 INTEGRITY-SHA256 or MESSAGE-INTEGRITY attributes. 1177 9.1.4. Receiving a Response 1179 The client looks for the MESSAGE-INTEGRITY or the MESSAGE-INTEGRITY- 1180 SHA256 attribute in the response. If present and if the client only 1181 sent only one of MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1182 attributes in the request (because of the external indication in 1183 Section 9.1.2, or this being a subsequent request as defined in 1184 Section 9.1.5) the algorithm in the response has to match otherwise 1185 the response MUST be discarded. 1187 The client then computes the message integrity over the response as 1188 defined in Section 14.5 or Section 14.6, respectively, using the same 1189 password it utilized for the request. If the resulting value matches 1190 the contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1191 attribute, respectively, the response is considered authenticated. 1192 If the value does not match, or if both MESSAGE-INTEGRITY and 1193 MESSAGE-INTEGRITY-SHA256 were absent, the processing depends on the 1194 request been sent over a reliable or an unreliable transport. 1196 If the request was sent over an unreliable transport, the response 1197 MUST be discarded, as if it was never received. This means that 1198 retransmits, if applicable, will continue. If all the responses 1199 received are discarded then instead of signaling a timeout after 1200 ending the transaction the layer MUST signal that the integrity 1201 protection was violated. 1203 If the request was sent over a reliable transport, the response MUST 1204 be discarded and the layer MUST immediately end the transaction and 1205 signal that the integrity protection was violated. 1207 9.1.5. Sending Subsequent Requests 1209 A client sending subsequent requests to the same server MUST send 1210 only the MESSAGE-INTEGRITY-SHA256 or the MESSAGE-INTEGRITY attribute 1211 that matches the attribute that was received in the response to the 1212 initial request. Here same server means same IP address and port 1213 number, not just the same URI or SRV lookup result. 1215 9.2. Long-Term Credential Mechanism 1217 The long-term credential mechanism relies on a long-term credential, 1218 in the form of a username and password that are shared between client 1219 and server. The credential is considered long-term since it is 1220 assumed that it is provisioned for a user, and remains in effect 1221 until the user is no longer a subscriber of the system, or is 1222 changed. This is basically a traditional "log-in" username and 1223 password given to users. 1225 Because these usernames and passwords are expected to be valid for 1226 extended periods of time, replay prevention is provided in the form 1227 of a digest challenge. In this mechanism, the client initially sends 1228 a request, without offering any credentials or any integrity checks. 1229 The server rejects this request, providing the user a realm (used to 1230 guide the user or agent in selection of a username and password) and 1231 a nonce. The nonce provides a limited replay protection. It is a 1232 cookie, selected by the server, and encoded in such a way as to 1233 indicate a duration of validity or client identity from which it is 1234 valid. Only the server needs to know about the internal structure of 1235 the cookie. The client retries the request, this time including its 1236 username and the realm, and echoing the nonce provided by the server. 1237 The client also includes one of the message-integrity attributes 1238 defined in this document, which provides an HMAC over the entire 1239 request, including the nonce. The server validates the nonce and 1240 checks the message integrity. If they match, the request is 1241 authenticated. If the nonce is no longer valid, it is considered 1242 "stale", and the server rejects the request, providing a new nonce. 1244 In subsequent requests to the same server, the client reuses the 1245 nonce, username, realm, and password it used previously. In this 1246 way, subsequent requests are not rejected until the nonce becomes 1247 invalid by the server, in which case the rejection provides a new 1248 nonce to the client. 1250 Note that the long-term credential mechanism cannot be used to 1251 protect indications, since indications cannot be challenged. Usages 1252 utilizing indications must either use a short-term credential or omit 1253 authentication and message integrity for them. 1255 To indicate that it supports this specification, a server MUST 1256 prepend the NONCE attribute value with the character string composed 1257 of "obMatJos2" concatenated with the (4 character) Base64 [RFC4648] 1258 encoding of the 24 bit STUN Security Features as defined in 1259 Section 18.1. The 24 bit Security Feature set is encoded as 3 bytes, 1260 with bit 0 as the most significant bit of the first byte and bit 23 1261 as the least significant bit of the third byte. If no security 1262 features are used, then a byte array with all 24 bits set to zero 1263 MUST be encoded instead. For the remainder of this document the term 1264 "nonce cookie" will refer to the complete 13 character string 1265 prepended to the NONCE attribute value. 1267 Since the long-term credential mechanism is susceptible to offline 1268 dictionary attacks, deployments SHOULD utilize passwords that are 1269 difficult to guess. In cases where the credentials are not entered 1270 by the user, but are rather placed on a client device during device 1271 provisioning, the password SHOULD have at least 128 bits of 1272 randomness. In cases where the credentials are entered by the user, 1273 they should follow best current practices around password structure. 1275 9.2.1. Bid Down Attack Prevention 1277 This document introduces two new security features that provide the 1278 ability to choose the algorithm used for password protection as well 1279 as the ability to use an anonymous username. Both of these 1280 capabilities are optional in order to remain backwards compatible 1281 with previous versions of the STUN protocol. 1283 These new capabilities are subject to bid-down attacks whereby an 1284 attacker in the message path can remove these capabilities and force 1285 weaker security properties. To prevent these kinds of attacks from 1286 going undetected, the nonce is enhanced with additional information. 1288 The value of the "nonce cookie" will vary based on the specific STUN 1289 Security Features bit values selected. When this document makes 1290 reference to the "nonce cookie" in a section discussing a specific 1291 STUN Security Feature it is understood that the corresponding STUN 1292 Security Feature bit in the "nonce cookie" is set to 1. 1294 For example, in Section 9.2.4 discussing the PASSWORD-ALGORITHMS 1295 security feature, it is implied that the "Password algorithms" bit, 1296 as defined in Section 18.1, is set to 1 in the "nonce cookie". 1298 9.2.2. HMAC Key 1300 For long-term credentials that do not use a different algorithm, as 1301 specified by the PASSWORD-ALGORITHM attribute, the key is 16 bytes: 1303 key = MD5(username ":" OpaqueString(realm) 1304 ":" OpaqueString(password)) 1306 Where MD5 is defined in [RFC1321] and [RFC6151], and the OpaqueString 1307 profile is defined in [RFC8265]. The encoding used is UTF-8 1308 [RFC3629]. 1310 The 16-byte key is formed by taking the MD5 hash of the result of 1311 concatenating the following five fields: (1) the username, with any 1312 quotes and trailing nulls removed, as taken from the USERNAME 1313 attribute (in which case OpaqueString has already been applied); (2) 1314 a single colon; (3) the realm, with any quotes and trailing nulls 1315 removed and after processing using OpaqueString; (4) a single colon; 1316 and (5) the password, with any trailing nulls removed and after 1317 processing using OpaqueString. For example, if the username was 1318 'user', the realm was 'realm', and the password was 'pass', then the 1319 16-byte HMAC key would be the result of performing an MD5 hash on the 1320 string 'user:realm:pass', the resulting hash being 1321 0x8493fbc53ba582fb4c044c456bdc40eb. 1323 The structure of the key when used with long-term credentials 1324 facilitates deployment in systems that also utilize SIP [RFC3261]. 1325 Typically, SIP systems utilizing SIP's digest authentication 1326 mechanism do not actually store the password in the database. 1327 Rather, they store a value called H(A1), which is equal to the key 1328 defined above. For example, this mechanism can be used with the 1329 authentication extensions defined in [RFC5090]. 1331 When a PASSWORD-ALGORITHM is used, the key length and algorithm to 1332 use are described in Section 18.5.1. 1334 9.2.3. Forming a Request 1336 There are two cases when forming a request. In the first case, this 1337 is the first request from the client to the server (as identified by 1338 hostname, if the DNS procedures of Section 8 are used, else IP 1339 address if not). In the second case, the client is submitting a 1340 subsequent request once a previous request/response transaction has 1341 completed successfully. Forming a request as a consequence of a 401 1342 or 438 error response is covered in Section 9.2.5 and is not 1343 considered a "subsequent request" and thus does not utilize the rules 1344 described in Section 9.2.3.2. 1346 The difference between a first request and a subsequent request is 1347 the presence or absence of some attributes, so omitting or including 1348 them is a MUST. 1350 9.2.3.1. First Request 1352 If the client has not completed a successful request/response 1353 transaction with the server, it MUST omit the USERNAME, USERHASH, 1354 MESSAGE-INTEGRITY, MESSAGE-INTEGRITY-SHA256, REALM, NONCE, PASSWORD- 1355 ALGORITHMS, and PASSWORD-ALGORITHM attributes. In other words, the 1356 first request is sent as if there were no authentication or message 1357 integrity applied. 1359 9.2.3.2. Subsequent Requests 1361 Once a request/response transaction has completed, the client will 1362 have been presented a realm and nonce by the server, and selected a 1363 username and password with which it authenticated. The client SHOULD 1364 cache the username, password, realm, and nonce for subsequent 1365 communications with the server. When the client sends a subsequent 1366 request, it MUST include either the USERNAME or USERHASH, REALM, 1367 NONCE, and PASSWORD-ALGORITHM attributes with these cached values. 1368 It MUST include a MESSAGE-INTEGRITY attribute or a MESSAGE-INTEGRITY- 1369 SHA256 attribute, computed as described in Section 14.5 and 1370 Section 14.6 using the cached password. The choice between the two 1371 attributes depends on the attribute received in the response to the 1372 first request. 1374 9.2.4. Receiving a Request 1376 After the server has done the basic processing of a request, it 1377 performs the checks listed below in the order specified. Note that 1378 it is RECOMMENDED that the REALM value be the domain name of the 1379 provider of the STUN server: 1381 o If the message does not contain a MESSAGE-INTEGRITY or MESSAGE- 1382 INTEGRITY-SHA256 attribute, the server MUST generate an error 1383 response with an error code of 401 (Unauthenticated). This 1384 response MUST include a REALM value. The response MUST include a 1385 NONCE, selected by the server. The server MUST NOT choose the 1386 same NONCE for two requests unless they have the same source IP 1387 address and port. The server MAY support alternate password 1388 algorithms, in which case it can list them in preferential order 1389 in a PASSWORD-ALGORITHMS attribute. If the server adds a 1390 PASSWORD-ALGORITHMS attribute it MUST set the STUN Security 1391 Feature "Password algorithms" bit set to 1. The server MAY 1392 support anonymous username, in which case it MUST set the STUN 1393 Security Feature "Username anonymity" bit set to 1. The response 1394 SHOULD NOT contain a USERNAME, USERHASH, MESSAGE-INTEGRITY or 1395 MESSAGE-INTEGRITY-SHA256 attribute. 1397 Note: Reusing a NONCE for different source IP addresses or ports was 1398 not explicitly forbidden in [RFC5389]. 1400 o If the message contains a MESSAGE-INTEGRITY or a MESSAGE- 1401 INTEGRITY-SHA256 attribute, but is missing either the USERNAME or 1402 USERHASH, REALM, or NONCE attribute, the server MUST generate an 1403 error response with an error code of 400 (Bad Request). This 1404 response SHOULD NOT include a USERNAME, USERHASH, NONCE, or REALM. 1405 The response cannot contain a MESSAGE-INTEGRITY or MESSAGE- 1406 INTEGRITY-SHA256 attribute, as the attributes required to generate 1407 them are missing. 1409 o If the NONCE attribute starts with the "nonce cookie" with the 1410 STUN Security Feature "Password algorithms" bit set to 1, the 1411 server performs these checks in the order specified: 1413 * If the request contains neither PASSWORD-ALGORITHMS nor 1414 PASSWORD-ALGORITHM, then the request is processed as though 1415 PASSWORD-ALGORITHM were MD5 (Note that if the PASSWORD- 1416 ALGORITHMS attribute is present but does not contain MD5, this 1417 will result in a 400 Bad Request in a later step below). 1419 * Otherwise, unless (1) PASSWORD-ALGORITHM and PASSWORD- 1420 ALGORITHMS are both present, (2) PASSWORD-ALGORITHMS matches 1421 the value sent in the response that sent this NONCE, and (3) 1422 PASSWORD-ALGORITHM matches one of the entries in PASSWORD- 1423 ALGORITHMS, the server MUST generate an error response with an 1424 error code of 400 (Bad Request). 1426 o If the NONCE is no longer valid and at the same time the MESSAGE- 1427 INTEGRITY or a MESSAGE-INTEGRITY-SHA256 attribute is invalid, the 1428 server MUST generate an error response with an error code of 401. 1429 This response MUST include NONCE, REALM, and PASSWORD-ALGORITHMS 1430 attributes and SHOULD NOT include the USERNAME or USERHASH 1431 attribute. The NONCE attribute value MUST be valid. The response 1432 MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1433 attribute, using the previous NONCE to calculate it. 1435 o If the NONCE is no longer valid, the server MUST generate an error 1436 response with an error code of 438 (Stale Nonce). This response 1437 MUST include NONCE, REALM, and PASSWORD-ALGORITHMS attributes and 1438 SHOULD NOT include the USERNAME, USERHASH attribute. The NONCE 1439 attribute value MUST be valid. The response MAY include a 1440 MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, using the 1441 previous NONCE to calculate it. Servers can revoke nonces in 1442 order to provide additional security. See Section 5.4 of 1443 [RFC7616] for guidelines. 1445 o If the value of the USERNAME or USERHASH attribute is not valid, 1446 the server MUST generate an error response with an error code of 1447 401 (Unauthenticated). This response MUST include a REALM value. 1448 The response MUST include a NONCE, selected by the server. The 1449 response MUST include a PASSWORD-ALGORITHMS attribute. The 1450 response SHOULD NOT contain a USERNAME, USERHASH attribute. The 1451 response MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1452 SHA256 attribute, using the previous key to calculate it. 1454 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1455 value for the message integrity as described in Section 14.6, 1456 using the password associated with the username. Else, using the 1457 same password, compute the value for the message integrity as 1458 described in Section 14.5. If the resulting value does not match 1459 the contents of the MESSAGE-INTEGRITY attribute or the MESSAGE- 1460 INTEGRITY-SHA256 attribute, the server MUST reject the request 1461 with an error response. This response MUST use an error code of 1462 401 (Unauthenticated). It MUST include REALM and NONCE attributes 1463 and SHOULD NOT include the USERNAME, USERHASH, MESSAGE-INTEGRITY, 1464 or MESSAGE-INTEGRITY-SHA256 attribute. 1466 If these checks pass, the server continues to process the request. 1467 Any response generated by the server MUST include MESSAGE-INTEGRITY- 1468 SHA256 attribute, computed using the username and password utilized 1469 to authenticate the request, unless the request was processed as 1470 though PASSWORD-ALGORITHM was MD5 (because the request contained 1471 neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM). In that case 1472 the MESSAGE-INTEGRITY attribute MUST be used instead of the MESSAGE- 1473 INTEGRITY-SHA256 attribute. The REALM, NONCE, USERNAME and USERHASH 1474 attributes SHOULD NOT be included. 1476 9.2.5. Receiving a Response 1478 If the response is an error response with an error code of 401 1479 (Unauthenticated) or 438 (Stale Nonce), the client MUST test if the 1480 NONCE attribute value starts with the "nonce cookie". If the test 1481 succeeds and the "nonce cookie" has the STUN Security Feature 1482 "Password algorithms" bit set to 1 but no PASSWORD-ALGORITHMS 1483 attribute is present, then the client MUST NOT retry the request with 1484 a new transaction. 1486 If the response is an error response with an error code of 401 1487 (Unauthenticated), the client SHOULD retry the request with a new 1488 transaction. This request MUST contain a USERNAME or a USERHASH, 1489 determined by the client as the appropriate username for the REALM 1490 from the error response. If the "nonce cookie" was present and had 1491 the STUN Security Feature "Username anonymity" bit set to 1 then the 1492 USERHASH attribute MUST be used, else the USERNAME attribute MUST be 1493 used. The request MUST contain the REALM, copied from the error 1494 response. The request MUST contain the NONCE, copied from the error 1495 response. If the response contains a PASSWORD-ALGORITHMS attribute, 1496 the request MUST contain the PASSWORD-ALGORITHMS attribute with the 1497 same content. If the response contains a PASSWORD-ALGORITHMS 1498 attribute, and this attribute contains at least one algorithm that is 1499 supported by the client then the request MUST contain a PASSWORD- 1500 ALGORITHM attribute with the first algorithm supported on the list. 1501 If the response contains a PASSWORD-ALGORITHMS attribute, and this 1502 attribute does not contain any algorithm that is supported by the 1503 client, then the client MUST NOT retry the request with a new 1504 transaction. The client MUST NOT perform this retry if it is not 1505 changing the USERNAME or USERHASH or REALM or its associated 1506 password, from the previous attempt. 1508 If the response is an error response with an error code of 438 (Stale 1509 Nonce), the client MUST retry the request, using the new NONCE 1510 attribute supplied in the 438 (Stale Nonce) response. This retry 1511 MUST also include either the USERNAME or USERHASH, REALM and either 1512 the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attributes. 1514 For all other responses, if the NONCE attribute starts with the 1515 "nonce cookie" with the STUN Security Feature "Password algorithms" 1516 bit set to 1 but PASSWORD-ALGORITHMS is not present, the response 1517 MUST be ignored. 1519 If the response is an error response with an error code of 400, and 1520 does not contains either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1521 SHA256 attribute then the response MUST be discarded, as if it was 1522 never received. This means that retransmits, if applicable, will 1523 continue. 1525 Note: In that case the 400 will never reach the application, 1526 resulting in a timeout. 1528 The client looks for the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1529 SHA256 attribute in the response (either success or failure). If 1530 present, the client computes the message integrity over the response 1531 as defined in Section 14.5 or Section 14.6, using the same password 1532 it utilized for the request. If the resulting value matches the 1533 contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1534 attribute, the response is considered authenticated. If the value 1535 does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 1536 SHA256 were absent, the processing depends on the request been sent 1537 over a reliable or an unreliable transport. 1539 If the request was sent over an unreliable transport, the response 1540 MUST be discarded, as if it was never received. This means that 1541 retransmits, if applicable, will continue. If all the responses 1542 received are discarded then instead of signaling a timeout after 1543 ending the transaction the layer MUST signal that the integrity 1544 protection was violated. 1546 If the request was sent over a reliable transport, the response MUST 1547 be discarded and the layer MUST immediately end the transaction and 1548 signal that the integrity protection was violated. 1550 If the response contains a PASSWORD-ALGORITHMS attribute, all the 1551 subsequent requests MUST be authenticated using MESSAGE-INTEGRITY- 1552 SHA256 only. 1554 10. ALTERNATE-SERVER Mechanism 1556 This section describes a mechanism in STUN that allows a server to 1557 redirect a client to another server. This extension is optional, and 1558 a usage must define if and when this extension is used. The 1559 ALTERNATE-SERVER attribute carries an IP address. 1561 A server using this extension redirects a client to another server by 1562 replying to a request message with an error response message with an 1563 error code of 300 (Try Alternate). The server MUST include at least 1564 one ALTERNATE-SERVER attribute in the error response, which MUST 1565 contain an IP address of the same family as the source IP address of 1566 the request message. The server SHOULD include an additional 1567 ALTERNATE-SERVER attribute, after the mandatory one, that contains an 1568 IP address of the other family than the source IP address of the 1569 request message. The error response message MAY be authenticated; 1570 however, there are use cases for ALTERNATE-SERVER where 1571 authentication of the response is not possible or practical. If the 1572 transaction uses TLS or DTLS and if the transaction is authenticated 1573 by a MESSAGE-INTEGRITY-SHA256 attribute and if the server wants to 1574 redirect to a server that uses a different certificate, then it MUST 1575 include an ALTERNATE-DOMAIN attribute containing the name inside the 1576 subjectAltName of that certificate. This series of conditions on the 1577 MESSAGE-INTEGRITY-SHA256 attribute indicates that the transaction is 1578 authenticated and that the client implements this specification and 1579 therefore can process the ALTERNATE-DOMAIN attribute. 1581 A client using this extension handles a 300 (Try Alternate) error 1582 code as follows. The client looks for an ALTERNATE-SERVER attribute 1583 in the error response. If one is found, then the client considers 1584 the current transaction as failed, and reattempts the request with 1585 the server specified in the attribute, using the same transport 1586 protocol used for the previous request. That request, if 1587 authenticated, MUST utilize the same credentials that the client 1588 would have used in the request to the server that performed the 1589 redirection. If the transport protocol uses TLS or DTLS, then the 1590 client looks for an ALTERNATE-DOMAIN attribute. If the attribute is 1591 found, the domain MUST be used to validate the certificate using the 1592 recommendations in [RFC6125]. The certificate MUST contain an 1593 identifier of type DNS-ID or CN-ID, eventually with wildcards, but 1594 not of type SRV-ID or URI-ID. If the attribute is not found, the 1595 same domain that was used for the original request MUST be used to 1596 validate the certificate. If the client has been redirected to a 1597 server to which it has already sent this request within the last five 1598 minutes, it MUST ignore the redirection and consider the transaction 1599 to have failed. This prevents infinite ping-ponging between servers 1600 in case of redirection loops. 1602 11. Backwards Compatibility with RFC 3489 1604 In addition to the backward compatibility already described in 1605 Section 12 of [RFC5389], DTLS MUST NOT be used with [RFC3489] (also 1606 referred to as "classic STUN"). Any STUN request or indication 1607 without the magic cookie (see Section 6 of [RFC5389]) over DTLS MUST 1608 be considered invalid: all requests MUST generate a "500 Server 1609 Error" error response and indications MUST be ignored. 1611 12. Basic Server Behavior 1613 This section defines the behavior of a basic, stand-alone STUN 1614 server. 1616 Historically, "classic STUN [RFC3489]" only defined the behavior of a 1617 server that was providing clients with server reflexive transport 1618 addresses by receiving and replying to STUN Binding requests. 1619 [RFC5389] redefined the protocol as an extensible framework and the 1620 server functionality became the sole STUN Usage defined in that 1621 document. This STUN Usage is also known as Basic STUN Server. 1623 The STUN server MUST support the Binding method. It SHOULD NOT 1624 utilize the short-term or long-term credential mechanism. This is 1625 because the work involved in authenticating the request is more than 1626 the work in simply processing it. It SHOULD NOT utilize the 1627 ALTERNATE-SERVER mechanism for the same reason. It MUST support UDP 1628 and TCP. It MAY support STUN over TCP/TLS or STUN over UDP/DTLS; 1629 however, DTLS and TLS provide minimal security benefits in this basic 1630 mode of operation. It does not require a keep-alive mechanism 1631 because a TCP or TLS-over-TCP connection is closed after the end of 1632 the Binding transaction. It MAY utilize the FINGERPRINT mechanism 1633 but MUST NOT require it. Since the stand-alone server only runs 1634 STUN, FINGERPRINT provides no benefit. Requiring it would break 1635 compatibility with RFC 3489, and such compatibility is desirable in a 1636 stand-alone server. Stand-alone STUN servers SHOULD support 1637 backwards compatibility with [RFC3489] clients, as described in 1638 Section 11. 1640 It is RECOMMENDED that administrators of STUN servers provide DNS 1641 entries for those servers as described in Section 8. If both A and 1642 AAAA Resource Records are returned then the client can simultaneously 1643 send STUN Binding requests to the IPv4 and IPv6 addresses (as 1644 specified in [RFC8305]), as the Binding request is idempotent. Note 1645 that the MAPPED-ADDRESS or XOR-MAPPED-ADDRESS attributes that are 1646 returned will not necessarily match the address family of the server 1647 address used. 1649 A basic STUN server is not a solution for NAT traversal by itself. 1650 However, it can be utilized as part of a solution through STUN 1651 usages. This is discussed further in Section 13. 1653 13. STUN Usages 1655 STUN by itself is not a solution to the NAT traversal problem. 1656 Rather, STUN defines a tool that can be used inside a larger 1657 solution. The term "STUN usage" is used for any solution that uses 1658 STUN as a component. 1660 A STUN usage defines how STUN is actually utilized -- when to send 1661 requests, what to do with the responses, and which optional 1662 procedures defined here (or in an extension to STUN) are to be used. 1663 A usage also defines: 1665 o Which STUN methods are used. 1667 o What transports are used. If DTLS-over-UDP is used then 1668 implementing the denial-of-service countermeasure described in 1669 Section 4.2.1 of [RFC6347] is mandatory. 1671 o What authentication and message-integrity mechanisms are used. 1673 o The considerations around manual vs. automatic key derivation for 1674 the integrity mechanism, as discussed in [RFC4107]. 1676 o What mechanisms are used to distinguish STUN messages from other 1677 messages. When STUN is run over TCP or TLS-over-TCP, a framing 1678 mechanism may be required. 1680 o How a STUN client determines the IP address and port of the STUN 1681 server. 1683 o How simultaneous use of IPv4 and IPv6 addresses (Happy Eyeballs 1684 [RFC8305]) works with non-idempotent transactions when both 1685 address families are found for the STUN server. 1687 o Whether backwards compatibility to RFC 3489 is required. 1689 o What optional attributes defined here (such as FINGERPRINT and 1690 ALTERNATE-SERVER) or in other extensions are required. 1692 o If MESSAGE-INTEGRITY-SHA256 truncation is permitted, and the 1693 limits permitted for truncation. 1695 o The keep-alive mechanism if STUN is run over TCP or TLS-over-TCP. 1697 o If Anycast addresses can be used for the server in case TCP or 1698 TLS-over-TCP, or authentication are used. 1700 In addition, any STUN usage must consider the security implications 1701 of using STUN in that usage. A number of attacks against STUN are 1702 known (see the Security Considerations section in this document), and 1703 any usage must consider how these attacks can be thwarted or 1704 mitigated. 1706 Finally, a usage must consider whether its usage of STUN is an 1707 example of the Unilateral Self-Address Fixing approach to NAT 1708 traversal, and if so, address the questions raised in RFC 3424 1709 [RFC3424]. 1711 14. STUN Attributes 1713 After the STUN header are zero or more attributes. Each attribute 1714 MUST be TLV encoded, with a 16-bit type, 16-bit length, and value. 1715 Each STUN attribute MUST end on a 32-bit boundary. As mentioned 1716 above, all fields in an attribute are transmitted most significant 1717 bit first. 1719 0 1 2 3 1720 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 1721 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1722 | Type | Length | 1723 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1724 | Value (variable) .... 1725 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1727 Figure 4: Format of STUN Attributes 1729 The value in the length field MUST contain the length of the Value 1730 part of the attribute, prior to padding, measured in bytes. Since 1731 STUN aligns attributes on 32-bit boundaries, attributes whose content 1732 is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of 1733 padding so that its value contains a multiple of 4 bytes. The 1734 padding bits MUST be set to zero on sending and MUST be ignored by 1735 the receiver. 1737 Any attribute type MAY appear more than once in a STUN message. 1738 Unless specified otherwise, the order of appearance is significant: 1739 only the first occurrence needs to be processed by a receiver, and 1740 any duplicates MAY be ignored by a receiver. 1742 To allow future revisions of this specification to add new attributes 1743 if needed, the attribute space is divided into two ranges. 1744 Attributes with type values between 0x0000 and 0x7FFF are 1745 comprehension-required attributes, which means that the STUN agent 1746 cannot successfully process the message unless it understands the 1747 attribute. Attributes with type values between 0x8000 and 0xFFFF are 1748 comprehension-optional attributes, which means that those attributes 1749 can be ignored by the STUN agent if it does not understand them. 1751 The set of STUN attribute types is maintained by IANA. The initial 1752 set defined by this specification is found in Section 18.3. 1754 The rest of this section describes the format of the various 1755 attributes defined in this specification. 1757 14.1. MAPPED-ADDRESS 1759 The MAPPED-ADDRESS attribute indicates a reflexive transport address 1760 of the client. It consists of an 8-bit address family and a 16-bit 1761 port, followed by a fixed-length value representing the IP address. 1762 If the address family is IPv4, the address MUST be 32 bits. If the 1763 address family is IPv6, the address MUST be 128 bits. All fields 1764 must be in network byte order. 1766 The format of the MAPPED-ADDRESS attribute is: 1768 0 1 2 3 1769 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 1770 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1771 |0 0 0 0 0 0 0 0| Family | Port | 1772 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1773 | | 1774 | Address (32 bits or 128 bits) | 1775 | | 1776 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1778 Figure 5: Format of MAPPED-ADDRESS Attribute 1780 The address family can take on the following values: 1782 0x01:IPv4 1783 0x02:IPv6 1785 The first 8 bits of the MAPPED-ADDRESS MUST be set to 0 and MUST be 1786 ignored by receivers. These bits are present for aligning parameters 1787 on natural 32-bit boundaries. 1789 This attribute is used only by servers for achieving backwards 1790 compatibility with [RFC3489] clients. 1792 14.2. XOR-MAPPED-ADDRESS 1794 The XOR-MAPPED-ADDRESS attribute is identical to the MAPPED-ADDRESS 1795 attribute, except that the reflexive transport address is obfuscated 1796 through the XOR function. 1798 The format of the XOR-MAPPED-ADDRESS is: 1800 0 1 2 3 1801 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 1802 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1803 |0 0 0 0 0 0 0 0| Family | X-Port | 1804 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1805 | X-Address (Variable) 1806 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1808 Figure 6: Format of XOR-MAPPED-ADDRESS Attribute 1810 The Family represents the IP address family, and is encoded 1811 identically to the Family in MAPPED-ADDRESS. 1813 X-Port is computed by XOR'ing the mapped port with the most 1814 significant 16 bits of the magic cookie. If the IP address family is 1815 IPv4, X-Address is computed by XOR'ing the mapped IP address with the 1816 magic cookie. If the IP address family is IPv6, X-Address is 1817 computed by XOR'ing the mapped IP address with the concatenation of 1818 the magic cookie and the 96-bit transaction ID. In all cases, the 1819 XOR operation works on its inputs in network byte order (that is, the 1820 order they will be encoded in the message). 1822 The rules for encoding and processing the first 8 bits of the 1823 attribute's value, the rules for handling multiple occurrences of the 1824 attribute, and the rules for processing address families are the same 1825 as for MAPPED-ADDRESS. 1827 Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only in their 1828 encoding of the transport address. The former encodes the transport 1829 address by exclusive-or'ing it with the magic cookie. The latter 1830 encodes it directly in binary. RFC 3489 originally specified only 1831 MAPPED-ADDRESS. However, deployment experience found that some NATs 1832 rewrite the 32-bit binary payloads containing the NAT's public IP 1833 address, such as STUN's MAPPED-ADDRESS attribute, in the well-meaning 1834 but misguided attempt at providing a generic Application Layer 1835 Gateway (ALG) function. Such behavior interferes with the operation 1836 of STUN and also causes failure of STUN's message-integrity checking. 1838 14.3. USERNAME 1840 The USERNAME attribute is used for message integrity. It identifies 1841 the username and password combination used in the message-integrity 1842 check. 1844 The value of USERNAME is a variable-length value containing the 1845 authentication username. It MUST contain a UTF-8 [RFC3629] encoded 1846 sequence of less than 509 bytes, and MUST have been processed using 1847 the UsernameCasePreserved profile [RFC8265]. A compliant 1848 implementation MUST be able to parse UTF-8 encoded sequence of 763 or 1849 less bytes, to be compatible with [RFC5389] that mistakenly assumed 1850 up to 6 bytes per characters encoded. 1852 14.4. USERHASH 1854 The USERHASH attribute is used as a replacement for the USERNAME 1855 attribute when username anonymity is supported. 1857 The value of USERHASH has a fixed length of 32 bytes. The username 1858 MUST have been processed using the UsernameCasePreserved profile 1859 [RFC8265] and the realm MUST have been processed using the 1860 OpaqueString profile [RFC8265] before hashing. 1862 The following is the operation that the client will perform to hash 1863 the username: 1865 userhash = SHA-256(UsernameCasePreserved(username) 1866 ":" OpaqueString(realm)) 1868 14.5. MESSAGE-INTEGRITY 1870 The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of 1871 the STUN message. The MESSAGE-INTEGRITY attribute can be present in 1872 any STUN message type. Since it uses the SHA-1 hash, the HMAC will 1873 be 20 bytes. 1875 The key for the HMAC depends on which credential mechanism is in use. 1876 Section 9.1.1 defines the key for the short-term credential mechanism 1877 and Section 9.2.2 defines the key for the long-term credential 1878 mechanism. Other credential mechanisms MUST define the key that is 1879 used for the HMAC. 1881 The text used as input to HMAC is the STUN message, up to and 1882 including the attribute preceding the MESSAGE-INTEGRITY attribute. 1883 The length field of the STUN message header is adjusted to point to 1884 the end of the MESSAGE-INTEGRITY attribute. The value of the 1885 MESSAGE-INTEGRITY attribute is set to a dummy value. 1887 Once the computation is performed, the value of the MESSAGE-INTEGRITY 1888 attribute is filled in, and the value of the length in the STUN 1889 header is set to its correct value -- the length of the entire 1890 message. Similarly, when validating the MESSAGE-INTEGRITY, the 1891 length field in the STUN header must be adjusted to point to the end 1892 of the MESSAGE-INTEGRITY attribute prior to calculating the HMAC over 1893 the STUN message, up to and including the attribute preceding the 1894 MESSAGE-INTEGRITY attribute. Such adjustment is necessary when 1895 attributes, such as FINGERPRINT and MESSAGE-INTEGRITY-SHA256, appear 1896 after MESSAGE-INTEGRITY. See also [RFC5769] for examples of such 1897 calculations. 1899 14.6. MESSAGE-INTEGRITY-SHA256 1901 The MESSAGE-INTEGRITY-SHA256 attribute contains an HMAC-SHA256 1902 [RFC2104] of the STUN message. The MESSAGE-INTEGRITY-SHA256 1903 attribute can be present in any STUN message type. The MESSAGE- 1904 INTEGRITY-SHA256 attribute contains an initial portion of the HMAC- 1905 SHA-256 [RFC2104] of the STUN message. The value will be at most 32 1906 bytes, but MUST be at least 16 bytes, and MUST be a multiple of 4 1907 bytes. The value must be the full 32 bytes unless the STUN Usage 1908 explicitly specifies that truncation is allowed. STUN Usages may 1909 specify a minimum length longer than 16 bytes. 1911 The key for the HMAC depends on which credential mechanism is in use. 1912 Section 9.1.1 defines the key for the short-term credential mechanism 1913 and Section 9.2.2 defines the key for the long-term credential 1914 mechanism. Other credential mechanism MUST define the key that is 1915 used for the HMAC. 1917 The text used as input to HMAC is the STUN message, up to and 1918 including the attribute preceding the MESSAGE-INTEGRITY-SHA256 1919 attribute. The length field of the STUN message header is adjusted 1920 to point to the end of the MESSAGE-INTEGRITY-SHA256 attribute. The 1921 value of the MESSAGE-INTEGRITY-SHA256 attribute is set to a dummy 1922 value. 1924 Once the computation is performed, the value of the MESSAGE- 1925 INTEGRITY-SHA256 attribute is filled in, and the value of the length 1926 in the STUN header is set to its correct value -- the length of the 1927 entire message. Similarly, when validating the MESSAGE-INTEGRITY- 1928 SHA256, the length field in the STUN header must be adjusted to point 1929 to the end of the MESSAGE-INTEGRITY-SHA256 attribute prior to 1930 calculating the HMAC over the STUN message, up to and including the 1931 attribute preceding the MESSAGE-INTEGRITY-SHA256 attribute. Such 1932 adjustment is necessary when attributes, such as FINGERPRINT, appear 1933 after MESSAGE-INTEGRITY-SHA256. See also Appendix B.1 for examples 1934 of such calculations. 1936 14.7. FINGERPRINT 1938 The FINGERPRINT attribute MAY be present in all STUN messages. 1940 The value of the attribute is computed as the CRC-32 of the STUN 1941 message up to (but excluding) the FINGERPRINT attribute itself, 1942 XOR'ed with the 32-bit value 0x5354554e. (The XOR operation ensures 1943 that the FINGERPRINT test will not report a false positive on a 1944 packet containing a CRC-32 generated by an application protocol.) 1945 The 32-bit CRC is the one defined in ITU V.42 [ITU.V42.2002], which 1946 has a generator polynomial of x^32 + x^26 + x^23 + x^22 + x^16 + x^12 1947 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1. See the sample 1948 code for the CRC-32 in Section 8 of [RFC1952]. 1950 When present, the FINGERPRINT attribute MUST be the last attribute in 1951 the message, and thus will appear after MESSAGE-INTEGRITY and 1952 MESSAGE-INTEGRITY-SHA256. 1954 The FINGERPRINT attribute can aid in distinguishing STUN packets from 1955 packets of other protocols. See Section 7. 1957 As with MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, the CRC used 1958 in the FINGERPRINT attribute covers the length field from the STUN 1959 message header. Therefore, this value must be correct and include 1960 the CRC attribute as part of the message length, prior to computation 1961 of the CRC. When using the FINGERPRINT attribute in a message, the 1962 attribute is first placed into the message with a dummy value, then 1963 the CRC is computed, and then the value of the attribute is updated. 1964 If the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute are 1965 also present, then they must be present with the correct message- 1966 integrity value before the CRC is computed, since the CRC is done 1967 over the value of the MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 1968 attributes as well. 1970 14.8. ERROR-CODE 1972 The ERROR-CODE attribute is used in error response messages. It 1973 contains a numeric error code value in the range of 300 to 699 plus a 1974 textual reason phrase encoded in UTF-8 [RFC3629], and is consistent 1975 in its code assignments and semantics with SIP [RFC3261] and HTTP 1976 [RFC7231]. The reason phrase is meant for diagnostic purposes, and 1977 can be anything appropriate for the error code. Recommended reason 1978 phrases for the defined error codes are included in the IANA registry 1979 for error codes. The reason phrase MUST be a UTF-8 [RFC3629] encoded 1980 sequence of less than 128 characters (which can be as long as 509 1981 bytes when encoding them or 763 bytes when decoding them). 1983 0 1 2 3 1984 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 1985 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1986 | Reserved, should be 0 |Class| Number | 1987 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1988 | Reason Phrase (variable) .. 1989 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1991 Figure 7: ERROR-CODE Attribute 1993 To facilitate processing, the class of the error code (the hundreds 1994 digit) is encoded separately from the rest of the code, as shown in 1995 Figure 7. 1997 The Reserved bits SHOULD be 0, and are for alignment on 32-bit 1998 boundaries. Receivers MUST ignore these bits. The Class represents 1999 the hundreds digit of the error code. The value MUST be between 3 2000 and 6. The Number represents the binary encoding of the error code 2001 modulo 100, and its value MUST be between 0 and 99. 2003 The following error codes, along with their recommended reason 2004 phrases, are defined: 2006 300 Try Alternate: The client should contact an alternate server for 2007 this request. This error response MUST only be sent if the 2008 request included either a USERNAME or USERHASH attribute and a 2009 valid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute; 2010 otherwise, it MUST NOT be sent and error code 400 (Bad Request) is 2011 suggested. This error response MUST be protected with the 2012 MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute, and 2013 receivers MUST validate the MESSAGE-INTEGRITY or MESSAGE- 2014 INTEGRITY-SHA256 of this response before redirecting themselves to 2015 an alternate server. 2017 Note: Failure to generate and validate message integrity for a 300 2018 response allows an on-path attacker to falsify a 300 response thus 2019 causing subsequent STUN messages to be sent to a victim. 2021 400 Bad Request: The request was malformed. The client SHOULD NOT 2022 retry the request without modification from the previous attempt. 2023 The server may not be able to generate a valid MESSAGE-INTEGRITY 2024 or MESSAGE-INTEGRITY-SHA256 for this error, so the client MUST NOT 2025 expect a valid MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 2026 attribute on this response. 2028 401 Unauthenticated: The request did not contain the correct 2029 credentials to proceed. The client should retry the request with 2030 proper credentials. 2032 420 Unknown Attribute: The server received a STUN packet containing 2033 a comprehension-required attribute that it did not understand. 2034 The server MUST put this unknown attribute in the UNKNOWN- 2035 ATTRIBUTE attribute of its error response. 2037 438 Stale Nonce: The NONCE used by the client was no longer valid. 2038 The client should retry, using the NONCE provided in the response. 2040 500 Server Error: The server has suffered a temporary error. The 2041 client should try again. 2043 14.9. REALM 2045 The REALM attribute may be present in requests and responses. It 2046 contains text that meets the grammar for "realm-value" as described 2047 in [RFC3261] but without the double quotes and their surrounding 2048 whitespace. That is, it is an unquoted realm-value (and is therefore 2049 a sequence of qdtext or quoted-pair). It MUST be a UTF-8 [RFC3629] 2050 encoded sequence of less than 128 characters (which can be as long as 2051 509 bytes when encoding them and as long as 763 bytes when decoding 2052 them), and MUST have been processed using the OpaqueString profile 2053 [RFC8265]. 2055 Presence of the REALM attribute in a request indicates that long-term 2056 credentials are being used for authentication. Presence in certain 2057 error responses indicates that the server wishes the client to use a 2058 long-term credential in that realm for authentication. 2060 14.10. NONCE 2062 The NONCE attribute may be present in requests and responses. It 2063 contains a sequence of qdtext or quoted-pair, which are defined in 2064 [RFC3261]. Note that this means that the NONCE attribute will not 2065 contain the actual surrounding quote characters. See [RFC7616], 2066 Section 5.4, for guidance on selection of nonce values in a server. 2067 It MUST be less than 128 characters (which can be as long as 509 2068 bytes when encoding them and a long as 763 bytes when decoding them). 2070 14.11. PASSWORD-ALGORITHMS 2072 The PASSWORD-ALGORITHMS attribute may be present in requests and 2073 responses. It contains the list of algorithms that the server can 2074 use to derive the long-term password. 2076 The set of known algorithms is maintained by IANA. The initial set 2077 defined by this specification is found in Section 18.5. 2079 The attribute contains a list of algorithm numbers and variable 2080 length parameters. The algorithm number is a 16-bit value as defined 2081 in Section 18.5. The parameters start with the length (prior to 2082 padding) of the parameters as a 16-bit value, followed by the 2083 parameters that are specific to each algorithm. The parameters are 2084 padded to a 32-bit boundary, in the same manner as an attribute. 2086 0 1 2 3 2087 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 2088 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2089 | Algorithm 1 | Algorithm 1 Parameters Length | 2090 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2091 | Algorithm 1 Parameters (variable) 2092 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2093 | Algorithm 2 | Algorithm 2 Parameters Length | 2094 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2095 | Algorithm 2 Parameter (variable) 2096 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2097 | ... 2099 Figure 8: Format of PASSWORD-ALGORITHMS Attribute 2101 14.12. PASSWORD-ALGORITHM 2103 The PASSWORD-ALGORITHM attribute is present only in requests. It 2104 contains the algorithms that the server must use to derive a key from 2105 the long-term password. 2107 The set of known algorithms is maintained by IANA. The initial set 2108 defined by this specification is found in Section 18.5. 2110 The attribute contains an algorithm number and variable length 2111 parameters. The algorithm number is a 16-bit value as defined in 2112 Section 18.5. The parameters starts with the length (prior to 2113 padding) of the parameters as a 16-bit value, followed by the 2114 parameters that are specific to the algorithm. The parameters are 2115 padded to a 32-bit boundary, in the same manner as an attribute. 2116 Similarly, the padding bits MUST be set to zero on sending and MUST 2117 be ignored by the receiver. 2119 0 1 2 3 2120 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 2121 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2122 | Algorithm | Algorithm Parameters Length | 2123 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2124 | Algorithm Parameters (variable) 2125 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2127 Figure 9: Format of PASSWORD-ALGORITHM Attribute 2129 14.13. UNKNOWN-ATTRIBUTES 2131 The UNKNOWN-ATTRIBUTES attribute is present only in an error response 2132 when the response code in the ERROR-CODE attribute is 420. 2134 The attribute contains a list of 16-bit values, each of which 2135 represents an attribute type that was not understood by the server. 2137 0 1 2 3 2138 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 2139 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2140 | Attribute 1 Type | Attribute 2 Type | 2141 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2142 | Attribute 3 Type | Attribute 4 Type ... 2143 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2145 Figure 10: Format of UNKNOWN-ATTRIBUTES Attribute 2147 Note: In [RFC3489], this field was padded to 32 by duplicating the 2148 last attribute. In this version of the specification, the normal 2149 padding rules for attributes are used instead. 2151 14.14. SOFTWARE 2153 The SOFTWARE attribute contains a textual description of the software 2154 being used by the agent sending the message. It is used by clients 2155 and servers. Its value SHOULD include manufacturer and version 2156 number. The attribute has no impact on operation of the protocol, 2157 and serves only as a tool for diagnostic and debugging purposes. The 2158 value of SOFTWARE is variable length. It MUST be a UTF-8 [RFC3629] 2159 encoded sequence of less than 128 characters (which can be as long as 2160 509 when encoding them and as long as 763 bytes when decoding them). 2162 14.15. ALTERNATE-SERVER 2164 The alternate server represents an alternate transport address 2165 identifying a different STUN server that the STUN client should try. 2167 It is encoded in the same way as MAPPED-ADDRESS, and thus refers to a 2168 single server by IP address. 2170 14.16. ALTERNATE-DOMAIN 2172 The alternate domain represents the domain name that is used to 2173 verify the IP address in the ALTERNATE-SERVER attribute when the 2174 transport protocol uses TLS or DTLS. 2176 The value of ALTERNATE-DOMAIN is variable length. It MUST be a valid 2177 DNS name [RFC1123] (including A-labels [RFC5890]) of 255 or less 2178 ASCII characters. 2180 15. Operational Considerations 2182 STUN MAY be used with anycast addresses, but only with UDP and in 2183 STUN Usages where authentication is not used. 2185 16. Security Considerations 2187 Implementations and deployments of a STUN Usage using TLS or DTLS 2188 MUST follow the recommendations in [BCP195]. 2190 Implementations and deployments of a STUN Usage using the Long-Term 2191 Credential Mechanism (Section 9.2) MUST follow the recommendations in 2192 Section 5 of [RFC7616]. 2194 16.1. Attacks against the Protocol 2196 16.1.1. Outside Attacks 2198 An attacker can try to modify STUN messages in transit, in order to 2199 cause a failure in STUN operation. These attacks are detected for 2200 both requests and responses through the message-integrity mechanism, 2201 using either a short-term or long-term credential. Of course, once 2202 detected, the manipulated packets will be dropped, causing the STUN 2203 transaction to effectively fail. This attack is possible only by an 2204 on-path attacker. 2206 An attacker that can observe, but not modify, STUN messages in- 2207 transit (for example, an attacker present on a shared access medium, 2208 such as Wi-Fi), can see a STUN request, and then immediately send a 2209 STUN response, typically an error response, in order to disrupt STUN 2210 processing. This attack is also prevented for messages that utilize 2211 MESSAGE-INTEGRITY. However, some error responses, those related to 2212 authentication in particular, cannot be protected by MESSAGE- 2213 INTEGRITY. When STUN itself is run over a secure transport protocol 2214 (e.g., TLS), these attacks are completely mitigated. 2216 Depending on the STUN usage, these attacks may be of minimal 2217 consequence and thus do not require message integrity to mitigate. 2218 For example, when STUN is used to a basic STUN server to discover a 2219 server reflexive candidate for usage with ICE, authentication and 2220 message integrity are not required since these attacks are detected 2221 during the connectivity check phase. The connectivity checks 2222 themselves, however, require protection for proper operation of ICE 2223 overall. As described in Section 13, STUN usages describe when 2224 authentication and message integrity are needed. 2226 Since STUN uses the HMAC of a shared secret for authentication and 2227 integrity protection, it is subject to offline dictionary attacks. 2228 When authentication is utilized, it SHOULD be with a strong password 2229 that is not readily subject to offline dictionary attacks. 2230 Protection of the channel itself, using TLS or DTLS, mitigates these 2231 attacks. 2233 STUN supports both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, 2234 which is subject to bid-down attacks by an on-path attacker that 2235 would strip the MESSAGE-INTEGRITY-SHA256 attribute leaving only the 2236 MESSAGE-INTEGRITY attribute and exploiting a potential vulnerability. 2237 Protection of the channel itself, using TLS or DTLS, mitigates these 2238 attacks. Timely removal of the support of MESSAGE-INTEGRITY in a 2239 future version of STUN is necessary. 2241 Note: The use of SHA-256 for password hashing does not meet modern 2242 standards, which are aimed at slowing down exhaustive password search 2243 by providing a relatively slow minimum time to compute the hash. 2244 Although better algorithms such as Argon2 [I-D.irtf-cfrg-argon2] are 2245 available, SHA-256 was chosen for consistency with [RFC7616]. 2247 16.1.2. Inside Attacks 2249 A rogue client may try to launch a DoS attack against a server by 2250 sending it a large number of STUN requests. Fortunately, STUN 2251 requests can be processed statelessly by a server, making such 2252 attacks hard to launch effectively. 2254 A rogue client may use a STUN server as a reflector, sending it 2255 requests with a falsified source IP address and port. In such a 2256 case, the response would be delivered to that source IP and port. 2257 There is no amplification of the number of packets with this attack 2258 (the STUN server sends one packet for each packet sent by the 2259 client), though there is a small increase in the amount of data, 2260 since STUN responses are typically larger than requests. This attack 2261 is mitigated by ingress source address filtering. 2263 Revealing the specific software version of the agent through the 2264 SOFTWARE attribute might allow them to become more vulnerable to 2265 attacks against software that is known to contain security holes. 2266 Implementers SHOULD make usage of the SOFTWARE attribute a 2267 configurable option. 2269 16.1.3. Bid-Down Attacks 2271 This document adds the possibility of selecting different algorithms 2272 for protecting the confidentiality of the passwords stored on the 2273 server side when using the Long-Term Credential Mechanism, while 2274 still ensuring compatibility with MD5, which was the algorithm used 2275 in a previous version of this protocol. It works by having the 2276 server send back to the client the list of algorithms supported in a 2277 PASSWORD-ALGORITHMS attribute, and having the client send back a 2278 PASSWORD-ALGORITHM attribute containing the algorithm selected. 2280 Because the PASSWORD-ALGORITHMS attribute has to be sent in an 2281 unauthenticated response, an on-path attacker wanting to exploit an 2282 eventual vulnerability in MD5 can just strip the PASSWORD-ALGORITHMS 2283 attribute from the unprotected response, thus making the server 2284 subsequently act as if the client was implementing a previous version 2285 of this protocol. 2287 To protect against this attack and other similar bid-down attacks, 2288 the nonce is enriched with a set of security bits which indicates 2289 which security features are in use. In the case of the selection of 2290 the password algorithm the matching bit is set in the nonce returned 2291 by the server in the same response that contains the PASSWORD- 2292 ALGORITHMS attribute. Because the nonce used in subsequent 2293 authenticated transactions is verified by the server to be identical 2294 to what was originally sent, it cannot be modified by an on-path 2295 attacker. Additionally, the client is mandated to copy the received 2296 PASSWORD-ALGORITHMS attribute in the next authenticated transaction 2297 to that server. 2299 An on-path attack that removes the PASSWORD-ALGORITHMS will be 2300 detected because the client will not be able to send it back to the 2301 server in the next authenticated transaction. The client will detect 2302 that attack because the security bit is set, but the matching 2303 attribute is missing, ending the session. A client using an older 2304 version of this protocol will not send the PASSWORD-ALGORITHMS back 2305 but can only use MD5 anyway, so the attack is inconsequential. 2307 The on-path attack may also try to remove the security bit together 2308 with the PASSWORD-ALGORITHMS attribute, but the server will discover 2309 that when the next authenticated transaction contains an invalid 2310 nonce. 2312 An on-path attack that removes some algorithms from the PASSWORD- 2313 ALGORITHMS attribute will be equally defeated because that attribute 2314 will be different from the original one when the server verifies it 2315 in the subsequent authenticated transaction. 2317 Note that the bid-down protection mechanism introduced in this 2318 document is inherently limited by the fact that it is not possible to 2319 detect an attack until the server receives the second request after 2320 the 401 response. 2322 SHA-256 was chosen as the new default for password hashing for its 2323 compatibility with [RFC7616] but because SHA-256 (like MD5) is a 2324 comparatively fast algorithm, it does little to deter brute force 2325 attacks. Specifically, this means that if the user has a weak 2326 password: 2328 o An attacker who captures the server's password file can often 2329 determine the user's password and thus impersonate the user to 2330 other servers where they have used that password. Note that such 2331 an attacker can impersonate the user to the server itself without 2332 any brute force attack. 2334 o An attacker who captures a single exchange can brute force the 2335 user's password and thus potentially impersonate the user to the 2336 server and other servers where they have used the same password. 2338 A stronger (which is to say slower) algorithm, like Argon2 2339 [I-D.irtf-cfrg-argon2], would help both of these cases, but in the 2340 case of the first attack, only after until the database entry for 2341 this user is updated to exclusively use that stronger mechanism. 2343 The bid-down defenses in this protocol prevent an attacker from 2344 forcing the client and server to complete a handshake using weaker 2345 algorithms than they jointly support, but only if the weakest joint 2346 algorithm is strong enough that it cannot be brute-forced. However, 2347 this does not defend against many attacks on those algorithms; 2348 specifically, an on-path attacker might perform a bid-down attack on 2349 a client which supported both Argon2 [I-D.irtf-cfrg-argon2] and 2350 SHA-256 for password hashing and use that to collect a MESSAGE- 2351 INTEGRITY-SHA256 value which it uses for an offline brute-force 2352 attack. This would be detected when the server receives the second 2353 request, but that does not prevent the attacker from obtaining the 2354 MESSAGE-INTEGRITY-SHA256 value. 2356 Similarly, an attack against the USERHASH mechanism will not succeed 2357 in establishing a session as the server will detect that the feature 2358 was discarded on-path, but the client would still have been convinced 2359 to send its username in clear in the USERNAME attribute, thus 2360 disclosing it to the attacker. 2362 Finally, when the bid-down protection mechanism is employed for a 2363 future upgrade of the HMAC algorithm used to protect message, it will 2364 offer only a limited protection if the current HMAC algorithm is 2365 already compromised. 2367 16.2. Attacks Affecting the Usage 2369 This section lists attacks that might be launched against a usage of 2370 STUN. Each STUN usage must consider whether these attacks are 2371 applicable to it, and if so, discuss counter-measures. 2373 Most of the attacks in this section revolve around an attacker 2374 modifying the reflexive address learned by a STUN client through a 2375 Binding request/response transaction. Since the usage of the 2376 reflexive address is a function of the usage, the applicability and 2377 remediation of these attacks are usage-specific. In common 2378 situations, modification of the reflexive address by an on-path 2379 attacker is easy to do. Consider, for example, the common situation 2380 where STUN is run directly over UDP. In this case, an on-path 2381 attacker can modify the source IP address of the Binding request 2382 before it arrives at the STUN server. The STUN server will then 2383 return this IP address in the XOR-MAPPED-ADDRESS attribute to the 2384 client, and send the response back to that (falsified) IP address and 2385 port. If the attacker can also intercept this response, it can 2386 direct it back towards the client. Protecting against this attack by 2387 using a message-integrity check is impossible, since a message- 2388 integrity value cannot cover the source IP address, since the 2389 intervening NAT must be able to modify this value. Instead, one 2390 solution to preventing the attacks listed below is for the client to 2391 verify the reflexive address learned, as is done in ICE [RFC8445]. 2393 Other usages may use other means to prevent these attacks. 2395 16.2.1. Attack I: Distributed DoS (DDoS) against a Target 2397 In this attack, the attacker provides one or more clients with the 2398 same faked reflexive address that points to the intended target. 2399 This will trick the STUN clients into thinking that their reflexive 2400 addresses are equal to that of the target. If the clients hand out 2401 that reflexive address in order to receive traffic on it (for 2402 example, in SIP messages), the traffic will instead be sent to the 2403 target. This attack can provide substantial amplification, 2404 especially when used with clients that are using STUN to enable 2405 multimedia applications. However, it can only be launched against 2406 targets for which packets from the STUN server to the target pass 2407 through the attacker, limiting the cases in which it is possible. 2409 16.2.2. Attack II: Silencing a Client 2411 In this attack, the attacker provides a STUN client with a faked 2412 reflexive address. The reflexive address it provides is a transport 2413 address that routes to nowhere. As a result, the client won't 2414 receive any of the packets it expects to receive when it hands out 2415 the reflexive address. This exploitation is not very interesting for 2416 the attacker. It impacts a single client, which is frequently not 2417 the desired target. Moreover, any attacker that can mount the attack 2418 could also deny service to the client by other means, such as 2419 preventing the client from receiving any response from the STUN 2420 server, or even a DHCP server. As with the attack in Section 16.2.1, 2421 this attack is only possible when the attacker is on path for packets 2422 sent from the STUN server towards this unused IP address. 2424 16.2.3. Attack III: Assuming the Identity of a Client 2426 This attack is similar to attack II. However, the faked reflexive 2427 address points to the attacker itself. This allows the attacker to 2428 receive traffic that was destined for the client. 2430 16.2.4. Attack IV: Eavesdropping 2432 In this attack, the attacker forces the client to use a reflexive 2433 address that routes to itself. It then forwards any packets it 2434 receives to the client. This attack would allow the attacker to 2435 observe all packets sent to the client. However, in order to launch 2436 the attack, the attacker must have already been able to observe 2437 packets from the client to the STUN server. In most cases (such as 2438 when the attack is launched from an access network), this means that 2439 the attacker could already observe packets sent to the client. This 2440 attack is, as a result, only useful for observing traffic by 2441 attackers on the path from the client to the STUN server, but not 2442 generally on the path of packets being routed towards the client. 2444 Note that this attack can be trivially launched by the STUN server 2445 itself, so users of STUN servers should have the same level of trust 2446 in them as any other node that can insert themselves into the 2447 communication flow. 2449 16.3. Hash Agility Plan 2451 This specification uses both HMAC-SHA256 for computation of the 2452 message integrity, sometimes in combination with HMAC-SHA1. If, at a 2453 later time, HMAC-SHA256 is found to be compromised, the following is 2454 the remedy that will be applied: 2456 o Both a new message-integrity attribute and a new STUN Security 2457 Feature bit will be allocated in a Standard Track document. The 2458 new message-integrity attribute will have its value computed using 2459 a new hash. The STUN Security Feature bit will be used to 2460 simultaneously signal to a STUN client using the Long Term 2461 Credential Mechanism that this server supports this new hash 2462 algorithm, and will prevent bid-down attacks on the new message- 2463 integrity attribute. 2465 o STUN Clients and Servers using the Short Term Credential Mechanism 2466 will need to update the external mechanism that they use to signal 2467 what message-integrity attributes are in use. 2469 The bid-down protection mechanism described in this document is new, 2470 and thus cannot currently protect against a bid-down attack that 2471 lowers the strength of the hash algorithm to HMAC-SHA1. This is why, 2472 after a transition period, a new document updating this document will 2473 assign a new STUN Security Feature bit for deprecating HMAC-SHA1. 2474 When used, this bit will signal that HMAC-SHA1 is deprecated and 2475 should no longer be used. 2477 Similarly, if SHA256 is found to be compromised, a new user-hash 2478 attribute and a new STUN Security Feature bit will be allocated in a 2479 Standards Track document. The new user-hash attribute will have its 2480 value computed using a new hash. The STUN Security Feature bit will 2481 be used to simultaneously signal to a STUN client using the Long Term 2482 Credential Mechanism that this server supports this new hash 2483 algorithm for the user-hash attribute, and will prevent bid-down 2484 attacks on the new user-hash attribute. 2486 17. IAB Considerations 2488 The IAB has studied the problem of Unilateral Self-Address Fixing 2489 (UNSAF), which is the general process by which a client attempts to 2490 determine its address in another realm on the other side of a NAT 2491 through a collaborative protocol reflection mechanism ([RFC3424]). 2492 STUN can be used to perform this function using a Binding request/ 2493 response transaction if one agent is behind a NAT and the other is on 2494 the public side of the NAT. 2496 The IAB has suggested that protocols developed for this purpose 2497 document a specific set of considerations. Because some STUN usages 2498 provide UNSAF functions (such as ICE [RFC8445] ), and others do not 2499 (such as SIP Outbound [RFC5626]), answers to these considerations 2500 need to be addressed by the usages themselves. 2502 18. IANA Considerations 2504 18.1. STUN Security Features Registry 2506 A STUN Security Feature set defines 24 bit as flags. 2508 IANA is requested to create a new registry containing the STUN 2509 Security Features that are protected by the bid-down attack 2510 prevention mechanism described in section Section 9.2.1. 2512 The initial STUN Security Features are: 2514 Bit 0: Password algorithms 2515 Bit 1: Username anonymity 2516 Bit 2-23: Unassigned 2518 Bits are assigned starting from the most significant side of the bit 2519 set, so Bit 0 is the leftmost bit and Bit 23 the rightmost bit. 2521 New Security Features are assigned by a Standards Action [RFC8126]. 2523 18.2. STUN Methods Registry 2525 IANA is requested to update the name for method 0x002 and the 2526 reference from RFC 5389 to RFC-to-be for the following STUN methods: 2528 0x000: (Reserved) 2529 0x001: Binding 2530 0x002: (Reserved; prior to [RFC5389] this was SharedSecret) 2532 18.3. STUN Attribute Registry 2534 18.3.1. Updated Attributes 2536 IANA is requested to update the names for attributes 0x0002, 0x0004, 2537 0x0005, 0x0007, and 0x000B, and the reference from RFC 5389 to RFC- 2538 to-be for the following STUN methods: 2540 Comprehension-required range (0x0000-0x7FFF): 2541 0x0000: (Reserved) 2542 0x0001: MAPPED-ADDRESS 2543 0x0002: (Reserved; prior to [RFC5389] this was RESPONSE-ADDRESS) 2544 0x0004: (Reserved; prior to [RFC5389] this was SOURCE-ADDRESS) 2545 0x0005: (Reserved; prior to [RFC5389] this was CHANGED-ADDRESS) 2546 0x0006: USERNAME 2547 0x0007: (Reserved; prior to [RFC5389] this was PASSWORD) 2548 0x0008: MESSAGE-INTEGRITY 2549 0x0009: ERROR-CODE 2550 0x000A: UNKNOWN-ATTRIBUTES 2551 0x000B: (Reserved; prior to [RFC5389] this was REFLECTED-FROM) 2552 0x0014: REALM 2553 0x0015: NONCE 2554 0x0020: XOR-MAPPED-ADDRESS 2556 Comprehension-optional range (0x8000-0xFFFF) 2557 0x8022: SOFTWARE 2558 0x8023: ALTERNATE-SERVER 2559 0x8028: FINGERPRINT 2561 18.3.2. New Attributes 2563 IANA is requested to add the following attribute to the STUN 2564 Attribute Registry: 2566 Comprehension-required range (0x0000-0x7FFF): 2567 0xXXXX: MESSAGE-INTEGRITY-SHA256 2568 0xXXXX: PASSWORD-ALGORITHM 2569 0xXXXX: USERHASH 2571 Comprehension-optional range (0x8000-0xFFFF) 2572 0xXXXX: PASSWORD-ALGORITHMS 2573 0xXXXX: ALTERNATE-DOMAIN 2575 18.4. STUN Error Code Registry 2577 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2578 for the Error Codes given in Section 14.8. 2580 IANA is requested to change the name of the 401 Error Code from 2581 "Unauthorized" to "Unauthenticated". 2583 18.5. STUN Password Algorithm Registry 2585 IANA is requested to create a new registry for Password Algorithm. 2587 A Password Algorithm is a hex number in the range 0x0000 - 0xFFFF. 2589 The initial Password Algorithms are: 2591 0x0000: Reserved 2592 0x0001: MD5 2593 0x0002: SHA-256 2594 0x0003-0xFFFF: Unassigned 2596 Password Algorithms in the first half of the range (0x0000 - 0x7FFF) 2597 are assigned by IETF Review [RFC8126]. Password Algorithms in the 2598 second half of the range (0x8000 - 0xFFFF) are assigned by Designated 2599 Expert [RFC8126]. 2601 18.5.1. Password Algorithms 2603 18.5.1.1. MD5 2605 This password algorithm is taken from [RFC1321]. 2607 The key length is 16 bytes and the parameters value is empty. 2609 Note: This algorithm MUST only be used for compatibility with legacy 2610 systems. 2612 key = MD5(username ":" OpaqueString(realm) 2613 ":" OpaqueString(password)) 2615 18.5.1.2. SHA-256 2617 This password algorithm is taken from [RFC7616]. 2619 The key length is 32 bytes and the parameters value is empty. 2621 key = SHA-256(username ":" OpaqueString(realm) 2622 ":" OpaqueString(password)) 2624 18.6. STUN UDP and TCP Port Numbers 2626 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2627 for the following ports in the Service Name and Transport Protocol 2628 Port Number Registry. 2630 stun 3478/tcp Session Traversal Utilities for NAT (STUN) port 2631 stun 3478/udp Session Traversal Utilities for NAT (STUN) port 2632 stuns 5349/tcp Session Traversal Utilities for NAT (STUN) port 2634 19. Changes Since RFC 5389 2636 This specification obsoletes [RFC5389]. This specification differs 2637 from RFC 5389 in the following ways: 2639 o Added support for DTLS-over-UDP [RFC6347]. 2641 o Made clear that the RTO is considered stale if there is no 2642 transactions with the server. 2644 o Aligned the RTO calculation with [RFC6298]. 2646 o Updated the cipher suites for TLS. 2648 o Added support for STUN URI [RFC7064]. 2650 o Added support for SHA256 message integrity. 2652 o Updated the PRECIS support to [RFC8265]. 2654 o Added protocol and registry to choose the password encryption 2655 algorithm. 2657 o Added support for anonymous username. 2659 o Added protocol and registry for preventing biddown attacks. 2661 o Sharing a NONCE is no longer permitted. 2663 o Added the possibility of using a domain name in the alternate 2664 server mechanism. 2666 o Added more C snippets. 2668 o Added test vector. 2670 20. References 2672 20.1. Normative References 2674 [ITU.V42.2002] 2675 International Telecommunications Union, "Error-correcting 2676 Procedures for DCEs Using Asynchronous-to-Synchronous 2677 Conversion", ITU-T Recommendation V.42, 2002. 2679 [KARN87] Karn, P. and C. Partridge, "Improving Round-Trip Time 2680 Estimates in Reliable Transport Protocols", August 1987. 2682 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 2683 DOI 10.17487/RFC0791, September 1981, 2684 . 2686 [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - 2687 Communication Layers", STD 3, RFC 1122, 2688 DOI 10.17487/RFC1122, October 1989, 2689 . 2691 [RFC1123] Braden, R., Ed., "Requirements for Internet Hosts - 2692 Application and Support", STD 3, RFC 1123, 2693 DOI 10.17487/RFC1123, October 1989, 2694 . 2696 [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, 2697 DOI 10.17487/RFC1321, April 1992, 2698 . 2700 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 2701 Hashing for Message Authentication", RFC 2104, 2702 DOI 10.17487/RFC2104, February 1997, 2703 . 2705 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2706 Requirement Levels", BCP 14, RFC 2119, 2707 DOI 10.17487/RFC2119, March 1997, 2708 . 2710 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2711 specifying the location of services (DNS SRV)", RFC 2782, 2712 DOI 10.17487/RFC2782, February 2000, 2713 . 2715 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2716 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2717 2003, . 2719 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 2720 Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, 2721 . 2723 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 2724 (TLS) Protocol Version 1.2", RFC 5246, 2725 DOI 10.17487/RFC5246, August 2008, 2726 . 2728 [RFC5890] Klensin, J., "Internationalized Domain Names for 2729 Applications (IDNA): Definitions and Document Framework", 2730 RFC 5890, DOI 10.17487/RFC5890, August 2010, 2731 . 2733 [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and 2734 Verification of Domain-Based Application Service Identity 2735 within Internet Public Key Infrastructure Using X.509 2736 (PKIX) Certificates in the Context of Transport Layer 2737 Security (TLS)", RFC 6125, DOI 10.17487/RFC6125, March 2738 2011, . 2740 [RFC6151] Turner, S. and L. Chen, "Updated Security Considerations 2741 for the MD5 Message-Digest and the HMAC-MD5 Algorithms", 2742 RFC 6151, DOI 10.17487/RFC6151, March 2011, 2743 . 2745 [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, 2746 "Computing TCP's Retransmission Timer", RFC 6298, 2747 DOI 10.17487/RFC6298, June 2011, 2748 . 2750 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 2751 Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, 2752 January 2012, . 2754 [RFC7064] Nandakumar, S., Salgueiro, G., Jones, P., and M. Petit- 2755 Huguenin, "URI Scheme for the Session Traversal Utilities 2756 for NAT (STUN) Protocol", RFC 7064, DOI 10.17487/RFC7064, 2757 November 2013, . 2759 [RFC7350] Petit-Huguenin, M. and G. Salgueiro, "Datagram Transport 2760 Layer Security (DTLS) as Transport for Session Traversal 2761 Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, 2762 August 2014, . 2764 [RFC7616] Shekh-Yusef, R., Ahrens, D., and S. Bremer, "HTTP Digest 2765 Access Authentication", RFC 7616, DOI 10.17487/RFC7616, 2766 September 2015, . 2768 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2769 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2770 May 2017, . 2772 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 2773 (IPv6) Specification", RFC 8200, STD 86, 2774 DOI 10.17487/RFC8200, July 2017, 2775 . 2777 [RFC8265] Saint-Andre, P. and A. Melnikov, "Preparation, 2778 Enforcement, and Comparison of Internationalized Strings 2779 Representing Usernames and Passwords", RFC 8265, 2780 DOI 10.17487/RFC8265, October 2017, 2781 . 2783 [RFC8305] Schinazi, D. and T. Pauly, "Happy Eyeballs Version 2: 2784 Better Connectivity Using Concurrency", RFC 8305, 2785 DOI 10.17487/RFC8305, December 2017, 2786 . 2788 20.2. Informative References 2790 [BCP195] Sheffer, Y., Holz, R., and P. Saint-Andre, 2791 "Recommendations for Secure Use of Transport Layer 2792 Security (TLS) and Datagram Transport Layer Security 2793 (DTLS)", BCP 195, RFC 7525, DOI 10.17487/RFC7525, May 2794 2015, . 2796 [I-D.ietf-tram-stun-pmtud] 2797 Petit-Huguenin, M. and G. Salgueiro, "Path MTU Discovery 2798 Using Session Traversal Utilities for NAT (STUN)", draft- 2799 ietf-tram-stun-pmtud-10 (work in progress), September 2800 2018. 2802 [I-D.irtf-cfrg-argon2] 2803 Biryukov, A., Dinu, D., Khovratovich, D., and S. 2804 Josefsson, "The memory-hard Argon2 password hash and 2805 proof-of-work function", draft-irtf-cfrg-argon2-04 (work 2806 in progress), November 2018. 2808 [RFC1952] Deutsch, P., "GZIP file format specification version 4.3", 2809 RFC 1952, DOI 10.17487/RFC1952, May 1996, 2810 . 2812 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 2813 A., Peterson, J., Sparks, R., Handley, M., and E. 2814 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 2815 DOI 10.17487/RFC3261, June 2002, 2816 . 2818 [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations for 2819 UNilateral Self-Address Fixing (UNSAF) Across Network 2820 Address Translation", RFC 3424, DOI 10.17487/RFC3424, 2821 November 2002, . 2823 [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, 2824 "STUN - Simple Traversal of User Datagram Protocol (UDP) 2825 Through Network Address Translators (NATs)", RFC 3489, 2826 DOI 10.17487/RFC3489, March 2003, 2827 . 2829 [RFC4107] Bellovin, S. and R. Housley, "Guidelines for Cryptographic 2830 Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, 2831 June 2005, . 2833 [RFC5090] Sterman, B., Sadolevsky, D., Schwartz, D., Williams, D., 2834 and W. Beck, "RADIUS Extension for Digest Authentication", 2835 RFC 5090, DOI 10.17487/RFC5090, February 2008, 2836 . 2838 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 2839 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 2840 DOI 10.17487/RFC5389, October 2008, 2841 . 2843 [RFC5626] Jennings, C., Ed., Mahy, R., Ed., and F. Audet, Ed., 2844 "Managing Client-Initiated Connections in the Session 2845 Initiation Protocol (SIP)", RFC 5626, 2846 DOI 10.17487/RFC5626, October 2009, 2847 . 2849 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 2850 Relays around NAT (TURN): Relay Extensions to Session 2851 Traversal Utilities for NAT (STUN)", RFC 5766, 2852 DOI 10.17487/RFC5766, April 2010, 2853 . 2855 [RFC5769] Denis-Courmont, R., "Test Vectors for Session Traversal 2856 Utilities for NAT (STUN)", RFC 5769, DOI 10.17487/RFC5769, 2857 April 2010, . 2859 [RFC5780] MacDonald, D. and B. Lowekamp, "NAT Behavior Discovery 2860 Using Session Traversal Utilities for NAT (STUN)", 2861 RFC 5780, DOI 10.17487/RFC5780, May 2010, 2862 . 2864 [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B., and A. Roach, 2865 "TCP Candidates with Interactive Connectivity 2866 Establishment (ICE)", RFC 6544, DOI 10.17487/RFC6544, 2867 March 2012, . 2869 [RFC7231] Fielding, R. and R. Reschke, "Hypertext Transfer Protocol 2870 (HTTP/1.1): Semantics and Content", RFC 7231, 2871 DOI 10.17487/RFC7231, June 2014, 2872 . 2874 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2875 Writing an IANA Considerations Section in RFCs", BCP 26, 2876 RFC 8126, DOI 10.17487/RFC8126, May 2008, 2877 . 2879 [RFC8445] Keranen, A., Holmberg, C., and J. Rosenberg, "Interactive 2880 Connectivity Establishment (ICE): A Protocol for Network 2881 Address Translator (NAT) Traversal", RFC 8445, 2882 DOI 10.17487/RFC8445, July 2018, 2883 . 2885 Appendix A. C Snippet to Determine STUN Message Types 2887 Given a 16-bit STUN message type value in host byte order in msg_type 2888 parameter, below are C macros to determine the STUN message types: 2890 2891 #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) 2892 #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) 2893 #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) 2894 #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) 2895 2897 A function to convert method and class into a message type: 2899 2900 int type(int method, int cls) { 2901 return (method & 0x1F80) << 2 | (method & 0x0070) << 1 2902 | (method & 0x000F) | (cls & 0x0002) << 7 2903 | (cls & 0x0001) << 4; 2904 } 2905 2907 A function to extract the method from the message type: 2909 2910 int method(int type) { 2911 return (type & 0x3E00) >> 2 | (type & 0x00E0) >> 1 2912 | (type & 0x000F); 2913 } 2914 2916 A function to extract the class from the message type: 2918 2919 int cls(int type) { 2920 return (type & 0x0100) >> 7 | (type & 0x0010) >> 4; 2921 } 2922 2924 Appendix B. Test Vectors 2926 This section augments the list of test vectors defined in [RFC5769] 2927 with MESSAGE-INTEGRITY-SHA256. All the formats and definitions 2928 listed in Section 2 of [RFC5769] apply here. 2930 B.1. Sample Request with Long-Term Authentication with MESSAGE- 2931 INTEGRITY-SHA256 and USERHASH 2933 This request uses the following parameters: 2935 Username: "" (without 2936 quotes) unaffected by OpaqueString [RFC8265] processing 2938 Password: "TheMtr" and "TheMatrIX" (without 2939 quotes) respectively before and after OpaqueString processing 2941 Nonce: "obMatJos2QAAAf//499k954d6OL34oL9FSTvy64sA" (without quotes) 2943 Realm: "example.org" (without quotes) 2944 00 01 00 9c Request type and message length 2945 21 12 a4 42 Magic cookie 2946 78 ad 34 33 } 2947 c6 ad 72 c0 } Transaction ID 2948 29 da 41 2e } 2949 XX XX 00 20 USERHASH attribute header 2950 4a 3c f3 8f } 2951 ef 69 92 bd } 2952 a9 52 c6 78 } 2953 04 17 da 0f } Userhash value (32 bytes) 2954 24 81 94 15 } 2955 56 9e 60 b2 } 2956 05 c4 6e 41 } 2957 40 7f 17 04 } 2958 00 15 00 29 NONCE attribute header 2959 6f 62 4d 61 } 2960 74 4a 6f 73 } 2961 32 41 41 41 } 2962 43 66 2f 2f } 2963 34 39 39 6b } Nonce value and padding (3 bytes) 2964 39 35 34 64 } 2965 36 4f 4c 33 } 2966 34 6f 4c 39 } 2967 46 53 54 76 } 2968 79 36 34 73 } 2969 41 00 00 00 } 2970 00 14 00 0b REALM attribute header 2971 65 78 61 6d } 2972 70 6c 65 2e } Realm value (11 bytes) and padding (1 byte) 2973 6f 72 67 00 } 2974 XX XX 00 20 MESSAGE-INTEGRITY-SHA256 attribute header 2975 c4 ec a2 b6 } 2976 24 6f 26 be } 2977 bc 2f 77 49 } 2978 07 c2 00 a3 } HMAC-SHA256 value 2979 76 c7 c2 8e } 2980 b4 d1 26 60 } 2981 bb fe 9f 28 } 2982 0e 85 71 f2 } 2984 Note: Before publication, the XX XX placeholder must be replaced by 2985 the value assigned to MESSAGE-INTEGRITY-SHA256 and USERHASH by 2986 IANA. The MESSAGE-INTEGRITY-SHA256 attribute value will need to 2987 be updated after this. 2989 Appendix C. Release notes 2991 This section must be removed before publication as an RFC. 2993 C.1. Modifications between draft-ietf-tram-stunbis-21 and draft-ietf- 2994 tram-stunbis-20 2996 o Final edits to clean up bid down protection text to address Eric 2997 Rescorla's DISCUSS and comments. 2999 C.2. Modifications between draft-ietf-tram-stunbis-20 and draft-ietf- 3000 tram-stunbis-19 3002 o Updates to address Eric Rescorla's DISCUSS and comments. 3004 o Addressed nits raised by Noriyuki Torii 3006 C.3. Modifications between draft-ietf-tram-stunbis-19 and draft-ietf- 3007 tram-stunbis-18 3009 o Updates following Adam Roach DISCUSS and comments. 3011 C.4. Modifications between draft-ietf-tram-stunbis-18 and draft-ietf- 3012 tram-stunbis-17 3014 o Nits. 3016 C.5. Modifications between draft-ietf-tram-stunbis-17 and draft-ietf- 3017 tram-stunbis-16 3019 o Modifications following IESG, GENART and SECDIR reviews. 3021 C.6. Modifications between draft-ietf-tram-stunbis-16 and draft-ietf- 3022 tram-stunbis-15 3024 o Replace "failure response" with "error response". 3026 o Fix wrong section number. 3028 o Use "Username anonymity" everywhere. 3030 o Align with UTF-8 deprecation. 3032 o Fix MESSAGE-INTEGRITY-256. 3034 o Update references. 3036 o Updates in the IANA sections. 3038 o s/HMAC-SHA-1/HMAC-SHA1/, s/HMAC-SHA-256/HMAC-SHA256/, s/SHA1/SHA- 3039 1/, and s/SHA256/SHA-256/. 3041 o Fixed definitions of STUN clients/servers. 3043 o Fixed STUN message structure definition. 3045 o Missing text. 3047 o Add text explicitly saying that responses do not have to be in the 3048 same orders than requests. 3050 o /other application/other protocol/ 3052 o Add text explicitly saying that the security feature encoding is 4 3053 character. 3055 o Fixed discrepancy in section 9.2.3/9.2.3.1. 3057 o s/invalidate/revoke/. 3059 o Removed sentences about checking USERHASH in responses, as this 3060 should not happen. 3062 o Specify that ALTERNATE-SERVER carries an IP address. 3064 o More modifications following review... 3066 C.7. Modifications between draft-ietf-tram-stunbis-15 and draft-ietf- 3067 tram-stunbis-14 3069 o Reverted the RFC 2119 boilerplate to what was in RFC 5389. 3071 o Reverted the V.42 reference to the 2002 version. 3073 o Updated some references. 3075 C.8. Modifications between draft-ietf-tram-stunbis-14 and draft-ietf- 3076 tram-stunbis-13 3078 o Reorder the paragraphs in section 9.1.4. 3080 o The realm is now processed through Opaque in section 9.2.2. 3082 o Make clear in section 9.2.4 that it is an exclusive-xor. 3084 o Removed text that implied that nonce sharing was explicitly 3085 permitted in RFC 5389. 3087 o In same section, s/username/value/ for USERCASH. 3089 o Modify the IANA requests to explicitly say that the reserved 3090 codepoints were prior to RFC 5389. 3092 C.9. Modifications between draft-ietf-tram-stunbis-13 and draft-ietf- 3093 tram-stunbis-12 3095 o Update references. 3097 o Fixes some text following Shepherd review. 3099 o Update co-author info. 3101 C.10. Modifications between draft-ietf-tram-stunbis-12 and draft-ietf- 3102 tram-stunbis-11 3104 o Clarifies the procedure to define a new hash algorithm for 3105 message-integrity. 3107 o Explain the procedure to deprecate SHA1 as message-integrity. 3109 o Added procedure for Happy Eyeballs (RFC 6555). 3111 o Added verification that Happy Eyeballs works in the STUN Usage 3112 checklist. 3114 o Add reference to Base64 RFC. 3116 o Changed co-author affiliation. 3118 C.11. Modifications between draft-ietf-tram-stunbis-11 and draft-ietf- 3119 tram-stunbis-10 3121 o Made clear that the same HMAC than received in response of short 3122 term credential must be used for subsequent transactions. 3124 o s/URL/URI/ 3126 o The "nonce cookie" is now mandatory to signal that SHA256 must be 3127 used in the next transaction. 3129 o s/SHA1/SHA256/ 3131 o Changed co-author affiliation. 3133 C.12. Modifications between draft-ietf-tram-stunbis-10 and draft-ietf- 3134 tram-stunbis-09 3136 o Removed the reserved value in the security registry, as it does 3137 not make sense in a bitset. 3139 o Updated change list. 3141 o Updated the minimum truncation size for M-I-256 to 16 bytes. 3143 o Changed the truncation order to match RFC 7518. 3145 o Fixed bugs in truncation boundary text. 3147 o Stated that STUN Usages have to explicitly state that they can use 3148 truncation. 3150 o Removed truncation from the MESSAGE-INTEGRITY attribute. 3152 o Add reference to C code in RFC 1952. 3154 o Replaced RFC 2818 reference to RFC 6125. 3156 C.13. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf- 3157 tram-stunbis-08 3159 o Packets discarded in a reliable or unreliable transaction triggers 3160 an attack error instead of a timeout error. An attack error on a 3161 reliable transport is signaled immediately instead of waiting for 3162 the timeout. 3164 o Explicitly state that a received 400 response without 3165 authentication will be dropped until timeout. 3167 o Clarify the SHOULD omit/include rules in LTCM. 3169 o If the nonce and the hmac are both invalid, then a 401 is sent 3170 instead of a 438. 3172 o The 401 and 438 error response to subsequent requests may use the 3173 previous NONCE/password to authenticate, if they are still 3174 available. 3176 o Change "401 Unauthorized" to "401 Unauthenticated" 3178 o Make clear that in some cases it is impossible to add a MI or MI2 3179 even if the text says SHOULD NOT. 3181 C.14. Modifications between draft-ietf-tram-stunbis-08 and draft-ietf- 3182 tram-stunbis-07 3184 o Updated list of changes since RFC 5389. 3186 o More examples are automatically generated. 3188 o Message integrity truncation is fixed at a multiple of 4 bytes, 3189 because the padding will not decrease by more than this. 3191 o USERHASH contains the 32 bytes of the hash, not a character 3192 string. 3194 o Updated the example to use the USERHASH attribute and the modified 3195 NONCE attribute. 3197 o Updated ICEbis reference. 3199 C.15. Modifications between draft-ietf-tram-stunbis-07 and draft-ietf- 3200 tram-stunbis-06 3202 o Add USERHASH attribute to carry the hashed version of the 3203 username. 3205 o Add IANA registry and nonce encoding for Security Features that 3206 need to be protected from bid-down attacks. 3208 o Modified MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 to support 3209 truncation limits (pending cryptographic review), 3211 C.16. Modifications between draft-ietf-tram-stunbis-06 and draft-ietf- 3212 tram-stunbis-05 3214 o Changed I-D references to RFC references. 3216 o Changed CHANGE-ADDRESS to CHANGE-REQUEST (Errata #4233). 3218 o Added test vector for MESSAGE-INTEGRITY-SHA256. 3220 o Address additional review comments from Jonathan Lennox and 3221 Brandon Williams. 3223 C.17. Modifications between draft-ietf-tram-stunbis-05 and draft-ietf- 3224 tram-stunbis-04 3226 o Address review comments from Jonathan Lennox and Brandon Williams. 3228 C.18. Modifications between draft-ietf-tram-stunbis-04 and draft-ietf- 3229 tram-stunbis-03 3231 o Remove SCTP. 3233 o Remove DANE. 3235 o s/MESSAGE-INTEGRITY2/MESSAGE-INTEGRITY-SHA256/ 3237 o Remove Salted SHA256 password hash. 3239 o The RTO delay between transactions is removed. 3241 o Make clear that reusing NONCE will trigger a wasted round trip. 3243 C.19. Modifications between draft-ietf-tram-stunbis-03 and draft-ietf- 3244 tram-stunbis-02 3246 o SCTP prefix is now 0b00000101 instead of 0x11. 3248 o Add SCTP at various places it was needed. 3250 o Update the hash agility plan to take in account HMAC-SHA-256. 3252 o Adds the bid-down attack on message-integrity in the security 3253 section. 3255 C.20. Modifications between draft-ietf-tram-stunbis-02 and draft-ietf- 3256 tram-stunbis-01 3258 o STUN hash algorithm agility (currently only SHA-1 is allowed). 3260 o Clarify terminology, text and guidance for STUN fragmentation. 3262 o Clarify whether it's valid to share nonces across TURN 3263 allocations. 3265 o Prevent the server to allocate the same NONCE to clients with 3266 different IP address and/or different port. This prevent sharing 3267 the nonce between TURN allocations in TURN. 3269 o Add reference to draft-ietf-uta-tls-bcp 3271 o Add a new attribute ALTERNATE-DOMAIN to verify the certificate of 3272 the ALTERNATE-SERVER after a 300 over (D)TLS. 3274 o The RTP delay between transactions applies only to parallel 3275 transactions, not to serial transactions. That prevents a 3RTT 3276 delay between the first transaction and the second transaction 3277 with long term authentication. 3279 o Add text saying ORIGIN can increase a request size beyond the MTU 3280 and so require an SCTPoUDP transport. 3282 o Move the Acknowledgments and Contributor sections to the end of 3283 the document, in accordance with RFC 7322 section 4. 3285 C.21. Modifications between draft-ietf-tram-stunbis-01 and draft-ietf- 3286 tram-stunbis-00 3288 o Add negotiation mechanism for new password algorithms. 3290 o Describe the MESSAGE-INTEGRITY/MESSAGE-INTEGRITY2 protocol. 3292 o Add support for SCTP to solve the fragmentation problem. 3294 o Merge RFC 7350: 3296 * Split the "Sending over..." sections in 3. 3298 * Add DTLS-over-UDP as transport. 3300 * Update the cipher suites and cipher/compression restrictions. 3302 * A stuns uri with an IP address is rejected. 3304 * Replace most of the RFC 3489 compatibility by a reference to 3305 the section in RFC 5389. 3307 * Update the STUN Usages list with transport applicability. 3309 o Merge RFC 7064: 3311 * DNS discovery is done from the URI. 3313 * Reorganized the text about default ports. 3315 o Add more C snippets. 3317 o Make clear that the cached RTO is discarded only if there is no 3318 new translations for 10 minutes. 3320 C.22. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 3321 ietf-tram-stunbis-00 3323 o Draft adopted as WG item. 3325 C.23. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 3326 salgueiro-tram-stunbis-01 3328 o Add definition of MESSAGE-INTEGRITY2. 3330 o Update text and reference from RFC 2988 to RFC 6298. 3332 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 3334 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 3336 o Fix section number and make clear that the original domain name is 3337 used for the server certificate verification. This is consistent 3338 with what RFC 5922 (section 4) is doing. (Errata #2010) 3340 o Remove text transitioning from RFC 3489. 3342 o Add definition of MESSAGE-INTEGRITY2. 3344 o Update text and reference from RFC 2988 to RFC 6298. 3346 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 3348 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 3350 o Fix section number and make clear that the original domain name is 3351 used for the server certificate verification. This is consistent 3352 with what RFC 5922 (section 4) is doing. (Errata #2010) 3354 C.24. Modifications between draft-salgueiro-tram-stunbis-01 and draft- 3355 salgueiro-tram-stunbis-00 3357 o Restore the RFC 5389 text. 3359 o Add list of open issues. 3361 Acknowledgements 3363 Thanks to Michael Tuexen, Tirumaleswar Reddy, Oleg Moskalenko, Simon 3364 Perreault, Benjamin Schwartz, Rifaat Shekh-Yusef, Alan Johnston, 3365 Jonathan Lennox, Brandon Williams, Olle Johansson, Martin Thomson, 3366 Mihaly Meszaros, Tolga Asveren, Noriyuki Torii, Spencer Dawkins, Dale 3367 Worley, Matthew Miller, Peter Saint-Andre, Julien Elie, Mirja 3368 Kuehlewind, Eric Rescorla, Ben Campbell, Adam Roach, Alexey Melnikov, 3369 and Benjamin Kaduk for the comments, suggestions, and questions that 3370 helped improve this document. 3372 The authors of RFC 5389 would like to thank Cedric Aoun, Pete 3373 Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, Magnus 3374 Westerlund, Miguel Garcia, Bruce Lowekamp, and Chris Sullivan for 3375 their comments, and Baruch Sterman and Alan Hawrylyshen for initial 3376 implementations. Thanks for Leslie Daigle, Allison Mankin, Eric 3377 Rescorla, and Henning Schulzrinne for IESG and IAB input on this 3378 work. 3380 Contributors 3382 Christian Huitema and Joel Weinberger were original co-authors of RFC 3383 3489. 3385 Authors' Addresses 3387 Marc Petit-Huguenin 3388 Impedance Mismatch 3390 Email: marc@petit-huguenin.org 3392 Gonzalo Salgueiro 3393 Cisco 3394 7200-12 Kit Creek Road 3395 Research Triangle Park, NC 27709 3396 US 3398 Email: gsalguei@cisco.com 3400 Jonathan Rosenberg 3401 Five9 3402 Edison, NJ 3403 US 3405 Email: jdrosen@jdrosen.net 3406 URI: http://www.jdrosen.net 3408 Dan Wing 3410 Email: dwing-ietf@fuggles.com 3411 Rohan Mahy 3412 Unaffiliated 3414 Email: rohan.ietf@gmail.com 3416 Philip Matthews 3417 Nokia 3418 600 March Road 3419 Ottawa, Ontario K2K 2T6 3420 Canada 3422 Phone: 613-784-3139 3423 Email: philip_matthews@magma.ca