idnits 2.17.1 draft-ietf-tram-stunbis-15.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). -- The document date (January 19, 2018) is 2282 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. 'ITU.V42.2002' ** Downref: Normative reference to an Informational RFC: RFC 1321 ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 6125 (Obsoleted by RFC 9525) ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) == Outdated reference: A later version (-20) exists of draft-ietf-ice-rfc5245bis-16 -- 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) -- Obsolete informational reference (is this intentional?): RFC 7525 (Obsoleted by RFC 9325) Summary: 5 errors (**), 0 flaws (~~), 3 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 TRAM M. Petit-Huguenin 3 Internet-Draft Impedance Mismatch 4 Obsoletes: 5389 (if approved) G. Salgueiro 5 Intended status: Standards Track J. Rosenberg 6 Expires: July 23, 2018 Cisco 7 D. Wing 9 R. Mahy 10 Unaffiliated 11 P. Matthews 12 Nokia 13 January 19, 2018 15 Session Traversal Utilities for NAT (STUN) 16 draft-ietf-tram-stunbis-15 18 Abstract 20 Session Traversal Utilities for NAT (STUN) is a protocol that serves 21 as a tool for other protocols in dealing with Network Address 22 Translator (NAT) traversal. It can be used by an endpoint to 23 determine the IP address and port allocated to it by a NAT. It can 24 also be used to check connectivity between two endpoints, and as a 25 keep-alive protocol to maintain NAT bindings. STUN works with many 26 existing NATs, and does not require any special behavior from them. 28 STUN is not a NAT traversal solution by itself. Rather, it is a tool 29 to be used in the context of a NAT traversal solution. 31 This document obsoletes RFC 5389. 33 Status of This Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at https://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on July 23, 2018. 50 Copyright Notice 52 Copyright (c) 2018 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 . . . . . . . . . . . . . . . . . . . . 5 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 . . . . . . . . . . . . . . . . 17 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 . . . . . . . . . . . . . . . . . . . . . . 23 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 . . . . . . . . . . . . . 27 97 9.2.2. HMAC Key . . . . . . . . . . . . . . . . . . . . . . 28 98 9.2.3. Forming a Request . . . . . . . . . . . . . . . . . . 28 99 9.2.3.1. First Request . . . . . . . . . . . . . . . . . . 29 100 9.2.3.2. Subsequent Requests . . . . . . . . . . . . . . . 29 101 9.2.4. Receiving a Request . . . . . . . . . . . . . . . . . 29 102 9.2.5. Receiving a Response . . . . . . . . . . . . . . . . 31 103 10. ALTERNATE-SERVER Mechanism . . . . . . . . . . . . . . . . . 33 104 11. Backwards Compatibility with RFC 3489 . . . . . . . . . . . . 34 105 12. Basic Server Behavior . . . . . . . . . . . . . . . . . . . . 34 106 13. STUN Usages . . . . . . . . . . . . . . . . . . . . . . . . . 35 107 14. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . . 36 108 14.1. MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . . . 37 109 14.2. XOR-MAPPED-ADDRESS . . . . . . . . . . . . . . . . . . . 38 110 14.3. USERNAME . . . . . . . . . . . . . . . . . . . . . . . . 39 111 14.4. USERHASH . . . . . . . . . . . . . . . . . . . . . . . . 39 112 14.5. MESSAGE-INTEGRITY . . . . . . . . . . . . . . . . . . . 39 113 14.6. MESSAGE-INTEGRITY-SHA256 . . . . . . . . . . . . . . . . 40 114 14.7. FINGERPRINT . . . . . . . . . . . . . . . . . . . . . . 41 115 14.8. ERROR-CODE . . . . . . . . . . . . . . . . . . . . . . . 41 116 14.9. REALM . . . . . . . . . . . . . . . . . . . . . . . . . 43 117 14.10. NONCE . . . . . . . . . . . . . . . . . . . . . . . . . 43 118 14.11. PASSWORD-ALGORITHMS . . . . . . . . . . . . . . . . . . 43 119 14.12. PASSWORD-ALGORITHM . . . . . . . . . . . . . . . . . . . 44 120 14.13. UNKNOWN-ATTRIBUTES . . . . . . . . . . . . . . . . . . . 45 121 14.14. SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . 45 122 14.15. ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . 45 123 14.16. ALTERNATE-DOMAIN . . . . . . . . . . . . . . . . . . . . 46 124 15. Security Considerations . . . . . . . . . . . . . . . . . . . 46 125 15.1. Attacks against the Protocol . . . . . . . . . . . . . . 46 126 15.1.1. Outside Attacks . . . . . . . . . . . . . . . . . . 46 127 15.1.2. Inside Attacks . . . . . . . . . . . . . . . . . . . 47 128 15.2. Attacks Affecting the Usage . . . . . . . . . . . . . . 47 129 15.2.1. Attack I: Distributed DoS (DDoS) against a Target . 48 130 15.2.2. Attack II: Silencing a Client . . . . . . . . . . . 48 131 15.2.3. Attack III: Assuming the Identity of a Client . . . 49 132 15.2.4. Attack IV: Eavesdropping . . . . . . . . . . . . . . 49 133 15.3. Hash Agility Plan . . . . . . . . . . . . . . . . . . . 49 134 16. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 50 135 17. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 50 136 17.1. STUN Security Features Registry . . . . . . . . . . . . 50 137 17.2. STUN Methods Registry . . . . . . . . . . . . . . . . . 50 138 17.3. STUN Attribute Registry . . . . . . . . . . . . . . . . 50 139 17.3.1. Updated Attributes . . . . . . . . . . . . . . . . . 51 140 17.3.2. New Attributes . . . . . . . . . . . . . . . . . . . 51 141 17.4. STUN Error Code Registry . . . . . . . . . . . . . . . . 51 142 17.5. Password Algorithm Registry . . . . . . . . . . . . . . 52 143 17.5.1. Password Algorithms . . . . . . . . . . . . . . . . 52 144 17.5.1.1. MD5 . . . . . . . . . . . . . . . . . . . . . . 52 145 17.5.1.2. SHA256 . . . . . . . . . . . . . . . . . . . . . 52 147 17.6. STUN UDP and TCP Port Numbers . . . . . . . . . . . . . 52 148 18. Changes since RFC 5389 . . . . . . . . . . . . . . . . . . . 53 149 19. References . . . . . . . . . . . . . . . . . . . . . . . . . 53 150 19.1. Normative References . . . . . . . . . . . . . . . . . . 53 151 19.2. Informative References . . . . . . . . . . . . . . . . . 55 152 Appendix A. C Snippet to Determine STUN Message Types . . . . . 57 153 Appendix B. Test Vectors . . . . . . . . . . . . . . . . . . . . 58 154 B.1. Sample Request with Long-Term Authentication with 155 MESSAGE-INTEGRITY-SHA256 and USERHASH . . . . . . . . . . 58 156 Appendix C. Release notes . . . . . . . . . . . . . . . . . . . 60 157 C.1. Modifications between draft-ietf-tram-stunbis-14 and 158 draft-ietf-tram-stunbis-13 . . . . . . . . . . . . . . . 60 159 C.2. Modifications between draft-ietf-tram-stunbis-13 and 160 draft-ietf-tram-stunbis-12 . . . . . . . . . . . . . . . 60 161 C.3. Modifications between draft-ietf-tram-stunbis-12 and 162 draft-ietf-tram-stunbis-11 . . . . . . . . . . . . . . . 60 163 C.4. Modifications between draft-ietf-tram-stunbis-11 and 164 draft-ietf-tram-stunbis-10 . . . . . . . . . . . . . . . 61 165 C.5. Modifications between draft-ietf-tram-stunbis-10 and 166 draft-ietf-tram-stunbis-09 . . . . . . . . . . . . . . . 61 167 C.6. Modifications between draft-ietf-tram-stunbis-09 and 168 draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 61 169 C.7. Modifications between draft-ietf-tram-stunbis-09 and 170 draft-ietf-tram-stunbis-08 . . . . . . . . . . . . . . . 62 171 C.8. Modifications between draft-ietf-tram-stunbis-08 and 172 draft-ietf-tram-stunbis-07 . . . . . . . . . . . . . . . 62 173 C.9. Modifications between draft-ietf-tram-stunbis-07 and 174 draft-ietf-tram-stunbis-06 . . . . . . . . . . . . . . . 63 175 C.10. Modifications between draft-ietf-tram-stunbis-06 and 176 draft-ietf-tram-stunbis-05 . . . . . . . . . . . . . . . 63 177 C.11. Modifications between draft-ietf-tram-stunbis-05 and 178 draft-ietf-tram-stunbis-04 . . . . . . . . . . . . . . . 63 179 C.12. Modifications between draft-ietf-tram-stunbis-04 and 180 draft-ietf-tram-stunbis-03 . . . . . . . . . . . . . . . 63 181 C.13. Modifications between draft-ietf-tram-stunbis-03 and 182 draft-ietf-tram-stunbis-02 . . . . . . . . . . . . . . . 64 183 C.14. Modifications between draft-ietf-tram-stunbis-02 and 184 draft-ietf-tram-stunbis-01 . . . . . . . . . . . . . . . 64 185 C.15. Modifications between draft-ietf-tram-stunbis-01 and 186 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 65 187 C.16. Modifications between draft-salgueiro-tram-stunbis-02 and 188 draft-ietf-tram-stunbis-00 . . . . . . . . . . . . . . . 65 189 C.17. Modifications between draft-salgueiro-tram-stunbis-02 and 190 draft-salgueiro-tram-stunbis-01 . . . . . . . . . . . . . 65 191 C.18. Modifications between draft-salgueiro-tram-stunbis-01 and 192 draft-salgueiro-tram-stunbis-00 . . . . . . . . . . . . . 66 193 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 66 194 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 66 195 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 67 197 1. Introduction 199 The protocol defined in this specification, Session Traversal 200 Utilities for NAT, provides a tool for dealing with NATs. It 201 provides a means for an endpoint to determine the IP address and port 202 allocated by a NAT that corresponds to its private IP address and 203 port. It also provides a way for an endpoint to keep a NAT binding 204 alive. With some extensions, the protocol can be used to do 205 connectivity checks between two endpoints [I-D.ietf-ice-rfc5245bis], 206 or to relay packets between two endpoints [RFC5766]. 208 In keeping with its tool nature, this specification defines an 209 extensible packet format, defines operation over several transport 210 protocols, and provides for two forms of authentication. 212 STUN is intended to be used in context of one or more NAT traversal 213 solutions. These solutions are known as STUN usages. Each usage 214 describes how STUN is utilized to achieve the NAT traversal solution. 215 Typically, a usage indicates when STUN messages get sent, which 216 optional attributes to include, what server is used, and what 217 authentication mechanism is to be used. Interactive Connectivity 218 Establishment (ICE) [I-D.ietf-ice-rfc5245bis] is one usage of STUN. 219 SIP Outbound [RFC5626] is another usage of STUN. In some cases, a 220 usage will require extensions to STUN. A STUN extension can be in 221 the form of new methods, attributes, or error response codes. More 222 information on STUN usages can be found in Section 13. 224 Implementations and deployments of a STUN usage using TLS or DTLS 225 should follow the recommendations in [RFC7525]. 227 2. Overview of Operation 229 This section is descriptive only. 231 /-----\ 232 // STUN \\ 233 | Server | 234 \\ // 235 \-----/ 237 +--------------+ Public Internet 238 ................| NAT 2 |....................... 239 +--------------+ 241 +--------------+ Private NET 2 242 ................| NAT 1 |....................... 243 +--------------+ 245 /-----\ 246 // STUN \\ 247 | Client | 248 \\ // Private NET 1 249 \-----/ 251 Figure 1: One Possible STUN Configuration 253 One possible STUN configuration is shown in Figure 1. In this 254 configuration, there are two entities (called STUN agents) that 255 implement the STUN protocol. The lower agent in the figure is the 256 client, and is connected to private network 1. This network connects 257 to private network 2 through NAT 1. Private network 2 connects to 258 the public Internet through NAT 2. The upper agent in the figure is 259 the server, and resides on the public Internet. 261 STUN is a client-server protocol. It supports two types of 262 transactions. One is a request/response transaction in which a 263 client sends a request to a server, and the server returns a 264 response. The second is an indication transaction in which either 265 agent -- client or server -- sends an indication that generates no 266 response. Both types of transactions include a transaction ID, which 267 is a randomly selected 96-bit number. For request/response 268 transactions, this transaction ID allows the client to associate the 269 response with the request that generated it; for indications, the 270 transaction ID serves as a debugging aid. 272 All STUN messages start with a fixed header that includes a method, a 273 class, and the transaction ID. The method indicates which of the 274 various requests or indications this is; this specification defines 275 just one method, Binding, but other methods are expected to be 276 defined in other documents. The class indicates whether this is a 277 request, a success response, an error response, or an indication. 278 Following the fixed header comes zero or more attributes, which are 279 Type-Length-Value extensions that convey additional information for 280 the specific message. 282 This document defines a single method called Binding. The Binding 283 method can be used either in request/response transactions or in 284 indication transactions. When used in request/response transactions, 285 the Binding method can be used to determine the particular "binding" 286 a NAT has allocated to a STUN client. When used in either request/ 287 response or in indication transactions, the Binding method can also 288 be used to keep these "bindings" alive. 290 In the Binding request/response transaction, a Binding request is 291 sent from a STUN client to a STUN server. When the Binding request 292 arrives at the STUN server, it may have passed through one or more 293 NATs between the STUN client and the STUN server (in Figure 1, there 294 were two such NATs). As the Binding request message passes through a 295 NAT, the NAT will modify the source transport address (that is, the 296 source IP address and the source port) of the packet. As a result, 297 the source transport address of the request received by the server 298 will be the public IP address and port created by the NAT closest to 299 the server. This is called a reflexive transport address. The STUN 300 server copies that source transport address into an XOR-MAPPED- 301 ADDRESS attribute in the STUN Binding response and sends the Binding 302 response back to the STUN client. As this packet passes back through 303 a NAT, the NAT will modify the destination transport address in the 304 IP header, but the transport address in the XOR-MAPPED-ADDRESS 305 attribute within the body of the STUN response will remain untouched. 306 In this way, the client can learn its reflexive transport address 307 allocated by the outermost NAT with respect to the STUN server. 309 In some usages, STUN must be multiplexed with other protocols (e.g., 310 [I-D.ietf-ice-rfc5245bis], [RFC5626]). In these usages, there must 311 be a way to inspect a packet and determine if it is a STUN packet or 312 not. STUN provides three fields in the STUN header with fixed values 313 that can be used for this purpose. If this is not sufficient, then 314 STUN packets can also contain a FINGERPRINT value, which can further 315 be used to distinguish the packets. 317 STUN defines a set of optional procedures that a usage can decide to 318 use, called mechanisms. These mechanisms include DNS discovery, a 319 redirection technique to an alternate server, a fingerprint attribute 320 for demultiplexing, and two authentication and message-integrity 321 exchanges. The authentication mechanisms revolve around the use of a 322 username, password, and message-integrity value. Two authentication 323 mechanisms, the long-term credential mechanism and the short-term 324 credential mechanism, are defined in this specification. Each usage 325 specifies the mechanisms allowed with that usage. 327 In the long-term credential mechanism, the client and server share a 328 pre-provisioned username and password and perform a digest challenge/ 329 response exchange inspired by (but differing in details) to the one 330 defined for HTTP [RFC7616]. In the short-term credential mechanism, 331 the client and the server exchange a username and password through 332 some out-of-band method prior to the STUN exchange. For example, in 333 the ICE usage [I-D.ietf-ice-rfc5245bis] the two endpoints use out-of- 334 band signaling to exchange a username and password. These are used 335 to integrity protect and authenticate the request and response. 336 There is no challenge or nonce used. 338 3. Terminology 340 In this document, the key words "MUST", "MUST NOT", "REQUIRED", 341 "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", 342 and "OPTIONAL" are to be interpreted as described in BCP14, RFC 2119 343 [RFC2119] and indicate requirement levels for compliant STUN 344 implementations. 346 4. Definitions 348 STUN Agent: A STUN agent is an entity that implements the STUN 349 protocol. The entity can be either a STUN client or a STUN 350 server. 352 STUN Client: A STUN client is an entity that sends STUN requests and 353 receives STUN responses. A STUN client can also send indications. 354 In this specification, the terms STUN client and client are 355 synonymous. 357 STUN Server: A STUN server is an entity that receives STUN requests 358 and sends STUN responses. A STUN server can also send 359 indications. In this specification, the terms STUN server and 360 server are synonymous. 362 Transport Address: The combination of an IP address and port number 363 (such as a UDP or TCP port number). 365 Reflexive Transport Address: A transport address learned by a client 366 that identifies that client as seen by another host on an IP 367 network, typically a STUN server. When there is an intervening 368 NAT between the client and the other host, the reflexive transport 369 address represents the mapped address allocated to the client on 370 the public side of the NAT. Reflexive transport addresses are 371 learned from the mapped address attribute (MAPPED-ADDRESS or XOR- 372 MAPPED-ADDRESS) in STUN responses. 374 Mapped Address: Same meaning as reflexive address. This term is 375 retained only for historic reasons and due to the naming of the 376 MAPPED-ADDRESS and XOR-MAPPED-ADDRESS attributes. 378 Long-Term Credential: A username and associated password that 379 represent a shared secret between client and server. Long-term 380 credentials are generally granted to the client when a subscriber 381 enrolls in a service and persist until the subscriber leaves the 382 service or explicitly changes the credential. 384 Long-Term Password: The password from a long-term credential. 386 Short-Term Credential: A temporary username and associated password 387 that represent a shared secret between client and server. Short- 388 term credentials are obtained through some kind of protocol 389 mechanism between the client and server, preceding the STUN 390 exchange. A short-term credential has an explicit temporal scope, 391 which may be based on a specific amount of time (such as 5 392 minutes) or on an event (such as termination of a SIP dialog). 393 The specific scope of a short-term credential is defined by the 394 application usage. 396 Short-Term Password: The password component of a short-term 397 credential. 399 STUN Indication: A STUN message that does not receive a response. 401 Attribute: The STUN term for a Type-Length-Value (TLV) object that 402 can be added to a STUN message. Attributes are divided into two 403 types: comprehension-required and comprehension-optional. STUN 404 agents can safely ignore comprehension-optional attributes they 405 don't understand, but cannot successfully process a message if it 406 contains comprehension-required attributes that are not 407 understood. 409 RTO: Retransmission TimeOut, which defines the initial period of 410 time between transmission of a request and the first retransmit of 411 that request. 413 5. STUN Message Structure 415 STUN messages are encoded in binary using network-oriented format 416 (most significant byte or octet first, also commonly known as big- 417 endian). The transmission order is described in detail in Appendix B 418 of [RFC0791]. Unless otherwise noted, numeric constants are in 419 decimal (base 10). 421 All STUN messages MUST start with a 20-byte header followed by zero 422 or more Attributes. The STUN header contains a STUN message type, 423 magic cookie, transaction ID, and message length. 425 0 1 2 3 426 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 427 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 428 |0 0| STUN Message Type | Message Length | 429 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 430 | Magic Cookie | 431 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 432 | | 433 | Transaction ID (96 bits) | 434 | | 435 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 437 Figure 2: Format of STUN Message Header 439 The most significant 2 bits of every STUN message MUST be zeroes. 440 This can be used to differentiate STUN packets from other protocols 441 when STUN is multiplexed with other protocols on the same port. 443 The message type defines the message class (request, success 444 response, failure response, or indication) and the message method 445 (the primary function) of the STUN message. Although there are four 446 message classes, there are only two types of transactions in STUN: 447 request/response transactions (which consist of a request message and 448 a response message) and indication transactions (which consist of a 449 single indication message). Response classes are split into error 450 and success responses to aid in quickly processing the STUN message. 452 The message type field is decomposed further into the following 453 structure: 455 0 1 456 2 3 4 5 6 7 8 9 0 1 2 3 4 5 457 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 458 |M |M |M|M|M|C|M|M|M|C|M|M|M|M| 459 |11|10|9|8|7|1|6|5|4|0|3|2|1|0| 460 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ 462 Figure 3: Format of STUN Message Type Field 464 Here the bits in the message type field are shown as most significant 465 (M11) through least significant (M0). M11 through M0 represent a 466 12-bit encoding of the method. C1 and C0 represent a 2-bit encoding 467 of the class. A class of 0b00 is a request, a class of 0b01 is an 468 indication, a class of 0b10 is a success response, and a class of 469 0b11 is an error response. This specification defines a single 470 method, Binding. The method and class are orthogonal, so that for 471 each method, a request, success response, error response, and 472 indication are possible for that method. Extensions defining new 473 methods MUST indicate which classes are permitted for that method. 475 For example, a Binding request has class=0b00 (request) and 476 method=0b000000000001 (Binding) and is encoded into the first 16 bits 477 as 0x0001. A Binding response has class=0b10 (success response) and 478 method=0b000000000001, and is encoded into the first 16 bits as 479 0x0101. 481 Note: This unfortunate encoding is due to assignment of values in 482 [RFC3489] that did not consider encoding Indications, Success, and 483 Errors using bit fields. 485 The magic cookie field MUST contain the fixed value 0x2112A442 in 486 network byte order. In [RFC3489], this field was part of the 487 transaction ID; placing the magic cookie in this location allows a 488 server to detect if the client will understand certain attributes 489 that were added in this revised specification. In addition, it aids 490 in distinguishing STUN packets from packets of other protocols when 491 STUN is multiplexed with those other protocols on the same port. 493 The transaction ID is a 96-bit identifier, used to uniquely identify 494 STUN transactions. For request/response transactions, the 495 transaction ID is chosen by the STUN client for the request and 496 echoed by the server in the response. For indications, it is chosen 497 by the agent sending the indication. It primarily serves to 498 correlate requests with responses, though it also plays a small role 499 in helping to prevent certain types of attacks. The server also uses 500 the transaction ID as a key to identify each transaction uniquely 501 across all clients. As such, the transaction ID MUST be uniformly 502 and randomly chosen from the interval 0 .. 2**96-1, and SHOULD be 503 cryptographically random. Resends of the same request reuse the same 504 transaction ID, but the client MUST choose a new transaction ID for 505 new transactions unless the new request is bit-wise identical to the 506 previous request and sent from the same transport address to the same 507 IP address. Success and error responses MUST carry the same 508 transaction ID as their corresponding request. When an agent is 509 acting as a STUN server and STUN client on the same port, the 510 transaction IDs in requests sent by the agent have no relationship to 511 the transaction IDs in requests received by the agent. 513 The message length MUST contain the size, in bytes, of the message 514 not including the 20-byte STUN header. Since all STUN attributes are 515 padded to a multiple of 4 bytes, the last 2 bits of this field are 516 always zero. This provides another way to distinguish STUN packets 517 from packets of other protocols. 519 Following the STUN fixed portion of the header are zero or more 520 attributes. Each attribute is TLV (Type-Length-Value) encoded. The 521 details of the encoding, and of the attributes themselves are given 522 in Section 14. 524 6. Base Protocol Procedures 526 This section defines the base procedures of the STUN protocol. It 527 describes how messages are formed, how they are sent, and how they 528 are processed when they are received. It also defines the detailed 529 processing of the Binding method. Other sections in this document 530 describe optional procedures that a usage may elect to use in certain 531 situations. Other documents may define other extensions to STUN, by 532 adding new methods, new attributes, or new error response codes. 534 6.1. Forming a Request or an Indication 536 When formulating a request or indication message, the agent MUST 537 follow the rules in Section 5 when creating the header. In addition, 538 the message class MUST be either "Request" or "Indication" (as 539 appropriate), and the method must be either Binding or some method 540 defined in another document. 542 The agent then adds any attributes specified by the method or the 543 usage. For example, some usages may specify that the agent use an 544 authentication method (Section 9) or the FINGERPRINT attribute 545 (Section 7). 547 If the agent is sending a request, it SHOULD add a SOFTWARE attribute 548 to the request. Agents MAY include a SOFTWARE attribute in 549 indications, depending on the method. Extensions to STUN should 550 discuss whether SOFTWARE is useful in new indications. 552 For the Binding method with no authentication, no attributes are 553 required unless the usage specifies otherwise. 555 All STUN messages sent over UDP or DTLS-over-UDP [RFC6347] SHOULD be 556 less than the path MTU, if known. 558 If the path MTU is unknown for UDP, messages SHOULD be the smaller of 559 576 bytes and the first-hop MTU for IPv4 [RFC1122] and 1280 bytes for 560 IPv6 [RFC8200]. This value corresponds to the overall size of the IP 561 packet. Consequently, for IPv4, the actual STUN message would need 562 to be less than 548 bytes (576 minus 20-byte IP header, minus 8-byte 563 UDP header, assuming no IP options are used). 565 If the path MTU is unknown for DTLS-over-UDP, the rules described in 566 the previous paragraph need to be adjusted to take into account the 567 size of the (13-byte) DTLS Record header, the MAC size, and the 568 padding size. 570 STUN provides no ability to handle the case where the request is 571 under the MTU but the response would be larger than the MTU. It is 572 not envisioned that this limitation will be an issue for STUN. The 573 MTU limitation is a SHOULD, and not a MUST, to account for cases 574 where STUN itself is being used to probe for MTU characteristics 575 [RFC5780]. Outside of this or similar applications, the MTU 576 constraint MUST be followed. 578 6.2. Sending the Request or Indication 580 The agent then sends the request or indication. This document 581 specifies how to send STUN messages over UDP, TCP, TLS-over-TCP, or 582 DTLS-over-UDP; other transport protocols may be added in the future. 583 The STUN usage must specify which transport protocol is used, and how 584 the agent determines the IP address and port of the recipient. 585 Section 8 describes a DNS-based method of determining the IP address 586 and port of a server that a usage may elect to use. STUN may be used 587 with anycast addresses, but only with UDP and in usages where 588 authentication is not used. 590 At any time, a client MAY have multiple outstanding STUN requests 591 with the same STUN server (that is, multiple transactions in 592 progress, with different transaction IDs). Absent other limits to 593 the rate of new transactions (such as those specified by ICE for 594 connectivity checks or when STUN is run over TCP), a client SHOULD 595 limit itself to ten outstanding transactions to the same server. 597 6.2.1. Sending over UDP or DTLS-over-UDP 599 When running STUN over UDP or STUN over DTLS-over-UDP [RFC7350], it 600 is possible that the STUN message might be dropped by the network. 601 Reliability of STUN request/response transactions is accomplished 602 through retransmissions of the request message by the client 603 application itself. STUN indications are not retransmitted; thus, 604 indication transactions over UDP or DTLS-over-UDP are not reliable. 606 A client SHOULD retransmit a STUN request message starting with an 607 interval of RTO ("Retransmission TimeOut"), doubling after each 608 retransmission. The RTO is an estimate of the round-trip time (RTT), 609 and is computed as described in [RFC6298], with two exceptions. 610 First, the initial value for RTO SHOULD be greater than 500 ms. The 611 exception cases for this "SHOULD" are when other mechanisms are used 612 to derive congestion thresholds (such as the ones defined in ICE for 613 fixed rate streams), or when STUN is used in non-Internet 614 environments with known network capacities. In fixed-line access 615 links, a value of 500 ms is RECOMMENDED. Second, the value of RTO 616 SHOULD NOT be rounded up to the nearest second. Rather, a 1 ms 617 accuracy SHOULD be maintained. As with TCP, the usage of Karn's 618 algorithm is RECOMMENDED [KARN87]. When applied to STUN, it means 619 that RTT estimates SHOULD NOT be computed from STUN transactions that 620 result in the retransmission of a request. 622 The value for RTO SHOULD be cached by a client after the completion 623 of the transaction, and used as the starting value for RTO for the 624 next transaction to the same server (based on equality of IP 625 address). The value SHOULD be considered stale and discarded after 626 10 minutes without any transactions to the same server. 628 Retransmissions continue until a response is received, or until a 629 total of Rc requests have been sent. Rc SHOULD be configurable and 630 SHOULD have a default of 7. If, after the last request, a duration 631 equal to Rm times the RTO has passed without a response (providing 632 ample time to get a response if only this final request actually 633 succeeds), the client SHOULD consider the transaction to have failed. 634 Rm SHOULD be configurable and SHOULD have a default of 16. A STUN 635 transaction over UDP or DTLS-over-UDP is also considered failed if 636 there has been a hard ICMP error [RFC1122]. For example, assuming an 637 RTO of 500ms, requests would be sent at times 0 ms, 500 ms, 1500 ms, 638 3500 ms, 7500 ms, 15500 ms, and 31500 ms. If the client has not 639 received a response after 39500 ms, the client will consider the 640 transaction to have timed out. 642 6.2.2. Sending over TCP or TLS-over-TCP 644 For TCP and TLS-over-TCP [RFC5246], the client opens a TCP connection 645 to the server. 647 In some usages of STUN, STUN is sent as the only protocol over the 648 TCP connection. In this case, it can be sent without the aid of any 649 additional framing or demultiplexing. In other usages, or with other 650 extensions, it may be multiplexed with other data over a TCP 651 connection. In that case, STUN MUST be run on top of some kind of 652 framing protocol, specified by the usage or extension, which allows 653 for the agent to extract complete STUN messages and complete 654 application layer messages. The STUN service running on the well- 655 known port or ports discovered through the DNS procedures in 656 Section 8 is for STUN alone, and not for STUN multiplexed with other 657 data. Consequently, no framing protocols are used in connections to 658 those servers. When additional framing is utilized, the usage will 659 specify how the client knows to apply it and what port to connect to. 660 For example, in the case of ICE connectivity checks, this information 661 is learned through out-of-band negotiation between client and server. 663 Reliability of STUN over TCP and TLS-over-TCP is handled by TCP 664 itself, and there are no retransmissions at the STUN protocol level. 665 However, for a request/response transaction, if the client has not 666 received a response by Ti seconds after it sent the SYN to establish 667 the connection, it considers the transaction to have timed out. Ti 668 SHOULD be configurable and SHOULD have a default of 39.5s. This 669 value has been chosen to equalize the TCP and UDP timeouts for the 670 default initial RTO. 672 In addition, if the client is unable to establish the TCP connection, 673 or the TCP connection is reset or fails before a response is 674 received, any request/response transaction in progress is considered 675 to have failed. 677 The client MAY send multiple transactions over a single TCP (or TLS- 678 over-TCP) connection, and it MAY send another request before 679 receiving a response to the previous. The client SHOULD keep the 680 connection open until it: 682 o has no further STUN requests or indications to send over that 683 connection, and 685 o has no plans to use any resources (such as a mapped address 686 (MAPPED-ADDRESS or XOR-MAPPED-ADDRESS) or relayed address 687 [RFC5766]) that were learned though STUN requests sent over that 688 connection, and 690 o if multiplexing other application protocols over that port, has 691 finished using that other application, and 693 o if using that learned port with a remote peer, has established 694 communications with that remote peer, as is required by some TCP 695 NAT traversal techniques (e.g., [RFC6544]). 697 At the server end, the server SHOULD keep the connection open, and 698 let the client close it, unless the server has determined that the 699 connection has timed out (for example, due to the client 700 disconnecting from the network). Bindings learned by the client will 701 remain valid in intervening NATs only while the connection remains 702 open. Only the client knows how long it needs the binding. The 703 server SHOULD NOT close a connection if a request was received over 704 that connection for which a response was not sent. A server MUST NOT 705 ever open a connection back towards the client in order to send a 706 response. Servers SHOULD follow best practices regarding connection 707 management in cases of overload. 709 6.2.3. Sending over TLS-over-TCP or DTLS-over-UDP 711 When STUN is run by itself over TLS-over-TCP or DTLS-over-UDP, the 712 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 and 713 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher suites MUST be 714 implemented and other cipher suites MAY be implemented. Perfect 715 Forward Secrecy (PFS) cipher suites MUST be preferred over non-PFS 716 cipher suites. Cipher suites with known weaknesses, such as those 717 based on (single) DES and RC4, MUST NOT be used. Implementations 718 MUST disable TLS-level compression. 720 When it receives the TLS Certificate message, the client SHOULD 721 verify the certificate and inspect the site identified by the 722 certificate. If the certificate is invalid or revoked, or if it does 723 not identify the appropriate party, the client MUST NOT send the STUN 724 message or otherwise proceed with the STUN transaction. The client 725 MUST verify the identity of the server. To do that, it follows the 726 identification procedures defined in [RFC6125]. Alternatively, a 727 client MAY be configured with a set of IP addresses that are trusted; 728 if a certificate is received that identifies one of those IP 729 addresses, the client considers the identity of the server to be 730 verified. 732 When STUN is run multiplexed with other protocols over a TLS-over-TCP 733 connection or a DTLS-over-UDP association, the mandatory ciphersuites 734 and TLS handling procedures operate as defined by those protocols. 736 6.3. Receiving a STUN Message 738 This section specifies the processing of a STUN message. The 739 processing specified here is for STUN messages as defined in this 740 specification; additional rules for backwards compatibility are 741 defined in Section 11. Those additional procedures are optional, and 742 usages can elect to utilize them. First, a set of processing 743 operations is applied that is independent of the class. This is 744 followed by class-specific processing, described in the subsections 745 that follow. 747 When a STUN agent receives a STUN message, it first checks that the 748 message obeys the rules of Section 5. It checks that the first two 749 bits are 0, that the magic cookie field has the correct value, that 750 the message length is sensible, and that the method value is a 751 supported method. It checks that the message class is allowed for 752 the particular method. If the message class is "Success Response" or 753 "Error Response", the agent checks that the transaction ID matches a 754 transaction that is still in progress. If the FINGERPRINT extension 755 is being used, the agent checks that the FINGERPRINT attribute is 756 present and contains the correct value. If any errors are detected, 757 the message is silently discarded. In the case when STUN is being 758 multiplexed with another protocol, an error may indicate that this is 759 not really a STUN message; in this case, the agent should try to 760 parse the message as a different protocol. 762 The STUN agent then does any checks that are required by a 763 authentication mechanism that the usage has specified (see 764 Section 9). 766 Once the authentication checks are done, the STUN agent checks for 767 unknown attributes and known-but-unexpected attributes in the 768 message. Unknown comprehension-optional attributes MUST be ignored 769 by the agent. Known-but-unexpected attributes SHOULD be ignored by 770 the agent. Unknown comprehension-required attributes cause 771 processing that depends on the message class and is described below. 773 At this point, further processing depends on the message class of the 774 request. 776 6.3.1. Processing a Request 778 If the request contains one or more unknown comprehension-required 779 attributes, the server replies with an error response with an error 780 code of 420 (Unknown Attribute), and includes an UNKNOWN-ATTRIBUTES 781 attribute in the response that lists the unknown comprehension- 782 required attributes. 784 The server then does any additional checking that the method or the 785 specific usage requires. If all the checks succeed, the server 786 formulates a success response as described below. 788 When run over UDP or DTLS-over-UDP, a request received by the server 789 could be the first request of a transaction, or a retransmission. 790 The server MUST respond to retransmissions such that the following 791 property is preserved: if the client receives the response to the 792 retransmission and not the response that was sent to the original 793 request, the overall state on the client and server is identical to 794 the case where only the response to the original retransmission is 795 received, or where both responses are received (in which case the 796 client will use the first). The easiest way to meet this requirement 797 is for the server to remember all transaction IDs received over UDP 798 or DTLS-over-UDP and their corresponding responses in the last 40 799 seconds. However, this requires the server to hold state, and will 800 be inappropriate for any requests which are not authenticated. 801 Another way is to reprocess the request and recompute the response. 802 The latter technique MUST only be applied to requests that are 803 idempotent (a request is considered idempotent when the same request 804 can be safely repeated without impacting the overall state of the 805 system) and result in the same success response for the same request. 806 The Binding method is considered to be idempotent. Note that there 807 are certain rare network events that could cause the reflexive 808 transport address value to change, resulting in a different mapped 809 address in different success responses. Extensions to STUN MUST 810 discuss the implications of request retransmissions on servers that 811 do not store transaction state. 813 6.3.1.1. Forming a Success or Error Response 815 When forming the response (success or error), the server follows the 816 rules of Section 6. The method of the response is the same as that 817 of the request, and the message class is either "Success Response" or 818 "Error Response". 820 For an error response, the server MUST add an ERROR-CODE attribute 821 containing the error code specified in the processing above. The 822 reason phrase is not fixed, but SHOULD be something suitable for the 823 error code. For certain errors, additional attributes are added to 824 the message. These attributes are spelled out in the description 825 where the error code is specified. For example, for an error code of 826 420 (Unknown Attribute), the server MUST include an UNKNOWN- 827 ATTRIBUTES attribute. Certain authentication errors also cause 828 attributes to be added (see Section 9). Extensions may define other 829 errors and/or additional attributes to add in error cases. 831 If the server authenticated the request using an authentication 832 mechanism, then the server SHOULD add the appropriate authentication 833 attributes to the response (see Section 9). 835 The server also adds any attributes required by the specific method 836 or usage. In addition, the server SHOULD add a SOFTWARE attribute to 837 the message. 839 For the Binding method, no additional checking is required unless the 840 usage specifies otherwise. When forming the success response, the 841 server adds a XOR-MAPPED-ADDRESS attribute to the response, where the 842 contents of the attribute are the source transport address of the 843 request message. For UDP or DTLS-over-UDP this is the source IP 844 address and source UDP port of the request message. For TCP and TLS- 845 over-TCP, this is the source IP address and source TCP port of the 846 TCP connection as seen by the server. 848 6.3.1.2. Sending the Success or Error Response 850 The response (success or error) is sent over the same transport as 851 the request was received on. If the request was received over UDP or 852 DTLS-over-UDP the destination IP address and port of the response are 853 the source IP address and port of the received request message, and 854 the source IP address and port of the response are equal to the 855 destination IP address and port of the received request message. If 856 the request was received over TCP or TLS-over-TCP, the response is 857 sent back on the same TCP connection as the request was received on. 859 6.3.2. Processing an Indication 861 If the indication contains unknown comprehension-required attributes, 862 the indication is discarded and processing ceases. 864 The agent then does any additional checking that the method or the 865 specific usage requires. If all the checks succeed, the agent then 866 processes the indication. No response is generated for an 867 indication. 869 For the Binding method, no additional checking or processing is 870 required, unless the usage specifies otherwise. The mere receipt of 871 the message by the agent has refreshed the "bindings" in the 872 intervening NATs. 874 Since indications are not re-transmitted over UDP or DTLS-over-UDP 875 (unlike requests), there is no need to handle re-transmissions of 876 indications at the sending agent. 878 6.3.3. Processing a Success Response 880 If the success response contains unknown comprehension-required 881 attributes, the response is discarded and the transaction is 882 considered to have failed. 884 The client then does any additional checking that the method or the 885 specific usage requires. If all the checks succeed, the client then 886 processes the success response. 888 For the Binding method, the client checks that the XOR-MAPPED-ADDRESS 889 attribute is present in the response. The client checks the address 890 family specified. If it is an unsupported address family, the 891 attribute SHOULD be ignored. If it is an unexpected but supported 892 address family (for example, the Binding transaction was sent over 893 IPv4, but the address family specified is IPv6), then the client MAY 894 accept and use the value. 896 6.3.4. Processing an Error Response 898 If the error response contains unknown comprehension-required 899 attributes, or if the error response does not contain an ERROR-CODE 900 attribute, then the transaction is simply considered to have failed. 902 The client then does any processing specified by the authentication 903 mechanism (see Section 9). This may result in a new transaction 904 attempt. 906 The processing at this point depends on the error code, the method, 907 and the usage; the following are the default rules: 909 o If the error code is 300 through 399, the client SHOULD consider 910 the transaction as failed unless the ALTERNATE-SERVER extension is 911 being used. See Section 10. 913 o If the error code is 400 through 499, the client declares the 914 transaction failed; in the case of 420 (Unknown Attribute), the 915 response should contain a UNKNOWN-ATTRIBUTES attribute that gives 916 additional information. 918 o If the error code is 500 through 599, the client MAY resend the 919 request; clients that do so MUST limit the number of times they do 920 this. 922 Any other error code causes the client to consider the transaction 923 failed. 925 7. FINGERPRINT Mechanism 927 This section describes an optional mechanism for STUN that aids in 928 distinguishing STUN messages from packets of other protocols when the 929 two are multiplexed on the same transport address. This mechanism is 930 optional, and a STUN usage must describe if and when it is used. The 931 FINGERPRINT mechanism is not backwards compatible with RFC3489, and 932 cannot be used in environments where such compatibility is required. 934 In some usages, STUN messages are multiplexed on the same transport 935 address as other protocols, such as the Real Time Transport Protocol 936 (RTP). In order to apply the processing described in Section 6, STUN 937 messages must first be separated from the application packets. 939 Section 5 describes three fixed fields in the STUN header that can be 940 used for this purpose. However, in some cases, these three fixed 941 fields may not be sufficient. 943 When the FINGERPRINT extension is used, an agent includes the 944 FINGERPRINT attribute in messages it sends to another agent. 945 Section 14.7 describes the placement and value of this attribute. 947 When the agent receives what it believes is a STUN message, then, in 948 addition to other basic checks, the agent also checks that the 949 message contains a FINGERPRINT attribute and that the attribute 950 contains the correct value. Section 6.3 describes when in the 951 overall processing of a STUN message the FINGERPRINT check is 952 performed. This additional check helps the agent detect messages of 953 other protocols that might otherwise seem to be STUN messages. 955 8. DNS Discovery of a Server 957 This section describes an optional procedure for STUN that allows a 958 client to use DNS to determine the IP address and port of a server. 959 A STUN usage must describe if and when this extension is used. To 960 use this procedure, the client must know a STUN URI [RFC7064]; the 961 usage must also describe how the client obtains this URI. Hard- 962 coding a STUN URI into software is NOT RECOMMENDED in case the domain 963 name is lost or needs to change for legal or other reasons. 965 When a client wishes to locate a STUN server on the public Internet 966 that accepts Binding request/response transactions, the STUN URI 967 scheme is "stun". When it wishes to locate a STUN server that 968 accepts Binding request/response transactions over a TLS, or DTLS 969 session, the URI scheme is "stuns". 971 The syntax of the "stun" and "stuns" URIs are defined in Section 3.1 972 of [RFC7064]. STUN usages MAY define additional URI schemes. 974 8.1. STUN URI Scheme Semantics 976 If the part of a "stun" URI contains an IP address, then this 977 IP address is used directly to contact the server. A "stuns" URI 978 containing an IP address MUST be rejected, unless the domain name is 979 provided by the same mechanism that provided the STUN URI, and that 980 domain name can be passed to the verification code. 982 If the URI does not contain an IP address, the domain name contained 983 in the part is resolved to a transport address using the SRV 984 procedures specified in [RFC2782]. The DNS SRV service name is the 985 content of the part. The protocol in the SRV lookup is the 986 transport protocol the client will run STUN over: "udp" for UDP and 987 "tcp" for TCP. 989 The procedures of RFC 2782 are followed to determine the server to 990 contact. RFC 2782 spells out the details of how a set of SRV records 991 is sorted and then tried. However, RFC 2782 only states that the 992 client should "try to connect to the (protocol, address, service)" 993 without giving any details on what happens in the event of failure. 994 When following these procedures, if the STUN transaction times out 995 without receipt of a response, the client SHOULD retry the request to 996 the next server in the ordered defined by RFC 2782. Such a retry is 997 only possible for request/response transmissions, since indication 998 transactions generate no response or timeout. 1000 In addition, instead of querying either the A or the AAAA resource 1001 records for a domain name, the client MUST query both and try the 1002 requests with all the IP addresses received, as specified in 1003 [RFC8305]. 1005 The default port for STUN requests is 3478, for both TCP and UDP. 1006 The default port for STUN over TLS and STUN over DTLS requests is 1007 5349. Servers can run STUN over DTLS on the same port as STUN over 1008 UDP if the server software supports determining whether the initial 1009 message is a DTLS or STUN message. Servers can run STUN over TLS on 1010 the same port as STUN over TCP if the server software supports 1011 determining whether the initial message is a TLS or STUN message. 1013 Administrators of STUN servers SHOULD use these ports in their SRV 1014 records for UDP and TCP. In all cases, the port in DNS MUST reflect 1015 the one on which the server is listening. 1017 If no SRV records were found, the client performs both an A and AAAA 1018 record lookup of the domain name, as described in [RFC8305]. The 1019 result will be a list of IP addresses, each of which can be 1020 simultaneously contacted at the default port using UDP or TCP, 1021 independent of the STUN usage. For usages that require TLS, the 1022 client connects to the IP addresses using the default STUN over TLS 1023 port. For usages that require DTLS, the client connects to the IP 1024 addresses using the default STUN over DTLS port. 1026 9. Authentication and Message-Integrity Mechanisms 1028 This section defines two mechanisms for STUN that a client and server 1029 can use to provide authentication and message integrity; these two 1030 mechanisms are known as the short-term credential mechanism and the 1031 long-term credential mechanism. These two mechanisms are optional, 1032 and each usage must specify if and when these mechanisms are used. 1033 Consequently, both clients and servers will know which mechanism (if 1034 any) to follow based on knowledge of which usage applies. For 1035 example, a STUN server on the public Internet supporting ICE would 1036 have no authentication, whereas the STUN server functionality in an 1037 agent supporting connectivity checks would utilize short-term 1038 credentials. An overview of these two mechanisms is given in 1039 Section 2. 1041 Each mechanism specifies the additional processing required to use 1042 that mechanism, extending the processing specified in Section 6. The 1043 additional processing occurs in three different places: when forming 1044 a message, when receiving a message immediately after the basic 1045 checks have been performed, and when doing the detailed processing of 1046 error responses. 1048 9.1. Short-Term Credential Mechanism 1050 The short-term credential mechanism assumes that, prior to the STUN 1051 transaction, the client and server have used some other protocol to 1052 exchange a credential in the form of a username and password. This 1053 credential is time-limited. The time limit is defined by the usage. 1054 As an example, in the ICE usage [I-D.ietf-ice-rfc5245bis], the two 1055 endpoints use out-of-band signaling to agree on a username and 1056 password, and this username and password are applicable for the 1057 duration of the media session. 1059 This credential is used to form a message-integrity check in each 1060 request and in many responses. There is no challenge and response as 1061 in the long-term mechanism; consequently, replay is prevented by 1062 virtue of the time-limited nature of the credential. 1064 9.1.1. HMAC Key 1066 For short-term credentials the HMAC key is defined as follow: 1068 key = OpaqueString(password) 1070 where the OpaqueString profile is defined in [RFC8265]. 1072 9.1.2. Forming a Request or Indication 1074 For a request or indication message, the agent MUST include the 1075 USERNAME, MESSAGE-INTEGRITY-SHA256, and MESSAGE-INTEGRITY attributes 1076 in the message unless the agent knows from an external indication 1077 which message integrity algorithm is supported by both agents. In 1078 this case either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 MUST 1079 be included in addition to USERNAME. The HMAC for the MESSAGE- 1080 INTEGRITY attribute is computed as described in Section 14.5 and the 1081 HMAC for the MESSAGE-INTEGRITY-SHA256 attributes is computed as 1082 described in Section 14.6. Note that the password is never included 1083 in the request or indication. 1085 9.1.3. Receiving a Request or Indication 1087 After the agent has done the basic processing of a message, the agent 1088 performs the checks listed below in order specified: 1090 o If the message does not contain 1) a MESSAGE-INTEGRITY or a 1091 MESSAGE-INTEGRITY-SHA256 attribute and 2) a USERNAME attribute: 1093 * If the message is a request, the server MUST reject the request 1094 with an error response. This response MUST use an error code 1095 of 400 (Bad Request). 1097 * If the message is an indication, the agent MUST silently 1098 discard the indication. 1100 o If the USERNAME does not contain a username value currently valid 1101 within the server: 1103 * If the message is a request, the server MUST reject the request 1104 with an error response. This response MUST use an error code 1105 of 401 (Unauthenticated). 1107 * If the message is an indication, the agent MUST silently 1108 discard the indication. 1110 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1111 value for the message integrity as described in Section 14.6, 1112 using the password associated with the username. If the MESSAGE- 1113 INTEGRITY-SHA256 attribute is not present, and using the same 1114 password, compute the value for the message integrity as described 1115 in Section 14.5. If the resulting value does not match the 1116 contents of the corresponding attribute (MESSAGE-INTEGRITY-SHA256 1117 or MESSAGE-INTEGRITY): 1119 * If the message is a request, the server MUST reject the request 1120 with an error response. This response MUST use an error code 1121 of 401 (Unauthenticated). 1123 * If the message is an indication, the agent MUST silently 1124 discard the indication. 1126 If these checks pass, the agent continues to process the request or 1127 indication. Any response generated by a server to a request that 1128 contains a MESSAGE-INTEGRITY-SHA256 attribute MUST include the 1129 MESSAGE-INTEGRITY-SHA256 attribute, computed using the password 1130 utilized to authenticate the request. Any response generated by a 1131 server to a request that contains only a MESSAGE-INTEGRITY attribute 1132 MUST include the MESSAGE-INTEGRITY attribute, computed using the 1133 password utilized to authenticate the request. This means that only 1134 one of these attributes can appear in a response. The response MUST 1135 NOT contain the USERNAME attribute. 1137 If any of the checks fail, a server MUST NOT include a MESSAGE- 1138 INTEGRITY-SHA256, MESSAGE-INTEGRITY, or USERNAME attribute in the 1139 error response. This is because, in these failure cases, the server 1140 cannot determine the shared secret necessary to compute the MESSAGE- 1141 INTEGRITY-SHA256 or MESSAGE-INTEGRITY attributes. 1143 9.1.4. Receiving a Response 1145 The client looks for the MESSAGE-INTEGRITY or the MESSAGE-INTEGRITY- 1146 SHA256 attribute in the response. If present and if the client only 1147 sent only one of MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1148 attributes in the request (because of the external indication in 1149 section Section 9.2.3, or this being a subsequent request as defined 1150 in Section 9.1.5) the algorithm in the response has to match 1151 otherwise the response MUST be discarded. 1153 The client then computes the message integrity over the response as 1154 defined in Section 14.5 or Section 14.6, respectively, using the same 1155 password it utilized for the request. If the resulting value matches 1156 the contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1157 attribute, respectively, the response is considered authenticated. 1158 If the value does not match, or if both MESSAGE-INTEGRITY and 1159 MESSAGE-INTEGRITY-SHA256 were absent, the processing depends on the 1160 request been sent over a reliable or an unreliable transport. 1162 If the request was sent over an unreliable transport, the response 1163 MUST be discarded, as if it was never received. This means that 1164 retransmits, if applicable, will continue. If all the responses 1165 received are discarded then instead of signalling a timeout after 1166 ending the transaction the layer MUST signal that an attack took 1167 place. 1169 If the request was sent over a reliable transport, the response MUST 1170 be discarded and the layer MUST immediately end the transaction and 1171 signal that an attack took place. 1173 9.1.5. Sending Subsequent Requests 1175 A client sending subsequent requests to the same server MUST send 1176 only the MESSAGE-INTEGRITY-SHA256 or the MESSAGE-INTEGRITY attribute 1177 that matches the attribute that was received in the response to the 1178 initial request. Here same server means same IP address and port 1179 number, not just the same URI or SRV lookup result. 1181 9.2. Long-Term Credential Mechanism 1183 The long-term credential mechanism relies on a long-term credential, 1184 in the form of a username and password that are shared between client 1185 and server. The credential is considered long-term since it is 1186 assumed that it is provisioned for a user, and remains in effect 1187 until the user is no longer a subscriber of the system, or is 1188 changed. This is basically a traditional "log-in" username and 1189 password given to users. 1191 Because these usernames and passwords are expected to be valid for 1192 extended periods of time, replay prevention is provided in the form 1193 of a digest challenge. In this mechanism, the client initially sends 1194 a request, without offering any credentials or any integrity checks. 1195 The server rejects this request, providing the user a realm (used to 1196 guide the user or agent in selection of a username and password) and 1197 a nonce. The nonce provides the replay protection. It is a cookie, 1198 selected by the server, and encoded in such a way as to indicate a 1199 duration of validity or client identity from which it is valid. The 1200 client retries the request, this time including its username and the 1201 realm, and echoing the nonce provided by the server. The client also 1202 includes a message-integrity, which provides an HMAC over the entire 1203 request, including the nonce. The server validates the nonce and 1204 checks the message integrity. If they match, the request is 1205 authenticated. If the nonce is no longer valid, it is considered 1206 "stale", and the server rejects the request, providing a new nonce. 1208 In subsequent requests to the same server, the client reuses the 1209 nonce, username, realm, and password it used previously. In this 1210 way, subsequent requests are not rejected until the nonce becomes 1211 invalid by the server, in which case the rejection provides a new 1212 nonce to the client. 1214 Note that the long-term credential mechanism cannot be used to 1215 protect indications, since indications cannot be challenged. Usages 1216 utilizing indications must either use a short-term credential or omit 1217 authentication and message integrity for them. 1219 To indicate that it supports this specification, a server MUST 1220 prepend the NONCE attribute value with the character string composed 1221 of "obMatJos2" concatenated with the Base64 [RFC4648] encoding of the 1222 24 bit STUN Security Features as defined in Section 17.1. The 24 bit 1223 Security Feature set is encoded as a 24 bit integer in network order. 1224 If no security features are used, then the value 0 MUST be encoded 1225 instead. For the remainder of this document the term "nonce cookie" 1226 will refer to the complete 13 character string prepended to the NONCE 1227 attribute value. 1229 Since the long-term credential mechanism is susceptible to offline 1230 dictionary attacks, deployments SHOULD utilize passwords that are 1231 difficult to guess. In cases where the credentials are not entered 1232 by the user, but are rather placed on a client device during device 1233 provisioning, the password SHOULD have at least 128 bits of 1234 randomness. In cases where the credentials are entered by the user, 1235 they should follow best current practices around password structure. 1237 9.2.1. Bid Down Attack Prevention 1239 This document introduces two new security features that provide the 1240 ability to choose the algorithm used for password protection as well 1241 as the ability to use an anonymous username. Both of these 1242 capabilities are optional in order to remain backwards compatible 1243 with previous versions of the STUN protocol. 1245 These new capabilities are subject to bid down attacks whereby an 1246 attacker in the message path can remove these capabilities and force 1247 weaker security properties. To prevent these kinds of attacks from 1248 going undetected, the nonce is enhanced with additional information. 1250 The value of the "nonce cookie" will vary based on the specific STUN 1251 Security Features bit values selected. When this document makes 1252 reference to the "nonce cookie" in a section discussing a specific 1253 STUN Security Feature it is understood that the corresponding STUN 1254 Security Feature bit in the "nonce cookie" is set to 1. 1256 For example, in Section 9.2.4 discussing the PASSWORD-ALGORITHMS 1257 security feature, it is implied that the "Password algorithms" bit, 1258 as defined in Section 17.1, is set to 1 in the "nonce cookie". 1260 9.2.2. HMAC Key 1262 For long-term credentials that do not use a different algorithm, as 1263 specified by the PASSWORD-ALGORITHM attribute, the key is 16 bytes: 1265 key = MD5(username ":" OpaqueString(realm) ":" OpaqueString(password)) 1267 Where MD5 is defined in [RFC1321] and the OpaqueString profile is 1268 defined in [RFC8265]. 1270 The 16-byte key is formed by taking the MD5 hash of the result of 1271 concatenating the following five fields: (1) the username, with any 1272 quotes and trailing nulls removed, as taken from the USERNAME 1273 attribute (in which case OpaqueString has already been applied); (2) 1274 a single colon; (3) the realm, with any quotes and trailing nulls 1275 removed and after processing using OpaqueString; (4) a single colon; 1276 and (5) the password, with any trailing nulls removed and after 1277 processing using OpaqueString. For example, if the username was 1278 'user', the realm was 'realm', and the password was 'pass', then the 1279 16-byte HMAC key would be the result of performing an MD5 hash on the 1280 string 'user:realm:pass', the resulting hash being 1281 0x8493fbc53ba582fb4c044c456bdc40eb. 1283 The structure of the key when used with long-term credentials 1284 facilitates deployment in systems that also utilize SIP. Typically, 1285 SIP systems utilizing SIP's digest authentication mechanism do not 1286 actually store the password in the database. Rather, they store a 1287 value called H(A1), which is equal to the key defined above. 1289 When a PASSWORD-ALGORITHM is used, the key length and algorithm to 1290 use are described in Section 17.5.1. 1292 9.2.3. Forming a Request 1294 There are two cases when forming a request. In the first case, this 1295 is the first request from the client to the server (as identified by 1296 its IP address and port). In the second case, the client is 1297 submitting a subsequent request once a previous request/response 1298 transaction has completed successfully. Forming a request as a 1299 consequence of a 401 or 438 error response is covered in 1300 Section 9.2.5 and is not considered a "subsequent request" and thus 1301 does not utilize the rules described in Section 9.2.3.2. 1303 The difference between a first request and a subsequent request is 1304 the presence or absence of some attributes, so omitting or including 1305 them is a MUST. 1307 9.2.3.1. First Request 1309 If the client has not completed a successful request/response 1310 transaction with the server (as identified by hostname, if the DNS 1311 procedures of Section 8 are used, else IP address if not), it MUST 1312 omit the USERNAME, USERHASH, MESSAGE-INTEGRITY, MESSAGE-INTEGRITY- 1313 SHA256, REALM, NONCE, PASSWORD-ALGORITHMS, and PASSWORD-ALGORITHM 1314 attributes. In other words, the very first request is sent as if 1315 there were no authentication or message integrity applied. 1317 9.2.3.2. Subsequent Requests 1319 Once a request/response transaction has completed successfully, the 1320 client will have been presented a realm and nonce by the server, and 1321 selected a username and password with which it authenticated. The 1322 client SHOULD cache the username, password, realm, and nonce for 1323 subsequent communications with the server. When the client sends a 1324 subsequent request, it MUST include either the USERNAME or USERHASH, 1325 REALM, NONCE, and PASSWORD-ALGORITHM attributes with these cached 1326 values. It MUST include a MESSAGE-INTEGRITY attribute or a MESSAGE- 1327 INTEGRITY-SHA256 attribute, computed as described in Section 14.5 and 1328 Section 14.6 using the cached password. The choice between the two 1329 attributes depends on the attribute received in the response to the 1330 first request. 1332 9.2.4. Receiving a Request 1334 After the server has done the basic processing of a request, it 1335 performs the checks listed below in the order specified: 1337 o If the message does not contain a MESSAGE-INTEGRITY or MESSAGE- 1338 INTEGRITY-SHA256 attribute, the server MUST generate an error 1339 response with an error code of 401 (Unauthenticated). This 1340 response MUST include a REALM value. It is RECOMMENDED that the 1341 REALM value be the domain name of the provider of the STUN server. 1342 The response MUST include a NONCE, selected by the server. The 1343 server MUST ensure that the same NONCE cannot be selected for 1344 clients that use different source IP addresses, different source 1345 ports, or both different source IP addresses and source ports. 1346 The server MAY support alternate password algorithms, in which 1347 case it can list them in preferential order in a PASSWORD- 1348 ALGORITHMS attribute. If the server adds a PASSWORD-ALGORITHMS 1349 attribute it MUST set the STUN Security Feature "Password 1350 algorithms" bit set to 1. The server MAY support anonymous 1351 username, in which case it MUST set the STUN Security Feature 1352 "Anonymous username" bit set to 1. The response SHOULD NOT 1353 contain a USERNAME, USERHASH, MESSAGE-INTEGRITY or MESSAGE- 1354 INTEGRITY-SHA256 attribute. 1356 Note: Reusing a NONCE for different source IP addresses or ports was 1357 not explicitly forbidden in [RFC5389]. 1359 o If the message contains a MESSAGE-INTEGRITY or a MESSAGE- 1360 INTEGRITY-SHA256 attribute, but is missing either the USERNAME or 1361 USERHASH, REALM, or NONCE attribute, the server MUST generate an 1362 error response with an error code of 400 (Bad Request). This 1363 response SHOULD NOT include a USERNAME, USERHASH, NONCE, or REALM. 1364 The response cannot contain a MESSAGE-INTEGRITY or MESSAGE- 1365 INTEGRITY-SHA256 attribute, as the attributes required to generate 1366 them are missing. 1368 o If the NONCE attribute starts with the "nonce cookie" with the 1369 STUN Security Feature "Password algorithm" bit set to 1 but 1370 PASSWORD-ALGORITHMS does not match the value sent in the response 1371 that sent this NONCE, then the server MUST generate an error 1372 response with an error code of 400 (Bad Request). 1374 o If the NONCE attribute starts with the "nonce cookie" with the 1375 STUN Security Feature "Password algorithm" bit set to 1 but the 1376 request contains neither PASSWORD-ALGORITHMS nor PASSWORD- 1377 ALGORITHM, then the request is processed as though PASSWORD- 1378 ALGORITHM were MD5 (Note that if the original PASSWORD-ALGORITHMS 1379 attribute did not contain MD5, this will result in a 400 Bad 1380 Request in a later step below). 1382 o If the NONCE attribute starts with the "nonce cookie" with the 1383 STUN Security Feature "Password algorithm" bit set to 1 but only 1384 one of PASSWORD-ALGORITHM or PASSWORD-ALGORITHMS is present, then 1385 the server MUST generate an error response with an error code of 1386 400 (Bad Request). 1388 o If the NONCE attribute starts with the "nonce cookie" with the 1389 STUN Security Feature "Password algorithm" bit set to 1 but 1390 PASSWORD-ALGORITHM does not match one of the entries in PASSWORD- 1391 ALGORITHMS, then the server MUST generate an error response with 1392 an error code of 400 (Bad Request). 1394 o If the NONCE is no longer valid and at the same time the MESSAGE- 1395 INTEGRITY or a MESSAGE-INTEGRITY-SHA256 attribute is invalid, the 1396 server MUST generate an error response with an error code of 401. 1397 This response MUST include NONCE, REALM, and PASSWORD-ALGORITHMS 1398 attributes and SHOULD NOT include the USERNAME or USERHASH 1399 attribute. The response MAY include a MESSAGE-INTEGRITY or 1400 MESSAGE-INTEGRITY-SHA256 attribute, using the previous NONCE to 1401 calculate it. 1403 o If the NONCE is no longer valid, the server MUST generate an error 1404 response with an error code of 438 (Stale Nonce). This response 1405 MUST include NONCE, REALM, and PASSWORD-ALGORITHMS attributes and 1406 SHOULD NOT include the USERNAME, USERHASH attribute, The response 1407 MAY include a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1408 attribute, using the previous NONCE to calculate it. Servers can 1409 invalidate nonces in order to provide additional security. See 1410 Section 4.3 of [RFC7616] for guidelines. 1412 o If the value of the USERNAME or USERHASH attribute is not valid, 1413 the server MUST generate an error response with an error code of 1414 401 (Unauthenticated). This response MUST include a REALM value. 1415 It is RECOMMENDED that the REALM value be the domain name of the 1416 provider of the STUN server. The response MUST include a NONCE, 1417 selected by the server. The response MUST include a PASSWORD- 1418 ALGORITHMS attribute. The response SHOULD NOT contain a USERNAME, 1419 USERHASH attribute. The response MAY include a MESSAGE-INTEGRITY 1420 or MESSAGE-INTEGRITY-SHA256 attribute, using the previous password 1421 to calculate it. 1423 o If the MESSAGE-INTEGRITY-SHA256 attribute is present compute the 1424 value for the message integrity as described in Section 14.6, 1425 using the password associated with the username. Else, using the 1426 same password, compute the value for the message integrity as 1427 described in Section 14.5. If the resulting value does not match 1428 the contents of the MESSAGE-INTEGRITY attribute or the MESSAGE- 1429 INTEGRITY-SHA256 attribute, the server MUST reject the request 1430 with an error response. This response MUST use an error code of 1431 401 (Unauthenticated). It MUST include REALM and NONCE attributes 1432 and SHOULD NOT include the USERNAME, USERHASH, MESSAGE-INTEGRITY, 1433 or MESSAGE-INTEGRITY-SHA256 attribute. 1435 If these checks pass, the server continues to process the request. 1436 Any response generated by the server MUST include MESSAGE-INTEGRITY- 1437 SHA256 attribute, computed using the username and password utilized 1438 to authenticate the request, unless the request was processed as 1439 though PASSWORD-ALGORITHM was MD5 (because the request contained 1440 neither PASSWORD-ALGORITHMS nor PASSWORD-ALGORITHM). In that case 1441 the MESSAGE-INTEGRITY attribute MUST be used instead of the MESSAGE- 1442 INTEGRITY-SHA256 attribute. The REALM, NONCE, USERNAME and USERHASH 1443 attributes SHOULD NOT be included. 1445 9.2.5. Receiving a Response 1447 If the response is an error response with an error code of 401 1448 (Unauthenticated) or 438 (Stale Nonce), the client MUST test if the 1449 NONCE attribute value starts with the "nonce cookie". If the test 1450 succeeds and the "nonce cookie" has the STUN Security Feature 1451 "Password algorithm" bit set to 1 but no PASSWORD-ALGORITHMS 1452 attribute is present, then the client MUST NOT retry the request with 1453 a new transaction. If the test succeeds and the "nonce cookie" has 1454 the STUN Security Feature "Username anonymity" bit set to 1 but no 1455 USERHASH attribute is present, then the client MUST NOT retry the 1456 request with a new transaction. 1458 If the response is an error response with an error code of 401 1459 (Unauthenticated), the client SHOULD retry the request with a new 1460 transaction. This request MUST contain a USERNAME or a USERHASH, 1461 determined by the client as the appropriate username for the REALM 1462 from the error response. If the "nonce cookie" was present and had 1463 the STUN Security Feature "Username anonymity" bit set to 1 then the 1464 USERHASH attribute MUST be used, else the USERNAME attribute MUST be 1465 used. The request MUST contain the REALM, copied from the error 1466 response. The request MUST contain the NONCE, copied from the error 1467 response. If the response contains a PASSWORD-ALGORITHMS attribute, 1468 the request MUST contain the PASSWORD-ALGORITHMS attribute with the 1469 same content. If the response contains a PASSWORD-ALGORITHMS 1470 attribute, and this attribute contains at least one algorithm that is 1471 supported by the client then the request MUST contain a PASSWORD- 1472 ALGORITHM attribute with the first algorithm supported on the list. 1473 If the response contains a PASSWORD-ALGORITHMS attribute, and this 1474 attribute does not contain any algorithm that is supported by the 1475 client, then the client MUST NOT retry the request with a new 1476 transaction. The client MUST NOT perform this retry if it is not 1477 changing the USERNAME or USERHASH or REALM or its associated 1478 password, from the previous attempt. 1480 If the response is an error response with an error code of 438 (Stale 1481 Nonce), the client MUST retry the request, using the new NONCE 1482 attribute supplied in the 438 (Stale Nonce) response. This retry 1483 MUST also include either the USERNAME or USERHASH, REALM and either 1484 the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attributes. 1486 For all other responses, if the NONCE attribute starts with the 1487 "nonce cookie" with the STUN Security Feature "Password algorithm" 1488 bit set to 1 but PASSWORD-ALGORITHMS is not present, the response 1489 MUST be ignored. For all other responses, if the NONCE attribute 1490 starts with the "nonce cookie" with the STUN Security Feature "User 1491 anonymity" bit set to 1 but USERHASH is not present, the response 1492 MUST be ignored. 1494 If the response is an error response with an error code of 400, and 1495 does not contains either MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1496 SHA256 attribute then the response MUST be discarded, as if it was 1497 never received. This means that retransmits, if applicable, will 1498 continue. 1500 The client looks for the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 1501 SHA256 attribute in the response (either success or failure). If 1502 present, the client computes the message integrity over the response 1503 as defined in Section 14.5 or Section 14.6, using the same password 1504 it utilized for the request. If the resulting value matches the 1505 contents of the MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 1506 attribute, the response is considered authenticated. If the value 1507 does not match, or if both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 1508 SHA256 were absent, the processing depends on the request been sent 1509 over a reliable or an unreliable transport. 1511 If the request was sent over an unreliable transport, the response 1512 MUST be discarded, as if it was never received. This means that 1513 retransmits, if applicable, will continue. If all the reponses 1514 received are discarded then instead of signalling a timeout after 1515 ending the transaction the layer MUST signal that an attack took 1516 place. 1518 If the request was sent over a reliable transport, the response MUST 1519 be discarded and the layer MUST immediately end the transaction and 1520 signal that an attack took place. 1522 If the response contains a PASSWORD-ALGORITHMS attribute, the 1523 subsequent request MUST be authenticated using MESSAGE-INTEGRITY- 1524 SHA256 only. 1526 10. ALTERNATE-SERVER Mechanism 1528 This section describes a mechanism in STUN that allows a server to 1529 redirect a client to another server. This extension is optional, and 1530 a usage must define if and when this extension is used. 1532 A server using this extension redirects a client to another server by 1533 replying to a request message with an error response message with an 1534 error code of 300 (Try Alternate). The server MUST include an 1535 ALTERNATE-SERVER attribute in the error response. The error response 1536 message MAY be authenticated; however, there are uses cases for 1537 ALTERNATE-SERVER where authentication of the response is not possible 1538 or practical. If the transaction uses TLS or DTLS and if the 1539 transaction is authenticated by a MESSAGE-INTEGRITY-SHA256 attribute 1540 and if the server wants to redirect to a server that uses a different 1541 certificate, then it MUST include an ALTERNATE-DOMAIN attribute 1542 containing the subjectAltName of that certificate. 1544 A client using this extension handles a 300 (Try Alternate) error 1545 code as follows. The client looks for an ALTERNATE-SERVER attribute 1546 in the error response. If one is found, then the client considers 1547 the current transaction as failed, and reattempts the request with 1548 the server specified in the attribute, using the same transport 1549 protocol used for the previous request. That request, if 1550 authenticated, MUST utilize the same credentials that the client 1551 would have used in the request to the server that performed the 1552 redirection. If the transport protocol uses TLS or DTLS, then the 1553 client looks for an ALTERNATE-DOMAIN attribute. If the attribute is 1554 found, the domain MUST be used to validate the certificate using the 1555 recommendations in [RFC6125]. If the attribute is not found, the 1556 same domain that was used for the original request MUST be used to 1557 validate the certificate. If the client has been redirected to a 1558 server on which it has already tried this request within the last 1559 five minutes, it MUST ignore the redirection and consider the 1560 transaction to have failed. This prevents infinite ping-ponging 1561 between servers in case of redirection loops. 1563 11. Backwards Compatibility with RFC 3489 1565 In addition to the backward compatibility already described in 1566 Section 12 of [RFC5389], DTLS MUST NOT be used with [RFC3489] (also 1567 referred to as "classic STUN"). Any STUN request or indication 1568 without the magic cookie (see Section 6 of [RFC5389]) over DTLS MUST 1569 always result in an error. 1571 12. Basic Server Behavior 1573 This section defines the behavior of a basic, stand-alone STUN 1574 server. 1576 Historically, "classic STUN [RFC3489]" only defined the behavior of a 1577 server that was providing clients with server reflexive transport 1578 addresses by receiving and replying to STUN Binding requests. 1579 [RFC5389] redefined the protocol as an extensible framework and the 1580 server functionality became the sole STUN Usage defined in that 1581 document. This STUN Usage is also known as Basic STUN Server. 1583 The STUN server MUST support the Binding method. It SHOULD NOT 1584 utilize the short-term or long-term credential mechanism. This is 1585 because the work involved in authenticating the request is more than 1586 the work in simply processing it. It SHOULD NOT utilize the 1587 ALTERNATE-SERVER mechanism for the same reason. It MUST support UDP 1588 and TCP. It MAY support STUN over TCP/TLS or STUN over UDP/DTLS; 1589 however, DTLS and TLS provide minimal security benefits in this basic 1590 mode of operation. It MAY utilize the FINGERPRINT mechanism but MUST 1591 NOT require it. Since the stand-alone server only runs STUN, 1592 FINGERPRINT provides no benefit. Requiring it would break 1593 compatibility with RFC 3489, and such compatibility is desirable in a 1594 stand-alone server. Stand-alone STUN servers SHOULD support 1595 backwards compatibility with [RFC3489] clients, as described in 1596 Section 11. 1598 It is RECOMMENDED that administrators of STUN servers provide DNS 1599 entries for those servers as described in Section 8. If both A and 1600 AAAA Resource Records are returned then the client can simultaneously 1601 send STUN Binding requests to the IPv4 and IPv6 addresses (as 1602 specified in [RFC8305]), as the Binding request is idempotent. Note 1603 that the MAPPED-ADDRESS or XOR-MAPPED-ADDRESS attributes that are 1604 returned will not necessarily match the address family of the server 1605 address used. 1607 A basic STUN server is not a solution for NAT traversal by itself. 1608 However, it can be utilized as part of a solution through STUN 1609 usages. This is discussed further in Section 13. 1611 13. STUN Usages 1613 STUN by itself is not a solution to the NAT traversal problem. 1614 Rather, STUN defines a tool that can be used inside a larger 1615 solution. The term "STUN usage" is used for any solution that uses 1616 STUN as a component. 1618 A STUN usage defines how STUN is actually utilized -- when to send 1619 requests, what to do with the responses, and which optional 1620 procedures defined here (or in an extension to STUN) are to be used. 1621 A usage would also define: 1623 o Which STUN methods are used. 1625 o What transports are used. If DTLS-over-UDP is used then 1626 implementing the denial-of-service countermeasure described in 1627 Section 4.2.1 of [RFC6347] is mandatory. 1629 o What authentication and message-integrity mechanisms are used. 1631 o The considerations around manual vs. automatic key derivation for 1632 the integrity mechanism, as discussed in [RFC4107]. 1634 o What mechanisms are used to distinguish STUN messages from other 1635 messages. When STUN is run over TCP, a framing mechanism may be 1636 required. 1638 o How a STUN client determines the IP address and port of the STUN 1639 server. 1641 o How simultaneous use of IPv4 and IPv6 addresses (Happy Eyeballs 1642 [RFC8305]) works with non-idempotent transactions when both 1643 address families are found for the STUN server. 1645 o Whether backwards compatibility to RFC 3489 is required. 1647 o What optional attributes defined here (such as FINGERPRINT and 1648 ALTERNATE-SERVER) or in other extensions are required. 1650 o If MESSAGE-INTEGRITY-256 truncation is permitted, and the limits 1651 permitted for truncation. 1653 In addition, any STUN usage must consider the security implications 1654 of using STUN in that usage. A number of attacks against STUN are 1655 known (see the Security Considerations section in this document), and 1656 any usage must consider how these attacks can be thwarted or 1657 mitigated. 1659 Finally, a usage must consider whether its usage of STUN is an 1660 example of the Unilateral Self-Address Fixing approach to NAT 1661 traversal, and if so, address the questions raised in RFC 3424 1662 [RFC3424]. 1664 14. STUN Attributes 1666 After the STUN header are zero or more attributes. Each attribute 1667 MUST be TLV encoded, with a 16-bit type, 16-bit length, and value. 1668 Each STUN attribute MUST end on a 32-bit boundary. As mentioned 1669 above, all fields in an attribute are transmitted most significant 1670 bit first. 1672 0 1 2 3 1673 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 1674 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1675 | Type | Length | 1676 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1677 | Value (variable) .... 1678 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1680 Figure 4: Format of STUN Attributes 1682 The value in the length field MUST contain the length of the Value 1683 part of the attribute, prior to padding, measured in bytes. Since 1684 STUN aligns attributes on 32-bit boundaries, attributes whose content 1685 is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of 1686 padding so that its value contains a multiple of 4 bytes. The 1687 padding bits are ignored, and may be any value. 1689 Any attribute type MAY appear more than once in a STUN message. 1690 Unless specified otherwise, the order of appearance is significant: 1691 only the first occurrence needs to be processed by a receiver, and 1692 any duplicates MAY be ignored by a receiver. 1694 To allow future revisions of this specification to add new attributes 1695 if needed, the attribute space is divided into two ranges. 1696 Attributes with type values between 0x0000 and 0x7FFF are 1697 comprehension-required attributes, which means that the STUN agent 1698 cannot successfully process the message unless it understands the 1699 attribute. Attributes with type values between 0x8000 and 0xFFFF are 1700 comprehension-optional attributes, which means that those attributes 1701 can be ignored by the STUN agent if it does not understand them. 1703 The set of STUN attribute types is maintained by IANA. The initial 1704 set defined by this specification is found in Section 17.3. 1706 The rest of this section describes the format of the various 1707 attributes defined in this specification. 1709 14.1. MAPPED-ADDRESS 1711 The MAPPED-ADDRESS attribute indicates a reflexive transport address 1712 of the client. It consists of an 8-bit address family and a 16-bit 1713 port, followed by a fixed-length value representing the IP address. 1714 If the address family is IPv4, the address MUST be 32 bits. If the 1715 address family is IPv6, the address MUST be 128 bits. All fields 1716 must be in network byte order. 1718 The format of the MAPPED-ADDRESS attribute is: 1720 0 1 2 3 1721 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 1722 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1723 |0 0 0 0 0 0 0 0| Family | Port | 1724 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1725 | | 1726 | Address (32 bits or 128 bits) | 1727 | | 1728 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1730 Figure 5: Format of MAPPED-ADDRESS Attribute 1732 The address family can take on the following values: 1734 0x01:IPv4 1735 0x02:IPv6 1736 The first 8 bits of the MAPPED-ADDRESS MUST be set to 0 and MUST be 1737 ignored by receivers. These bits are present for aligning parameters 1738 on natural 32-bit boundaries. 1740 This attribute is used only by servers for achieving backwards 1741 compatibility with [RFC3489] clients. 1743 14.2. XOR-MAPPED-ADDRESS 1745 The XOR-MAPPED-ADDRESS attribute is identical to the MAPPED-ADDRESS 1746 attribute, except that the reflexive transport address is obfuscated 1747 through the XOR function. 1749 The format of the XOR-MAPPED-ADDRESS is: 1751 0 1 2 3 1752 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 1753 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1754 |0 0 0 0 0 0 0 0| Family | X-Port | 1755 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1756 | X-Address (Variable) 1757 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1759 Figure 6: Format of XOR-MAPPED-ADDRESS Attribute 1761 The Family represents the IP address family, and is encoded 1762 identically to the Family in MAPPED-ADDRESS. 1764 X-Port is computed by taking the mapped port in host byte order, 1765 XOR'ing it with the most significant 16 bits of the magic cookie, and 1766 then the converting the result to network byte order. If the IP 1767 address family is IPv4, X-Address is computed by taking the mapped IP 1768 address in host byte order, XOR'ing it with the magic cookie, and 1769 converting the result to network byte order. If the IP address 1770 family is IPv6, X-Address is computed by taking the mapped IP address 1771 in host byte order, XOR'ing it with the concatenation of the magic 1772 cookie and the 96-bit transaction ID, and converting the result to 1773 network byte order. 1775 The rules for encoding and processing the first 8 bits of the 1776 attribute's value, the rules for handling multiple occurrences of the 1777 attribute, and the rules for processing address families are the same 1778 as for MAPPED-ADDRESS. 1780 Note: XOR-MAPPED-ADDRESS and MAPPED-ADDRESS differ only in their 1781 encoding of the transport address. The former encodes the transport 1782 address by exclusive-or'ing it with the magic cookie. The latter 1783 encodes it directly in binary. RFC 3489 originally specified only 1784 MAPPED-ADDRESS. However, deployment experience found that some NATs 1785 rewrite the 32-bit binary payloads containing the NAT's public IP 1786 address, such as STUN's MAPPED-ADDRESS attribute, in the well-meaning 1787 but misguided attempt at providing a generic ALG function. Such 1788 behavior interferes with the operation of STUN and also causes 1789 failure of STUN's message-integrity checking. 1791 14.3. USERNAME 1793 The USERNAME attribute is used for message integrity. It identifies 1794 the username and password combination used in the message-integrity 1795 check. 1797 The value of USERNAME is a variable-length value. It MUST contain a 1798 UTF-8 [RFC3629] encoded sequence of less than 513 bytes, and MUST 1799 have been processed using the OpaqueString profile [RFC8265]. 1801 14.4. USERHASH 1803 The USERHASH attribute is used as a replacement for the USERNAME 1804 attribute when username anonymity is supported. 1806 The value of USERHASH has a fixed length of 32 bytes. The username 1807 MUST have been processed using the OpaqueString profile [RFC8265] 1808 before hashing. 1810 The following is the operation that the client will perform to hash 1811 the username: 1813 userhash = SHA256(username ":" realm) 1815 14.5. MESSAGE-INTEGRITY 1817 The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of 1818 the STUN message. The MESSAGE-INTEGRITY attribute can be present in 1819 any STUN message type. Since it uses the SHA1 hash, the HMAC will be 1820 at 20 bytes. 1822 The text used as input to HMAC is the STUN message, including the 1823 header, up to and including the attribute preceding the MESSAGE- 1824 INTEGRITY attribute. With the exception of the MESSAGE-INTEGRITY- 1825 SHA256 and FINGERPRINT attributes, which appear after MESSAGE- 1826 INTEGRITY, agents MUST ignore all other attributes that follow 1827 MESSAGE-INTEGRITY. 1829 The key for the HMAC depends on which credential mechanism is in use. 1830 Section 9.1.1 defines the key for the short-term credential mechanism 1831 and Section 9.2.2 defines the key for the long-term credential 1832 mechanism. Other credential mechanisms MUST define the key that is 1833 used for the HMAC. 1835 Based on the rules above, the hash used to construct MESSAGE- 1836 INTEGRITY includes the length field from the STUN message header. 1837 Prior to performing the hash, the MESSAGE-INTEGRITY attribute MUST be 1838 inserted into the message (with dummy content). The length MUST then 1839 be set to point to the length of the message up to, and including, 1840 the MESSAGE-INTEGRITY attribute itself, but excluding any attributes 1841 after it. Once the computation is performed, the value of the 1842 MESSAGE-INTEGRITY attribute can be filled in, and the value of the 1843 length in the STUN header can be set to its correct value -- the 1844 length of the entire message. Similarly, when validating the 1845 MESSAGE-INTEGRITY, the length field should be adjusted to point to 1846 the end of the MESSAGE-INTEGRITY attribute prior to calculating the 1847 HMAC. Such adjustment is necessary when attributes, such as 1848 FINGERPRINT, appear after MESSAGE-INTEGRITY. 1850 14.6. MESSAGE-INTEGRITY-SHA256 1852 The MESSAGE-INTEGRITY-SHA256 attribute contains an HMAC-SHA-256 1853 [RFC2104] of the STUN message. The MESSAGE-INTEGRITY-SHA256 1854 attribute can be present in any STUN message type. Since it uses the 1855 SHA256 hash, the HMAC will be at most 32 bytes. The HMAC MUST NOT be 1856 truncated below a minimum size of 16 bytes. If truncation is 1857 employed then the HMAC size MUST be a multiple of 4. Truncation MUST 1858 be done by stripping off the final bytes. STUN Usages can define 1859 their own truncation limits, as long as they adhere to the guidelines 1860 specificed above. STUN Usages that do not define truncation limits 1861 MUST NOT use truncation at all. 1863 The text used as input to HMAC is the STUN message, including the 1864 header, up to and including the attribute preceding the MESSAGE- 1865 INTEGRITY-SHA256 attribute. With the exception of the FINGERPRINT 1866 attribute, which appears after MESSAGE-INTEGRITY-SHA256, agents MUST 1867 ignore all other attributes that follow MESSAGE-INTEGRITY-SHA256. 1869 The key for the HMAC depends on which credential mechanism is in use. 1870 Section 9.1.1 defines the key for the short-term credential mechanism 1871 and Section 9.2.2 defines the key for the long-term credential 1872 mechanism. Other credential mechanism MUST define the key that is 1873 used for the HMAC. 1875 Based on the rules above, the hash used to construct MESSAGE- 1876 INTEGRITY-SHA256 includes the length field from the STUN message 1877 header. Prior to performing the hash, the MESSAGE-INTEGRITY-SHA256 1878 attribute MUST be inserted into the message (with dummy content). 1879 The length MUST then be set to point to the length of the message up 1880 to, and including, the MESSAGE-INTEGRITY-SHA256 attribute itself, but 1881 excluding any attributes after it. Once the computation is 1882 performed, the value of the MESSAGE-INTEGRITY-SHA256 attribute can be 1883 filled in, and the value of the length in the STUN header can be set 1884 to its correct value -- the length of the entire message. Similarly, 1885 when validating the MESSAGE-INTEGRITY-SHA256, the length field should 1886 be adjusted to point to the end of the MESSAGE-INTEGRITY-SHA256 1887 attribute prior to calculating the HMAC. Such adjustment is 1888 necessary when attributes, such as FINGERPRINT, appear after MESSAGE- 1889 INTEGRITY-SHA256. 1891 14.7. FINGERPRINT 1893 The FINGERPRINT attribute MAY be present in all STUN messages. The 1894 value of the attribute is computed as the CRC-32 of the STUN message 1895 up to (but excluding) the FINGERPRINT attribute itself, XOR'ed with 1896 the 32-bit value 0x5354554e (the XOR helps in cases where an 1897 application packet is also using CRC-32 in it). The 32-bit CRC is 1898 the one defined in ITU V.42 [ITU.V42.2002], which has a generator 1899 polynomial of x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1. 1900 See the sample code for the CRC-32 in Section 8 of [RFC1952]. 1902 When present, the FINGERPRINT attribute MUST be the last attribute in 1903 the message, and thus will appear after MESSAGE-INTEGRITY. 1905 The FINGERPRINT attribute can aid in distinguishing STUN packets from 1906 packets of other protocols. See Section 7. 1908 As with MESSAGE-INTEGRITY, the CRC used in the FINGERPRINT attribute 1909 covers the length field from the STUN message header. Therefore, 1910 this value must be correct and include the CRC attribute as part of 1911 the message length, prior to computation of the CRC. When using the 1912 FINGERPRINT attribute in a message, the attribute is first placed 1913 into the message with a dummy value, then the CRC is computed, and 1914 then the value of the attribute is updated. If the MESSAGE-INTEGRITY 1915 attribute is also present, then it must be present with the correct 1916 message-integrity value before the CRC is computed, since the CRC is 1917 done over the value of the MESSAGE-INTEGRITY attribute as well. 1919 14.8. ERROR-CODE 1921 The ERROR-CODE attribute is used in error response messages. It 1922 contains a numeric error code value in the range of 300 to 699 plus a 1923 textual reason phrase encoded in UTF-8 [RFC3629], and is consistent 1924 in its code assignments and semantics with SIP [RFC3261] and HTTP 1925 [RFC7231]. The reason phrase is meant for user consumption, and can 1926 be anything appropriate for the error code. Recommended reason 1927 phrases for the defined error codes are included in the IANA registry 1928 for error codes. The reason phrase MUST be a UTF-8 [RFC3629] encoded 1929 sequence of less than 128 characters (which can be as long as 763 1930 bytes). 1932 0 1 2 3 1933 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 1934 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1935 | Reserved, should be 0 |Class| Number | 1936 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1937 | Reason Phrase (variable) .. 1938 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1940 Figure 7: ERROR-CODE Attribute 1942 To facilitate processing, the class of the error code (the hundreds 1943 digit) is encoded separately from the rest of the code, as shown in 1944 Figure 7. 1946 The Reserved bits SHOULD be 0, and are for alignment on 32-bit 1947 boundaries. Receivers MUST ignore these bits. The Class represents 1948 the hundreds digit of the error code. The value MUST be between 3 1949 and 6. The Number represents the error code modulo 100, and its 1950 value MUST be between 0 and 99. 1952 The following error codes, along with their recommended reason 1953 phrases, are defined: 1955 300 Try Alternate: The client should contact an alternate server for 1956 this request. This error response MUST only be sent if the 1957 request included either a USERNAME or USERHASH attribute and a 1958 valid MESSAGE-INTEGRITY attribute; otherwise, it MUST NOT be sent 1959 and error code 400 (Bad Request) is suggested. This error 1960 response MUST be protected with the MESSAGE-INTEGRITY attribute, 1961 and receivers MUST validate the MESSAGE-INTEGRITY of this response 1962 before redirecting themselves to an alternate server. 1964 Note: Failure to generate and validate message integrity for a 300 1965 response allows an on-path attacker to falsify a 300 response thus 1966 causing subsequent STUN messages to be sent to a victim. 1968 400 Bad Request: The request was malformed. The client SHOULD NOT 1969 retry the request without modification from the previous attempt. 1970 The server may not be able to generate a valid MESSAGE-INTEGRITY 1971 for this error, so the client MUST NOT expect a valid MESSAGE- 1972 INTEGRITY attribute on this response. 1974 401 Unauthenticated: The request did not contain the correct 1975 credentials to proceed. The client should retry the request with 1976 proper credentials. 1978 420 Unknown Attribute: The server received a STUN packet containing 1979 a comprehension-required attribute that it did not understand. 1980 The server MUST put this unknown attribute in the UNKNOWN- 1981 ATTRIBUTE attribute of its error response. 1983 438 Stale Nonce: The NONCE used by the client was no longer valid. 1984 The client should retry, using the NONCE provided in the response. 1986 500 Server Error: The server has suffered a temporary error. The 1987 client should try again. 1989 14.9. REALM 1991 The REALM attribute may be present in requests and responses. It 1992 contains text that meets the grammar for "realm-value" as described 1993 in [RFC3261] but without the double quotes and their surrounding 1994 whitespace. That is, it is an unquoted realm-value (and is therefore 1995 a sequence of qdtext or quoted-pair). It MUST be a UTF-8 [RFC3629] 1996 encoded sequence of less than 128 characters (which can be as long as 1997 763 bytes), and MUST have been processed using the OpaqueString 1998 profile [RFC8265]. 2000 Presence of the REALM attribute in a request indicates that long-term 2001 credentials are being used for authentication. Presence in certain 2002 error responses indicates that the server wishes the client to use a 2003 long-term credential for authentication. 2005 14.10. NONCE 2007 The NONCE attribute may be present in requests and responses. It 2008 contains a sequence of qdtext or quoted-pair, which are defined in 2009 RFC 3261 [RFC3261]. Note that this means that the NONCE attribute 2010 will not contain actual quote characters. See [RFC7616], 2011 Section 5.4, for guidance on selection of nonce values in a server. 2012 It MUST be less than 128 characters (which can be as long as 763 2013 bytes). 2015 14.11. PASSWORD-ALGORITHMS 2017 The PASSWORD-ALGORITHMS attribute may be present in requests and 2018 responses. It contains the list of algorithms that the server can 2019 use to derive the long-term password. 2021 The set of known algorithms is maintained by IANA. The initial set 2022 defined by this specification is found in Section 17.5. 2024 The attribute contains a list of algorithm numbers and variable 2025 length parameters. The algorithm number is a 16-bit value as defined 2026 in Section 17.5. The parameters start with the actual length of the 2027 parameters as a 16-bit value, followed by the parameters that are 2028 specific to each algorithm. The parameters are padded to a 32-bit 2029 boundary, in the same manner as an attribute. 2031 0 1 2 3 2032 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 2033 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2034 | Algorithm 1 | Algorithm 1 Parameters Length | 2035 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2036 | Algorithm 1 Parameters (variable) 2037 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2038 | Algorithm 2 | Algorithm 2 Parameters Length | 2039 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2040 | Algorithm 2 Parameter (variable) 2041 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2042 | ... 2044 Figure 8: Format of PASSWORD-ALGORITHMS Attribute 2046 14.12. PASSWORD-ALGORITHM 2048 The PASSWORD-ALGORITHM attribute is present only in requests. It 2049 contains the algorithms that the server must use to derive the long- 2050 term password. 2052 The set of known algorithms is maintained by IANA. The initial set 2053 defined by this specification is found in Section 17.5. 2055 The attribute contains an algorithm number and variable length 2056 parameters. The algorithm number is a 16-bit value as defined in 2057 Section 17.5. The parameters starts with the actual length of the 2058 parameters as a 16-bit value, followed by the parameters that are 2059 specific to the algorithm. The parameters are padded to a 32-bit 2060 boundary, in the same manner as an attribute. 2062 0 1 2 3 2063 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 2064 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2065 | Algorithm | Algorithm Parameters Length | 2066 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2067 | Algorithm Parameters (variable) 2068 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2070 Figure 9: Format of PASSWORD-ALGORITHM Attribute 2072 14.13. UNKNOWN-ATTRIBUTES 2074 The UNKNOWN-ATTRIBUTES attribute is present only in an error response 2075 when the response code in the ERROR-CODE attribute is 420. 2077 The attribute contains a list of 16-bit values, each of which 2078 represents an attribute type that was not understood by the server. 2080 0 1 2 3 2081 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 2082 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2083 | Attribute 1 Type | Attribute 2 Type | 2084 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2085 | Attribute 3 Type | Attribute 4 Type ... 2086 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2088 Figure 10: Format of UNKNOWN-ATTRIBUTES Attribute 2090 Note: In [RFC3489], this field was padded to 32 by duplicating the 2091 last attribute. In this version of the specification, the normal 2092 padding rules for attributes are used instead. 2094 14.14. SOFTWARE 2096 The SOFTWARE attribute contains a textual description of the software 2097 being used by the agent sending the message. It is used by clients 2098 and servers. Its value SHOULD include manufacturer and version 2099 number. The attribute has no impact on operation of the protocol, 2100 and serves only as a tool for diagnostic and debugging purposes. The 2101 value of SOFTWARE is variable length. It MUST be a UTF-8 [RFC3629] 2102 encoded sequence of less than 128 characters (which can be as long as 2103 763 bytes). 2105 14.15. ALTERNATE-SERVER 2107 The alternate server represents an alternate transport address 2108 identifying a different STUN server that the STUN client should try. 2110 It is encoded in the same way as MAPPED-ADDRESS, and thus refers to a 2111 single server by IP address. The IP address family MUST be identical 2112 to that of the source IP address of the request. 2114 14.16. ALTERNATE-DOMAIN 2116 The alternate domain represents the domain name that is used to 2117 verify the IP address in the ALTERNATE-SERVER attribute when the 2118 transport protocol uses TLS or DTLS. 2120 The value of ALTERNATE-DOMAIN is variable length. It MUST be a UTF-8 2121 [RFC3629] encoded sequence of less than 128 characters (which can be 2122 as long as 763 bytes). 2124 15. Security Considerations 2126 15.1. Attacks against the Protocol 2128 15.1.1. Outside Attacks 2130 An attacker can try to modify STUN messages in transit, in order to 2131 cause a failure in STUN operation. These attacks are detected for 2132 both requests and responses through the message-integrity mechanism, 2133 using either a short-term or long-term credential. Of course, once 2134 detected, the manipulated packets will be dropped, causing the STUN 2135 transaction to effectively fail. This attack is possible only by an 2136 on-path attacker. 2138 An attacker that can observe, but not modify, STUN messages in- 2139 transit (for example, an attacker present on a shared access medium, 2140 such as Wi-Fi), can see a STUN request, and then immediately send a 2141 STUN response, typically an error response, in order to disrupt STUN 2142 processing. This attack is also prevented for messages that utilize 2143 MESSAGE-INTEGRITY. However, some error responses, those related to 2144 authentication in particular, cannot be protected by MESSAGE- 2145 INTEGRITY. When STUN itself is run over a secure transport protocol 2146 (e.g., TLS), these attacks are completely mitigated. 2148 Depending on the STUN usage, these attacks may be of minimal 2149 consequence and thus do not require message integrity to mitigate. 2150 For example, when STUN is used to a basic STUN server to discover a 2151 server reflexive candidate for usage with ICE, authentication and 2152 message integrity are not required since these attacks are detected 2153 during the connectivity check phase. The connectivity checks 2154 themselves, however, require protection for proper operation of ICE 2155 overall. As described in Section 13, STUN usages describe when 2156 authentication and message integrity are needed. 2158 Since STUN uses the HMAC of a shared secret for authentication and 2159 integrity protection, it is subject to offline dictionary attacks. 2160 When authentication is utilized, it SHOULD be with a strong password 2161 that is not readily subject to offline dictionary attacks. 2162 Protection of the channel itself, using TLS or DTLS, mitigates these 2163 attacks. 2165 STUN supports both MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256, 2166 which is subject to bid down attacks by an on-path attacker. 2167 Protection of the channel itself, using TLS or DTLS, mitigates these 2168 attacks. Timely removal of the support of MESSAGE-INTEGRITY in a 2169 future version of STUN is necessary. 2171 15.1.2. Inside Attacks 2173 A rogue client may try to launch a DoS attack against a server by 2174 sending it a large number of STUN requests. Fortunately, STUN 2175 requests can be processed statelessly by a server, making such 2176 attacks hard to launch. 2178 A rogue client may use a STUN server as a reflector, sending it 2179 requests with a falsified source IP address and port. In such a 2180 case, the response would be delivered to that source IP and port. 2181 There is no amplification of the number of packets with this attack 2182 (the STUN server sends one packet for each packet sent by the 2183 client), though there is a small increase in the amount of data, 2184 since STUN responses are typically larger than requests. This attack 2185 is mitigated by ingress source address filtering. 2187 Revealing the specific software version of the agent through the 2188 SOFTWARE attribute might allow them to become more vulnerable to 2189 attacks against software that is known to contain security holes. 2190 Implementers SHOULD make usage of the SOFTWARE attribute a 2191 configurable option. 2193 15.2. Attacks Affecting the Usage 2195 This section lists attacks that might be launched against a usage of 2196 STUN. Each STUN usage must consider whether these attacks are 2197 applicable to it, and if so, discuss counter-measures. 2199 Most of the attacks in this section revolve around an attacker 2200 modifying the reflexive address learned by a STUN client through a 2201 Binding request/response transaction. Since the usage of the 2202 reflexive address is a function of the usage, the applicability and 2203 remediation of these attacks are usage-specific. In common 2204 situations, modification of the reflexive address by an on-path 2205 attacker is easy to do. Consider, for example, the common situation 2206 where STUN is run directly over UDP. In this case, an on-path 2207 attacker can modify the source IP address of the Binding request 2208 before it arrives at the STUN server. The STUN server will then 2209 return this IP address in the XOR-MAPPED-ADDRESS attribute to the 2210 client, and send the response back to that (falsified) IP address and 2211 port. If the attacker can also intercept this response, it can 2212 direct it back towards the client. Protecting against this attack by 2213 using a message-integrity check is impossible, since a message- 2214 integrity value cannot cover the source IP address, since the 2215 intervening NAT must be able to modify this value. Instead, one 2216 solution to preventing the attacks listed below is for the client to 2217 verify the reflexive address learned, as is done in ICE 2218 [I-D.ietf-ice-rfc5245bis]. Other usages may use other means to 2219 prevent these attacks. 2221 15.2.1. Attack I: Distributed DoS (DDoS) against a Target 2223 In this attack, the attacker provides one or more clients with the 2224 same faked reflexive address that points to the intended target. 2225 This will trick the STUN clients into thinking that their reflexive 2226 addresses are equal to that of the target. If the clients hand out 2227 that reflexive address in order to receive traffic on it (for 2228 example, in SIP messages), the traffic will instead be sent to the 2229 target. This attack can provide substantial amplification, 2230 especially when used with clients that are using STUN to enable 2231 multimedia applications. However, it can only be launched against 2232 targets for which packets from the STUN server to the target pass 2233 through the attacker, limiting the cases in which it is possible. 2235 15.2.2. Attack II: Silencing a Client 2237 In this attack, the attacker provides a STUN client with a faked 2238 reflexive address. The reflexive address it provides is a transport 2239 address that routes to nowhere. As a result, the client won't 2240 receive any of the packets it expects to receive when it hands out 2241 the reflexive address. This exploitation is not very interesting for 2242 the attacker. It impacts a single client, which is frequently not 2243 the desired target. Moreover, any attacker that can mount the attack 2244 could also deny service to the client by other means, such as 2245 preventing the client from receiving any response from the STUN 2246 server, or even a DHCP server. As with the attack in Section 15.2.1, 2247 this attack is only possible when the attacker is on path for packets 2248 sent from the STUN server towards this unused IP address. 2250 15.2.3. Attack III: Assuming the Identity of a Client 2252 This attack is similar to attack II. However, the faked reflexive 2253 address points to the attacker itself. This allows the attacker to 2254 receive traffic that was destined for the client. 2256 15.2.4. Attack IV: Eavesdropping 2258 In this attack, the attacker forces the client to use a reflexive 2259 address that routes to itself. It then forwards any packets it 2260 receives to the client. This attack would allow the attacker to 2261 observe all packets sent to the client. However, in order to launch 2262 the attack, the attacker must have already been able to observe 2263 packets from the client to the STUN server. In most cases (such as 2264 when the attack is launched from an access network), this means that 2265 the attacker could already observe packets sent to the client. This 2266 attack is, as a result, only useful for observing traffic by 2267 attackers on the path from the client to the STUN server, but not 2268 generally on the path of packets being routed towards the client. 2270 15.3. Hash Agility Plan 2272 This specification uses both HMAC-SHA-1 and HMAC-SHA-256 for 2273 computation of the message integrity. If, at a later time, HMAC- 2274 SHA-256 is found to be compromised, the following is the remedy that 2275 will be applied: 2277 o Both a new message-integrity attribute and a new STUN Security 2278 Feature bit will be allocated in a Standard Track document. The 2279 new message-integrity attribute will have its value computed using 2280 a new hash. The STUN Security Feature bit will be used to 2281 simultaneously signal to a STUN client using the Long Term 2282 Credential Mechanism that this server supports this new hash 2283 algorithm, and will prevent bid down attacks on the new message- 2284 integrity attribute. 2286 o STUN Client and Server using the Short Term Credential Mechanism 2287 will need to get an updated external mechanism that they can use 2288 to signal what message-integrity attributes are in use. 2290 The bid down protection mechanism described in this document is new, 2291 and thus cannot currently protect against a bid down attack that 2292 lowers the strength of the hash algorithm to HMAC-SHA-1. This is 2293 why, after a transition period, a new document updating this document 2294 will assign a new STUN Security Feature bit for deprecating HMAC-SHA- 2295 1. When used, this bit will signal that HMAC-SHA-1 is deprecated and 2296 should no longer be used. 2298 16. IAB Considerations 2300 The IAB has studied the problem of Unilateral Self-Address Fixing 2301 (UNSAF), which is the general process by which a client attempts to 2302 determine its address in another realm on the other side of a NAT 2303 through a collaborative protocol reflection mechanism ([RFC3424]). 2304 STUN can be used to perform this function using a Binding request/ 2305 response transaction if one agent is behind a NAT and the other is on 2306 the public side of the NAT. 2308 The IAB has suggested that protocols developed for this purpose 2309 document a specific set of considerations. Because some STUN usages 2310 provide UNSAF functions (such as ICE [I-D.ietf-ice-rfc5245bis] ), and 2311 others do not (such as SIP Outbound [RFC5626]), answers to these 2312 considerations need to be addressed by the usages themselves. 2314 17. IANA Considerations 2316 17.1. STUN Security Features Registry 2318 A STUN Security Feature set is a 24 bit value. 2320 IANA is requested to create a new registry containing the STUN 2321 Security Features that are protected by the bid down attack 2322 prevention mechanism described in section Section 9.2.1. 2324 The initial STUN Security Features are: 2326 0x000001: Password algorithms 2327 0x000002: Username anonymity 2329 New Security Features are assigned by a Standard Action [RFC8126]. 2331 17.2. STUN Methods Registry 2333 IANA is requested to update the name for method 0x002 and the 2334 reference from RFC 5389 to RFC-to-be for the following STUN methods: 2336 0x000: (Reserved) 2337 0x001: Binding 2338 0x002: (Reserved; prior to [RFC5389] this was SharedSecret) 2340 17.3. STUN Attribute Registry 2341 17.3.1. Updated Attributes 2343 IANA is requested to update the names for attributes 0x0002, 0x0003, 2344 0x0004, 0x0005, 0x0007, and 0x000B, and the reference from RFC 5389 2345 to RFC-to-be for the following STUN methods: 2347 Comprehension-required range (0x0000-0x7FFF): 2348 0x0000: (Reserved) 2349 0x0001: MAPPED-ADDRESS 2350 0x0002: (Reserved; prior to [RFC5389] this was RESPONSE-ADDRESS) 2351 0x0003: (Reserved; prior to [RFC5389] this was CHANGE-REQUEST) 2352 0x0004: (Reserved; prior to [RFC5389] this was SOURCE-ADDRESS) 2353 0x0005: (Reserved; prior to [RFC5389] this was CHANGED-ADDRESS) 2354 0x0006: USERNAME 2355 0x0007: (Reserved; prior to [RFC5389] this was PASSWORD) 2356 0x0008: MESSAGE-INTEGRITY 2357 0x0009: ERROR-CODE 2358 0x000A: UNKNOWN-ATTRIBUTES 2359 0x000B: (Reserved; prior to [RFC5389] this was REFLECTED-FROM) 2360 0x0014: REALM 2361 0x0015: NONCE 2362 0x0020: XOR-MAPPED-ADDRESS 2364 Comprehension-optional range (0x8000-0xFFFF) 2365 0x8022: SOFTWARE 2366 0x8023: ALTERNATE-SERVER 2367 0x8028: FINGERPRINT 2369 17.3.2. New Attributes 2371 IANA is requested to add the following attribute to the STUN 2372 Attribute Registry: 2374 Comprehension-required range (0x0000-0x7FFF): 2375 0xXXXX: MESSAGE-INTEGRITY-SHA256 2376 0xXXXX: PASSWORD-ALGORITHM 2377 0xXXXX: USERHASH 2379 Comprehension-optional range (0x8000-0xFFFF) 2380 0xXXXX: PASSSORD-ALGORITHMS 2381 0xXXXX: ALTERNATE-DOMAIN 2383 17.4. STUN Error Code Registry 2385 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2386 for the Error Codes given in Section 14.8. 2388 17.5. Password Algorithm Registry 2390 IANA is requested to create a new registry for Password Algorithm. 2392 A Password Algorithm is a hex number in the range 0x0000 - 0xFFFF. 2394 The initial Password Algorithms are: 2396 0x0001: MD5 2397 0x0002: SHA256 2399 Password Algorithms in the first half of the range (0x0000 - 0x7FFF) 2400 are assigned by IETF Review [RFC8126]. Password Algorithms in the 2401 second half of the range (0x8000 - 0xFFFF) are assigned by Designated 2402 Expert [RFC8126]. 2404 17.5.1. Password Algorithms 2406 17.5.1.1. MD5 2408 This password algorithm is taken from [RFC1321]. 2410 The key length is 20 bytes and the parameters value is empty. 2412 Note: This algorithm MUST only be used for compatibility with legacy 2413 systems. 2415 key = MD5(username ":" realm ":" OpaqueString(password)) 2417 17.5.1.2. SHA256 2419 This password algorithm is taken from [RFC7616]. 2421 The key length is 32 bytes and the parameters value is empty. 2423 key = SHA256(username ":" realm ":" OpaqueString(password)) 2425 17.6. STUN UDP and TCP Port Numbers 2427 IANA is requested to update the reference from RFC 5389 to RFC-to-be 2428 for the following ports: 2430 stun 3478/tcp Session Traversal Utilities for NAT (STUN) port 2431 stun 3478/udp Session Traversal Utilities for NAT (STUN) port 2432 stuns 5349/tcp Session Traversal Utilities for NAT (STUN) port 2434 18. Changes since RFC 5389 2436 This specification obsoletes [RFC5389]. This specification differs 2437 from RFC 5389 in the following ways: 2439 o Added support for DTLS-over-UDP (RFC 6347). 2441 o Made clear that the RTO is considered stale if there is no 2442 transactions with the server. 2444 o Aligned the RTO calculation with RFC 6298. 2446 o Updated the cipher suites for TLS. 2448 o Added support for STUN URI (RFC 7064). 2450 o Added support for SHA256 message integrity. 2452 o Updated the PRECIS support to RFC 8265. 2454 o Added protocol and registry to choose the password encryption 2455 algorithm. 2457 o Added support for anonymous username. 2459 o Added protocol and registry for preventing biddown attacks. 2461 o Sharing a NONCE is no longer permitted. 2463 o Added the possibility of using a domain name in the alternate 2464 server mechanism. 2466 o Added more C snippets. 2468 o Added test vector. 2470 19. References 2472 19.1. Normative References 2474 [ITU.V42.2002] 2475 International Telecommunications Union, "Error-correcting 2476 Procedures for DCEs Using Asynchronous-to-Synchronous 2477 Conversion", ITU-T Recommendation V.42, 2002. 2479 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 2480 DOI 10.17487/RFC0791, September 1981, 2481 . 2483 [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - 2484 Communication Layers", STD 3, RFC 1122, 2485 DOI 10.17487/RFC1122, October 1989, 2486 . 2488 [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, 2489 DOI 10.17487/RFC1321, April 1992, 2490 . 2492 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 2493 Hashing for Message Authentication", RFC 2104, 2494 DOI 10.17487/RFC2104, February 1997, 2495 . 2497 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2498 Requirement Levels", BCP 14, RFC 2119, 2499 DOI 10.17487/RFC2119, March 1997, 2500 . 2502 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2503 specifying the location of services (DNS SRV)", RFC 2782, 2504 DOI 10.17487/RFC2782, February 2000, 2505 . 2507 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2508 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2509 2003, . 2511 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 2512 Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, 2513 . 2515 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 2516 (TLS) Protocol Version 1.2", RFC 5246, 2517 DOI 10.17487/RFC5246, August 2008, 2518 . 2520 [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and 2521 Verification of Domain-Based Application Service Identity 2522 within Internet Public Key Infrastructure Using X.509 2523 (PKIX) Certificates in the Context of Transport Layer 2524 Security (TLS)", RFC 6125, DOI 10.17487/RFC6125, March 2525 2011, . 2527 [RFC6298] Paxson, V., Allman, M., Chu, J., and M. Sargent, 2528 "Computing TCP's Retransmission Timer", RFC 6298, 2529 DOI 10.17487/RFC6298, June 2011, 2530 . 2532 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 2533 Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, 2534 January 2012, . 2536 [RFC7064] Nandakumar, S., Salgueiro, G., Jones, P., and M. Petit- 2537 Huguenin, "URI Scheme for the Session Traversal Utilities 2538 for NAT (STUN) Protocol", RFC 7064, DOI 10.17487/RFC7064, 2539 November 2013, . 2541 [RFC7350] Petit-Huguenin, M. and G. Salgueiro, "Datagram Transport 2542 Layer Security (DTLS) as Transport for Session Traversal 2543 Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, 2544 August 2014, . 2546 [RFC7616] Shekh-Yusef, R., Ahrens, D., and S. Bremer, "HTTP Digest 2547 Access Authentication", RFC 7616, DOI 10.17487/RFC7616, 2548 September 2015, . 2550 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 2551 (IPv6) Specification", RFC 8200, STD 86, 2552 DOI 10.17487/RFC8200, July 2017, 2553 . 2555 [RFC8265] Saint-Andre, P. and A. Melnikov, "Preparation, 2556 Enforcement, and Comparison of Internationalized Strings 2557 Representing Usernames and Passwords", RFC 8265, 2558 DOI 10.17487/RFC8265, October 2017, 2559 . 2561 [RFC8305] Schinazi, D. and T. Pauly, "Happy Eyeballs Version 2: 2562 Better Connectivity Using Concurrency", RFC 8305, 2563 DOI 10.17487/RFC8305, December 2017, 2564 . 2566 19.2. Informative References 2568 [I-D.ietf-ice-rfc5245bis] 2569 Keranen, A., Holmberg, C., and J. Rosenberg, "Interactive 2570 Connectivity Establishment (ICE): A Protocol for Network 2571 Address Translator (NAT) Traversal", draft-ietf-ice- 2572 rfc5245bis-16 (work in progress), January 2018. 2574 [KARN87] Karn, P. and C. Partridge, "Improving Round-Trip Time 2575 Estimates in Reliable Transport Protocols", August 1987. 2577 [RFC1952] Deutsch, P., "GZIP file format specification version 4.3", 2578 RFC 1952, DOI 10.17487/RFC1952, May 1996, 2579 . 2581 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 2582 A., Peterson, J., Sparks, R., Handley, M., and E. 2583 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 2584 DOI 10.17487/RFC3261, June 2002, 2585 . 2587 [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations for 2588 UNilateral Self-Address Fixing (UNSAF) Across Network 2589 Address Translation", RFC 3424, DOI 10.17487/RFC3424, 2590 November 2002, . 2592 [RFC3489] Rosenberg, J., Weinberger, J., Huitema, C., and R. Mahy, 2593 "STUN - Simple Traversal of User Datagram Protocol (UDP) 2594 Through Network Address Translators (NATs)", RFC 3489, 2595 DOI 10.17487/RFC3489, March 2003, 2596 . 2598 [RFC4107] Bellovin, S. and R. Housley, "Guidelines for Cryptographic 2599 Key Management", BCP 107, RFC 4107, DOI 10.17487/RFC4107, 2600 June 2005, . 2602 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 2603 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 2604 DOI 10.17487/RFC5389, October 2008, 2605 . 2607 [RFC5626] Jennings, C., Ed., Mahy, R., Ed., and F. Audet, Ed., 2608 "Managing Client-Initiated Connections in the Session 2609 Initiation Protocol (SIP)", RFC 5626, 2610 DOI 10.17487/RFC5626, October 2009, 2611 . 2613 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 2614 Relays around NAT (TURN): Relay Extensions to Session 2615 Traversal Utilities for NAT (STUN)", RFC 5766, 2616 DOI 10.17487/RFC5766, April 2010, 2617 . 2619 [RFC5769] Denis-Courmont, R., "Test Vectors for Session Traversal 2620 Utilities for NAT (STUN)", RFC 5769, DOI 10.17487/RFC5769, 2621 April 2010, . 2623 [RFC5780] MacDonald, D. and B. Lowekamp, "NAT Behavior Discovery 2624 Using Session Traversal Utilities for NAT (STUN)", 2625 RFC 5780, DOI 10.17487/RFC5780, May 2010, 2626 . 2628 [RFC6544] Rosenberg, J., Keranen, A., Lowekamp, B., and A. Roach, 2629 "TCP Candidates with Interactive Connectivity 2630 Establishment (ICE)", RFC 6544, DOI 10.17487/RFC6544, 2631 March 2012, . 2633 [RFC7231] Fielding, R. and R. Reschke, "Hypertext Transfer Protocol 2634 (HTTP/1.1): Semantics and Content", RFC 7231, 2635 DOI 10.17487/RFC7231, June 2014, 2636 . 2638 [RFC7525] Sheffer, Y., Holz, R., and P. Saint-Andre, 2639 "Recommendations for Secure Use of Transport Layer 2640 Security (TLS) and Datagram Transport Layer Security 2641 (DTLS)", BCP 195, RFC 7525, DOI 10.17487/RFC7525, May 2642 2015, . 2644 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2645 Writing an IANA Considerations Section in RFCs", BCP 26, 2646 RFC 8126, DOI 10.17487/RFC8126, May 2008, 2647 . 2649 Appendix A. C Snippet to Determine STUN Message Types 2651 Given a 16-bit STUN message type value in host byte order in msg_type 2652 parameter, below are C macros to determine the STUN message types: 2654 2655 #define IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) 2656 #define IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) 2657 #define IS_SUCCESS_RESP(msg_type) (((msg_type) & 0x0110) == 0x0100) 2658 #define IS_ERR_RESP(msg_type) (((msg_type) & 0x0110) == 0x0110) 2659 2661 A function to convert method and class into a message type: 2663 2664 int type(int method, int cls) { 2665 return (method & 0x0F80) << 9 | (method & 0x0070) << 5 2666 | (method & 0x000F) | (cls & 0x0002) << 8 2667 | (cls & 0x0001) << 4; 2668 } 2669 2671 A function to extract the method from the message type: 2673 2674 int method(int type) { 2675 return (type & 0x3E00) >> 2 | (type & 0x00E0) >> 1 2676 | (type & 0x000F); 2677 } 2678 2680 A function to extract the class from the message type: 2682 2683 int cls(int type) { 2684 return (type & 0x0100) >> 7 | (type & 0x0010) >> 4; 2685 } 2686 2688 Appendix B. Test Vectors 2690 This section augments the list of test vectors defined in [RFC5769] 2691 with MESSAGE-INTEGRITY-SHA256. All the formats and definitions 2692 listed in Section 2 of [RFC5769] apply here. 2694 B.1. Sample Request with Long-Term Authentication with MESSAGE- 2695 INTEGRITY-SHA256 and USERHASH 2697 This request uses the following parameters: 2699 Username: "" (without 2700 quotes) unaffected by OpaqueString [RFC8265] processing 2702 Password: "TheMtr" and "TheMatrIX" (without 2703 quotes) respectively before and after OpaqueString processing 2705 Nonce: "obMatJos2AAACf//499k954d6OL34oL9FSTvy64sA" (without quotes) 2707 Realm: "example.org" (without quotes) 2708 00 01 00 9c Request type and message length 2709 21 12 a4 42 Magic cookie 2710 78 ad 34 33 } 2711 c6 ad 72 c0 } Transaction ID 2712 29 da 41 2e } 2713 XX XX 00 20 USERHASH attribute header 2714 4a 3c f3 8f } 2715 ef 69 92 bd } 2716 a9 52 c6 78 } 2717 04 17 da 0f } Userhash value (32 bytes) 2718 24 81 94 15 } 2719 56 9e 60 b2 } 2720 05 c4 6e 41 } 2721 40 7f 17 04 } 2722 00 15 00 29 NONCE attribute header 2723 6f 62 4d 61 } 2724 74 4a 6f 73 } 2725 32 41 41 41 } 2726 43 66 2f 2f } 2727 34 39 39 6b } Nonce value and padding (3 bytes) 2728 39 35 34 64 } 2729 36 4f 4c 33 } 2730 34 6f 4c 39 } 2731 46 53 54 76 } 2732 79 36 34 73 } 2733 41 00 00 00 } 2734 00 14 00 0b REALM attribute header 2735 65 78 61 6d } 2736 70 6c 65 2e } Realm value (11 bytes) and padding (1 byte) 2737 6f 72 67 00 } 2738 XX XX 00 20 MESSAGE-INTEGRITY-SHA256 attribute header 2739 c4 ec a2 b6 } 2740 24 6f 26 be } 2741 bc 2f 77 49 } 2742 07 c2 00 a3 } HMAC-SHA256 value 2743 76 c7 c2 8e } 2744 b4 d1 26 60 } 2745 bb fe 9f 28 } 2746 0e 85 71 f2 } 2748 Note: Before publication, the XX XX placeholder must be replaced by 2749 the value assigned to MESSAGE-INTEGRITY-SHA256 and USERHASH by 2750 IANA. The MESSAGE-INTEGRITY-SHA256 attribute value will need to 2751 be updated after this. 2753 Appendix C. Release notes 2755 This section must be removed before publication as an RFC. 2757 C.1. Modifications between draft-ietf-tram-stunbis-14 and draft-ietf- 2758 tram-stunbis-13 2760 o Reorder the paragraphs in section 9.1.4. 2762 o The realm is now processed through Opaque in section 9.2.2. 2764 o Make clear in section 9.2.4 that it is an exclusive-xor. 2766 o Removed text that implied that nonce sharing was explicitly 2767 permitted in RFC 5389. 2769 o In same section, s/username/value/ for USERCASH. 2771 o Modify the IANA requests to explicitly say that the reserved 2772 codepoints were prior to RFC 5389. 2774 C.2. Modifications between draft-ietf-tram-stunbis-13 and draft-ietf- 2775 tram-stunbis-12 2777 o Update references. 2779 o Fixes some text following Shepherd review. 2781 o Update co-author info. 2783 C.3. Modifications between draft-ietf-tram-stunbis-12 and draft-ietf- 2784 tram-stunbis-11 2786 o Clarifies the procedure to define a new hash algorithm for 2787 message-integrity. 2789 o Explain the procedure to deprecate SHA1 as message-integrity. 2791 o Added procedure for Happy Eyeballs (RFC 6555). 2793 o Added verification that Happy Eyeballs works in the STUN Usage 2794 checklist. 2796 o Add reference to Base64 RFC. 2798 o Changed co-author affiliation. 2800 C.4. Modifications between draft-ietf-tram-stunbis-11 and draft-ietf- 2801 tram-stunbis-10 2803 o Made clear that the same HMAC than received in response of short 2804 term credential must be used for subsequent transactions. 2806 o s/URL/URI/ 2808 o The "nonce cookie" is now mandatory to signal that SHA256 must be 2809 used in the next transaction. 2811 o s/SHA1/SHA256/ 2813 o Changed co-author affiliation. 2815 C.5. Modifications between draft-ietf-tram-stunbis-10 and draft-ietf- 2816 tram-stunbis-09 2818 o Removed the reserved value in the security registry, as it does 2819 not make sense in a bitset. 2821 o Updated change list. 2823 o Updated the minimum truncation size for M-I-256 to 16 bytes. 2825 o Changed the truncation order to match RFC 7518. 2827 o Fixed bugs in truncation boundary text. 2829 o Stated that STUN Usages have to explicitly state that they can use 2830 truncation. 2832 o Removed truncation from the MESSAGE-INTEGRITY attribute. 2834 o Add reference to C code in RFC 1952. 2836 o Replaced RFC 2818 reference to RFC 6125. 2838 C.6. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf- 2839 tram-stunbis-08 2841 o Removed the reserved value in the security registry, as it does 2842 not make sense in a bitset. 2844 o Updated change list. 2846 o Updated the minimum truncation size for M-I-256 to 16 bytes. 2848 o Changed the truncation order to match RFC 7518. 2850 o Fixed bugs in truncation boundary text. 2852 o Stated that STUN Usages have to explicitly state that they can use 2853 truncation. 2855 o Removed truncation from the MESSAGE-INTEGRITY attribute. 2857 o Add reference to C code in RFC 1952. 2859 o Replaced RFC 2818 reference to RFC 6125. 2861 C.7. Modifications between draft-ietf-tram-stunbis-09 and draft-ietf- 2862 tram-stunbis-08 2864 o Packets discarded in a reliable or unreliable transaction triggers 2865 an attack error instead of a timeout error. An attack error on a 2866 reliable transport is signaled immediately instead of waiting for 2867 the timeout. 2869 o Explicitly state that a received 400 response without 2870 authentication will be dropped until timeout. 2872 o Clarify the SHOULD omit/include rules in LTCM. 2874 o If the nonce and the hmac are both invalid, then a 401 is sent 2875 instead of a 438. 2877 o The 401 and 438 error response to subsequent requests may use the 2878 previous NONCE/password to authenticate, if they are still 2879 available. 2881 o Change "401 Unauthorized" to "401 Unauthenticated" 2883 o Make clear that in some cases it is impossible to add a MI or MI2 2884 even if the text says SHOULD NOT. 2886 C.8. Modifications between draft-ietf-tram-stunbis-08 and draft-ietf- 2887 tram-stunbis-07 2889 o Updated list of changes since RFC 5389. 2891 o More examples are automatically generated. 2893 o Message integrity truncation is fixed at a multiple of 4 bytes, 2894 because the padding will not decrease by more than this. 2896 o USERHASH contains the 32 bytes of the hash, not a character 2897 string. 2899 o Updated the example to use the USERHASH attribute and the modified 2900 NONCE attribute. 2902 o Updated ICEbis reference. 2904 C.9. Modifications between draft-ietf-tram-stunbis-07 and draft-ietf- 2905 tram-stunbis-06 2907 o Add USERHASH attribute to carry the hashed version of the 2908 username. 2910 o Add IANA registry and nonce encoding for Security Features that 2911 need to be protected from bid down attacks. 2913 o Modified MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 to support 2914 truncation limits (pending cryptographic review), 2916 C.10. Modifications between draft-ietf-tram-stunbis-06 and draft-ietf- 2917 tram-stunbis-05 2919 o Changed I-D references to RFC references. 2921 o Changed CHANGE-ADDRESS to CHANGE-REQUEST (Errata #4233). 2923 o Added test vector for MESSAGE-INTEGRITY-SHA256. 2925 o Address additional review comments from Jonathan Lennox and 2926 Brandon Williams. 2928 C.11. Modifications between draft-ietf-tram-stunbis-05 and draft-ietf- 2929 tram-stunbis-04 2931 o Address review comments from Jonathan Lennox and Brandon Williams. 2933 C.12. Modifications between draft-ietf-tram-stunbis-04 and draft-ietf- 2934 tram-stunbis-03 2936 o Remove SCTP. 2938 o Remove DANE. 2940 o s/MESSAGE-INTEGRITY2/MESSAGE-INTEGRITY-SHA256/ 2942 o Remove Salted SHA256 password hash. 2944 o The RTO delay between transactions is removed. 2946 o Make clear that reusing NONCE will trigger a wasted round trip. 2948 C.13. Modifications between draft-ietf-tram-stunbis-03 and draft-ietf- 2949 tram-stunbis-02 2951 o SCTP prefix is now 0b00000101 instead of 0x11. 2953 o Add SCTP at various places it was needed. 2955 o Update the hash agility plan to take in account HMAC-SHA-256. 2957 o Adds the bid down attack on message-integrity in the security 2958 section. 2960 C.14. Modifications between draft-ietf-tram-stunbis-02 and draft-ietf- 2961 tram-stunbis-01 2963 o STUN hash algorithm agility (currently only SHA-1 is allowed). 2965 o Clarify terminology, text and guidance for STUN fragmentation. 2967 o Clarify whether it's valid to share nonces across TURN 2968 allocations. 2970 o Prevent the server to allocate the same NONCE to clients with 2971 different IP address and/or different port. This prevent sharing 2972 the nonce between TURN allocations in TURN. 2974 o Add reference to draft-ietf-uta-tls-bcp 2976 o Add a new attribute ALTERNATE-DOMAIN to verify the certificate of 2977 the ALTERNATE-SERVER after a 300 over (D)TLS. 2979 o The RTP delay between transactions applies only to parallel 2980 transactions, not to serial transactions. That prevents a 3RTT 2981 delay between the first transaction and the second transaction 2982 with long term authentication. 2984 o Add text saying ORIGIN can increase a request size beyond the MTU 2985 and so require an SCTPoUDP transport. 2987 o Move the Acknowledgments and Contributor sections to the end of 2988 the document, in accordance with RFC 7322 section 4. 2990 C.15. Modifications between draft-ietf-tram-stunbis-01 and draft-ietf- 2991 tram-stunbis-00 2993 o Add negotiation mechanism for new password algorithms. 2995 o Describe the MESSAGE-INTEGRITY/MESSAGE-INTEGRITY2 protocol. 2997 o Add support for SCTP to solve the fragmentation problem. 2999 o Merge RFC 7350: 3001 * Split the "Sending over..." sections in 3. 3003 * Add DTLS-over-UDP as transport. 3005 * Update the cipher suites and cipher/compression restrictions. 3007 * A stuns uri with an IP address is rejected. 3009 * Replace most of the RFC 3489 compatibility by a reference to 3010 the section in RFC 5389. 3012 * Update the STUN Usages list with transport applicability. 3014 o Merge RFC 7064: 3016 * DNS discovery is done from the URI. 3018 * Reorganized the text about default ports. 3020 o Add more C snippets. 3022 o Make clear that the cached RTO is discarded only if there is no 3023 new transations for 10 minutes. 3025 C.16. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 3026 ietf-tram-stunbis-00 3028 o Draft adopted as WG item. 3030 C.17. Modifications between draft-salgueiro-tram-stunbis-02 and draft- 3031 salgueiro-tram-stunbis-01 3033 o Add definition of MESSAGE-INTEGRITY2. 3035 o Update text and reference from RFC 2988 to RFC 6298. 3037 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 3039 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 3041 o Fix section number and make clear that the original domain name is 3042 used for the server certificate verification. This is consistent 3043 with what RFC 5922 (section 4) is doing. (Errata #2010) 3045 o Remove text transitioning from RFC 3489. 3047 o Add definition of MESSAGE-INTEGRITY2. 3049 o Update text and reference from RFC 2988 to RFC 6298. 3051 o s/The IAB has mandated/The IAB has suggested/ (Errata #3737). 3053 o Fix the figure for the UNKNOWN-ATTRIBUTES (Errata #2972). 3055 o Fix section number and make clear that the original domain name is 3056 used for the server certificate verification. This is consistent 3057 with what RFC 5922 (section 4) is doing. (Errata #2010) 3059 C.18. Modifications between draft-salgueiro-tram-stunbis-01 and draft- 3060 salgueiro-tram-stunbis-00 3062 o Restore the RFC 5389 text. 3064 o Add list of open issues. 3066 Acknowledgements 3068 Thanks to Michael Tuexen, Tirumaleswar Reddy, Oleg Moskalenko, Simon 3069 Perreault, Benjamin Schwartz, Rifaat Shekh-Yusef, Alan Johnston, 3070 Jonathan Lennox, Brandon Williams, Olle Johansson, Martin Thomson, 3071 Mihaly Meszaros and Tolga Asveren for the comments, suggestions, and 3072 questions that helped improve this document. 3074 The authors of RFC 5389 would like to thank Cedric Aoun, Pete 3075 Cordell, Cullen Jennings, Bob Penfield, Xavier Marjou, Magnus 3076 Westerlund, Miguel Garcia, Bruce Lowekamp, and Chris Sullivan for 3077 their comments, and Baruch Sterman and Alan Hawrylyshen for initial 3078 implementations. Thanks for Leslie Daigle, Allison Mankin, Eric 3079 Rescorla, and Henning Schulzrinne for IESG and IAB input on this 3080 work. 3082 Contributors 3084 Christian Huitema and Joel Weinberger were original co-authors of RFC 3085 3489. 3087 Authors' Addresses 3089 Marc Petit-Huguenin 3090 Impedance Mismatch 3092 Email: marc@petit-huguenin.org 3094 Gonzalo Salgueiro 3095 Cisco 3096 7200-12 Kit Creek Road 3097 Research Triangle Park, NC 27709 3098 US 3100 Email: gsalguei@cisco.com 3102 Jonathan Rosenberg 3103 Cisco 3104 Edison, NJ 3105 US 3107 Email: jdrosen@cisco.com 3108 URI: http://www.jdrosen.net 3110 Dan Wing 3112 Email: dwing-ietf@fuggles.com 3114 Rohan Mahy 3115 Unaffiliated 3117 Email: rohan.ietf@gmail.com 3119 Philip Matthews 3120 Nokia 3121 600 March Road 3122 Ottawa, Ontario K2K 2T6 3123 Canada 3125 Phone: 613-784-3139 3126 Email: philip_matthews@magma.ca