idnits 2.17.00 (12 Aug 2021) /tmp/idnits47994/draft-rosenberg-midcom-turn-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the RFC 3978 Section 5.4 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 seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (March 3, 2003) is 7019 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) == Outdated reference: draft-ietf-midcom-stun has been published as RFC 3489 ** Obsolete normative reference: RFC 2617 (ref. '4') (Obsoleted by RFC 7235, RFC 7615, RFC 7616, RFC 7617) -- Obsolete informational reference (is this intentional?): RFC 1889 (ref. '5') (Obsoleted by RFC 3550) -- Obsolete informational reference (is this intentional?): RFC 2327 (ref. '7') (Obsoleted by RFC 4566) -- Obsolete informational reference (is this intentional?): RFC 2326 (ref. '8') (Obsoleted by RFC 7826) -- Obsolete informational reference (is this intentional?): RFC 2402 (ref. '10') (Obsoleted by RFC 4302, RFC 4305) -- Obsolete informational reference (is this intentional?): RFC 2406 (ref. '11') (Obsoleted by RFC 4303, RFC 4305) == Outdated reference: A later version (-01) exists of draft-rosenberg-sipping-ice-00 Summary: 3 errors (**), 0 flaws (~~), 5 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 MIDCOM J. Rosenberg 3 Internet-Draft J. Weinberger 4 Expires: September 1, 2003 dynamicsoft 5 R. Mahy 6 Cisco Systems 7 C. Huitema 8 Microsoft 9 March 3, 2003 11 Traversal Using Relay NAT (TURN) 12 draft-rosenberg-midcom-turn-01 14 Status of this Memo 16 This document is an Internet-Draft and is in full conformance with 17 all provisions of Section 10 of RFC2026. 19 Internet-Drafts are working documents of the Internet Engineering 20 Task Force (IETF), its areas, and its working groups. Note that other 21 groups may also distribute working documents as Internet-Drafts. 23 Internet-Drafts are draft documents valid for a maximum of six months 24 and may be updated, replaced, or obsoleted by other documents at any 25 time. It is inappropriate to use Internet-Drafts as reference 26 material or to cite them other than as "work in progress." 28 The list of current Internet-Drafts can be accessed at http:// 29 www.ietf.org/ietf/1id-abstracts.txt. 31 The list of Internet-Draft Shadow Directories can be accessed at 32 http://www.ietf.org/shadow.html. 34 This Internet-Draft will expire on September 1, 2003. 36 Copyright Notice 38 Copyright (C) The Internet Society (2003). All Rights Reserved. 40 Abstract 42 Traversal Using Relay NAT (TURN) is a protocol that allows for an 43 element behind a NAT or firewall to receive incoming data over TCP or 44 UDP connections. It is most useful for elements behind symmetric NATs 45 or firewalls that wish to be on the receiving end of a connection to 46 a single peer. TURN does not allow for users to run servers on well 47 known ports if they are behind a nat; it supports the connection of a 48 user behind a nat to only a single peer. In that regard, its role is 49 to provide the same security functions provided by symmetric NATs and 50 firewalls, but to ``turn'' the tables so that the element on the 51 inside can be on the receiving end, rather than the sending end, of a 52 connection that is requested by the client. 54 Table of Contents 56 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 57 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . 5 58 3. Definitions . . . . . . . . . . . . . . . . . . . . . . . . 6 59 4. Applicability Statement . . . . . . . . . . . . . . . . . . 7 60 5. Overview of Operation . . . . . . . . . . . . . . . . . . . 8 61 6. Message Overview . . . . . . . . . . . . . . . . . . . . . . 10 62 7. Server Behavior . . . . . . . . . . . . . . . . . . . . . . 11 63 7.1 Shared Secret Request . . . . . . . . . . . . . . . . . . . 11 64 7.2 Allocate Request . . . . . . . . . . . . . . . . . . . . . . 13 65 7.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . 13 66 7.2.2 Initial Requests . . . . . . . . . . . . . . . . . . . . . . 13 67 7.2.3 Requests for Pre-Allocated Ports . . . . . . . . . . . . . . 17 68 7.2.4 Subsequent Requests . . . . . . . . . . . . . . . . . . . . 18 69 7.3 Receiving Packets and Connections . . . . . . . . . . . . . 19 70 7.4 Lifetime Expiration . . . . . . . . . . . . . . . . . . . . 20 71 8. Client Behavior . . . . . . . . . . . . . . . . . . . . . . 22 72 8.1 Discovery . . . . . . . . . . . . . . . . . . . . . . . . . 22 73 8.2 Obtaining a One Time Password . . . . . . . . . . . . . . . 22 74 8.3 Allocating a Binding . . . . . . . . . . . . . . . . . . . . 23 75 8.4 Processing Allocate Responses . . . . . . . . . . . . . . . 24 76 8.5 Allocating a Pre-Allocated Binding . . . . . . . . . . . . . 25 77 8.6 Refreshing a Binding . . . . . . . . . . . . . . . . . . . . 26 78 8.7 Tearing Down a Binding . . . . . . . . . . . . . . . . . . . 26 79 8.8 Receiving and Sending Data . . . . . . . . . . . . . . . . . 26 80 9. Protocol Details . . . . . . . . . . . . . . . . . . . . . . 27 81 9.1 Message Types . . . . . . . . . . . . . . . . . . . . . . . 27 82 9.2 Message Attributes . . . . . . . . . . . . . . . . . . . . . 27 83 9.2.1 TRANSPORT-PREFERENCES . . . . . . . . . . . . . . . . . . . 27 84 9.2.2 LIFETIME . . . . . . . . . . . . . . . . . . . . . . . . . . 28 85 9.2.3 ALTERNATE-SERVER . . . . . . . . . . . . . . . . . . . . . . 28 86 9.2.4 MAGIC-COOKIE . . . . . . . . . . . . . . . . . . . . . . . . 28 87 9.2.5 BANDWIDTH . . . . . . . . . . . . . . . . . . . . . . . . . 28 88 9.3 Response Codes . . . . . . . . . . . . . . . . . . . . . . . 29 89 10. Security Considerations . . . . . . . . . . . . . . . . . . 30 90 11. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 32 91 11.1 Problem Definition . . . . . . . . . . . . . . . . . . . . . 32 92 11.2 Exit Strategy . . . . . . . . . . . . . . . . . . . . . . . 32 93 11.3 Brittleness Introduced by TURN . . . . . . . . . . . . . . . 33 94 11.4 Requirements for a Long Term Solution . . . . . . . . . . . 34 95 11.5 Issues with Existing NAPT Boxes . . . . . . . . . . . . . . 34 96 12. Requirements Analysis . . . . . . . . . . . . . . . . . . . 35 97 13. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 36 98 Normative References . . . . . . . . . . . . . . . . . . . . 37 99 Informative References . . . . . . . . . . . . . . . . . . . 38 100 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . 38 101 Intellectual Property and Copyright Statements . . . . . . . 40 103 1. Introduction 105 Network Address Translators (NATs), while providing many benefits, 106 also come with many drawbacks. The most troublesome of those 107 drawbacks is the fact that they break many existing IP applications, 108 and make it difficult to deploy new ones. Guidelines [9] have been 109 developed that describe how to build "NAT friendly" protocols, but 110 many protocols simply cannot be constructed according to those 111 guidelines. Examples of such protocols include multimedia 112 applications and file sharing. 114 Simple Traversal of UDP Through NAT (STUN) [1] provides one means for 115 an application to traverse a NAT. STUN allows a client to obtain a 116 transport address (and IP address and port) which may be useful for 117 receiving packets from a peer. However, addresses obtained by STUN 118 may not be usable by all peers. Those addresses work depending on the 119 topological conditions of the network. Therefore, STUN by itself 120 cannot provide a complete solution for NAT traversal. 122 A complete solution requires a means by which a client can obtain a 123 transport address from which it can receive media from any peer which 124 can send packets to the public Internet. This can only be 125 accomplished by relaying data though a server that resides on the 126 public Internet. This specification describes Traversal Using Relay 127 NAT (TURN), a protocol that allows a client to obtain IP addresses 128 and ports from such a relay. 130 Although TURN will almost always provide connectivity to a client, it 131 comes at high cost to the provider of the TURN server. It is 132 therefore desirable to use TURN as a last resort only, preferring 133 other mechanisms (such as STUN or direct connectivity) when possible. 134 To accomplish that, the Interactive Connectivity Establishment (ICE) 135 [13] methodology can be used to discover the optimal means of 136 connectivity. 138 2. Terminology 140 In this document, the key words MUST, MUST NOT, REQUIRED, SHALL, 141 SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL are to 142 be interpreted as described in RFC 2119 [2] and indicate requirement 143 levels for compliant TURN implementations. 145 3. Definitions 147 TURN Client: A TURN client (also just referred to as a client) is 148 an entity that generates TURN requests. A TURN client can be an 149 end system, such as a Session Initiation Protocol (SIP) [6] User 150 Agent, or can be a network element, such as a Back-to-Back User 151 Agent (B2BUA) SIP server. The TURN protocol will provide the STUN 152 client with IP addresses that route to it from the public 153 Internet. 155 TURN Server: A TURN Server (also just referred to as a server) is 156 an entity that receives TURN requests, and sends TURN responses. 157 The server is capable of acting as a data relay, receiving data on 158 the address it provides to clients, and forwarding them to the 159 clients. 161 Transport Address: An IP address and port. 163 4. Applicability Statement 165 TURN is useful for applications that require a client to place a 166 transport address into a protocol message, with the expectation that 167 the client will be able to receive packets from a single host that 168 will send to this address. Examples of such protocols include SIP, 169 which makes use of the Session Description Protocol (SDP) [7]. SDP 170 carries and IP address on which the client will receive media packets 171 from its peer. Another example of a protocol meeting this criteria is 172 the Real Time Streaming Protocol (RTSP) [8]. 174 When a client is behind a NAT, transport addresses obtained from the 175 local operating system will not be publically routable, and 176 therefore, not useful in these protocols. TURN allows a client to 177 obtain a transport address, from a server on the public Internet, 178 which can be used in protocols meeting the above criteria. However, 179 the transport addresses obtained from TURN servers are not generally 180 useful for receiving data from anywhere. They are only useful for 181 communicating with a single peer. Once a host sends packets to that 182 transport address, it is ``locked down'', meaning that packets from 183 other hosts will not be forwarded to the client. This is done 184 purposefully, so as to prevent TURN from being used to run servers 185 (such as a web server) on a client behind a NAT. In this way, 186 enterprises which deploy NATs and firewalls to prevent users from 187 running servers, can be confident that TURN will not cause any 188 violations in their enterprise security policies. 190 5. Overview of Operation 192 The typical TURN configuration is shown in Figure 1. A TURN client is 193 connected to private network 1. This network connects to private 194 network 2 through NAT 1. Private network 2 connects to the public 195 Internet through NAT 2. On the public Internet is a TURN server. 197 /-----\ 198 // TURN \\ 199 | Server | 200 \\ // 201 \-----/ 203 +--------------+ Public Internet 204 ................| NAT 2 |....................... 205 +--------------+ 207 +--------------+ Private NET 2 208 ................| NAT 1 |....................... 209 +--------------+ 211 /-----\ 212 // TURN \\ 213 | Client | 214 \\ // Private NET 1 215 \-----/ 217 Figure 1 219 TURN is a simple client-server protocol. It is identical in syntax 220 and general operation to STUN, in order to facilitate a joint 221 implementation of both. TURN defines a request message, called 222 Allocate, which asks for a public IP address and port. TURN can run 223 over UDP and TCP, as it allows for a client to request address/port 224 pairs for receiving both UDP and TCP. 226 A TURN client first discovers the address of a TURN server. This can 227 be preconfigured, or it can be discovered using SRV records [3] This 228 will allow for different TURN servers for UDP and TCP. Once a TURN 229 server is discovered, the client sends a TURN Allocate request to the 230 TURN server. TURN provides a mechanism for mutual authentication and 231 integrity checks for both requests and responses, based on a shared 232 secret. Assuming the request is authenticated and has not been 233 tampered with, the TURN server remembers the source transport address 234 that the request came from (call this SA), and returns a public 235 transport address, PA, in the TURN response. The TURN server is 236 responsible for guaranteeing that packets sent to PA route to the 237 TURN server. The TURN server then waits for data on PA. When data is 238 received (either a UDP packet or a TCP connection request), the TURN 239 server accepts the connection (in the case of TCP), and then stores 240 the remote address and port where the data came from (RA). The data 241 just received, if any, are then forwarded to SA. The TURN server then 242 acts as a relay. Any data received from SA are forwarded to RA. Any 243 data sent from RA to PA are sent to SA. 245 For TCP, the TURN server does not need to examine the data received; 246 it merely forwards all data between the socket pairs it has 247 associated together. In the case of UDP, the TURN server looks for a 248 magic cookie in the first 128 bytes of each UDP packet. If present, 249 it indicates that the packet is a TURN control packet, used for 250 keepalives and teardown of the binding. In the case of TCP, if either 251 side closes a connection, the TURN server closes the other 252 connection. For both UDP and TCP, the TURN server can also time out a 253 connection in the event data is not received after some configured 254 time out period. This period is sent to the client in the TURN 255 response to the Allocate request. 257 TURN also allows a client to request an odd or even port when one is 258 allocated, and for it to pre-allocate the next higher port. This is 259 useful for securing consecutive ports for usage with the Real Time 260 Transport Protocol (RTP) [5]. 262 6. Message Overview 264 TURN messages are identical to STUN messages in their syntax. TURN 265 defines three new messages - the Allocate Request, the Allocate 266 Response, and the Allocate Error Response. TURN also uses the Shared 267 Secret Request, Shared Secret Response, and Shared Secret Error 268 Response defined by STUN. TURN makes use of some of the STUN 269 attributes (MAPPED-ADDRESS, USERNAME, MESSAGE-INTEGRITY, ERROR-CODE, 270 and UNKNOWN-ATTRIBUTES) and also defines several of its own. 271 Specifically, TURN adds TRANSPORT-PREFERENCES attribute, which allows 272 a client to request an odd or even port, and to pre-allocate the next 273 higher port. It defines the LIFETIME attribute, which allows the TURN 274 server to tell the client when the binding will be released. It 275 defines the MAGIC-COOKIE attribute, which allows the TURN client to 276 find TURN messages in a stream of UDP packets. It defines the 277 BANDWIDTH attribute, which allows a client to inform the server of 278 the expected bandwidth usage on the connection. Finally, it defines 279 the ALTERNATE-SERVER attribute, which allows the server to redirect 280 the TURN client to connect to an alternate server. 282 7. Server Behavior 284 The server behavior depends on whether the request is a Shared Secret 285 Request or an Allocate Request. 287 7.1 Shared Secret Request 289 Unlike a STUN server, a TURN server provides resources to clients 290 that connect to it. Therefore, only authorized clients can gain 291 access to a TURN server. This requires that TURN requests be 292 authenticated. TURN assumes the existence of a long-lived shared 293 secret between the client and the TURN server in order to achieve 294 this authentication. The client uses this long-lived shared secret to 295 authenticate itself in a Shared Secret Request, sent over TLS. The 296 Shared Secret Response provides the client with a one-time username 297 and password. This one-time credential is then used by the server to 298 authenticate an Allocate Request. The usage of a separate long lived 299 and one-time credentials prevents dictionary attacks, whereby an 300 observer of a message and its HMAC could guess the password by an 301 offline dictionary search. 303 When a TURN server receives a Shared Secret Request, it first 304 executes the processing described in the first three paragraphs of 305 Section 8.2 of STUN. This processing will ensure that the Shared 306 Secret Request is received over TLS. 308 Assuming it was, the server checks the Shared Secret Request for a 309 MESSAGE-INTEGRITY attribute. If not present, the server generates a 310 Shared Secret Error Response with an ERROR-CODE attribute with 311 response code 401. That response MUST include a NONCE attribute, 312 containing a nonce that the server wishes the client to reflect back 313 in a subsequent Shared Secret Request (and therefore include the 314 message integrity computation). The response MUST include a REALM 315 attribute, containing a realm from which the username and password 316 are scoped [4]. 318 If the MESSAGE-INTEGRITY attribute was present, the server checks for 319 the existence of the REALM attribute. If the attribute is not 320 present, the server MUST generate a Shared Secret Error Response. 321 That response MUST include an ERROR-CODE attribute with response code 322 434. That response MUST include a NONCE and a REALM attribute. 324 If the REALM attribute was present, the server checks for the 325 existence of the NONCE attribute. If the NONCE attribute is not 326 present, the server MUST generate a Shared Secret Error Response. 327 That response MUST include an ERROR-CODE attribute with response code 328 435. That response MUST include a NONCE attribute and a REALM 329 attribute. 331 If the NONCE attribute was present, the server checks for the 332 existence of the USERNAME attribute. If it was not present, the 333 server MUST generate a Shared Secret Error Response. The Shared 334 Secret Error Response MUST include an ERROR-CODE attribute with 335 response code 432. It MUST include a NONCE attribute and a REALM 336 attribute. 338 If the USERNAME is present, the server computes the HMAC over the 339 request as described in Section 11.2.8 of STUN. The key is computed 340 as MD5(unq(USERNAME-value) ":" unq(REALM-value) ":" passwd), where 341 the password is the password associated with the username and realm 342 provided in the request. If the server does not have a record for 343 that username within that realm, the server generates a Shared Secret 344 Error Response. That response MUST include an ERROR-CODE attribute 345 with response code 436. That response MUST include a NONCE attribute 346 and a REALM attribute. 348 This format for the key was chosen so as to enable a common 349 authentication database for SIP and for TURN, as it is expected 350 that credentials are usually stored in their hashed forms. [[OPEN 351 ISSUE: Is support of MD5-sess needed?]] 353 If the computed HMAC differs from the one from the MESSAGE-INTEGRITY 354 attribute in the request, the server MUST generate a Shared Secret 355 Error Response with an ERROR-CODE attribute with response code 431. 356 This response MUST include a NONCE attribute and a REALM attribute. 358 If the computed HMAC doesn't differ from the one in the request, but 359 the nonce is stale, the server MUST generate a Shared Secret Error 360 Response. That response MUST include an ERROR-CODE attribute with 361 response code 430. That response MUST include a NONCE attribute and a 362 REALM attribute. 364 In all cases, the Shared Secret Error Response is sent over the TLS 365 connection on which the Shared Secret Request was received. 367 The server proceeds to authorize the client. The means for 368 authorization are outside the scope of this specification. It is 369 anticipated that TURN servers will be run by providers that also 370 provide an application service, such as SIP or RTSP. In that case, a 371 user would be authorized to use TURN if they are authorized to use 372 the application service. 374 The server then generates a Shared Secret Response as in Section 8.2 375 of STUN. This response will contain a USERNAME and PASSWORD, which 376 are used by the client as a short-term shared secret in subsequent 377 Allocate requests. Note that STUN specifies that the server has to 378 invalidate this username and password after 30 minutes. This is not 379 the case in TURN. In TURN, the server MUST store the allocated 380 username and password for a duration of at least 30 minutes. Once an 381 Allocate request has been authenticated using that username and 382 password, if the result was an Allocate Error Response, the username 383 and password are discarded. If the result was an Allocate Response, 384 resulting in the creation of a new binding, the username and password 385 become associated with that binding. They can only be used to 386 authenticate Allocate requests sent from the same source transport 387 address in order to refresh or de-allocate that binding. Once the 388 binding is deleted, the username and password are discarded. 390 This policy avoids replay attacks, whereby a recorded Allocate 391 request is replayed in order to obtain a binding without proper 392 authentication. It also ensures that existing bindings can be 393 refreshed without needed to continuously obtain one-time passwords 394 from the TURN server. 396 7.2 Allocate Request 398 7.2.1 Overview 400 Allocate requests are used to obtain an IP address and port that the 401 client can use to receive UDP and TCP packets from any host on the 402 network, even when the client is behind a symmetric NAT. To do this, 403 a TURN server allocates a local transport address, and passes it to 404 the client in an Allocate Response. When the server receives packets 405 on this allocated address, it acts as a relay, and forwards them 406 towards the source of the Allocate request. The server remembers the 407 source transport address where that packet came from, and "locks 408 down". This means that packets sent from the client to the TURN 409 server are forwarded to that address. 411 As a result, the server maintains a set of bindings. These bindings 412 are associations between the five-tuple of received Allocate requests 413 (source IP address and port, destination IP address and port, and 414 protocol), called the allocate five-tuple, and another five tuple, 415 called the remote five-tuple. 417 The behavior of the server when receiving an Allocate Request depends 418 on whether the request is an initial one, or a subsequent one. An 419 initial request is one received with a source transport address which 420 is not associated with any existing bindings. A subsequent request is 421 one received that is associated with an existing binding. 423 7.2.2 Initial Requests 425 A TURN server MUST be prepared to receive Binding Requests over TCP 426 and UDP. The port on which to listen is based on the DNS SRV entries 427 provided by the server. Typically, this will be XXXX, the default 428 TURN port. [[OPEN ISSUE: Can we just use the STUN port?]]. 430 The server MUST check the Allocate Request for a MESSAGE-INTEGRITY 431 attribute. If not present, the server generates a Allocate Error 432 Response with an ERROR-CODE attribute with response code 401. 434 If the MESSAGE-INTEGRITY attribute was present, the server checks for 435 the existence of the USERNAME attribute. If it was not present, the 436 server MUST generate a Allocate Error Response. The Allocate Error 437 Response MUST include an ERROR-CODE attribute with response code 432. 439 If the USERNAME is present, the server computes the HMAC over the 440 request as described in Section 11.2.8 of STUN. The key is equal to 441 the password associated with the username in the request, where that 442 username is a short term username allocated by the TURN server. The 443 username MUST be one which has been allocated by the server in a 444 Shared Secret Response, but has not yet been used to authenticate an 445 Allocate request. If that username is not known by the server, or has 446 already been used, the server generates an Allocate Error Response. 447 That response MUST include an ERROR-CODE attribute with response code 448 430. 450 If the computed HMAC differs from the one from the MESSAGE-INTEGRITY 451 attribute in the request, the server MUST generate a Allocate Error 452 Response with an ERROR-CODE attribute with response code 431. 454 Assuming the message integrity check passed, processing continues. 455 The server MUST check for any attributes in the request with values 456 less than or equal to 0x7fff which it does not understand. If it 457 encounters any, the server MUST generate an Allocate Error Response, 458 and it MUST include an ERROR-CODE attribute with a 420 response code. 460 That response MUST contain an UNKNOWN-ATTRIBUTES attribute listing 461 the attributes with values less than or equal to 0x7fff which were 462 not understood. 464 If the Allocate request arrived over TCP, the Allocate Error Response 465 is sent on the connection from which the request arrived. If the 466 Allocate request arrived over UDP, the Allocate Error Response is 467 sent to the transport address from which the request was received 468 (i.e., the source IP address and port), and sent from the transport 469 address on which the request was received (i.e., the destination IP 470 address and port). 472 Assuming the Allocate request was authenticated and was well-formed, 473 the server attempts to allocate transport addresses. It first looks 474 for the BANDWIDTH attribute for the request. If present, the server 475 determines whether or not it has sufficient capacity to handle a 476 binding that will generate the requested bandwidth. If so, the server 477 looks for the presence of the TRANSPORT-PREFERENCES attribute in the 478 request. If the attribute indicates that an even port is requested, 479 the server attempts to allocate a transport address with an even 480 port. If the attribute indicates that an odd port is requested, the 481 server attempts to allocate a transport address with an odd port. If 482 the attribute indicates that there is no preference for port parity, 483 or if the TRANSPORT-PREFERENCES attribute was absent, the server 484 attempts to allocate a port with either parity. The server MUST NOT 485 allocate ports from the well-known port range (0-1023) and MUST NOT 486 allocate ports from the user registered port range (1024 through 487 49151). 489 This aspect of the protocol helps guarantee that users cannot run 490 servers (such as a web server, SIP server, or SMTP server) using 491 TURN. 493 The TRANSPORT-PREFERENCES attribute can also indicate a preference 494 for a specific port, pre-allocated previously by a prior Allocate 495 request. This case is described in Section 7.2.3. 497 If a port meeting the constraints (including bandwidth) cannot be 498 allocated, the server MUST generate a Allocate Error Response that 499 includes an ERROR-CODE attribute with a response code of 300. That 500 response MAY include an ALTERNATE-SERVER attribute pointing to an 501 alternate server which can be used by the client. 503 Assuming a port was allocated according to the preferences (call this 504 the base port), the server checks to see if the TRANSPORT-PREFERENCES 505 attribute is present, and indicates a desire to pre-allocate the next 506 higher port (called the pre-allocated port). If so, the server 507 attempts to allocate that port from its local operating system. If it 508 cannot be allocated, the server can do one of two things. First, it 509 MAY try to allocate a different base port, in the hopes that the next 510 higher port is available. If the server believes that there are no 511 adjacent ports meeting the parity constraints present in the request, 512 the server MAY generate an Allocate Error Response that includes an 513 ERROR-CODE attribute with a response code of 300. That response MAY 514 include an ALTERNATE-SERVER attribute pointing to an alternate server 515 which can be used by the client. 517 Once a base port is allocated, the server creates a binding for it. 518 This binding is a mapping between two five-tuples - the allocate 519 five-tuple and the remote five-tuple. The allocate five-tuple is set 520 to the five-tuple of the Allocate Request (that is, the protocol of 521 the allocate five-tuple is set to the protocol of the Allocate 522 Request (TCP or UDP), the source IP address and port of the allocate 523 five-tuple are set to the source IP address and port in the Allocate 524 Request, and the destination IP address and port of the allocate 525 five-tuple are set to the destination IP address and port in the 526 Allocate Request). The protocol in the remote five-tuple is set to 527 the protocol from the Allocate Request. The source IP address of the 528 remote five-tuple is set to the interface from which the base port 529 was allocated. The source port of the remote five-tuple is set to the 530 base port. If the binding was allocated for TCP, the connection on 531 which the Allocate request was received is associated with the 532 allocate five-tuple in the binding. 534 The server MUST remember the one-time username and password used to 535 obtain the binding. 537 If a port was pre-allocated, a binding is also created for it. The 538 allocate five-tuple is left empty. The protocol in the remote 539 five-tuple is set to the protocol from the Allocate Request. The 540 source IP address of the remote five-tuple is set to the interface 541 from which the pre-allocated port was allocated. The source port of 542 the remote five-tuple is set to the pre-allocated port. The identity 543 of the user (defined as the username provided in the Shared Secret 544 Request used to obtain the one-time password used in the Allocate 545 Request) is associated with this pre-allocated tuple. Only that user 546 can perform an allocation for this tuple. Furthermore, a timer is 547 set. If no allocation is made against this pre-allocation within 5 548 minutes, the port is released and the binding is deleted. 550 If the LIFETIME attribute was present in the request, and the value 551 is larger than the maximum duration the server is willing to use for 552 the lifetime of the binding, the server MAY lower it to that maximum. 553 However, the server MUST NOT increase the duration requested in the 554 LIFETIME attribute. If there was no LIFETIME attribute, the server 555 may choose a default duration at its discretion. In either cae, the 556 resulting duration is added to the current time, and a timer is set 557 to fire at or after that time. Section 7.4 discusses behavior when 558 the timer fires. 560 Once the base port has been obtained from the operating system, the 561 pre-allocated port obtained, and the activity timer started for the 562 base port binding, the server generates an Allocate Response. The 563 Allocate Response MUST contain the same transaction ID contained in 564 the Allocate Request. The length in the message header MUST contain 565 the total length of the message in bytes, excluding the header. The 566 Allocate Response MUST have a message type of "Allocate Response". 568 The server MUST add a MAPPED-ADDRESS attribute to the Allocate 569 Response. The IP address component of this attribute MUST be set to 570 the interface from which the base port was allocated. The port 571 component of this attribute MUST be set to the base port. 573 The server MUST add a LIFETIME attribute to the Allocate Response. 574 This attribute contains the duration, in seconds, of the activity 575 timer associated with this binding. 577 The server MUST add a BANDWIDTH attribute to the Allocate Response. 578 This MUST be equal to the attribute from the request, if one was 579 present. Otherwise, it indicates a per-binding cap that the server is 580 placing on the bandwidth usage on each binding. Such caps are needed 581 to prevent against denial-of-service attacks (See Section 10. 583 The server MUST add, as the final attribute of the request, a 584 MESSAGE-INTEGRITY attribute. The key used in the HMAC MUST be the 585 same as that used to validate the request. 587 The TURN server then sends the response. If the Allocate request was 588 received over TCP, the response is sent over that TCP connection. 589 Once the response is sent, the TURN server begins acting as a relay 590 for that connection (see Section 7.3). If the Allocate request was 591 received over UDP, the response is sent to the transport address from 592 which the request was received (i.e., the source IP address and 593 port), and sent from the transport address on which the request was 594 received (i.e., the destination IP address and port). 596 Additionally, if the base port was for UDP, the server MUST be 597 prepared to receive UDP packets once the TURN response is sent. If 598 the base port was for TCP, the server MUST be prepared to receive a 599 TCP connection request on that port. Behavior when either occurs is 600 described in Section 7.3. 602 7.2.3 Requests for Pre-Allocated Ports 604 The TRANSPORT-PREFERENCES attribute of the Allocate Request can 605 indicate a desire to allocate a port that was previously 606 pre-allocated by a prior Allocate request. If such an indication is 607 present, the server checks that this port has been pre-allocated by a 608 previous Allocate Request. The only user authorized to allocate a 609 pre-allocated address is the same one that generated the 610 pre-allocation. Note that the one-time usernames for both requests 611 (the pre-allocation and the final allocation) will be different. 612 However, both MUST have been obtained through Shared Secret Requests 613 authenticated as being sent from the same user. 615 If the Allocate request arrives on a different protocol than was used 616 to make the pre-allocation, the server MUST send an Allocate Error 617 Response. That response MUST contain an ERROR-CODE attribute with a 618 response code of 400. 620 Assuming the requested port has been pre-allocated by the same user, 621 the server completes the allocation by setting the allocate 622 five-tuple for the binding to be equal to that of the Allocate 623 request. The server sets the activity timer for this binding, and 624 generates an Allocate Response. This response MUST contain a 625 MAPPED-ADDRESS attribute which contains the interface from which the 626 pre-allocated port was obtained, along with the pre-allocated port. 627 The response MUST contain a LIFETIME attribute and a 628 MESSAGE-INTEGRITY attribute as well. 630 7.2.4 Subsequent Requests 632 Once a binding has been created, packets received from the client are 633 generally forwarded to the remote client. However, if the binding is 634 UDP, the client can send subsequent Allocate requests to the TURN 635 server. To determine which packets are for the TURN server, and which 636 need to be relayed, the server looks at the packet. If the packet is 637 shorter than 28 bytes, it is not a TURN request. If it is longer than 638 28 bytes, the server checks bytes 25-28. If these bytes are equal to 639 the MAGIC-COOKIE, the request is a TURN request. Otherwise, it is a 640 data packet, and is to be relayed. 642 The server first authenticates the request. This is done as in 643 Section 7.2.2. The request MUST be authenticated using the same 644 one-time username and password used to allocate that binding 645 previously. That is, the five-tuple from the Allocate request is 646 compared to the allocate five-tuples in existing bindings. The 647 matching binding is selected. The one-time username and password 648 associated with that binding MUST match the ones used in the request. 650 Any TRANSPORT-PREFERENCE attribute in the request is ignored. An 651 Allocate Request sent to an existing binding is always a refresh or 652 deallocation. The server looks for the LIFETIME attribute in the 653 Allocate Request. If not found, it determines the default refresh 654 duration, in seconds, for this binding. If the LIFETIME attribute was 655 present in the request, and the value is larger than the maximum 656 duration the server is willing to extend the lifetime of the binding, 657 the server MAY lower it to that maximum. However, the server MUST NOT 658 increase the duration requested in the LIFETIME attribute. The 659 resulting duration is added to the current time, and the activity 660 timer for this binding is reset to fire at or after that time. 661 Section 7.4 discusses behavior when the timer fires. 663 Once the timer is set, the server MUST generate an Allocate Response. 664 The Allocate Response MUST contain the same transaction ID contained 665 in the Allocate Request. The length in the message header MUST 666 contain the total length of the message in bytes, excluding the 667 header. The Allocate Response MUST have a message type of "Allocate 668 Response". The response MUST contain a MAGIC-COOKIE as the first 669 attribute. It MUST contain a MAPPED-ADDRESS which contains the source 670 IP address and port from the remote five-tuple of the binding. It 671 MUST contain a LIFETIME attribute which contains the time from now 672 until the point at which the binding will be deleted. The final 673 attribute MUST be a MESSAGE-INTEGRITY attribute, which MUST use the 674 same one-time username and password used to authenticate the request. 676 The TURN server then sends the response. If the Allocate request was 677 received over TCP, the response is sent over that TCP connection. If 678 the Allocate request was received over UDP, the response is sent to 679 the transport address from which the request was received (i.e., the 680 source IP address and port), and sent from the transport address on 681 which the request was received (i.e., the destination IP address and 682 port). 684 7.3 Receiving Packets and Connections 686 If a TURN server receives a TCP connection request on a port it has 687 allocated, the server retrieves the binding whose remote five-tuple 688 has a source address and source port that match the IP address and 689 port to which the connection was made, and whose transport is TCP. If 690 the destination IP address and port of the remote five-tuple in the 691 binding are already filled in (which means that a connection was 692 already made to this tuple), the connection request is rejected. 693 Otherwise, it is accepted. If the connection is accepted, the server 694 MUST set the destination IP address and port of the remote five-tuple 695 to the source IP address and port in the SYN packet. It also 696 associates this connection with the remote five-tuple. 698 If a TURN server receives a UDP packet on a port it has allocated, 699 the server retrieves the binding whose remote five-tuple has a source 700 address and source port that match the IP address and port to which 701 the connection was made, and whose transport is UDP. If the 702 destination IP address and port of the remote five-tuple in the 703 binding are already filled in, and do not match the source IP address 704 and port of the UDP packet, the server drops the packet and MAY 705 generate a port unreachable ICMP error. If the packet was not 706 discareded, it is forwarded. To forward, the packet is sent with a 707 source IP address and port equal to the destination IP address and 708 port in the allocate five-tuple, and with a destination address and 709 port equal to the source IP address and port in the allocate 710 five-tuple. If the destination address and port of the remote 711 five-tuple were not filled in, they are populated at this time. The 712 server MUST set the destination IP address and port of the remote 713 five-tuple to the source IP address and port in the UDP packet. 715 The process of filling in the destination IP address and port of the 716 remote five-tuple is called "locking down". Once done, the client can 717 only send and receive packets with the specific peer from which the 718 first packet or connection was received. 720 If a TURN server receives a UDP packet on a port it has allocated, 721 the server retrieves the binding whose remote five-tuple has a source 722 address and source port that match the IP address and port to which 723 the connection was made, and whose transport is UDP. If the 724 destination IP address and port of the remote five-tuple in the 725 binding are already filled in, and they match the source IP address 726 and port of the UDP packet, the server MUST forward the UDP packet as 727 above. 729 If a TURN server receives data on a TCP connection that was opened to 730 a port it had allocated, the server MUST forward this data onto the 731 connection associated with allocate-tuple in the binding. 733 If a TURN server receives data on a TCP connection that is associated 734 with an allocate five-tuple, the binding for that tuple is retrieved. 735 If the destination IP address and port of that tuple have not been 736 filled in yet, the data is discarded. If the destination address and 737 port have been filled in, the connection associated with the remote 738 five-tuple is obtained, and the data is forwarded on that connection. 740 Note that, because data is forwarded blindly across TCP bindings, TLS 741 will successfully operate over a TURN allocated TCP port. 743 Similarly, if a TURN server receives a UDP packet on one of its 744 public TURN ports, it checks to see if the source IP address and port 745 match those of the allocate five-tuples in an existing binding. If 746 there is a match, the the UDP packet is not a TURN request (see 747 Section 7.2.4 for details on how this determination is made), the 748 destination IP address and port in the remote five-tuple of the 749 binding are checked. If they are not filled in yet, the UDP packet is 750 discarded. If they are, the packet is forwarded. It is forwarded 751 using the source IP address and port from the remote five-tuple, and 752 a destination IP address and port from the remote five-tuple. 754 If a TCP connection associated with an allocate five-tuple is closed, 755 the connection associated with the corresponding remote five-tuple is 756 also closed. At that point, the binding is destroyed. Similarly, if 757 the TCP connection associated with a remote five-tuple is closed, the 758 connection associated with the corresponding allocate five-tuple is 759 closed, and the binding is destroyed. 761 7.4 Lifetime Expiration 763 When the activity timer for a binding fires, the server checks to see 764 if there has been any activity on the binding since its creation, or 765 since the last firing of the timer, whichever is more recent. 766 Activity is defined as connection establishment, or packet 767 transmission in either direction. If there has been activity, the 768 timer is set to fire once again in M seconds, where M is the value of 769 the LIFETIME attribute returned in the most recent Allocate Response 770 for this binding. 772 If there has been no activity, the server MUST destroy the binding, 773 along with its associated one-time password. If the binding was over 774 TCP, the server MUST close any connections it is holding to the 775 client and to the remote client. 777 8. Client Behavior 779 Client behavior is broken into several separate steps. First, the 780 client obtains a one-time username and password. Secondly, it 781 generates initial Allocate Requests, and processes the responses. It 782 manages those addresses (refreshing and tearing them down), and 783 processes data received on those addresses. 785 8.1 Discovery 787 Generally, the client will be configured with a domain name of the 788 provider of the TURN servers. This domain name is resolved to an IP 789 address and port of using the SRV procedures [3]. When sending a 790 Shared Secret request, the service name is "turn" and the protocol is 791 "tcp". RFC 2782 spells out the details of how a set of SRV records 792 are sorted and then tried. However, it only states that the client 793 should "try to connect to the (protocol, address, service)" without 794 giving any details on what happens in the event of failure. Those 795 details are described here for TURN. 797 For TURN requests, failure occurs if there is a transport failure of 798 some sort (generally, due to fatal ICMP errors in UDP or connection 799 failures in TCP). Failure also occurs if the the request does not 800 solicit a response after 9.5 seconds. If a failure occurs, the client 801 SHOULD create a new request, which is identical to the previous, but 802 has a different transaction ID and MESSAGE-INTEGRITY attribute. That 803 request is sent to the next element in the list as specified by 804 RFC~2782. 806 8.2 Obtaining a One Time Password 808 In order to allocate addresses, a client must obtain a one-time 809 username and password from the TURN server. A unique username and 810 password are required for each distinct address allocated from the 811 server. 813 To obtain a one-time username and password, the client generates and 814 sends a Shared Secret Request. This is done as described in Section 815 9.2 of STUN. This request will have no attributes, and therefore, 816 based on the processing in Section 7.1, the server will reject it 817 with a Shared Secret Error Response with a 401 response code. That 818 response will contain a NONCE and a REALM. The client SHOULD generate 819 a new Shared Secret Request (with a new transaction ID), which 820 contains the NONCE and REALM attributes copied from the 401 response. 821 The request MUST include the USERNAME attribute, which contains a 822 username supplied by the user for the specified realm. The request 823 MUST include a MESSAGE-INTEGRITY attribute as the last attribute. The 824 key for the HMAC is computed as described in Section 7.1. 826 If the response (either to the initial request or to the second 827 attempt with the credentials) is a Shared Secret Error Response, the 828 processing depends on the the value of the response code in the 829 ERROR-CODE attribute. If the response code was a 430, the client 830 SHOULD generate a new Shared Secret Request, using the username and 831 password provided by the user, and the REALM and NONCE provided in 832 the 430 response. For a 431 or 436 response code, the client SHOULD 833 alert the user. For a 432, 434 and 435 response codes, if the client 834 had omitted the USERNAME, REALM or NONCE attributes, respectively, 835 from the previous request, it SHOULD retry, this time including the 836 USERNAME, NONCE, REALM, and MESSAGE-INTEGRITY attributes. For a 500 837 response code, the client MAY wait several seconds and then retry the 838 request. For a 600 response code, the client MUST NOT retry the 839 request, and SHOULD display the reason phrase to the user. Unknown 840 attributes between 400 and 499 are treated like a 400, unknown 841 attributes between 500 and 599 are treated like a 500, and unknown 842 attributes between 600 and 699 are treated like a 600. Any response 843 between 100 and 399 MUST result in the cessation of request 844 retransmissions, but otherwise is discarded. 846 If a client receives a Shared Secret Response with an attribute whose 847 type is greater than 0x7fff, the attribute MUST be ignored. If the 848 client receives a Shared Secret Response with an attribute whose type 849 is less than or equal to 0x7fff, the response is ignored. 851 If the response is a Shared Secret Response, it will contain the 852 USERNAME and PASSWORD attributes. The client can use these to 853 authenticate an Allocate Request, as described below. 855 A client MAY send multiple Shared Secret Requests over the same TLS 856 connection, and MAY do so without waiting for responses to previous 857 requests. The client SHOULD close its connection when it has 858 completed allocating usernames and passwords. 860 8.3 Allocating a Binding 862 When a client wishes to obtain a transport address, it sends an 863 Allocate Request to the TURN server. Requests for TCP transport 864 addresses MUST be sent over a TCP connection, and requests for UDP 865 transport addresses MUST be sent over UDP. 867 First, the client obtains a one-time username and password, using the 868 mechanisms described in Section 8.2. The client then formulates an 869 Allocate Request. The request MUST contain a transaction ID, unique 870 for each request, and uniformly and randomly distributed between 0 871 and 2**128 - 1. The message type of the request MUST be ``Allocate 872 Request''. The length is set as described in Section 11.1 of STUN. 874 The Allocate request MUST contain the MAGIC-COOKIE attribute as the 875 first attribute. If the client wishes to allocate an odd or even 876 port, it can do so by including the TRANSPORT-PREFERENCES attribute 877 in the request. That attribute can also be used by the client if it 878 wishes to pre-allocate the port one higher. 880 The client SHOULD include a BANDWIDTH attribute, which indicates the 881 maximum bandwidth that will be used with this binding. If the maximum 882 is unknown, the attribute is not included in the request. 884 The client MAY request a particular lifetime for the binding by 885 including it in the LIFETIME attribute in the request. If the no data 886 is sent or received on the binding before expiration of the lifetime, 887 the binding will be deleted by the client. 889 The client MUST include a USERNAME attribute, containing a username 890 obtained from a previous Shared Secret Response. The request MUST 891 include a MESSAGE-INTEGRITY attribute as the last attribute. The key 892 is equal to the password obtained from the PASSWORD attribute of the 893 Shared Secret Response. The Allocate Request MUST be sent to the same 894 IP address and port as the Shared Secret Request. This is because one 895 time passwords are expected to be host-specific. Rules for 896 retransmissions for Allocate Requests sent over UDP are identical to 897 those for STUN Binding Requests. Allocate Requests sent over TCP are 898 not retransmitted. Transaction timeouts are identical to those for 899 STUN Binding Requests, independent of the transport protocol. 901 8.4 Processing Allocate Responses 903 If the response is an Allocate Error Response, the client checks the 904 response code from the ERROR-CODE attribute of the response. For a 905 400 response code, the client SHOULD display the reason phrase to the 906 user. For a 420 response code, the client SHOULD retry the request, 907 this time omitting any attributes listed in the UNKNOWN-ATTRIBUTES 908 attribute of the response. For a 430 response code, the client SHOULD 909 obtain a new one-time username and password, and retry the Allocate 910 Request with a new transaction. For 401 and 432 response codes, if 911 the client had omitted the USERNAME or MESSAGE-INTEGRITY attribute as 912 indicated by the error, it SHOULD try again with those attributes. A 913 new one-time username and password is needed in that case. For a 431 914 response code, the client SHOULD alert the user, and MAY try the 915 request again after obtaining a new username and password. For a 300 916 response code, the client SHOULD attempt a new TURN transaction to 917 the server indicated in the ALTERNATE-SERVER attribute. For a 500 918 response code, the client MAY wait several seconds and then retry the 919 request with a new username and password. For a 600 response code, 920 the client MUST NOT retry the request, and SHOULD display the reason 921 phrase to the user. Unknown attributes between 400 and 499 are 922 treated like a 400, unknown attributes between 500 and 599 are 923 treated like a 500, and unknown attributes between 600 and 699 are 924 treated like a 600. Unknown attributes between 300 and 399 are 925 treated like 300. Any response between 100 and 299 MUST result in the 926 cessation of any request retransmissions, but otherwise is discarded. 928 If a client receives a response with an attribute whose type is 929 greater than 0x7fff, the attribute MUST be ignored. If the client 930 receives a response with an attribute whose type is less than or 931 equal to 0x7fff, any request retransmissions MUST cease, but the 932 entire response is otherwise ignored. 934 If the response is an Allocate Response, the client MUST check the 935 response for a MESSAGE-INTEGRITY attribute. If not present, the 936 client MUST discard the response. If present, the client computes the 937 HMAC over the response. The key MUST be same as used to compute the 938 MESSAGE-INTEGRITY attribute in the request. If the computed HMAC 939 differs from the one in the response, the client MUST discard the 940 response, and SHOULD alert the user about a possible attack. If the 941 computed HMAC matches the one from the response, processing 942 continues. 944 The MAPPED-ADDRESS in the Binding Response can be used by the client 945 for receiving packets. The server will expire the binding after 946 LIFETIME seconds have passed with no activity. The server will allow 947 the user to send and receive no more than the amount of data 948 indicated in the BANDWIDTH attribute. 950 8.5 Allocating a Pre-Allocated Binding 952 If the initial Allocate Request included TRANSPORT-PREFERENCES that 953 indicated a desire to pre-allocate the port one-higher, the client 954 MAY allocate that port at a later time. It MUST do so within 4 955 minutes of receiving the Allocate Response, or the pre-allocated port 956 will expire. 958 To allocate the port, the client generates an Allocate Request as 959 described in Section 8.3. A new username and password MUST be used 960 for this allocation. The request MUST contain a TRANSPORT-PREFERENCES 961 attribute. It MUST indicate an explicit interface and port, whose 962 value is one higher than the port number returned in the prior 963 Allocate Response. 965 Processing of the responses is identical to Section 8.4. However, the 966 client SHOULD explicitly check that received packets are TURN 967 responses, as opposed to data packets, using the techniques described 968 in Section 7.2.4. 970 8.6 Refreshing a Binding 972 If there has been no activity on a UDP binding for a period of time 973 equalling 3/4 of the lifetime of the binding (as conveyed in the 974 LIFETIME attribute of the Allocate Response), the client SHOULD 975 refresh the binding with another Allocate Request if it wishes to 976 keep it. Note that only UDP bindings can be refreshed. For TCP, 977 application-specific keepalives are needed. 979 To perform a refresh, the client generates an Allocate Request as 980 described in Section 8.3. However, the one-time username and password 981 used MUST be the same as those used in the successful Allocate 982 Request for that binding. The client will need to look for the TURN 983 response amongst the data packets using the MAGIC-COOKIE, as 984 described in Section 7.2.4. Processing of that response is as defined 985 in Section 8.4. If the response was an Allocate Response, and the 986 MAPPED-ADDRESS contains the same transport address as previously 987 obtained, the binding has been refreshed. The LIFETIME attribute 988 indicates the amount of additional time the binding will live without 989 activity. If, however, the response was an Allocate Error Response 990 with an ERROR-CODE indicating a 430 response, it means that the 991 binding has expired at the server. The client MAY use the procedures 992 in Section 8.3 to obtain a new binding (this will require a new 993 one-time username and password. Other response codes do not imply 994 that the binding has been expired, just that the refresh has failed. 996 8.7 Tearing Down a Binding 998 If a client no longer needs a binding, it SHOULD tear it down. For 999 TCP, this is done by closing the connection. For UDP, this is done by 1000 performing a refresh, as described in Section 8.6, but with a 1001 LIFETIME attribute indicating a time of 0. 1003 8.8 Receiving and Sending Data 1005 Once a binding has been allocated by an Allocate Response, the client 1006 MUST be prepared to receive data from the socket on which the 1007 Allocate Request was sent. For UDP, the client MUST be prepared to 1008 disambiguate TURN messages from data for a period of 32 seconds 1009 following the first TURN response. This disambiguation is done using 1010 the MAGIC-COOKIE, as described in Section 7.2.4. 1012 Once data has been received, the client MAY send data to its peer by 1013 sending data on that same socket. Sending data on the socket before 1014 data is received will cause the data to be discarded by the server. 1016 9. Protocol Details 1018 This section presents the detailed encoding of the message types, 1019 attributes, and response codes which are new to TURN. The general 1020 message structure of TURN is identical to STUN [1]. 1022 9.1 Message Types 1024 TURN defines three new Message Types: 1026 0x0003 : Allocate Request 1027 0x0103 : Allocate Response 1028 0x0113 : Allocate Error Response 1030 9.2 Message Attributes 1032 TURN defines the following message attributes: 1034 0x000c: TRANSPORT-PREFERENCES 1035 0x000d: LIFETIME 1036 0x000e: ALTERNATE-SERVER 1037 0x000f: MAGIC-COOKIE 1038 0x0010: BANDWIDTH 1040 9.2.1 TRANSPORT-PREFERENCES 1042 The TRANSPORT-PREFERENCES attribute indicates preferences for the 1043 ports allocated by the TURN server. It is either 32 or 96 bits long, 1044 depending on the value of the Typ bits. These bits indicate the 1045 preferences for the allocated port: 1047 0b00: no preferences 1048 0b01: odd port parity 1049 0b10: even port parity 1050 0b11: allocate a pre-allocated port 1052 When the Typ bits are 0b11, the following 64 bits encode the 1053 pre-allocated transport address. They are in the same format used for 1054 MAPPED-ADDRESS. 1056 The P bit indicates a desire for pre-allocating the port one-higher. 1057 If 1, it means pre-allocation is desired. This bit MUST NOT be set to 1058 1 if the Typ bits are 0b11. That is, pre-allocation cannot be done 1059 again when allocating a previously pre-allocated port. 1061 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1062 | 0 |P|Typ| 1063 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1064 |x x x x x x x x| Family | Port | 1065 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1066 | Address | 1067 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1069 9.2.2 LIFETIME 1071 The lifetime attribute represents the duration for which the server 1072 will maintain a binding in the absence of data traffic either from or 1073 to the client. It is a 32 bit value representing the number of 1074 seconds remaining until expiration. 1076 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1077 | Lifetime | 1078 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1080 9.2.3 ALTERNATE-SERVER 1082 The alternate server represents an alternate IP address and port for 1083 a different TURN server to try. It is encoded in the same way as 1084 MAPPED-ADDRESS. 1086 9.2.4 MAGIC-COOKIE 1088 The MAGIC-COOKIE is used by TURN clients and servers to disambiguate 1089 TURN traffic from data traffic. Its value ix 0x72c64bc6. 1091 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1092 |0|1|1|1|0|0|1|0|1|1|0|0|0|1|1|0|0|1|0|0|1|0|1|1|1|1|0|0|0|1|1|0| 1093 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1095 9.2.5 BANDWIDTH 1097 The bandwidth attribute represents the peak bandwidth, measured in 1098 kbits per second, that the client expects to use on the binding. The 1099 value represents the sum in the receive and send directions. 1100 [[Editors note: Need to define leaky bucket parameters for this.]] 1101 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1102 | Bandwidth | 1103 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1105 9.3 Response Codes 1107 TURN defines the following new response codes: 1109 300 (Try Alternate): The client should contact an alternate server 1110 for this request. 1112 434 (Missing Realm): The REALM attribute was not present in the 1113 request. 1115 435 (Missing Nonce): The NONCE attribute was not present in the 1116 request. 1118 436 (Unknown Username): The USERNAME supplied in the Shared Secret 1119 Request is not known in the given REALM. 1121 10. Security Considerations 1123 TURN servers allocate bandwidth and port resources to clients. 1124 Therefore, a TURN server requires authentication and authorization of 1125 TURN requests. This authentication is provided by a client digest 1126 over TLS, which results in the generation of a one-time password that 1127 is used in a single subsequent Allocate Request. This mechanism 1128 protects against eavesdropping attacks and man-in-the-middle attacks. 1129 The usage of one-time passwords ensures that the Allocate Requests, 1130 which do not run over TLS, are not susceptible to offline dictionary 1131 attacks that can be used to guess the long lived shared secret 1132 between the client and the server. 1134 Because TURN servers allocate resources, they can be susceptible to 1135 denial-of-service attacks. All Allocate Requests are authenticated, 1136 so that an unknown attacker cannot launch an attack. An authenticated 1137 attacker can generate multiple Allocate Requests, but each requires a 1138 new one-time username and password. It is RECOMMENDED that servers 1139 implement a cap on the number of one-time passwords that are 1140 allocated to any specific user at a time (around 5 or 10 should be 1141 sufficient). This will prevent floods of Allocate requests from a 1142 single user, in an attempt to use up the resources of the system. A 1143 single malicious user could generate a single Allocate Request, 1144 obtain a binding, and then flood the server with data over this 1145 binding, in an attempt to deny others service. However, this attack 1146 requires the attacker themselves to receive the data being sent at 1147 the server. To ameliorate these kinds of attacks, servers SHOULD 1148 implement a bandwidth cap on each binding (conveyed to the client in 1149 the BANDWIDTH attribute of the Allocate Response), and discard 1150 packets beyond the threshold. 1152 A client will use the transport address learned from the 1153 MAPPED-ADDRESS attribute of the Binding Response to tell other users 1154 how to reach them. Therefore, a client needs to be certain that this 1155 address is valid, and will actually route to them. Such validation 1156 occurs through the TLS and HMAC-based authentication and integrity 1157 checks provided in TURN. They can guarantee the authenticity and 1158 integrity of the mapped addressses. Note that TURN is not susceptible 1159 to the attacks described in Section 12.2.3, 12.2.4, 12.2.5 or 12.2.6 1160 of STUN. These attacks are based on the fact that a STUN server 1161 mirrors the source IP address, which cannot be authenticated. TURN 1162 does not use the source address of the Binding Request, and 1163 therefore, those attacks do not apply. 1165 Confidentiality of the transport addresses learned through TURN does 1166 not appear to be that important, and therefore, this capability is 1167 not provided. 1169 TURN servers are useful even for users not behind a NAT. They can 1170 provide a way for truly anonymous communications. A user can cause a 1171 call to have its media routed through a TURN server, so that the 1172 user's IP addresses are never revealed. 1174 TCP transport addresses allocated by TURN will properly work with TLS 1175 and SSL. However, any addresses allocated by TURN will not operate 1176 properly with IPSec Authentication Header (AH) [10] in transport 1177 mode. IPSec ESP [11] and any tunnel-mode ESP or AH should still 1178 operate. 1180 11. IAB Considerations 1182 The IAB has studied the problem of ``Unilateral Self Address 1183 Fixing'', which is the general process by which a client attempts to 1184 determine its address in another realm on the other side of a NAT 1185 through a collaborative protocol reflection mechanism RFC 3424 [12]. 1186 TURN is an example of a protocol that performs this type of function. 1187 The IAB has mandated that any protocols developed for this purpose 1188 document a specific set of considerations. This section meets those 1189 requirements. 1191 11.1 Problem Definition 1193 From RFC 3424 [12], any UNSAF proposal must provide: 1195 Precise definition of a specific, limited-scope problem that is to 1196 be solved with the UNSAF proposal. A short term fix should not 1197 be generalized to solve other problems; this is why "short term 1198 fixes usually aren't". 1200 The specific problem being solved by TURN is for a client, which may 1201 be located behind a NAT of any type, to obtain an IP address and port 1202 on the public Internet, useful for applications that require a client 1203 to place a transport address into a protocol message, with the 1204 expectation that the client will be able to receive packets from a 1205 single host that will send to this address. Both UDP and TCP are 1206 addressed. It is also possible to send packets so that the recipient 1207 sees a source address equal to the allocated address. TURN, by 1208 design, does not allow a client to run a server (such as a web or 1209 SMTP server) using a TURN address. TURN is useful even when NAT is 1210 not present, to provide anonymity services. 1212 11.2 Exit Strategy 1214 From [12], any UNSAF proposal must provide: 1216 Description of an exit strategy/transition plan. The better short 1217 term fixes are the ones that will naturally see less and less use 1218 as the appropriate technology is deployed. 1220 It is expected that TURN will be useful indefinitely, to provide 1221 anonymity services. When used to facilitate NAT traversal, TURN does 1222 not iself provide an exit strategy. That is provided by the 1223 Interactive Connectivity Establishment (ICE) [13] mechanism. ICE 1224 allows two cooperating clients to interactively determine the best 1225 addresses to use when communicating. ICE uses TURN-allocated 1226 addresses as a last resort, only when no other means of connectivity 1227 exists. As a result, as NATs phase out, and as IPv6 is deployed, ICE 1228 will increasingly use other addresses (host local addresses). 1229 Therefore, clients will allocate TURN addresses, but not use them, 1230 and therefore, de-allocate them. Servers will see a decrease in 1231 usage. Once a provider sees that its TURN servers are not being used 1232 at all (that is, no media flows through them), they can simply remove 1233 them. ICE will operate without TURN-allocated addresses. 1235 11.3 Brittleness Introduced by TURN 1237 From [12], any UNSAF proposal must provide: 1239 Discussion of specific issues that may render systems more 1240 "brittle". For example, approaches that involve using data at 1241 multiple network layers create more dependencies, increase 1242 debugging challenges, and make it harder to transition. 1244 TURN introduces brittleness in a few ways. First, it adds another 1245 server element to any system, which adds another point of failure. 1246 TURN requires clients to demultiplex TURN packets and data based on 1247 hunting for a MAGIC-COOKIE in the TURN messages. It is possible (with 1248 extremely small probabilities) that this cookie could appear within a 1249 data stream, resulting in mis-classification. That might introduce 1250 errors into the data stream (they would appear as lost packets), and 1251 also result in loss of a binding. TURN relies on any NAT bindings 1252 existing for the duration of the bindings held by the TURN server. 1253 Neither the client nor the TURN server have a way of reliably 1254 determining this lifetime (STUN can provide a means, but it is 1255 heuristic in nature and not reliable). Therefore, if there is no 1256 activity on an address learned from TURN for some period, the address 1257 might become useless spontaneously. 1259 TURN will result in potentially significant increases in packet 1260 latencies, and also increases in packet loss probabilities. That is 1261 because it introduces an intermediary on the path of a packet from 1262 point A to B, whose location is determined by application-layer 1263 processing, not underlying routing topologies. Therefore, a packet 1264 sent from one user on a LAN to another on the same LAN may do a trip 1265 around the world before arriving. When combined with ICE, some of the 1266 most problematic cases are avoided (such as this example) by avoiding 1267 the usage of TURN addresses. However, when used, this problem will 1268 exist. 1270 Note that TURN does not suffer from many of the points of brittleness 1271 introduced by STUN. TURN will work with all existing NAT types known 1272 at the time of writing, and for the forseeable future. TURN does not 1273 introduce any topological constraints. TURN does not rely on any 1274 heuristics for NAT type classification. 1276 11.4 Requirements for a Long Term Solution 1278 From [12]}, any UNSAF proposal must provide: 1280 Identify requirements for longer term, sound technical solutions 1281 -- contribute to the process of finding the right longer term 1282 solution. 1284 Our experience with TURN continues to validate our belief in the 1285 requirements outlined in Section 14.4 of STUN. 1287 11.5 Issues with Existing NAPT Boxes 1289 From [12], any UNSAF proposal must provide: 1291 Discussion of the impact of the noted practical issues with 1292 existing, deployed NA[P]Ts and experience reports. 1294 A number of NAT boxes are now being deployed into the market which 1295 try and provide "generic" ALG functionality. These generic ALGs hunt 1296 for IP addresses, either in text or binary form within a packet, and 1297 rewrite them if they match a binding. This will interfere with proper 1298 operation of any UNSAF mechanism, including TURN. However, if a NAT 1299 tries to modify a MAPPED-ADDRESS in a TURN Allocate Response, this 1300 will be detected by the client as an attack. 1302 12. Requirements Analysis 1304 TODO. 1306 13. Examples 1308 TODO. 1310 Normative References 1312 [1] Rosenberg, J., Huitema, C., Mahy, R. and J. Weinberger, "STUN - 1313 Simple Traversal of UDP Through Network Address Translators", 1314 draft-ietf-midcom-stun-05 (work in progress), December 2002. 1316 [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement 1317 Levels", BCP 14, RFC 2119, March 1997. 1319 [3] Gulbrandsen, A., Vixie, P. and L. Esibov, "A DNS RR for 1320 specifying the location of services (DNS SRV)", RFC 2782, 1321 February 2000. 1323 [4] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., 1324 Leach, P., Luotonen, A. and L. Stewart, "HTTP Authentication: 1325 Basic and Digest Access Authentication", RFC 2617, June 1999. 1327 Informative References 1329 [5] Schulzrinne, H., Casner, S., Frederick, R. and V. Jacobson, 1330 "RTP: A Transport Protocol for Real-Time Applications", RFC 1331 1889, January 1996. 1333 [6] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, A., 1334 Peterson, J., Sparks, R., Handley, M. and E. Schooler, "SIP: 1335 Session Initiation Protocol", RFC 3261, June 2002. 1337 [7] Handley, M. and V. Jacobson, "SDP: Session Description 1338 Protocol", RFC 2327, April 1998. 1340 [8] Schulzrinne, H., Rao, A. and R. Lanphier, "Real Time Streaming 1341 Protocol (RTSP)", RFC 2326, April 1998. 1343 [9] Senie, D., "Network Address Translator (NAT)-Friendly 1344 Application Design Guidelines", RFC 3235, January 2002. 1346 [10] Kent, S. and R. Atkinson, "IP Authentication Header", RFC 2402, 1347 November 1998. 1349 [11] Kent, S. and R. Atkinson, "IP Encapsulating Security Payload 1350 (ESP)", RFC 2406, November 1998. 1352 [12] Daigle, L. and IAB, "IAB Considerations for UNilateral 1353 Self-Address Fixing (UNSAF) Across Network Address 1354 Translation", RFC 3424, November 2002. 1356 [13] Rosenberg, J., "Interactive Connectivity Establishment (ICE): A 1357 Methodology for Nettwork Address Translator (NAT) Traversal 1358 for the Session Initiation Protocol (SIP)", 1359 draft-rosenberg-sipping-ice-00 (work in progress), February 1360 2003. 1362 Authors' Addresses 1364 Jonathan Rosenberg 1365 dynamicsoft 1366 72 Eagle Rock Avenue 1367 East Hanover, NJ 07936 1368 US 1370 Phone: +1 973 952-5000 1371 EMail: jdrosen@dynamicsoft.com 1372 URI: http://www.jdrosen.net 1373 Joel Weinberger 1374 dynamicsoft 1375 72 Eagle Rock Avenue 1376 East Hanover, NJ 07936 1377 US 1379 Phone: +1 973 952-5000 1380 EMail: jweinberger@dynamicsoft.com 1382 Rohan Mahy 1383 Cisco Systems 1384 101 Cooper St 1385 Santa Cruz, CA 95060 1386 US 1388 EMail: rohan@cisco.com 1390 Christian Huitema 1391 Microsoft 1392 One Microsoft Way 1393 Redmond, WA 98052-6399 1394 US 1396 EMail: huitema@microsoft.com 1398 Intellectual Property Statement 1400 The IETF takes no position regarding the validity or scope of any 1401 intellectual property or other rights that might be claimed to 1402 pertain to the implementation or use of the technology described in 1403 this document or the extent to which any license under such rights 1404 might or might not be available; neither does it represent that it 1405 has made any effort to identify any such rights. Information on the 1406 IETF's procedures with respect to rights in standards-track and 1407 standards-related documentation can be found in BCP-11. Copies of 1408 claims of rights made available for publication and any assurances of 1409 licenses to be made available, or the result of an attempt made to 1410 obtain a general license or permission for the use of such 1411 proprietary rights by implementors or users of this specification can 1412 be obtained from the IETF Secretariat. 1414 The IETF invites any interested party to bring to its attention any 1415 copyrights, patents or patent applications, or other proprietary 1416 rights which may cover technology that may be required to practice 1417 this standard. Please address the information to the IETF Executive 1418 Director. 1420 Full Copyright Statement 1422 Copyright (C) The Internet Society (2003). All Rights Reserved. 1424 This document and translations of it may be copied and furnished to 1425 others, and derivative works that comment on or otherwise explain it 1426 or assist in its implementation may be prepared, copied, published 1427 and distributed, in whole or in part, without restriction of any 1428 kind, provided that the above copyright notice and this paragraph are 1429 included on all such copies and derivative works. However, this 1430 document itself may not be modified in any way, such as by removing 1431 the copyright notice or references to the Internet Society or other 1432 Internet organizations, except as needed for the purpose of 1433 developing Internet standards in which case the procedures for 1434 copyrights defined in the Internet Standards process must be 1435 followed, or as required to translate it into languages other than 1436 English. 1438 The limited permissions granted above are perpetual and will not be 1439 revoked by the Internet Society or its successors or assignees. 1441 This document and the information contained herein is provided on an 1442 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING 1443 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 1444 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 1445 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 1446 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 1448 Acknowledgement 1450 Funding for the RFC Editor function is currently provided by the 1451 Internet Society.