idnits 2.17.1 draft-johnston-tram-turnbis-01.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 : ---------------------------------------------------------------------------- == There are 4 instances of lines with private range IPv4 addresses in the document. If these are generic example addresses, they should be changed to use any of the ranges defined in RFC 6890 (or successor): 192.0.2.x, 198.51.100.x or 203.0.113.x. -- The document has examples using IPv4 documentation addresses according to RFC6890, but does not use any IPv6 documentation addresses. Maybe there should be IPv6 examples, too? Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (August 10, 2014) is 3546 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) == Missing Reference: '0x4001' is mentioned on line 656, but not defined ** Obsolete normative reference: RFC 5389 (Obsoleted by RFC 8489) -- Obsolete informational reference (is this intentional?): RFC 5245 (Obsoleted by RFC 8445, RFC 8839) -- Obsolete informational reference (is this intentional?): RFC 6156 (Obsoleted by RFC 8656) == Outdated reference: A later version (-12) exists of draft-ietf-tram-turn-server-discovery-00 Summary: 1 error (**), 0 flaws (~~), 4 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 TRAM WG T. Reddy, Ed. 3 Internet-Draft Cisco Systems, Inc. 4 Intended status: Standards Track A. Johnston, Ed. 5 Expires: February 11, 2015 Avaya 6 R. Mahy 7 (Unaffiliated) 8 P. Matthews 9 Alcatel-Lucent 10 J. Rosenberg 11 jdrosen.net 12 August 10, 2014 14 Traversal Using Relays around NAT (TURN): Relay Extensions to Session 15 Traversal Utilities for NAT (STUN) 16 draft-johnston-tram-turnbis-01 18 Abstract 20 If a host is located behind a NAT, then in certain situations it can 21 be impossible for that host to communicate directly with other hosts 22 (peers). In these situations, it is necessary for the host to use 23 the services of an intermediate node that acts as a communication 24 relay. This specification defines a protocol, called TURN (Traversal 25 Using Relays around NAT), that allows the host to control the 26 operation of the relay and to exchange packets with its peers using 27 the relay. TURN differs from some other relay control protocols in 28 that it allows a client to communicate with multiple peers using a 29 single relay address. 31 The TURN protocol was designed to be used as part of the ICE 32 (Interactive Connectivity Establishment) approach to NAT traversal, 33 though it also can be used without ICE. 35 Status of this Memo 37 This Internet-Draft is submitted in full conformance with the 38 provisions of BCP 78 and BCP 79. 40 Internet-Drafts are working documents of the Internet Engineering 41 Task Force (IETF). Note that other groups may also distribute 42 working documents as Internet-Drafts. The list of current Internet- 43 Drafts is at http://datatracker.ietf.org/drafts/current/. 45 Internet-Drafts are draft documents valid for a maximum of six months 46 and may be updated, replaced, or obsoleted by other documents at any 47 time. It is inappropriate to use Internet-Drafts as reference 48 material or to cite them other than as "work in progress." 49 This Internet-Draft will expire on February 11, 2015. 51 Copyright Notice 53 Copyright (c) 2014 IETF Trust and the persons identified as the 54 document authors. All rights reserved. 56 This document is subject to BCP 78 and the IETF Trust's Legal 57 Provisions Relating to IETF Documents 58 (http://trustee.ietf.org/license-info) in effect on the date of 59 publication of this document. Please review these documents 60 carefully, as they describe your rights and restrictions with respect 61 to this document. Code Components extracted from this document must 62 include Simplified BSD License text as described in Section 4.e of 63 the Trust Legal Provisions and are provided without warranty as 64 described in the Simplified BSD License. 66 Table of Contents 68 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 69 2. Overview of Operation . . . . . . . . . . . . . . . . . . . . 6 70 2.1. Transports . . . . . . . . . . . . . . . . . . . . . . . . 9 71 2.2. Allocations . . . . . . . . . . . . . . . . . . . . . . . 10 72 2.3. Permissions . . . . . . . . . . . . . . . . . . . . . . . 12 73 2.4. Send Mechanism . . . . . . . . . . . . . . . . . . . . . . 13 74 2.5. Channels . . . . . . . . . . . . . . . . . . . . . . . . . 15 75 2.6. Unprivileged TURN Servers . . . . . . . . . . . . . . . . 17 76 2.7. Avoiding IP Fragmentation . . . . . . . . . . . . . . . . 17 77 2.8. RTP Support . . . . . . . . . . . . . . . . . . . . . . . 19 78 2.9. Discovery of Servers . . . . . . . . . . . . . . . . . . . 19 79 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 19 80 4. General Behavior . . . . . . . . . . . . . . . . . . . . . . . 21 81 5. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . 23 82 6. Creating an Allocation . . . . . . . . . . . . . . . . . . . . 24 83 6.1. Sending an Allocate Request . . . . . . . . . . . . . . . 24 84 6.2. Receiving an Allocate Request . . . . . . . . . . . . . . 26 85 6.3. Receiving an Allocate Success Response . . . . . . . . . . 30 86 6.4. Receiving an Allocate Error Response . . . . . . . . . . . 31 87 7. Refreshing an Allocation . . . . . . . . . . . . . . . . . . . 33 88 7.1. Sending a Refresh Request . . . . . . . . . . . . . . . . 33 89 7.2. Receiving a Refresh Request . . . . . . . . . . . . . . . 33 90 7.3. Receiving a Refresh Response . . . . . . . . . . . . . . . 34 91 8. Permissions . . . . . . . . . . . . . . . . . . . . . . . . . 34 92 9. CreatePermission . . . . . . . . . . . . . . . . . . . . . . . 35 93 9.1. Forming a CreatePermission Request . . . . . . . . . . . . 36 94 9.2. Receiving a CreatePermission Request . . . . . . . . . . . 36 95 9.3. Receiving a CreatePermission Response . . . . . . . . . . 37 96 10. Send and Data Methods . . . . . . . . . . . . . . . . . . . . 37 97 10.1. Forming a Send Indication . . . . . . . . . . . . . . . . 37 98 10.2. Receiving a Send Indication . . . . . . . . . . . . . . . 37 99 10.3. Receiving a UDP Datagram . . . . . . . . . . . . . . . . . 38 100 10.4. Receiving a Data Indication . . . . . . . . . . . . . . . 39 101 11. Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 102 11.1. Sending a ChannelBind Request . . . . . . . . . . . . . . 41 103 11.2. Receiving a ChannelBind Request . . . . . . . . . . . . . 41 104 11.3. Receiving a ChannelBind Response . . . . . . . . . . . . . 42 105 11.4. The ChannelData Message . . . . . . . . . . . . . . . . . 43 106 11.5. Sending a ChannelData Message . . . . . . . . . . . . . . 43 107 11.6. Receiving a ChannelData Message . . . . . . . . . . . . . 44 108 11.7. Relaying Data from the Peer . . . . . . . . . . . . . . . 45 109 12. IP Header Fields . . . . . . . . . . . . . . . . . . . . . . . 45 110 13. New STUN Methods . . . . . . . . . . . . . . . . . . . . . . . 46 111 14. New STUN Attributes . . . . . . . . . . . . . . . . . . . . . 47 112 14.1. CHANNEL-NUMBER . . . . . . . . . . . . . . . . . . . . . . 47 113 14.2. LIFETIME . . . . . . . . . . . . . . . . . . . . . . . . . 48 114 14.3. XOR-PEER-ADDRESS . . . . . . . . . . . . . . . . . . . . . 48 115 14.4. DATA . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 116 14.5. XOR-RELAYED-ADDRESS . . . . . . . . . . . . . . . . . . . 48 117 14.6. EVEN-PORT . . . . . . . . . . . . . . . . . . . . . . . . 48 118 14.7. REQUESTED-TRANSPORT . . . . . . . . . . . . . . . . . . . 49 119 14.8. DONT-FRAGMENT . . . . . . . . . . . . . . . . . . . . . . 49 120 14.9. RESERVATION-TOKEN . . . . . . . . . . . . . . . . . . . . 49 121 15. New STUN Error Response Codes . . . . . . . . . . . . . . . . 50 122 16. Detailed Example . . . . . . . . . . . . . . . . . . . . . . . 50 123 17. Security Considerations . . . . . . . . . . . . . . . . . . . 57 124 17.1. Outsider Attacks . . . . . . . . . . . . . . . . . . . . . 57 125 17.1.1. Obtaining Unauthorized Allocations . . . . . . . . . 57 126 17.1.2. Offline Dictionary Attacks . . . . . . . . . . . . . 58 127 17.1.3. Faked Refreshes and Permissions . . . . . . . . . . . 58 128 17.1.4. Fake Data . . . . . . . . . . . . . . . . . . . . . . 58 129 17.1.5. Impersonating a Server . . . . . . . . . . . . . . . 59 130 17.1.6. Eavesdropping Traffic . . . . . . . . . . . . . . . . 59 131 17.1.7. TURN Loop Attack . . . . . . . . . . . . . . . . . . 60 132 17.2. Firewall Considerations . . . . . . . . . . . . . . . . . 61 133 17.2.1. Faked Permissions . . . . . . . . . . . . . . . . . . 61 134 17.2.2. Blacklisted IP Addresses . . . . . . . . . . . . . . 62 135 17.2.3. Running Servers on Well-Known Ports . . . . . . . . . 62 136 17.3. Insider Attacks . . . . . . . . . . . . . . . . . . . . . 62 137 17.3.1. DoS against TURN Server . . . . . . . . . . . . . . . 62 138 17.3.2. Anonymous Relaying of Malicious Traffic . . . . . . . 63 139 17.3.3. Manipulating Other Allocations . . . . . . . . . . . 63 140 17.4. Other Considerations . . . . . . . . . . . . . . . . . . . 63 141 18. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 63 142 19. IAB Considerations . . . . . . . . . . . . . . . . . . . . . . 64 143 20. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 65 144 21. References . . . . . . . . . . . . . . . . . . . . . . . . . . 66 145 21.1. Normative References . . . . . . . . . . . . . . . . . . . 66 146 21.2. Informative References . . . . . . . . . . . . . . . . . . 66 147 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 68 149 1. Introduction 151 A host behind a NAT may wish to exchange packets with other hosts, 152 some of which may also be behind NATs. To do this, the hosts 153 involved can use "hole punching" techniques (see [RFC5128]) in an 154 attempt discover a direct communication path; that is, a 155 communication path that goes from one host to another through 156 intervening NATs and routers, but does not traverse any relays. 158 As described in [RFC5128] and [RFC4787], hole punching techniques 159 will fail if both hosts are behind NATs that are not well behaved. 160 For example, if both hosts are behind NATs that have a mapping 161 behavior of "address-dependent mapping" or "address- and port- 162 dependent mapping", then hole punching techniques generally fail. 164 When a direct communication path cannot be found, it is necessary to 165 use the services of an intermediate host that acts as a relay for the 166 packets. This relay typically sits in the public Internet and relays 167 packets between two hosts that both sit behind NATs. 169 This specification defines a protocol, called TURN, that allows a 170 host behind a NAT (called the TURN client) to request that another 171 host (called the TURN server) act as a relay. The client can arrange 172 for the server to relay packets to and from certain other hosts 173 (called peers) and can control aspects of how the relaying is done. 174 The client does this by obtaining an IP address and port on the 175 server, called the relayed transport address. When a peer sends a 176 packet to the relayed transport address, the server relays the packet 177 to the client. When the client sends a data packet to the server, 178 the server relays it to the appropriate peer using the relayed 179 transport address as the source. 181 A client using TURN must have some way to communicate the relayed 182 transport address to its peers, and to learn each peer's IP address 183 and port (more precisely, each peer's server-reflexive transport 184 address, see Section 2). How this is done is out of the scope of the 185 TURN protocol. One way this might be done is for the client and 186 peers to exchange email messages. Another way is for the client and 187 its peers to use a special-purpose "introduction" or "rendezvous" 188 protocol (see [RFC5128] for more details). 190 If TURN is used with ICE [RFC5245], then the relayed transport 191 address and the IP addresses and ports of the peers are included in 192 the ICE candidate information that the rendezvous protocol must 193 carry. For example, if TURN and ICE are used as part of a multimedia 194 solution using SIP [RFC3261], then SIP serves the role of the 195 rendezvous protocol, carrying the ICE candidate information inside 196 the body of SIP messages. If TURN and ICE are used with some other 197 rendezvous protocol, then [I-D.rosenberg-mmusic-ice-nonsip] provides 198 guidance on the services the rendezvous protocol must perform. 200 Though the use of a TURN server to enable communication between two 201 hosts behind NATs is very likely to work, it comes at a high cost to 202 the provider of the TURN server, since the server typically needs a 203 high-bandwidth connection to the Internet . As a consequence, it is 204 best to use a TURN server only when a direct communication path 205 cannot be found. When the client and a peer use ICE to determine the 206 communication path, ICE will use hole punching techniques to search 207 for a direct path first and only use a TURN server when a direct path 208 cannot be found. 210 TURN was originally invented to support multimedia sessions signaled 211 using SIP. Since SIP supports forking, TURN supports multiple peers 212 per relayed transport address; a feature not supported by other 213 approaches (e.g., SOCKS [RFC1928]). However, care has been taken to 214 make sure that TURN is suitable for other types of applications. 216 TURN was designed as one piece in the larger ICE approach to NAT 217 traversal. Implementors of TURN are urged to investigate ICE and 218 seriously consider using it for their application. However, it is 219 possible to use TURN without ICE. 221 TURN is an extension to the STUN (Session Traversal Utilities for 222 NAT) protocol [RFC5389]. Most, though not all, TURN messages are 223 STUN-formatted messages. A reader of this document should be 224 familiar with STUN. 226 2. Overview of Operation 228 This section gives an overview of the operation of TURN. It is non- 229 normative. 231 In a typical configuration, a TURN client is connected to a private 232 network [RFC1918] and through one or more NATs to the public 233 Internet. On the public Internet is a TURN server. Elsewhere in the 234 Internet are one or more peers with which the TURN client wishes to 235 communicate. These peers may or may not be behind one or more NATs. 236 The client uses the server as a relay to send packets to these peers 237 and to receive packets from these peers. 239 Peer A 240 Server-Reflexive +---------+ 241 Transport Address | | 242 192.0.2.150:32102 | | 243 | /| | 244 TURN | / ^| Peer A | 245 Client's Server | / || | 246 Host Transport Transport | // || | 247 Address Address | // |+---------+ 248 10.1.1.2:49721 192.0.2.15:3478 |+-+ // Peer A 249 | | ||N| / Host Transport 250 | +-+ | ||A|/ Address 251 | | | | v|T| 192.168.100.2:49582 252 | | | | /+-+ 253 +---------+| | | |+---------+ / +---------+ 254 | || |N| || | // | | 255 | TURN |v | | v| TURN |/ | | 256 | Client |----|A|----------| Server |------------------| Peer B | 257 | | | |^ | |^ ^| | 258 | | |T|| | || || | 259 +---------+ | || +---------+| |+---------+ 260 | || | | 261 | || | | 262 +-+| | | 263 | | | 264 | | | 265 Client's | Peer B 266 Server-Reflexive Relayed Transport 267 Transport Address Transport Address Address 268 192.0.2.1:7000 192.0.2.15:50000 192.0.2.210:49191 270 Figure 1 272 Figure 1 shows a typical deployment. In this figure, the TURN client 273 and the TURN server are separated by a NAT, with the client on the 274 private side and the server on the public side of the NAT. This NAT 275 is assumed to be a "bad" NAT; for example, it might have a mapping 276 property of "address-and-port-dependent mapping" (see [RFC4787]). 278 The client talks to the server from a (IP address, port) combination 279 called the client's HOST TRANSPORT ADDRESS. (The combination of an 280 IP address and port is called a TRANSPORT ADDRESS.) 282 The client sends TURN messages from its host transport address to a 283 transport address on the TURN server that is known as the TURN SERVER 284 TRANSPORT ADDRESS. The client learns the TURN server transport 285 address through some unspecified means (e.g., configuration), and 286 this address is typically used by many clients simultaneously. 288 Since the client is behind a NAT, the server sees packets from the 289 client as coming from a transport address on the NAT itself. This 290 address is known as the client's SERVER-REFLEXIVE transport address; 291 packets sent by the server to the client's server-reflexive transport 292 address will be forwarded by the NAT to the client's host transport 293 address. 295 The client uses TURN commands to create and manipulate an ALLOCATION 296 on the server. An allocation is a data structure on the server. 297 This data structure contains, amongst other things, the RELAYED 298 TRANSPORT ADDRESS for the allocation. The relayed transport address 299 is the transport address on the server that peers can use to have the 300 server relay data to the client. An allocation is uniquely 301 identified by its relayed transport address. 303 Once an allocation is created, the client can send application data 304 to the server along with an indication of to which peer the data is 305 to be sent, and the server will relay this data to the appropriate 306 peer. The client sends the application data to the server inside a 307 TURN message; at the server, the data is extracted from the TURN 308 message and sent to the peer in a UDP datagram. In the reverse 309 direction, a peer can send application data in a UDP datagram to the 310 relayed transport address for the allocation; the server will then 311 encapsulate this data inside a TURN message and send it to the client 312 along with an indication of which peer sent the data. Since the TURN 313 message always contains an indication of which peer the client is 314 communicating with, the client can use a single allocation to 315 communicate with multiple peers. 317 When the peer is behind a NAT, then the client must identify the peer 318 using its server-reflexive transport address rather than its host 319 transport address. For example, to send application data to Peer A 320 in the example above, the client must specify 192.0.2.150:32102 (Peer 321 A's server-reflexive transport address) rather than 192.168.100.2: 322 49582 (Peer A's host transport address). 324 Each allocation on the server belongs to a single client and has 325 exactly one relayed transport address that is used only by that 326 allocation. Thus, when a packet arrives at a relayed transport 327 address on the server, the server knows for which client the data is 328 intended. 330 The client may have multiple allocations on a server at the same 331 time. 333 2.1. Transports 335 TURN, as defined in this specification, always uses UDP between the 336 server and the peer. However, this specification allows the use of 337 any one of UDP, TCP, Transport Layer Security (TLS) over TCP or 338 Datagram Transport Layer Security (DTLS) over UDP to carry the TURN 339 messages between the client and the server. 341 +----------------------------+---------------------+ 342 | TURN client to TURN server | TURN server to peer | 343 +----------------------------+---------------------+ 344 | UDP | UDP | 345 | TCP | UDP | 346 | TLS-over-TCP | UDP | 347 | DTLS-over-UDP | UDP | 348 +----------------------------+---------------------+ 350 If TCP or TLS-over-TCP is used between the client and the server, 351 then the server will convert between these transports and UDP 352 transport when relaying data to/from the peer. 354 Since this version of TURN only supports UDP between the server and 355 the peer, it is expected that most clients will prefer to use UDP 356 between the client and the server as well. That being the case, some 357 readers may wonder: Why also support TCP and TLS-over-TCP? 359 TURN supports TCP transport between the client and the server because 360 some firewalls are configured to block UDP entirely. These firewalls 361 block UDP but not TCP, in part because TCP has properties that make 362 the intention of the nodes being protected by the firewall more 363 obvious to the firewall. For example, TCP has a three-way handshake 364 that makes in clearer that the protected node really wishes to have 365 that particular connection established, while for UDP the best the 366 firewall can do is guess which flows are desired by using filtering 367 rules. Also, TCP has explicit connection teardown; while for UDP, 368 the firewall has to use timers to guess when the flow is finished. 370 TURN supports TLS-over-TCP transport and DTLS-over-UDP transport 371 between the client and the server because (D)TLS provides additional 372 security properties not provided by TURN's default digest 373 authentication; properties that some clients may wish to take 374 advantage of. In particular, (D)TLS provides a way for the client to 375 ascertain that it is talking to the correct server, and provides for 376 confidentiality of TURN control messages. TURN does not require 377 (D)TLS because the overhead of using (D)TLS is higher than that of 378 digest authentication; for example, using (D)TLS likely means that 379 most application data will be doubly encrypted (once by (D)TLS and 380 once to ensure it is still encrypted in the UDP datagram). 382 There is an extension to TURN for TCP transport between the server 383 and the peers [RFC6062]. For this reason, allocations that use UDP 384 between the server and the peers are known as UDP allocations, while 385 allocations that use TCP between the server and the peers are known 386 as TCP allocations. This specification describes only UDP 387 allocations. 389 Editor's Note: Should we merge RFC 6062 text on TCP transport into 390 this document? 392 TURN as defined in this specification, only supports IPv4. All IP 393 addresses in this specification must be IPv4 addresses. TURN usage 394 for IPv6 and for relaying between IPv4 and IPv6 is defined in 395 [RFC6156]. 397 Editor's Note: Should we merge RFC 6156 text on IPv6 into this 398 document? 400 In some applications for TURN, the client may send and receive 401 packets other than TURN packets on the host transport address it uses 402 to communicate with the server. This can happen, for example, when 403 using TURN with ICE. In these cases, the client can distinguish TURN 404 packets from other packets by examining the source address of the 405 arriving packet: those arriving from the TURN server will be TURN 406 packets. 408 2.2. Allocations 410 To create an allocation on the server, the client uses an Allocate 411 transaction. The client sends an Allocate request to the server, and 412 the server replies with an Allocate success response containing the 413 allocated relayed transport address. The client can include 414 attributes in the Allocate request that describe the type of 415 allocation it desires (e.g., the lifetime of the allocation). Since 416 relaying data has security implications, the server requires that the 417 client authenticate itself, typically using STUN's long-term 418 credential mechanism, to show that it is authorized to use the 419 server. 421 Once a relayed transport address is allocated, a client must keep the 422 allocation alive. To do this, the client periodically sends a 423 Refresh request to the server. TURN deliberately uses a different 424 method (Refresh rather than Allocate) for refreshes to ensure that 425 the client is informed if the allocation vanishes for some reason. 427 The frequency of the Refresh transaction is determined by the 428 lifetime of the allocation. The default lifetime of an allocation is 429 10 minutes -- this value was chosen to be long enough so that 430 refreshing is not typically a burden on the client, while expiring 431 allocations where the client has unexpectedly quit in a timely 432 manner. However, the client can request a longer lifetime in the 433 Allocate request and may modify its request in a Refresh request, and 434 the server always indicates the actual lifetime in the response. The 435 client must issue a new Refresh transaction within "lifetime" seconds 436 of the previous Allocate or Refresh transaction. Once a client no 437 longer wishes to use an allocation, it should delete the allocation 438 using a Refresh request with a requested lifetime of 0. 440 Both the server and client keep track of a value known as the 441 5-TUPLE. At the client, the 5-tuple consists of the client's host 442 transport address, the server transport address, and the transport 443 protocol used by the client to communicate with the server. At the 444 server, the 5-tuple value is the same except that the client's host 445 transport address is replaced by the client's server-reflexive 446 address, since that is the client's address as seen by the server. 448 Both the client and the server remember the 5-tuple used in the 449 Allocate request. Subsequent messages between the client and the 450 server use the same 5-tuple. In this way, the client and server know 451 which allocation is being referred to. If the client wishes to 452 allocate a second relayed transport address, it must create a second 453 allocation using a different 5-tuple (e.g., by using a different 454 client host address or port). 456 NOTE: While the terminology used in this document refers to 457 5-tuples, the TURN server can store whatever identifier it likes 458 that yields identical results. Specifically, an implementation 459 may use a file-descriptor in place of a 5-tuple to represent a TCP 460 connection. 462 TURN TURN Peer Peer 463 client server A B 464 |-- Allocate request --------------->| | | 465 | | | | 466 |<--------------- Allocate failure --| | | 467 | (401 Unauthorized) | | | 468 | | | | 469 |-- Allocate request --------------->| | | 470 | | | | 471 |<---------- Allocate success resp --| | | 472 | (192.0.2.15:50000) | | | 473 // // // // 474 | | | | 475 |-- Refresh request ---------------->| | | 476 | | | | 477 |<----------- Refresh success resp --| | | 478 | | | | 480 Figure 2 482 In Figure 2, the client sends an Allocate request to the server 483 without credentials. Since the server requires that all requests be 484 authenticated using STUN's long-term credential mechanism, the server 485 rejects the request with a 401 (Unauthorized) error code. The client 486 then tries again, this time including credentials (not shown). This 487 time, the server accepts the Allocate request and returns an Allocate 488 success response containing (amongst other things) the relayed 489 transport address assigned to the allocation. Sometime later, the 490 client decides to refresh the allocation and thus sends a Refresh 491 request to the server. The refresh is accepted and the server 492 replies with a Refresh success response. 494 2.3. Permissions 496 To ease concerns amongst enterprise IT administrators that TURN could 497 be used to bypass corporate firewall security, TURN includes the 498 notion of permissions. TURN permissions mimic the address-restricted 499 filtering mechanism of NATs that comply with [RFC4787]. 501 An allocation can have zero or more permissions. Each permission 502 consists of an IP address and a lifetime. When the server receives a 503 UDP datagram on the allocation's relayed transport address, it first 504 checks the list of permissions. If the source IP address of the 505 datagram matches a permission, the application data is relayed to the 506 client, otherwise the UDP datagram is silently discarded. 508 A permission expires after 5 minutes if it is not refreshed, and 509 there is no way to explicitly delete a permission. This behavior was 510 selected to match the behavior of a NAT that complies with [RFC4787]. 512 The client can install or refresh a permission using either a 513 CreatePermission request or a ChannelBind request. Using the 514 CreatePermission request, multiple permissions can be installed or 515 refreshed with a single request -- this is important for applications 516 that use ICE. For security reasons, permissions can only be 517 installed or refreshed by transactions that can be authenticated; 518 thus, Send indications and ChannelData messages (which are used to 519 send data to peers) do not install or refresh any permissions. 521 Note that permissions are within the context of an allocation, so 522 adding or expiring a permission in one allocation does not affect 523 other allocations. 525 2.4. Send Mechanism 527 There are two mechanisms for the client and peers to exchange 528 application data using the TURN server. The first mechanism uses the 529 Send and Data methods, the second way uses channels. Common to both 530 ways is the ability of the client to communicate with multiple peers 531 using a single allocated relayed transport address; thus, both ways 532 include a means for the client to indicate to the server which peer 533 should receive the data, and for the server to indicate to the client 534 which peer sent the data. 536 The Send mechanism uses Send and Data indications. Send indications 537 are used to send application data from the client to the server, 538 while Data indications are used to send application data from the 539 server to the client. 541 When using the Send mechanism, the client sends a Send indication to 542 the TURN server containing (a) an XOR-PEER-ADDRESS attribute 543 specifying the (server-reflexive) transport address of the peer and 544 (b) a DATA attribute holding the application data. When the TURN 545 server receives the Send indication, it extracts the application data 546 from the DATA attribute and sends it in a UDP datagram to the peer, 547 using the allocated relay address as the source address. Note that 548 there is no need to specify the relayed transport address, since it 549 is implied by the 5-tuple used for the Send indication. 551 In the reverse direction, UDP datagrams arriving at the relayed 552 transport address on the TURN server are converted into Data 553 indications and sent to the client, with the server-reflexive 554 transport address of the peer included in an XOR-PEER-ADDRESS 555 attribute and the data itself in a DATA attribute. Since the relayed 556 transport address uniquely identified the allocation, the server 557 knows which client should receive the data. 559 Send and Data indications cannot be authenticated, since the long- 560 term credential mechanism of STUN does not support authenticating 561 indications. This is not as big an issue as it might first appear, 562 since the client-to-server leg is only half of the total path to the 563 peer. Applications that want proper security should encrypt the data 564 sent between the client and a peer. 566 Because Send indications are not authenticated, it is possible for an 567 attacker to send bogus Send indications to the server, which will 568 then relay these to a peer. To partly mitigate this attack, TURN 569 requires that the client install a permission towards a peer before 570 sending data to it using a Send indication. 571 TURN TURN Peer Peer 572 client server A B 573 | | | | 574 |-- CreatePermission req (Peer A) -->| | | 575 |<-- CreatePermission success resp --| | | 576 | | | | 577 |--- Send ind (Peer A)-------------->| | | 578 | |=== data ===>| | 579 | | | | 580 | |<== data ====| | 581 |<-------------- Data ind (Peer A) --| | | 582 | | | | 583 | | | | 584 |--- Send ind (Peer B)-------------->| | | 585 | | dropped | | 586 | | | | 587 | |<== data ==================| 588 | dropped | | | 589 | | | | 591 Figure 3 593 In Figure 3, the client has already created an allocation and now 594 wishes to send data to its peers. The client first creates a 595 permission by sending the server a CreatePermission request 596 specifying Peer A's (server-reflexive) IP address in the XOR-PEER- 597 ADDRESS attribute; if this was not done, the server would not relay 598 data between the client and the server. The client then sends data 599 to Peer A using a Send indication; at the server, the application 600 data is extracted and forwarded in a UDP datagram to Peer A, using 601 the relayed transport address as the source transport address. When 602 a UDP datagram from Peer A is received at the relayed transport 603 address, the contents are placed into a Data indication and forwarded 604 to the client. Later, the client attempts to exchange data with Peer 605 B; however, no permission has been installed for Peer B, so the Send 606 indication from the client and the UDP datagram from the peer are 607 both dropped by the server. 609 2.5. Channels 611 For some applications (e.g., Voice over IP), the 36 bytes of overhead 612 that a Send indication or Data indication adds to the application 613 data can substantially increase the bandwidth required between the 614 client and the server. To remedy this, TURN offers a second way for 615 the client and server to associate data with a specific peer. 617 This second way uses an alternate packet format known as the 618 ChannelData message. The ChannelData message does not use the STUN 619 header used by other TURN messages, but instead has a 4-byte header 620 that includes a number known as a channel number. Each channel 621 number in use is bound to a specific peer and thus serves as a 622 shorthand for the peer's host transport address. 624 To bind a channel to a peer, the client sends a ChannelBind request 625 to the server, and includes an unbound channel number and the 626 transport address of the peer. Once the channel is bound, the client 627 can use a ChannelData message to send the server data destined for 628 the peer. Similarly, the server can relay data from that peer 629 towards the client using a ChannelData message. 631 Channel bindings last for 10 minutes unless refreshed -- this 632 lifetime was chosen to be longer than the permission lifetime. 633 Channel bindings are refreshed by sending another ChannelBind request 634 rebinding the channel to the peer. Like permissions (but unlike 635 allocations), there is no way to explicitly delete a channel binding; 636 the client must simply wait for it to time out. 638 TURN TURN Peer Peer 639 client server A B 640 | | | | 641 |-- ChannelBind req ---------------->| | | 642 | (Peer A to 0x4001) | | | 643 | | | | 644 |<---------- ChannelBind succ resp --| | | 645 | | | | 646 |-- [0x4001] data ------------------>| | | 647 | |=== data ===>| | 648 | | | | 649 | |<== data ====| | 650 |<------------------ [0x4001] data --| | | 651 | | | | 652 |--- Send ind (Peer A)-------------->| | | 653 | |=== data ===>| | 654 | | | | 655 | |<== data ====| | 656 |<------------------ [0x4001] data --| | | 657 | | | | 659 Figure 4 661 Figure 4 shows the channel mechanism in use. The client has already 662 created an allocation and now wishes to bind a channel to Peer A. To 663 do this, the client sends a ChannelBind request to the server, 664 specifying the transport address of Peer A and a channel number 665 (0x4001). After that, the client can send application data 666 encapsulated inside ChannelData messages to Peer A: this is shown as 667 "[0x4001] data" where 0x4001 is the channel number. When the 668 ChannelData message arrives at the server, the server transfers the 669 data to a UDP datagram and sends it to Peer A (which is the peer 670 bound to channel number 0x4001). 672 In the reverse direction, when Peer A sends a UDP datagram to the 673 relayed transport address, this UDP datagram arrives at the server on 674 the relayed transport address assigned to the allocation. Since the 675 UDP datagram was received from Peer A, which has a channel number 676 assigned to it, the server encapsulates the data into a ChannelData 677 message when sending the data to the client. 679 Once a channel has been bound, the client is free to intermix 680 ChannelData messages and Send indications. In the figure, the client 681 later decides to use a Send indication rather than a ChannelData 682 message to send additional data to Peer A. The client might decide to 683 do this, for example, so it can use the DONT-FRAGMENT attribute (see 684 the next section). However, once a channel is bound, the server will 685 always use a ChannelData message, as shown in the call flow. 687 Note that ChannelData messages can only be used for peers to which 688 the client has bound a channel. In the example above, Peer A has 689 been bound to a channel, but Peer B has not, so application data to 690 and from Peer B would use the Send mechanism. 692 2.6. Unprivileged TURN Servers 694 This version of TURN is designed so that the server can be 695 implemented as an application that runs in user space under commonly 696 available operating systems without requiring special privileges. 697 This design decision was made to make it easy to deploy a TURN 698 server: for example, to allow a TURN server to be integrated into a 699 peer-to-peer application so that one peer can offer NAT traversal 700 services to another peer. 702 This design decision has the following implications for data relayed 703 by a TURN server: 705 o The value of the Diffserv field may not be preserved across the 706 server; 708 o The Time to Live (TTL) field may be reset, rather than 709 decremented, across the server; 711 o The Explicit Congestion Notification (ECN) field may be reset by 712 the server; 714 o ICMP messages are not relayed by the server; 716 o There is no end-to-end fragmentation, since the packet is re- 717 assembled at the server. 719 Future work may specify alternate TURN semantics that address these 720 limitations. 722 2.7. Avoiding IP Fragmentation 724 For reasons described in [Frag-Harmful], applications, especially 725 those sending large volumes of data, should try hard to avoid having 726 their packets fragmented. Applications using TCP can more or less 727 ignore this issue because fragmentation avoidance is now a standard 728 part of TCP, but applications using UDP (and thus any application 729 using this version of TURN) must handle fragmentation avoidance 730 themselves. 732 The application running on the client and the peer can take one of 733 two approaches to avoid IP fragmentation. 735 The first approach is to avoid sending large amounts of application 736 data in the TURN messages/UDP datagrams exchanged between the client 737 and the peer. This is the approach taken by most VoIP 738 (Voice-over-IP) applications. In this approach, the application 739 exploits the fact that the IP specification [RFC0791] specifies that 740 IP packets up to 576 bytes should never need to be fragmented. 742 The exact amount of application data that can be included while 743 avoiding fragmentation depends on the details of the TURN session 744 between the client and the server: whether UDP, TCP, or (D)TLS 745 transport is used, whether ChannelData messages or Send/Data 746 indications are used, and whether any additional attributes (such as 747 the DONT-FRAGMENT attribute) are included. Another factor, which is 748 hard to determine, is whether the MTU is reduced somewhere along the 749 path for other reasons, such as the use of IP-in-IP tunneling. 751 As a guideline, sending a maximum of 500 bytes of application data in 752 a single TURN message (by the client on the client-to-server leg) or 753 a UDP datagram (by the peer on the peer-to-server leg) will generally 754 avoid IP fragmentation. To further reduce the chance of 755 fragmentation, it is recommended that the client use ChannelData 756 messages when transferring significant volumes of data, since the 757 overhead of the ChannelData message is less than Send and Data 758 indications. 760 The second approach the client and peer can take to avoid 761 fragmentation is to use a path MTU discovery algorithm to determine 762 the maximum amount of application data that can be sent without 763 fragmentation. 765 Unfortunately, because servers implementing this version of TURN do 766 not relay ICMP messages, the classic path MTU discovery algorithm 767 defined in [RFC1191] is not able to discover the MTU of the 768 transmission path between the client and the peer. (Even if they did 769 relay ICMP messages, the algorithm would not always work since ICMP 770 messages are often filtered out by combined NAT/firewall devices). 772 So the client and server need to use a path MTU discovery algorithm 773 that does not require ICMP messages. The Packetized Path MTU 774 Discovery algorithm defined in [RFC4821] is one such algorithm. 776 The details of how to use the algorithm of [RFC4821] with TURN are 777 still under investigation. However, as a step towards this goal, 778 this version of TURN supports a DONT-FRAGMENT attribute. When the 779 client includes this attribute in a Send indication, this tells the 780 server to set the DF bit in the resulting UDP datagram that it sends 781 to the peer. Since some servers may be unable to set the DF bit, the 782 client should also include this attribute in the Allocate request -- 783 any server that does not support the DONT-FRAGMENT attribute will 784 indicate this by rejecting the Allocate request. 786 2.8. RTP Support 788 One of the envisioned uses of TURN is as a relay for clients and 789 peers wishing to exchange real-time data (e.g., voice or video) using 790 RTP. To facilitate the use of TURN for this purpose, TURN includes 791 some special support for older versions of RTP. 793 Old versions of RTP [RFC3550] required that the RTP stream be on an 794 even port number and the associated RTP Control Protocol (RTCP) 795 stream, if present, be on the next highest port. To allow clients to 796 work with peers that still require this, TURN allows the client to 797 request that the server allocate a relayed transport address with an 798 even port number, and to optionally request the server reserve the 799 next-highest port number for a subsequent allocation. 801 2.9. Discovery of Servers 803 Methods of TURN server discovery, including using anycast, are 804 described in [I-D.ietf-tram-turn-server-discovery]. 806 3. Terminology 808 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 809 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 810 document are to be interpreted as described in RFC 2119 [RFC2119]. 812 Readers are expected to be familiar with [RFC5389] and the terms 813 defined there. 815 The following terms are used in this document: 817 TURN: The protocol spoken between a TURN client and a TURN server. 818 It is an extension to the STUN protocol [RFC5389]. The protocol 819 allows a client to allocate and use a relayed transport address. 821 TURN client: A STUN client that implements this specification. 823 TURN server: A STUN server that implements this specification. It 824 relays data between a TURN client and its peer(s). 826 Peer: A host with which the TURN client wishes to communicate. The 827 TURN server relays traffic between the TURN client and its 828 peer(s). The peer does not interact with the TURN server using 829 the protocol defined in this document; rather, the peer receives 830 data sent by the TURN server and the peer sends data towards the 831 TURN server. 833 Transport Address: The combination of an IP address and a port. 835 Host Transport Address: A transport address on a client or a peer. 837 Server-Reflexive Transport Address: A transport address on the 838 "public side" of a NAT. This address is allocated by the NAT to 839 correspond to a specific host transport address. 841 Relayed Transport Address: A transport address on the TURN server 842 that is used for relaying packets between the client and a peer. 843 A peer sends to this address on the TURN server, and the packet is 844 then relayed to the client. 846 TURN Server Transport Address: A transport address on the TURN 847 server that is used for sending TURN messages to the server. This 848 is the transport address that the client uses to communicate with 849 the server. 851 Peer Transport Address: The transport address of the peer as seen by 852 the server. When the peer is behind a NAT, this is the peer's 853 server-reflexive transport address. 855 Allocation: The relayed transport address granted to a client 856 through an Allocate request, along with related state, such as 857 permissions and expiration timers. 859 5-tuple: The combination (client IP address and port, server IP 860 address and port, and transport protocol (currently one of UDP, 861 TCP, or (D)TLS)) used to communicate between the client and the 862 server. The 5-tuple uniquely identifies this communication 863 stream. The 5-tuple also uniquely identifies the Allocation on 864 the server. 866 Channel: A channel number and associated peer transport address. 867 Once a channel number is bound to a peer's transport address, the 868 client and server can use the more bandwidth-efficient ChannelData 869 message to exchange data. 871 Permission: The IP address and transport protocol (but not the port) 872 of a peer that is permitted to send traffic to the TURN server and 873 have that traffic relayed to the TURN client. The TURN server 874 will only forward traffic to its client from peers that match an 875 existing permission. 877 Realm: A string used to describe the server or a context within the 878 server. The realm tells the client which username and password 879 combination to use to authenticate requests. 881 Nonce: A string chosen at random by the server and included in the 882 message-digest. To prevent reply attacks, the server should 883 change the nonce regularly. 885 4. General Behavior 887 This section contains general TURN processing rules that apply to all 888 TURN messages. 890 TURN is an extension to STUN. All TURN messages, with the exception 891 of the ChannelData message, are STUN-formatted messages. All the 892 base processing rules described in [RFC5389] apply to STUN-formatted 893 messages. This means that all the message-forming and message- 894 processing descriptions in this document are implicitly prefixed with 895 the rules of [RFC5389]. 897 [RFC5389] specifies an authentication mechanism called the long-term 898 credential mechanism. TURN servers and clients MUST implement this 899 mechanism. The server MUST demand that all requests from the client 900 be authenticated using this mechanism, or that a equally strong or 901 stronger mechanism for client authentication is used. 903 Note that the long-term credential mechanism applies only to requests 904 and cannot be used to authenticate indications; thus, indications in 905 TURN are never authenticated. If the server requires requests to be 906 authenticated, then the server's administrator MUST choose a realm 907 value that will uniquely identify the username and password 908 combination that the client must use, even if the client uses 909 multiple servers under different administrations. The server's 910 administrator MAY choose to allocate a unique username to each 911 client, or MAY choose to allocate the same username to more than one 912 client (for example, to all clients from the same department or 913 company). For each allocation, the server SHOULD generate a new 914 random nonce when the allocation is first attempted following the 915 randomness recommendations in [RFC4086] and SHOULD expire the nonce 916 at least once every hour during the lifetime of the allocation. 918 All requests after the initial Allocate must use the same username as 919 that used to create the allocation, to prevent attackers from 920 hijacking the client's allocation. Specifically, if the server 921 requires the use of the long-term credential mechanism, and if a non- 922 Allocate request passes authentication under this mechanism, and if 923 the 5-tuple identifies an existing allocation, but the request does 924 not use the same username as used to create the allocation, then the 925 request MUST be rejected with a 441 (Wrong Credentials) error. 927 When a TURN message arrives at the server from the client, the server 928 uses the 5-tuple in the message to identify the associated 929 allocation. For all TURN messages (including ChannelData) EXCEPT an 930 Allocate request, if the 5-tuple does not identify an existing 931 allocation, then the message MUST either be rejected with a 437 932 Allocation Mismatch error (if it is a request) or silently ignored 933 (if it is an indication or a ChannelData message). A client 934 receiving a 437 error response to a request other than Allocate MUST 935 assume the allocation no longer exists. 937 [RFC5389] defines a number of attributes, including the SOFTWARE and 938 FINGERPRINT attributes. The client SHOULD include the SOFTWARE 939 attribute in all Allocate and Refresh requests and MAY include it in 940 any other requests or indications. The server SHOULD include the 941 SOFTWARE attribute in all Allocate and Refresh responses (either 942 success or failure) and MAY include it in other responses or 943 indications. The client and the server MAY include the FINGERPRINT 944 attribute in any STUN-formatted messages defined in this document. 946 TURN does not use the backwards-compatibility mechanism described in 947 [RFC5389]. 949 TURN, as defined in this specification, only supports IPv4. The 950 client's IP address, the server's IP address, and all IP addresses 951 appearing in a relayed transport address MUST be IPv4 addresses. 953 By default, TURN runs on the same ports as STUN: 3478 for TURN over 954 UDP and TCP, and 5349 for TURN over (D)TLS. However, TURN has its 955 own set of Service Record (SRV) names: "turn" for UDP and TCP, and 956 "turns" for (D)TLS. Either the SRV procedures or the ALTERNATE- 957 SERVER procedures, both described in Section 6, can be used to run 958 TURN on a different port. 960 To ensure interoperability, a TURN server MUST support the use of UDP 961 transport between the client and the server, and SHOULD support the 962 use of TCP and (D)TLS transport. 964 When UDP transport is used between the client and the server, the 965 client will retransmit a request if it does not receive a response 966 within a certain timeout period. Because of this, the server may 967 receive two (or more) requests with the same 5-tuple and same 968 transaction id. STUN requires that the server recognize this case 969 and treat the request as idempotent (see [RFC5389]). Some 970 implementations may choose to meet this requirement by remembering 971 all received requests and the corresponding responses for 40 seconds. 973 Other implementations may choose to reprocess the request and arrange 974 that such reprocessing returns essentially the same response. To aid 975 implementors who choose the latter approach (the so-called "stateless 976 stack approach"), this specification includes some implementation 977 notes on how this might be done. Implementations are free to choose 978 either approach or choose some other approach that gives the same 979 results. 981 When TCP transport is used between the client and the server, it is 982 possible that a bit error will cause a length field in a TURN packet 983 to become corrupted, causing the receiver to lose synchronization 984 with the incoming stream of TURN messages. A client or server that 985 detects a long sequence of invalid TURN messages over TCP transport 986 SHOULD close the corresponding TCP connection to help the other end 987 detect this situation more rapidly. 989 To mitigate either intentional or unintentional denial-of-service 990 attacks against the server by clients with valid usernames and 991 passwords, it is RECOMMENDED that the server impose limits on both 992 the number of allocations active at one time for a given username and 993 on the amount of bandwidth those allocations can use. The server 994 should reject new allocations that would exceed the limit on the 995 allowed number of allocations active at one time with a 486 996 (Allocation Quota Exceeded) (see Section 6.2), and should discard 997 application data traffic that exceeds the bandwidth quota. 999 5. Allocations 1001 All TURN operations revolve around allocations, and all TURN messages 1002 are associated with an allocation. An allocation conceptually 1003 consists of the following state data: 1005 o the relayed transport address; 1007 o the 5-tuple: (client's IP address, client's port, server IP 1008 address, server port, transport protocol); 1010 o the authentication information; 1012 o the time-to-expiry; 1014 o a list of permissions; 1016 o a list of channel to peer bindings. 1018 The relayed transport address is the transport address allocated by 1019 the server for communicating with peers, while the 5-tuple describes 1020 the communication path between the client and the server. On the 1021 client, the 5-tuple uses the client's host transport address; on the 1022 server, the 5-tuple uses the client's server-reflexive transport 1023 address. 1025 Both the relayed transport address and the 5-tuple MUST be unique 1026 across all allocations, so either one can be used to uniquely 1027 identify the allocation. 1029 The authentication information (e.g., username, password, realm, and 1030 nonce) is used to both verify subsequent requests and to compute the 1031 message integrity of responses. The username, realm, and nonce 1032 values are initially those used in the authenticated Allocate request 1033 that creates the allocation, though the server can change the nonce 1034 value during the lifetime of the allocation using a 438 (Stale Nonce) 1035 reply. Note that, rather than storing the password explicitly, for 1036 security reasons, it may be desirable for the server to store the key 1037 value, which is an MD5 hash over the username, realm, and password 1038 (see [RFC5389]). 1040 Editor's Note: Remove MD5 based on the changes in STUN bis draft. 1042 The time-to-expiry is the time in seconds left until the allocation 1043 expires. Each Allocate or Refresh transaction sets this timer, which 1044 then ticks down towards 0. By default, each Allocate or Refresh 1045 transaction resets this timer to the default lifetime value of 600 1046 seconds (10 minutes), but the client can request a different value in 1047 the Allocate and Refresh request. Allocations can only be refreshed 1048 using the Refresh request; sending data to a peer does not refresh an 1049 allocation. When an allocation expires, the state data associated 1050 with the allocation can be freed. 1052 The list of permissions is described in Section 8 and the list of 1053 channels is described in Section 11. 1055 6. Creating an Allocation 1057 An allocation on the server is created using an Allocate transaction. 1059 6.1. Sending an Allocate Request 1061 The client forms an Allocate request as follows. 1063 The client first picks a host transport address. It is RECOMMENDED 1064 that the client pick a currently unused transport address, typically 1065 by allowing the underlying OS to pick a currently unused port for a 1066 new socket. 1068 The client then picks a transport protocol to use between the client 1069 and the server. The transport protocol MUST be one of UDP, TCP, TLS- 1070 over-TCP or DTLS-over-UDP. Since this specification only allows UDP 1071 between the server and the peers, it is RECOMMENDED that the client 1072 pick UDP unless it has a reason to use a different transport. One 1073 reason to pick a different transport would be that the client 1074 believes, either through configuration or by experiment, that it is 1075 unable to contact any TURN server using UDP. See Section 2.1 for 1076 more discussion. 1078 The client also picks a server transport address, which SHOULD be 1079 done as follows. The client receives (perhaps through configuration) 1080 a domain name for a TURN server. The client then uses the DNS 1081 procedures described in [RFC5389], but using an SRV service name of 1082 "turn" (or "turns" for TURN over (D)TLS) instead of "stun" (or 1083 "stuns"). For example, to find servers in the example.com domain, 1084 the client performs a lookup for '_turn._udp.example.com', 1085 '_turn._tcp.example.com', and '_turns._tcp.example.com' if the client 1086 wants to communicate with the server using UDP, TCP, TLS-over-TCP, or 1087 DTLS-over-UDP, respectively. 1089 The client MUST include a REQUESTED-TRANSPORT attribute in the 1090 request. This attribute specifies the transport protocol between the 1091 server and the peers (note that this is NOT the transport protocol 1092 that appears in the 5-tuple). In this specification, the REQUESTED- 1093 TRANSPORT type is always UDP. This attribute is included to allow 1094 future extensions to specify other protocols. 1096 If the client wishes the server to initialize the time-to-expiry 1097 field of the allocation to some value other than the default 1098 lifetime, then it MAY include a LIFETIME attribute specifying its 1099 desired value. This is just a request, and the server may elect to 1100 use a different value. Note that the server will ignore requests to 1101 initialize the field to less than the default value. 1103 If the client wishes to later use the DONT-FRAGMENT attribute in one 1104 or more Send indications on this allocation, then the client SHOULD 1105 include the DONT-FRAGMENT attribute in the Allocate request. This 1106 allows the client to test whether this attribute is supported by the 1107 server. 1109 If the client requires the port number of the relayed transport 1110 address be even, the client includes the EVEN-PORT attribute. If 1111 this attribute is not included, then the port can be even or odd. By 1112 setting the R bit in the EVEN-PORT attribute to 1, the client can 1113 request that the server reserve the next highest port number (on the 1114 same IP address) for a subsequent allocation. If the R bit is 0, no 1115 such request is made. 1117 The client MAY also include a RESERVATION-TOKEN attribute in the 1118 request to ask the server to use a previously reserved port for the 1119 allocation. If the RESERVATION-TOKEN attribute is included, then the 1120 client MUST omit the EVEN-PORT attribute. 1122 Once constructed, the client sends the Allocate request on the 1123 5-tuple. 1125 6.2. Receiving an Allocate Request 1127 When the server receives an Allocate request, it performs the 1128 following checks: 1130 1. The server MUST require that the request be authenticated. This 1131 authentication MUST be done using the long-term credential 1132 mechanism of [RFC5389] unless the client and server agree to use 1133 another mechanism through some procedure outside the scope of 1134 this document. 1136 2. The server checks if the 5-tuple is currently in use by an 1137 existing allocation. If yes, the server rejects the request with 1138 a 437 (Allocation Mismatch) error. 1140 3. The server checks if the request contains a REQUESTED-TRANSPORT 1141 attribute. If the REQUESTED-TRANSPORT attribute is not included 1142 or is malformed, the server rejects the request with a 400 (Bad 1143 Request) error. Otherwise, if the attribute is included but 1144 specifies a protocol other that UDP, the server rejects the 1145 request with a 442 (Unsupported Transport Protocol) error. 1147 4. The request may contain a DONT-FRAGMENT attribute. If it does, 1148 but the server does not support sending UDP datagrams with the DF 1149 bit set to 1 (see Section 12), then the server treats the DONT- 1150 FRAGMENT attribute in the Allocate request as an unknown 1151 comprehension-required attribute. 1153 5. The server checks if the request contains a RESERVATION-TOKEN 1154 attribute. If yes, and the request also contains an EVEN-PORT 1155 attribute, then the server rejects the request with a 400 (Bad 1156 Request) error. Otherwise, it checks to see if the token is 1157 valid (i.e., the token is in range and has not expired and the 1158 corresponding relayed transport address is still available). If 1159 the token is not valid for some reason, the server rejects the 1160 request with a 508 (Insufficient Capacity) error. 1162 6. The server checks if the request contains an EVEN-PORT attribute. 1163 If yes, then the server checks that it can satisfy the request 1164 (i.e., can allocate a relayed transport address as described 1165 below). If the server cannot satisfy the request, then the 1166 server rejects the request with a 508 (Insufficient Capacity) 1167 error. 1169 7. At any point, the server MAY choose to reject the request with a 1170 486 (Allocation Quota Reached) error if it feels the client is 1171 trying to exceed some locally defined allocation quota. The 1172 server is free to define this allocation quota any way it wishes, 1173 but SHOULD define it based on the username used to authenticate 1174 the request, and not on the client's transport address. 1176 8. Also at any point, the server MAY choose to reject the request 1177 with a 300 (Try Alternate) error if it wishes to redirect the 1178 client to a different server. The use of this error code and 1179 attribute follow the specification in [RFC5389]. 1181 If all the checks pass, the server creates the allocation. The 1182 5-tuple is set to the 5-tuple from the Allocate request, while the 1183 list of permissions and the list of channels are initially empty. 1185 The server chooses a relayed transport address for the allocation as 1186 follows: 1188 o If the request contains a RESERVATION-TOKEN, the server uses the 1189 previously reserved transport address corresponding to the 1190 included token (if it is still available). Note that the 1191 reservation is a server-wide reservation and is not specific to a 1192 particular allocation, since the Allocate request containing the 1193 RESERVATION-TOKEN uses a different 5-tuple than the Allocate 1194 request that made the reservation. The 5-tuple for the Allocate 1195 request containing the RESERVATION-TOKEN attribute can be any 1196 allowed 5-tuple; it can use a different client IP address and 1197 port, a different transport protocol, and even different server IP 1198 address and port (provided, of course, that the server IP address 1199 and port are ones on which the server is listening for TURN 1200 requests). 1202 o If the request contains an EVEN-PORT attribute with the R bit set 1203 to 0, then the server allocates a relayed transport address with 1204 an even port number. 1206 o If the request contains an EVEN-PORT attribute with the R bit set 1207 to 1, then the server looks for a pair of port numbers N and N+1 1208 on the same IP address, where N is even. Port N is used in the 1209 current allocation, while the relayed transport address with port 1210 N+1 is assigned a token and reserved for a future allocation. The 1211 server MUST hold this reservation for at least 30 seconds, and MAY 1212 choose to hold longer (e.g., until the allocation with port N 1213 expires). The server then includes the token in a RESERVATION- 1214 TOKEN attribute in the success response. 1216 o Otherwise, the server allocates any available relayed transport 1217 address. 1219 In all cases, the server SHOULD only allocate ports from the range 1220 49152 - 65535 (the Dynamic and/or Private Port range [Port-Numbers]), 1221 unless the TURN server application knows, through some means not 1222 specified here, that other applications running on the same host as 1223 the TURN server application will not be impacted by allocating ports 1224 outside this range. This condition can often be satisfied by running 1225 the TURN server application on a dedicated machine and/or by 1226 arranging that any other applications on the machine allocate ports 1227 before the TURN server application starts. In any case, the TURN 1228 server SHOULD NOT allocate ports in the range 0 - 1023 (the Well- 1229 Known Port range) to discourage clients from using TURN to run 1230 standard services. 1232 NOTE: The use of randomized port assignments to avoid certain 1233 types of attacks is described in [RFC6056]. It is RECOMMENDED 1234 that a TURN server implement a randomized port assignment 1235 algorithm from [RFC6056]. This is especially applicable to 1236 servers that choose to pre-allocate a number of ports from the 1237 underlying OS and then later assign them to allocations; for 1238 example, a server may choose this technique to implement the EVEN- 1239 PORT attribute. 1241 Editor's Note: Should we recommend a specific algorithm from RFC 1242 6056? 1244 The server determines the initial value of the time-to-expiry field 1245 as follows. If the request contains a LIFETIME attribute, then the 1246 server computes the minimum of the client's proposed lifetime and the 1247 server's maximum allowed lifetime. If this computed value is greater 1248 than the default lifetime, then the server uses the computed lifetime 1249 as the initial value of the time-to-expiry field. Otherwise, the 1250 server uses the default lifetime. It is RECOMMENDED that the server 1251 use a maximum allowed lifetime value of no more than 3600 seconds (1 1252 hour). Servers that implement allocation quotas or charge users for 1253 allocations in some way may wish to use a smaller maximum allowed 1254 lifetime (perhaps as small as the default lifetime) to more quickly 1255 remove orphaned allocations (that is, allocations where the 1256 corresponding client has crashed or terminated or the client 1257 connection has been lost for some reason). Also, note that the time- 1258 to-expiry is recomputed with each successful Refresh request, and 1259 thus the value computed here applies only until the first refresh. 1261 Once the allocation is created, the server replies with a success 1262 response. The success response contains: 1264 o An XOR-RELAYED-ADDRESS attribute containing the relayed transport 1265 address. 1267 o A LIFETIME attribute containing the current value of the time-to- 1268 expiry timer. 1270 o A RESERVATION-TOKEN attribute (if a second relayed transport 1271 address was reserved). 1273 o An XOR-MAPPED-ADDRESS attribute containing the client's IP address 1274 and port (from the 5-tuple). 1276 NOTE: The XOR-MAPPED-ADDRESS attribute is included in the response 1277 as a convenience to the client. TURN itself does not make use of 1278 this value, but clients running ICE can often need this value and 1279 can thus avoid having to do an extra Binding transaction with some 1280 STUN server to learn it. 1282 The response (either success or error) is sent back to the client on 1283 the 5-tuple. 1285 NOTE: When the Allocate request is sent over UDP, section 7.3.1 of 1286 [RFC5389] requires that the server handle the possible 1287 retransmissions of the request so that retransmissions do not 1288 cause multiple allocations to be created. Implementations may 1289 achieve this using the so-called "stateless stack approach" as 1290 follows. To detect retransmissions when the original request was 1291 successful in creating an allocation, the server can store the 1292 transaction id that created the request with the allocation data 1293 and compare it with incoming Allocate requests on the same 1294 5-tuple. Once such a request is detected, the server can stop 1295 parsing the request and immediately generate a success response. 1296 When building this response, the value of the LIFETIME attribute 1297 can be taken from the time-to-expiry field in the allocate state 1298 data, even though this value may differ slightly from the LIFETIME 1299 value originally returned. In addition, the server may need to 1300 store an indication of any reservation token returned in the 1301 original response, so that this may be returned in any 1302 retransmitted responses. 1304 For the case where the original request was unsuccessful in 1305 creating an allocation, the server may choose to do nothing 1306 special. Note, however, that there is a rare case where the 1307 server rejects the original request but accepts the retransmitted 1308 request (because conditions have changed in the brief intervening 1309 time period). If the client receives the first failure response, 1310 it will ignore the second (success) response and believe that an 1311 allocation was not created. An allocation created in this matter 1312 will eventually timeout, since the client will not refresh it. 1313 Furthermore, if the client later retries with the same 5-tuple but 1314 different transaction id, it will receive a 437 (Allocation 1315 Mismatch), which will cause it to retry with a different 5-tuple. 1316 The server may use a smaller maximum lifetime value to minimize 1317 the lifetime of allocations "orphaned" in this manner. 1319 6.3. Receiving an Allocate Success Response 1321 If the client receives an Allocate success response, then it MUST 1322 check that the mapped address and the relayed transport address are 1323 in an address family that the client understands and is prepared to 1324 handle. This specification only covers the case where these two 1325 addresses are IPv4 addresses. If these two addresses are not in an 1326 address family which the client is prepared to handle, then the 1327 client MUST delete the allocation (Section 7) and MUST NOT attempt to 1328 create another allocation on that server until it believes the 1329 mismatch has been fixed. 1331 The IETF is currently considering mechanisms for transitioning 1332 between IPv4 and IPv6 that could result in a client originating an 1333 Allocate request over IPv6, but the request would arrive at the 1334 server over IPv4, or vice versa. 1336 Editor's Note: This text on IPv6 should be updated. 1338 Otherwise, the client creates its own copy of the allocation data 1339 structure to track what is happening on the server. In particular, 1340 the client needs to remember the actual lifetime received back from 1341 the server, rather than the value sent to the server in the request. 1342 The client must also remember the 5-tuple used for the request and 1343 the username and password it used to authenticate the request to 1344 ensure that it reuses them for subsequent messages. The client also 1345 needs to track the channels and permissions it establishes on the 1346 server. 1348 The client will probably wish to send the relayed transport address 1349 to peers (using some method not specified here) so the peers can 1350 communicate with it. The client may also wish to use the server- 1351 reflexive address it receives in the XOR-MAPPED-ADDRESS attribute in 1352 its ICE processing. 1354 6.4. Receiving an Allocate Error Response 1356 If the client receives an Allocate error response, then the 1357 processing depends on the actual error code returned: 1359 o (Request timed out): There is either a problem with the server, or 1360 a problem reaching the server with the chosen transport. The 1361 client considers the current transaction as having failed but MAY 1362 choose to retry the Allocate request using a different transport 1363 (e.g., TCP instead of UDP). 1365 o 300 (Try Alternate): The server would like the client to use the 1366 server specified in the ALTERNATE-SERVER attribute instead. The 1367 client considers the current transaction as having failed, but 1368 SHOULD try the Allocate request with the alternate server before 1369 trying any other servers (e.g., other servers discovered using the 1370 SRV procedures). When trying the Allocate request with the 1371 alternate server, the client follows the ALTERNATE-SERVER 1372 procedures specified in [RFC5389]. 1374 o 400 (Bad Request): The server believes the client's request is 1375 malformed for some reason. The client considers the current 1376 transaction as having failed. The client MAY notify the user or 1377 operator and SHOULD NOT retry the request with this server until 1378 it believes the problem has been fixed. 1380 o 401 (Unauthorized): If the client has followed the procedures of 1381 the long-term credential mechanism and still gets this error, then 1382 the server is not accepting the client's credentials. In this 1383 case, the client considers the current transaction as having 1384 failed and SHOULD notify the user or operator. The client SHOULD 1385 NOT send any further requests to this server until it believes the 1386 problem has been fixed. 1388 o 403 (Forbidden): The request is valid, but the server is refusing 1389 to perform it, likely due to administrative restrictions. The 1390 client considers the current transaction as having failed. The 1391 client MAY notify the user or operator and SHOULD NOT retry the 1392 same request with this server until it believes the problem has 1393 been fixed. 1395 o 420 (Unknown Attribute): If the client included a DONT-FRAGMENT 1396 attribute in the request and the server rejected the request with 1397 a 420 error code and listed the DONT-FRAGMENT attribute in the 1398 UNKNOWN-ATTRIBUTES attribute in the error response, then the 1399 client now knows that the server does not support the DONT- 1400 FRAGMENT attribute. The client considers the current transaction 1401 as having failed but MAY choose to retry the Allocate request 1402 without the DONT-FRAGMENT attribute. 1404 o 437 (Allocation Mismatch): This indicates that the client has 1405 picked a 5-tuple that the server sees as already in use. One way 1406 this could happen is if an intervening NAT assigned a mapped 1407 transport address that was used by another client that recently 1408 crashed. The client considers the current transaction as having 1409 failed. The client SHOULD pick another client transport address 1410 and retry the Allocate request (using a different transaction id). 1411 The client SHOULD try three different client transport addresses 1412 before giving up on this server. Once the client gives up on the 1413 server, it SHOULD NOT try to create another allocation on the 1414 server for 2 minutes. 1416 o 438 (Stale Nonce): See the procedures for the long-term credential 1417 mechanism [RFC5389]. 1419 o 441 (Wrong Credentials): The client should not receive this error 1420 in response to a Allocate request. The client MAY notify the user 1421 or operator and SHOULD NOT retry the same request with this server 1422 until it believes the problem has been fixed. 1424 o 442 (Unsupported Transport Address): The client should not receive 1425 this error in response to a request for a UDP allocation. The 1426 client MAY notify the user or operator and SHOULD NOT reattempt 1427 the request with this server until it believes the problem has 1428 been fixed. 1430 o 486 (Allocation Quota Reached): The server is currently unable to 1431 create any more allocations with this username. The client 1432 considers the current transaction as having failed. The client 1433 SHOULD wait at least 1 minute before trying to create any more 1434 allocations on the server. 1436 o 508 (Insufficient Capacity): The server has no more relayed 1437 transport addresses available, or has none with the requested 1438 properties, or the one that was reserved is no longer available. 1439 The client considers the current operation as having failed. If 1440 the client is using either the EVEN-PORT or the RESERVATION-TOKEN 1441 attribute, then the client MAY choose to remove or modify this 1442 attribute and try again immediately. Otherwise, the client SHOULD 1443 wait at least 1 minute before trying to create any more 1444 allocations on this server. 1446 An unknown error response MUST be handled as described in [RFC5389]. 1448 7. Refreshing an Allocation 1450 A Refresh transaction can be used to either (a) refresh an existing 1451 allocation and update its time-to-expiry or (b) delete an existing 1452 allocation. 1454 If a client wishes to continue using an allocation, then the client 1455 MUST refresh it before it expires. It is suggested that the client 1456 refresh the allocation roughly 1 minute before it expires. If a 1457 client no longer wishes to use an allocation, then it SHOULD 1458 explicitly delete the allocation. A client MAY refresh an allocation 1459 at any time for other reasons. 1461 7.1. Sending a Refresh Request 1463 If the client wishes to immediately delete an existing allocation, it 1464 includes a LIFETIME attribute with a value of 0. All other forms of 1465 the request refresh the allocation. 1467 The Refresh transaction updates the time-to-expiry timer of an 1468 allocation. If the client wishes the server to set the time-to- 1469 expiry timer to something other than the default lifetime, it 1470 includes a LIFETIME attribute with the requested value. The server 1471 then computes a new time-to-expiry value in the same way as it does 1472 for an Allocate transaction, with the exception that a requested 1473 lifetime of 0 causes the server to immediately delete the allocation. 1475 7.2. Receiving a Refresh Request 1477 When the server receives a Refresh request, it processes as per 1478 Section 4 plus the specific rules mentioned here. 1480 The server computes a value called the "desired lifetime" as follows: 1481 if the request contains a LIFETIME attribute and the attribute value 1482 is 0, then the "desired lifetime" is 0. Otherwise, if the request 1483 contains a LIFETIME attribute, then the server computes the minimum 1484 of the client's requested lifetime and the server's maximum allowed 1485 lifetime. If this computed value is greater than the default 1486 lifetime, then the "desired lifetime" is the computed value. 1487 Otherwise, the "desired lifetime" is the default lifetime. 1489 Subsequent processing depends on the "desired lifetime" value: 1491 o If the "desired lifetime" is 0, then the request succeeds and the 1492 allocation is deleted. 1494 o If the "desired lifetime" is non-zero, then the request succeeds 1495 and the allocation's time-to-expiry is set to the "desired 1496 lifetime". 1498 If the request succeeds, then the server sends a success response 1499 containing: 1501 o A LIFETIME attribute containing the current value of the time-to- 1502 expiry timer. 1504 NOTE: A server need not do anything special to implement 1505 idempotency of Refresh requests over UDP using the "stateless 1506 stack approach". Retransmitted Refresh requests with a non-zero 1507 "desired lifetime" will simply refresh the allocation. A 1508 retransmitted Refresh request with a zero "desired lifetime" will 1509 cause a 437 (Allocation Mismatch) response if the allocation has 1510 already been deleted, but the client will treat this as equivalent 1511 to a success response (see below). 1513 7.3. Receiving a Refresh Response 1515 If the client receives a success response to its Refresh request with 1516 a non-zero lifetime, it updates its copy of the allocation data 1517 structure with the time-to-expiry value contained in the response. 1519 If the client receives a 437 (Allocation Mismatch) error response to 1520 a request to delete the allocation, then the allocation no longer 1521 exists and it should consider its request as having effectively 1522 succeeded. 1524 8. Permissions 1526 For each allocation, the server keeps a list of zero or more 1527 permissions. Each permission consists of an IP address and an 1528 associated time-to-expiry. While a permission exists, all peers 1529 using the IP address in the permission are allowed to send data to 1530 the client. The time-to-expiry is the number of seconds until the 1531 permission expires. Within the context of an allocation, a 1532 permission is uniquely identified by its associated IP address. 1534 By sending either CreatePermission requests or ChannelBind requests, 1535 the client can cause the server to install or refresh a permission 1536 for a given IP address. This causes one of two things to happen: 1538 o If no permission for that IP address exists, then a permission is 1539 created with the given IP address and a time-to-expiry equal to 1540 Permission Lifetime. 1542 o If a permission for that IP address already exists, then the time- 1543 to-expiry for that permission is reset to Permission Lifetime. 1545 The Permission Lifetime MUST be 300 seconds (= 5 minutes). 1547 Each permission's time-to-expiry decreases down once per second until 1548 it reaches 0; at which point, the permission expires and is deleted. 1550 CreatePermission and ChannelBind requests may be freely intermixed on 1551 a permission. A given permission may be initially installed and/or 1552 refreshed with a CreatePermission request, and then later refreshed 1553 with a ChannelBind request, or vice versa. 1555 When a UDP datagram arrives at the relayed transport address for the 1556 allocation, the server extracts the source IP address from the IP 1557 header. The server then compares this address with the IP address 1558 associated with each permission in the list of permissions for the 1559 allocation. If no match is found, relaying is not permitted, and the 1560 server silently discards the UDP datagram. If an exact match is 1561 found, then the permission check is considered to have succeeded and 1562 the server continues to process the UDP datagram as specified 1563 elsewhere (Section 10.3). Note that only addresses are compared and 1564 port numbers are not considered. 1566 The permissions for one allocation are totally unrelated to the 1567 permissions for a different allocation. If an allocation expires, 1568 all its permissions expire with it. 1570 NOTE: Though TURN permissions expire after 5 minutes, many NATs 1571 deployed at the time of publication expire their UDP bindings 1572 considerably faster. Thus, an application using TURN will 1573 probably wish to send some sort of keep-alive traffic at a much 1574 faster rate. Applications using ICE should follow the keep-alive 1575 guidelines of ICE [RFC5245], and applications not using ICE are 1576 advised to do something similar. 1578 9. CreatePermission 1580 TURN supports two ways for the client to install or refresh 1581 permissions on the server. This section describes one way: the 1582 CreatePermission request. 1584 A CreatePermission request may be used in conjunction with either the 1585 Send mechanism in Section 10 or the Channel mechanism in Section 11. 1587 9.1. Forming a CreatePermission Request 1589 The client who wishes to install or refresh one or more permissions 1590 can send a CreatePermission request to the server. 1592 When forming a CreatePermission request, the client MUST include at 1593 least one XOR-PEER-ADDRESS attribute, and MAY include more than one 1594 such attribute. The IP address portion of each XOR-PEER-ADDRESS 1595 attribute contains the IP address for which a permission should be 1596 installed or refreshed. The port portion of each XOR-PEER-ADDRESS 1597 attribute will be ignored and can be any arbitrary value. The 1598 various XOR-PEER-ADDRESS attributes can appear in any order. 1600 9.2. Receiving a CreatePermission Request 1602 When the server receives the CreatePermission request, it processes 1603 as per Section 4 plus the specific rules mentioned here. 1605 The message is checked for validity. The CreatePermission request 1606 MUST contain at least one XOR-PEER-ADDRESS attribute and MAY contain 1607 multiple such attributes. If no such attribute exists, or if any of 1608 these attributes are invalid, then a 400 (Bad Request) error is 1609 returned. If the request is valid, but the server is unable to 1610 satisfy the request due to some capacity limit or similar, then a 508 1611 (Insufficient Capacity) error is returned. 1613 The server MAY impose restrictions on the IP address allowed in the 1614 XOR-PEER-ADDRESS attribute -- if a value is not allowed, the server 1615 rejects the request with a 403 (Forbidden) error. 1617 If the message is valid and the server is capable of carrying out the 1618 request, then the server installs or refreshes a permission for the 1619 IP address contained in each XOR-PEER-ADDRESS attribute as described 1620 in Section 8. The port portion of each attribute is ignored and may 1621 be any arbitrary value. 1623 The server then responds with a CreatePermission success response. 1624 There are no mandatory attributes in the success response. 1626 NOTE: A server need not do anything special to implement 1627 idempotency of CreatePermission requests over UDP using the 1628 "stateless stack approach". Retransmitted CreatePermission 1629 requests will simply refresh the permissions. 1631 9.3. Receiving a CreatePermission Response 1633 If the client receives a valid CreatePermission success response, 1634 then the client updates its data structures to indicate that the 1635 permissions have been installed or refreshed. 1637 10. Send and Data Methods 1639 TURN supports two mechanisms for sending and receiving data from 1640 peers. This section describes the use of the Send and Data 1641 mechanisms, while Section 11 describes the use of the Channel 1642 mechanism. 1644 10.1. Forming a Send Indication 1646 The client can use a Send indication to pass data to the server for 1647 relaying to a peer. A client may use a Send indication even if a 1648 channel is bound to that peer. However, the client MUST ensure that 1649 there is a permission installed for the IP address of the peer to 1650 which the Send indication is being sent; this prevents a third party 1651 from using a TURN server to send data to arbitrary destinations. 1653 When forming a Send indication, the client MUST include an XOR-PEER- 1654 ADDRESS attribute and a DATA attribute. The XOR-PEER-ADDRESS 1655 attribute contains the transport address of the peer to which the 1656 data is to be sent, and the DATA attribute contains the actual 1657 application data to be sent to the peer. 1659 The client MAY include a DONT-FRAGMENT attribute in the Send 1660 indication if it wishes the server to set the DF bit on the UDP 1661 datagram sent to the peer. 1663 10.2. Receiving a Send Indication 1665 When the server receives a Send indication, it processes as per 1666 Section 4 plus the specific rules mentioned here. 1668 The message is first checked for validity. The Send indication MUST 1669 contain both an XOR-PEER-ADDRESS attribute and a DATA attribute. If 1670 one of these attributes is missing or invalid, then the message is 1671 discarded. Note that the DATA attribute is allowed to contain zero 1672 bytes of data. 1674 The Send indication may also contain the DONT-FRAGMENT attribute. If 1675 the server is unable to set the DF bit on outgoing UDP datagrams when 1676 this attribute is present, then the server acts as if the DONT- 1677 FRAGMENT attribute is an unknown comprehension-required attribute 1678 (and thus the Send indication is discarded). 1680 The server also checks that there is a permission installed for the 1681 IP address contained in the XOR-PEER-ADDRESS attribute. If no such 1682 permission exists, the message is discarded. Note that a Send 1683 indication never causes the server to refresh the permission. 1685 The server MAY impose restrictions on the IP address and port values 1686 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1687 allowed, the server silently discards the Send indication. 1689 If everything is OK, then the server forms a UDP datagram as follows: 1691 o the source transport address is the relayed transport address of 1692 the allocation, where the allocation is determined by the 5-tuple 1693 on which the Send indication arrived; 1695 o the destination transport address is taken from the XOR-PEER- 1696 ADDRESS attribute; 1698 o the data following the UDP header is the contents of the value 1699 field of the DATA attribute. 1701 The handling of the DONT-FRAGMENT attribute (if present), is 1702 described in Section 12. 1704 The resulting UDP datagram is then sent to the peer. 1706 10.3. Receiving a UDP Datagram 1708 When the server receives a UDP datagram at a currently allocated 1709 relayed transport address, the server looks up the allocation 1710 associated with the relayed transport address. The server then 1711 checks to see whether the set of permissions for the allocation allow 1712 the relaying of the UDP datagram as described in Section 8. 1714 If relaying is permitted, then the server checks if there is a 1715 channel bound to the peer that sent the UDP datagram (see 1716 Section 11). If a channel is bound, then processing proceeds as 1717 described in Section 11.7. 1719 If relaying is permitted but no channel is bound to the peer, then 1720 the server forms and sends a Data indication. The Data indication 1721 MUST contain both an XOR-PEER-ADDRESS and a DATA attribute. The DATA 1722 attribute is set to the value of the 'data octets' field from the 1723 datagram, and the XOR-PEER-ADDRESS attribute is set to the source 1724 transport address of the received UDP datagram. The Data indication 1725 is then sent on the 5-tuple associated with the allocation. 1727 10.4. Receiving a Data Indication 1729 When the client receives a Data indication, it checks that the Data 1730 indication contains both an XOR-PEER-ADDRESS and a DATA attribute, 1731 and discards the indication if it does not. The client SHOULD also 1732 check that the XOR-PEER-ADDRESS attribute value contains an IP 1733 address with which the client believes there is an active permission, 1734 and discard the Data indication otherwise. Note that the DATA 1735 attribute is allowed to contain zero bytes of data. 1737 NOTE: The latter check protects the client against an attacker who 1738 somehow manages to trick the server into installing permissions 1739 not desired by the client. 1741 If the Data indication passes the above checks, the client delivers 1742 the data octets inside the DATA attribute to the application, along 1743 with an indication that they were received from the peer whose 1744 transport address is given by the XOR-PEER-ADDRESS attribute. 1746 11. Channels 1748 Channels provide a way for the client and server to send application 1749 data using ChannelData messages, which have less overhead than Send 1750 and Data indications. 1752 The ChannelData message (see Section 11.4) starts with a two-byte 1753 field that carries the channel number. The values of this field are 1754 allocated as follows: 1756 0x0000 through 0x3FFF: These values can never be used for channel 1757 numbers. 1759 0x4000 through 0x7FFF: These values are the allowed channel 1760 numbers (16,384 possible values). 1762 0x8000 through 0xFFFF: These values are reserved for future use. 1764 Because of this division, ChannelData messages can be distinguished 1765 from STUN-formatted messages (e.g., Allocate request, Send 1766 indication, etc.) by examining the first two bits of the message: 1768 0b00: STUN-formatted message (since the first two bits of a STUN- 1769 formatted message are always zero). 1771 0b01: ChannelData message (since the channel number is the first 1772 field in the ChannelData message and channel numbers fall in the 1773 range 0x4000 - 0x7FFF). 1775 0b10: Reserved 1777 0b11: Reserved 1779 The reserved values may be used in the future to extend the range of 1780 channel numbers. Thus, an implementation MUST NOT assume that a TURN 1781 message always starts with a 0 bit. 1783 Channel bindings are always initiated by the client. The client can 1784 bind a channel to a peer at any time during the lifetime of the 1785 allocation. The client may bind a channel to a peer before 1786 exchanging data with it, or after exchanging data with it (using Send 1787 and Data indications) for some time, or may choose never to bind a 1788 channel to it. The client can also bind channels to some peers while 1789 not binding channels to other peers. 1791 Channel bindings are specific to an allocation, so that the use of a 1792 channel number or peer transport address in a channel binding in one 1793 allocation has no impact on their use in a different allocation. If 1794 an allocation expires, all its channel bindings expire with it. 1796 A channel binding consists of: 1798 o a channel number; 1800 o a transport address (of the peer); and 1802 o A time-to-expiry timer. 1804 Within the context of an allocation, a channel binding is uniquely 1805 identified either by the channel number or by the peer's transport 1806 address. Thus, the same channel cannot be bound to two different 1807 transport addresses, nor can the same transport address be bound to 1808 two different channels. 1810 A channel binding lasts for 10 minutes unless refreshed. Refreshing 1811 the binding (by the server receiving a ChannelBind request rebinding 1812 the channel to the same peer) resets the time-to-expiry timer back to 1813 10 minutes. 1815 When the channel binding expires, the channel becomes unbound. Once 1816 unbound, the channel number can be bound to a different transport 1817 address, and the transport address can be bound to a different 1818 channel number. To prevent race conditions, the client MUST wait 5 1819 minutes after the channel binding expires before attempting to bind 1820 the channel number to a different transport address or the transport 1821 address to a different channel number. 1823 When binding a channel to a peer, the client SHOULD be prepared to 1824 receive ChannelData messages on the channel from the server as soon 1825 as it has sent the ChannelBind request. Over UDP, it is possible for 1826 the client to receive ChannelData messages from the server before it 1827 receives a ChannelBind success response. 1829 In the other direction, the client MAY elect to send ChannelData 1830 messages before receiving the ChannelBind success response. Doing 1831 so, however, runs the risk of having the ChannelData messages dropped 1832 by the server if the ChannelBind request does not succeed for some 1833 reason (e.g., packet lost if the request is sent over UDP, or the 1834 server being unable to fulfill the request). A client that wishes to 1835 be safe should either queue the data or use Send indications until 1836 the channel binding is confirmed. 1838 11.1. Sending a ChannelBind Request 1840 A channel binding is created or refreshed using a ChannelBind 1841 transaction. A ChannelBind transaction also creates or refreshes a 1842 permission towards the peer (see Section 8). 1844 To initiate the ChannelBind transaction, the client forms a 1845 ChannelBind request. The channel to be bound is specified in a 1846 CHANNEL-NUMBER attribute, and the peer's transport address is 1847 specified in an XOR-PEER-ADDRESS attribute. Section 11.2 describes 1848 the restrictions on these attributes. 1850 Rebinding a channel to the same transport address that it is already 1851 bound to provides a way to refresh a channel binding and the 1852 corresponding permission without sending data to the peer. Note 1853 however, that permissions need to be refreshed more frequently than 1854 channels. 1856 11.2. Receiving a ChannelBind Request 1858 When the server receives a ChannelBind request, it processes as per 1859 Section 4 plus the specific rules mentioned here. 1861 The server checks the following: 1863 o The request contains both a CHANNEL-NUMBER and an XOR-PEER-ADDRESS 1864 attribute; 1866 o The channel number is in the range 0x4000 through 0x7FFE 1867 (inclusive); 1869 o The channel number is not currently bound to a different transport 1870 address (same transport address is OK); 1872 o The transport address is not currently bound to a different 1873 channel number. 1875 If any of these tests fail, the server replies with a 400 (Bad 1876 Request) error. 1878 The server MAY impose restrictions on the IP address and port values 1879 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1880 allowed, the server rejects the request with a 403 (Forbidden) error. 1882 If the request is valid, but the server is unable to fulfill the 1883 request due to some capacity limit or similar, the server replies 1884 with a 508 (Insufficient Capacity) error. 1886 Otherwise, the server replies with a ChannelBind success response. 1887 There are no required attributes in a successful ChannelBind 1888 response. 1890 If the server can satisfy the request, then the server creates or 1891 refreshes the channel binding using the channel number in the 1892 CHANNEL-NUMBER attribute and the transport address in the XOR-PEER- 1893 ADDRESS attribute. The server also installs or refreshes a 1894 permission for the IP address in the XOR-PEER-ADDRESS attribute as 1895 described in Section 8. 1897 NOTE: A server need not do anything special to implement 1898 idempotency of ChannelBind requests over UDP using the "stateless 1899 stack approach". Retransmitted ChannelBind requests will simply 1900 refresh the channel binding and the corresponding permission. 1901 Furthermore, the client must wait 5 minutes before binding a 1902 previously bound channel number or peer address to a different 1903 channel, eliminating the possibility that the transaction would 1904 initially fail but succeed on a retransmission. 1906 11.3. Receiving a ChannelBind Response 1908 When the client receives a ChannelBind success response, it updates 1909 its data structures to record that the channel binding is now active. 1910 It also updates its data structures to record that the corresponding 1911 permission has been installed or refreshed. 1913 If the client receives a ChannelBind failure response that indicates 1914 that the channel information is out-of-sync between the client and 1915 the server (e.g., an unexpected 400 "Bad Request" response), then it 1916 is RECOMMENDED that the client immediately delete the allocation and 1917 start afresh with a new allocation. 1919 11.4. The ChannelData Message 1921 The ChannelData message is used to carry application data between the 1922 client and the server. It has the following format: 1924 0 1 2 3 1925 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 1926 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1927 | Channel Number | Length | 1928 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1929 | | 1930 / Application Data / 1931 / / 1932 | | 1933 | +-------------------------------+ 1934 | | 1935 +-------------------------------+ 1937 The Channel Number field specifies the number of the channel on which 1938 the data is traveling, and thus the address of the peer that is 1939 sending or is to receive the data. 1941 The Length field specifies the length in bytes of the application 1942 data field (i.e., it does not include the size of the ChannelData 1943 header). Note that 0 is a valid length. 1945 The Application Data field carries the data the client is trying to 1946 send to the peer, or that the peer is sending to the client. 1948 11.5. Sending a ChannelData Message 1950 Once a client has bound a channel to a peer, then when the client has 1951 data to send to that peer it may use either a ChannelData message or 1952 a Send indication; that is, the client is not obligated to use the 1953 channel when it exists and may freely intermix the two message types 1954 when sending data to the peer. The server, on the other hand, MUST 1955 use the ChannelData message if a channel has been bound to the peer. 1957 The fields of the ChannelData message are filled in as described in 1958 Section 11.4. 1960 Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to 1961 a multiple of four bytes in order to ensure the alignment of 1962 subsequent messages. The padding is not reflected in the length 1963 field of the ChannelData message, so the actual size of a ChannelData 1964 message (including padding) is (4 + Length) rounded up to the nearest 1965 multiple of 4. Over UDP, the padding is not required but MAY be 1966 included. 1968 The ChannelData message is then sent on the 5-tuple associated with 1969 the allocation. 1971 11.6. Receiving a ChannelData Message 1973 The receiver of the ChannelData message uses the first two bits to 1974 distinguish it from STUN-formatted messages, as described above. If 1975 the message uses a value in the reserved range (0x8000 through 1976 0xFFFF), then the message is silently discarded. 1978 If the ChannelData message is received in a UDP datagram, and if the 1979 UDP datagram is too short to contain the claimed length of the 1980 ChannelData message (i.e., the UDP header length field value is less 1981 than the ChannelData header length field value + 4 + 8), then the 1982 message is silently discarded. 1984 If the ChannelData message is received over TCP or over TLS-over-TCP, 1985 then the actual length of the ChannelData message is as described in 1986 Section 11.5. 1988 If the ChannelData message is received on a channel that is not bound 1989 to any peer, then the message is silently discarded. 1991 On the client, it is RECOMMENDED that the client discard the 1992 ChannelData message if the client believes there is no active 1993 permission towards the peer. On the server, the receipt of a 1994 ChannelData message MUST NOT refresh either the channel binding or 1995 the permission towards the peer. 1997 On the server, if no errors are detected, the server relays the 1998 application data to the peer by forming a UDP datagram as follows: 2000 o the source transport address is the relayed transport address of 2001 the allocation, where the allocation is determined by the 5-tuple 2002 on which the ChannelData message arrived; 2004 o the destination transport address is the transport address to 2005 which the channel is bound; 2007 o the data following the UDP header is the contents of the data 2008 field of the ChannelData message. 2010 The resulting UDP datagram is then sent to the peer. Note that if 2011 the Length field in the ChannelData message is 0, then there will be 2012 no data in the UDP datagram, but the UDP datagram is still formed and 2013 sent. 2015 11.7. Relaying Data from the Peer 2017 When the server receives a UDP datagram on the relayed transport 2018 address associated with an allocation, the server processes it as 2019 described in Section 10.3. If that section indicates that a 2020 ChannelData message should be sent (because there is a channel bound 2021 to the peer that sent to the UDP datagram), then the server forms and 2022 sends a ChannelData message as described in Section 11.5. 2024 12. IP Header Fields 2026 This section describes how the server sets various fields in the IP 2027 header when relaying between the client and the peer or vice versa. 2028 The descriptions in this section apply: (a) when the server sends a 2029 UDP datagram to the peer, or (b) when the server sends a Data 2030 indication or ChannelData message to the client over UDP transport. 2031 The descriptions in this section do not apply to TURN messages sent 2032 over TCP or TLS transport from the server to the client. 2034 The descriptions below have two parts: a preferred behavior and an 2035 alternate behavior. The server SHOULD implement the preferred 2036 behavior, but if that is not possible for a particular field, then it 2037 SHOULD implement the alternative behavior. 2039 Time to Live (TTL) field 2041 Preferred Behavior: If the incoming value is 0, then the drop the 2042 incoming packet. Otherwise, set the outgoing Time to Live/Hop 2043 Count to one less than the incoming value. 2045 Alternate Behavior: Set the outgoing value to the default for 2046 outgoing packets. 2048 Differentiated Services Code Point (DSCP) field [RFC2474] 2050 Preferred Behavior: Set the outgoing value to the incoming value, 2051 unless the server includes a differentiated services classifier 2052 and marker [RFC2474]. 2054 Alternate Behavior: Set the outgoing value to a fixed value, which 2055 by default is Best Effort unless configured otherwise. 2057 In both cases, if the server is immediately adjacent to a 2058 differentiated services classifier and marker, then DSCP MAY be 2059 set to any arbitrary value in the direction towards the 2060 classifier. 2062 Explicit Congestion Notification (ECN) field [RFC3168] 2064 Preferred Behavior: Set the outgoing value to the incoming value, 2065 UNLESS the server is doing Active Queue Management, the incoming 2066 ECN field is ECT(1) (=0b01) or ECT(0) (=0b10), and the server 2067 wishes to indicate that congestion has been experienced, in which 2068 case set the outgoing value to CE (=0b11). 2070 Alternate Behavior: Set the outgoing value to Not-ECT (=0b00). 2072 IPv4 Fragmentation fields 2074 Preferred Behavior: When the server sends a packet to a peer in 2075 response to a Send indication containing the DONT-FRAGMENT 2076 attribute, then set the DF bit in the outgoing IP header to 1. In 2077 all other cases when sending an outgoing packet containing 2078 application data (e.g., Data indication, ChannelData message, or 2079 DONT-FRAGMENT attribute not included in the Send indication), copy 2080 the DF bit from the DF bit of the incoming packet that contained 2081 the application data. 2083 Set the other fragmentation fields (Identification, More 2084 Fragments, Fragment Offset) as appropriate for a packet 2085 originating from the server. 2087 Alternate Behavior: As described in the Preferred Behavior, except 2088 always assume the incoming DF bit is 0. 2090 In both the Preferred and Alternate Behaviors, the resulting 2091 packet may be too large for the outgoing link. If this is the 2092 case, then the normal fragmentation rules apply [RFC1122]. 2094 IPv4 Options 2096 Preferred Behavior: The outgoing packet is sent without any IPv4 2097 options. 2099 Alternate Behavior: Same as preferred. 2101 13. New STUN Methods 2103 This section lists the codepoints for the new STUN methods defined in 2104 this specification. See elsewhere in this document for the semantics 2105 of these new methods. 2107 0x003 : Allocate (only request/response semantics defined) 2108 0x004 : Refresh (only request/response semantics defined) 2109 0x006 : Send (only indication semantics defined) 2110 0x007 : Data (only indication semantics defined) 2111 0x008 : CreatePermission (only request/response semantics defined 2112 0x009 : ChannelBind (only request/response semantics defined) 2114 14. New STUN Attributes 2116 This STUN extension defines the following new attributes: 2118 0x000C: CHANNEL-NUMBER 2119 0x000D: LIFETIME 2120 0x0010: Reserved (was BANDWIDTH) 2121 0x0012: XOR-PEER-ADDRESS 2122 0x0013: DATA 2123 0x0016: XOR-RELAYED-ADDRESS 2124 0x0018: EVEN-PORT 2125 0x0019: REQUESTED-TRANSPORT 2126 0x001A: DONT-FRAGMENT 2127 0x0021: Reserved (was TIMER-VAL) 2128 0x0022: RESERVATION-TOKEN 2130 Some of these attributes have lengths that are not multiples of 4. 2131 By the rules of STUN, any attribute whose length is not a multiple of 2132 4 bytes MUST be immediately followed by 1 to 3 padding bytes to 2133 ensure the next attribute (if any) would start on a 4-byte boundary 2134 (see [RFC5389]). 2136 14.1. CHANNEL-NUMBER 2138 The CHANNEL-NUMBER attribute contains the number of the channel. The 2139 value portion of this attribute is 4 bytes long and consists of a 16- 2140 bit unsigned integer, followed by a two-octet RFFU (Reserved For 2141 Future Use) field, which MUST be set to 0 on transmission and MUST be 2142 ignored on reception. 2144 0 1 2 3 2145 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 2146 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2147 | Channel Number | RFFU = 0 | 2148 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2150 14.2. LIFETIME 2152 The LIFETIME attribute represents the duration for which the server 2153 will maintain an allocation in the absence of a refresh. The value 2154 portion of this attribute is 4-bytes long and consists of a 32-bit 2155 unsigned integral value representing the number of seconds remaining 2156 until expiration. 2158 14.3. XOR-PEER-ADDRESS 2160 The XOR-PEER-ADDRESS specifies the address and port of the peer as 2161 seen from the TURN server. (For example, the peer's server-reflexive 2162 transport address if the peer is behind a NAT.) It is encoded in the 2163 same way as XOR-MAPPED-ADDRESS [RFC5389]. 2165 14.4. DATA 2167 The DATA attribute is present in all Send and Data indications. The 2168 value portion of this attribute is variable length and consists of 2169 the application data (that is, the data that would immediately follow 2170 the UDP header if the data was been sent directly between the client 2171 and the peer). If the length of this attribute is not a multiple of 2172 4, then padding must be added after this attribute. 2174 14.5. XOR-RELAYED-ADDRESS 2176 The XOR-RELAYED-ADDRESS is present in Allocate responses. It 2177 specifies the address and port that the server allocated to the 2178 client. It is encoded in the same way as XOR-MAPPED-ADDRESS 2179 [RFC5389]. 2181 14.6. EVEN-PORT 2183 This attribute allows the client to request that the port in the 2184 relayed transport address be even, and (optionally) that the server 2185 reserve the next-higher port number. The value portion of this 2186 attribute is 1 byte long. Its format is: 2188 0 2189 0 1 2 3 4 5 6 7 2190 +-+-+-+-+-+-+-+-+ 2191 |R| RFFU | 2192 +-+-+-+-+-+-+-+-+ 2194 The value contains a single 1-bit flag: 2196 R: If 1, the server is requested to reserve the next-higher port 2197 number (on the same IP address) for a subsequent allocation. If 2198 0, no such reservation is requested. 2200 The other 7 bits of the attribute's value must be set to zero on 2201 transmission and ignored on reception. 2203 Since the length of this attribute is not a multiple of 4, padding 2204 must immediately follow this attribute. 2206 14.7. REQUESTED-TRANSPORT 2208 This attribute is used by the client to request a specific transport 2209 protocol for the allocated transport address. The value of this 2210 attribute is 4 bytes with the following format: 2211 0 1 2 3 2212 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 2213 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2214 | Protocol | RFFU | 2215 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2217 The Protocol field specifies the desired protocol. The codepoints 2218 used in this field are taken from those allowed in the Protocol field 2219 in the IPv4 header and the NextHeader field in the IPv6 header 2220 [Protocol-Numbers]. This specification only allows the use of 2221 codepoint 17 (User Datagram Protocol). 2223 The RFFU field MUST be set to zero on transmission and MUST be 2224 ignored on reception. It is reserved for future uses. 2226 14.8. DONT-FRAGMENT 2228 This attribute is used by the client to request that the server set 2229 the DF (Don't Fragment) bit in the IP header when relaying the 2230 application data onward to the peer. This attribute has no value 2231 part and thus the attribute length field is 0. 2233 14.9. RESERVATION-TOKEN 2235 The RESERVATION-TOKEN attribute contains a token that uniquely 2236 identifies a relayed transport address being held in reserve by the 2237 server. The server includes this attribute in a success response to 2238 tell the client about the token, and the client includes this 2239 attribute in a subsequent Allocate request to request the server use 2240 that relayed transport address for the allocation. 2242 The attribute value is 8 bytes and contains the token value. 2244 15. New STUN Error Response Codes 2246 This document defines the following new error response codes: 2248 403 (Forbidden): The request was valid but cannot be performed due 2249 to administrative or similar restrictions. 2251 437 (Allocation Mismatch): A request was received by the server that 2252 requires an allocation to be in place, but no allocation exists, 2253 or a request was received that requires no allocation, but an 2254 allocation exists. 2256 441 (Wrong Credentials): The credentials in the (non-Allocate) 2257 request do not match those used to create the allocation. 2259 442 (Unsupported Transport Protocol): The Allocate request asked the 2260 server to use a transport protocol between the server and the peer 2261 that the server does not support. NOTE: This does NOT refer to 2262 the transport protocol used in the 5-tuple. 2264 486 (Allocation Quota Reached): No more allocations using this 2265 username can be created at the present time. 2267 508 (Insufficient Capacity): The server is unable to carry out the 2268 request due to some capacity limit being reached. In an Allocate 2269 response, this could be due to the server having no more relayed 2270 transport addresses available at that time, having none with the 2271 requested properties, or the one that corresponds to the specified 2272 reservation token is not available. 2274 16. Detailed Example 2276 This section gives an example of the use of TURN, showing in detail 2277 the contents of the messages exchanged. The example uses the network 2278 diagram shown in the Overview (Figure 1). 2280 For each message, the attributes included in the message and their 2281 values are shown. For convenience, values are shown in a human- 2282 readable format rather than showing the actual octets; for example, 2283 "XOR-RELAYED-ADDRESS=192.0.2.15:9000" shows that the XOR-RELAYED- 2284 ADDRESS attribute is included with an address of 192.0.2.15 and a 2285 port of 9000, here the address and port are shown before the xor-ing 2286 is done. For attributes with string-like values (e.g., 2287 SOFTWARE="Example client, version 1.03" and 2288 NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm"), the value of the attribute 2289 is shown in quotes for readability, but these quotes do not appear in 2290 the actual value. 2292 TURN TURN Peer Peer 2293 client server A B 2294 | | | | 2295 |--- Allocate request -------------->| | | 2296 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2297 | SOFTWARE="Example client, version 1.03" | | 2298 | LIFETIME=3600 (1 hour) | | | 2299 | REQUESTED-TRANSPORT=17 (UDP) | | | 2300 | DONT-FRAGMENT | | | 2301 | | | | 2302 |<-- Allocate error response --------| | | 2303 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2304 | SOFTWARE="Example server, version 1.17" | | 2305 | ERROR-CODE=401 (Unauthorized) | | | 2306 | REALM="example.com" | | | 2307 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2308 | | | | 2309 |--- Allocate request -------------->| | | 2310 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2311 | SOFTWARE="Example client 1.03" | | | 2312 | LIFETIME=3600 (1 hour) | | | 2313 | REQUESTED-TRANSPORT=17 (UDP) | | | 2314 | DONT-FRAGMENT | | | 2315 | USERNAME="George" | | | 2316 | REALM="example.com" | | | 2317 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2318 | MESSAGE-INTEGRITY=... | | | 2319 | | | | 2320 |<-- Allocate success response ------| | | 2321 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2322 | SOFTWARE="Example server, version 1.17" | | 2323 | LIFETIME=1200 (20 minutes) | | | 2324 | XOR-RELAYED-ADDRESS=192.0.2.15:50000 | | 2325 | XOR-MAPPED-ADDRESS=192.0.2.1:7000 | | 2326 | MESSAGE-INTEGRITY=... | | | 2328 The client begins by selecting a host transport address to use for 2329 the TURN session; in this example, the client has selected 10.1.1.2: 2330 49721 as shown in Figure 1. The client then sends an Allocate 2331 request to the server at the server transport address. The client 2332 randomly selects a 96-bit transaction id of 2333 0xA56250D3F17ABE679422DE85 for this transaction; this is encoded in 2334 the transaction id field in the fixed header. The client includes a 2335 SOFTWARE attribute that gives information about the client's 2336 software; here the value is "Example client, version 1.03" to 2337 indicate that this is version 1.03 of something called the Example 2338 client. The client includes the LIFETIME attribute because it wishes 2339 the allocation to have a longer lifetime than the default of 10 2340 minutes; the value of this attribute is 3600 seconds, which 2341 corresponds to 1 hour. The client must always include a REQUESTED- 2342 TRANSPORT attribute in an Allocate request and the only value allowed 2343 by this specification is 17, which indicates UDP transport between 2344 the server and the peers. The client also includes the DONT-FRAGMENT 2345 attribute because it wishes to use the DONT-FRAGMENT attribute later 2346 in Send indications; this attribute consists of only an attribute 2347 header, there is no value part. We assume the client has not 2348 recently interacted with the server, thus the client does not include 2349 USERNAME, REALM, NONCE, or MESSAGE-INTEGRITY attribute. Finally, 2350 note that the order of attributes in a message is arbitrary (except 2351 for the MESSAGE-INTEGRITY and FINGERPRINT attributes) and the client 2352 could have used a different order. 2354 Servers require any request to be authenticated. Thus, when the 2355 server receives the initial Allocate request, it rejects the request 2356 because the request does not contain the authentication attributes. 2357 Following the procedures of the long-term credential mechanism of 2358 STUN [RFC5389], the server includes an ERROR-CODE attribute with a 2359 value of 401 (Unauthorized), a REALM attribute that specifies the 2360 authentication realm used by the server (in this case, the server's 2361 domain "example.com"), and a nonce value in a NONCE attribute. The 2362 server also includes a SOFTWARE attribute that gives information 2363 about the server's software. 2365 The client, upon receipt of the 401 error, re-attempts the Allocate 2366 request, this time including the authentication attributes. The 2367 client selects a new transaction id, and then populates the new 2368 Allocate request with the same attributes as before. The client 2369 includes a USERNAME attribute and uses the realm value received from 2370 the server to help it determine which value to use; here the client 2371 is configured to use the username "George" for the realm 2372 "example.com". The client also includes the REALM and NONCE 2373 attributes, which are just copied from the 401 error response. 2374 Finally, the client includes a MESSAGE-INTEGRITY attribute as the 2375 last attribute in the message, whose value is a Hashed Message 2376 Authentication Code - Secure Hash Algorithm 1 (HMAC-SHA1) hash over 2377 the contents of the message (shown as just "..." above); this HMAC- 2378 SHA1 computation includes a password value. Thus, an attacker cannot 2379 compute the message integrity value without somehow knowing the 2380 secret password. 2382 The server, upon receipt of the authenticated Allocate request, 2383 checks that everything is OK, then creates an allocation. The server 2384 replies with an Allocate success response. The server includes a 2385 LIFETIME attribute giving the lifetime of the allocation; here, the 2386 server has reduced the client's requested 1-hour lifetime to just 20 2387 minutes, because this particular server doesn't allow lifetimes 2388 longer than 20 minutes. The server includes an XOR-RELAYED-ADDRESS 2389 attribute whose value is the relayed transport address of the 2390 allocation. The server includes an XOR-MAPPED-ADDRESS attribute 2391 whose value is the server-reflexive address of the client; this value 2392 is not used otherwise in TURN but is returned as a convenience to the 2393 client. The server includes a MESSAGE-INTEGRITY attribute to 2394 authenticate the response and to ensure its integrity; note that the 2395 response does not contain the USERNAME, REALM, and NONCE attributes. 2396 The server also includes a SOFTWARE attribute. 2398 TURN TURN Peer Peer 2399 client server A B 2400 |--- CreatePermission request ------>| | | 2401 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2402 | XOR-PEER-ADDRESS=192.0.2.150:0 | | | 2403 | USERNAME="George" | | | 2404 | REALM="example.com" | | | 2405 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2406 | MESSAGE-INTEGRITY=... | | | 2407 | | | | 2408 |<-- CreatePermission success resp.--| | | 2409 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2410 | MESSAGE-INTEGRITY=... | | | 2412 The client then creates a permission towards Peer A in preparation 2413 for sending it some application data. This is done through a 2414 CreatePermission request. The XOR-PEER-ADDRESS attribute contains 2415 the IP address for which a permission is established (the IP address 2416 of peer A); note that the port number in the attribute is ignored 2417 when used in a CreatePermission request, and here it has been set to 2418 0; also, note how the client uses Peer A's server-reflexive IP 2419 address and not its (private) host address. The client uses the same 2420 username, realm, and nonce values as in the previous request on the 2421 allocation. Though it is allowed to do so, the client has chosen not 2422 to include a SOFTWARE attribute in this request. 2424 The server receives the CreatePermission request, creates the 2425 corresponding permission, and then replies with a CreatePermission 2426 success response. Like the client, the server chooses not to include 2427 the SOFTWARE attribute in its reply. Again, note how success 2428 responses contain a MESSAGE-INTEGRITY attribute (assuming the server 2429 uses the long-term credential mechanism), but no USERNAME, REALM, and 2430 NONCE attributes. 2432 TURN TURN Peer Peer 2433 client server A B 2434 |--- Send indication --------------->| | | 2435 | Transaction-Id=0x1278E9ACA2711637EF7D3328 | | 2436 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2437 | DONT-FRAGMENT | | | 2438 | DATA=... | | | 2439 | |-- UDP dgm ->| | 2440 | | data=... | | 2441 | | | | 2442 | |<- UDP dgm --| | 2443 | | data=... | | 2444 |<-- Data indication ----------------| | | 2445 | Transaction-Id=0x8231AE8F9242DA9FF287FEFF | | 2446 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2447 | DATA=... | | | 2449 The client now sends application data to Peer A using a Send 2450 indication. Peer A's server-reflexive transport address is specified 2451 in the XOR-PEER-ADDRESS attribute, and the application data (shown 2452 here as just "...") is specified in the DATA attribute. The client 2453 is doing a form of path MTU discovery at the application layer and 2454 thus specifies (by including the DONT-FRAGMENT attribute) that the 2455 server should set the DF bit in the UDP datagram to send to the peer. 2456 Indications cannot be authenticated using the long-term credential 2457 mechanism of STUN, so no MESSAGE-INTEGRITY attribute is included in 2458 the message. An application wishing to ensure that its data is not 2459 altered or forged must integrity-protect its data at the application 2460 level. 2462 Upon receipt of the Send indication, the server extracts the 2463 application data and sends it in a UDP datagram to Peer A, with the 2464 relayed transport address as the source transport address of the 2465 datagram, and with the DF bit set as requested. Note that, had the 2466 client not previously established a permission for Peer A's server- 2467 reflexive IP address, then the server would have silently discarded 2468 the Send indication instead. 2470 Peer A then replies with its own UDP datagram containing application 2471 data. The datagram is sent to the relayed transport address on the 2472 server. When this arrives, the server creates a Data indication 2473 containing the source of the UDP datagram in the XOR-PEER-ADDRESS 2474 attribute, and the data from the UDP datagram in the DATA attribute. 2475 The resulting Data indication is then sent to the client. 2477 TURN TURN Peer Peer 2478 client server A B 2479 |--- ChannelBind request ----------->| | | 2480 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2481 | CHANNEL-NUMBER=0x4000 | | | 2482 | XOR-PEER-ADDRESS=192.0.2.210:49191 | | 2483 | USERNAME="George" | | | 2484 | REALM="example.com" | | | 2485 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2486 | MESSAGE-INTEGRITY=... | | | 2487 | | | | 2488 |<-- ChannelBind success response ---| | | 2489 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2490 | MESSAGE-INTEGRITY=... | | | 2492 The client now binds a channel to Peer B, specifying a free channel 2493 number (0x4000) in the CHANNEL-NUMBER attribute, and Peer B's 2494 transport address in the XOR-PEER-ADDRESS attribute. As before, the 2495 client re-uses the username, realm, and nonce from its last request 2496 in the message. 2498 Upon receipt of the request, the server binds the channel number to 2499 the peer, installs a permission for Peer B's IP address, and then 2500 replies with ChannelBind success response. 2502 TURN TURN Peer Peer 2503 client server A B 2504 |--- ChannelData ------------------->| | | 2505 | Channel-number=0x4000 |--- UDP datagram --------->| 2506 | Data=... | Data=... | 2507 | | | | 2508 | |<-- UDP datagram ----------| 2509 | | Data=... | | 2510 |<-- ChannelData --------------------| | | 2511 | Channel-number=0x4000 | | | 2512 | Data=... | | | 2514 The client now sends a ChannelData message to the server with data 2515 destined for Peer B. The ChannelData message is not a STUN message, 2516 and thus has no transaction id. Instead, it has only three fields: a 2517 channel number, data, and data length; here the channel number field 2518 is 0x4000 (the channel the client just bound to Peer B). When the 2519 server receives the ChannelData message, it checks that the channel 2520 is currently bound (which it is) and then sends the data onward to 2521 Peer B in a UDP datagram, using the relayed transport address as the 2522 source transport address and 192.0.2.210:49191 (the value of the XOR- 2523 PEER-ADDRESS attribute in the ChannelBind request) as the destination 2524 transport address. 2526 Later, Peer B sends a UDP datagram back to the relayed transport 2527 address. This causes the server to send a ChannelData message to the 2528 client containing the data from the UDP datagram. The server knows 2529 to which client to send the ChannelData message because of the 2530 relayed transport address at which the UDP datagram arrived, and 2531 knows to use channel 0x4000 because this is the channel bound to 2532 192.0.2.210:49191. Note that if there had not been any channel 2533 number bound to that address, the server would have used a Data 2534 indication instead. 2536 TURN TURN Peer Peer 2537 client server A B 2538 |--- Refresh request --------------->| | | 2539 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 2540 | SOFTWARE="Example client 1.03" | | | 2541 | USERNAME="George" | | | 2542 | REALM="example.com" | | | 2543 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2544 | MESSAGE-INTEGRITY=... | | | 2545 | | | | 2546 |<-- Refresh error response ---------| | | 2547 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 2548 | SOFTWARE="Example server, version 1.17" | | 2549 | ERROR-CODE=438 (Stale Nonce) | | | 2550 | REALM="example.com" | | | 2551 | NONCE="npSw1Xw239bBwGYhjNWgz2yH47sxB2j" | | 2552 | | | | 2553 |--- Refresh request --------------->| | | 2554 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 2555 | SOFTWARE="Example client 1.03" | | | 2556 | USERNAME="George" | | | 2557 | REALM="example.com" | | | 2558 | NONCE="npSw1Xw239bBwGYhjNWgz2yH47sxB2j" | | 2559 | MESSAGE-INTEGRITY=... | | | 2560 | | | | 2561 |<-- Refresh success response -------| | | 2562 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 2563 | SOFTWARE="Example server, version 1.17" | | 2564 | LIFETIME=600 (10 minutes) | | | 2566 Sometime before the 20 minute lifetime is up, the client refreshes 2567 the allocation. This is done using a Refresh request. As before, 2568 the client includes the latest username, realm, and nonce values in 2569 the request. The client also includes the SOFTWARE attribute, 2570 following the recommended practice of always including this attribute 2571 in Allocate and Refresh messages. When the server receives the 2572 Refresh request, it notices that the nonce value has expired, and so 2573 replies with 438 (Stale Nonce) error given a new nonce value. The 2574 client then reattempts the request, this time with the new nonce 2575 value. This second attempt is accepted, and the server replies with 2576 a success response. Note that the client did not include a LIFETIME 2577 attribute in the request, so the server refreshes the allocation for 2578 the default lifetime of 10 minutes (as can be seen by the LIFETIME 2579 attribute in the success response). 2581 17. Security Considerations 2583 This section considers attacks that are possible in a TURN 2584 deployment, and discusses how they are mitigated by mechanisms in the 2585 protocol or recommended practices in the implementation. 2587 Most of the attacks on TURN are mitigated by the server requiring 2588 requests be authenticated. Thus, this specification requires the use 2589 of authentication. The mandatory-to-implement mechanism is the long- 2590 term credential mechanism of STUN. Other authentication mechanisms 2591 of equal or stronger security properties may be used. However, it is 2592 important to ensure that they can be invoked in an inter-operable 2593 way. 2595 17.1. Outsider Attacks 2597 Outsider attacks are ones where the attacker has no credentials in 2598 the system, and is attempting to disrupt the service seen by the 2599 client or the server. 2601 17.1.1. Obtaining Unauthorized Allocations 2603 An attacker might wish to obtain allocations on a TURN server for any 2604 number of nefarious purposes. A TURN server provides a mechanism for 2605 sending and receiving packets while cloaking the actual IP address of 2606 the client. This makes TURN servers an attractive target for 2607 attackers who wish to use it to mask their true identity. 2609 An attacker might also wish to simply utilize the services of a TURN 2610 server without paying for them. Since TURN services require 2611 resources from the provider, it is anticipated that their usage will 2612 come with a cost. 2614 These attacks are prevented using the long-term credential mechanism, 2615 which allows the TURN server to determine the identity of the 2616 requestor and whether the requestor is allowed to obtain the 2617 allocation. 2619 17.1.2. Offline Dictionary Attacks 2621 The long-term credential mechanism used by TURN is subject to offline 2622 dictionary attacks. An attacker that is capable of eavesdropping on 2623 a message exchange between a client and server can determine the 2624 password by trying a number of candidate passwords and seeing if one 2625 of them is correct. This attack works when the passwords are low 2626 entropy, such as a word from the dictionary. This attack can be 2627 mitigated by using strong passwords with large entropy. In 2628 situations where even stronger mitigation is required, (D)TLS 2629 transport between the client and the server can be used. 2631 17.1.3. Faked Refreshes and Permissions 2633 An attacker might wish to attack an active allocation by sending it a 2634 Refresh request with an immediate expiration, in order to delete it 2635 and disrupt service to the client. This is prevented by 2636 authentication of refreshes. Similarly, an attacker wishing to send 2637 CreatePermission requests to create permissions to undesirable 2638 destinations is prevented from doing so through authentication. The 2639 motivations for such an attack are described in Section 17.2. 2641 17.1.4. Fake Data 2643 An attacker might wish to send data to the client or the peer, as if 2644 they came from the peer or client, respectively. To do that, the 2645 attacker can send the client a faked Data Indication or ChannelData 2646 message, or send the TURN server a faked Send Indication or 2647 ChannelData message. 2649 Since indications and ChannelData messages are not authenticated, 2650 this attack is not prevented by TURN. However, this attack is 2651 generally present in IP-based communications and is not substantially 2652 worsened by TURN. Consider a normal, non-TURN IP session between 2653 hosts A and B. An attacker can send packets to B as if they came from 2654 A by sending packets towards A with a spoofed IP address of B. This 2655 attack requires the attacker to know the IP addresses of A and B. 2656 With TURN, an attacker wishing to send packets towards a client using 2657 a Data indication needs to know its IP address (and port), the IP 2658 address and port of the TURN server, and the IP address and port of 2659 the peer (for inclusion in the XOR-PEER-ADDRESS attribute). To send 2660 a fake ChannelData message to a client, an attacker needs to know the 2661 IP address and port of the client, the IP address and port of the 2662 TURN server, and the channel number. This particular combination is 2663 mildly more guessable than in the non-TURN case. 2665 These attacks are more properly mitigated by application-layer 2666 authentication techniques. In the case of real-time traffic, usage 2667 of SRTP [RFC3711] prevents these attacks. 2669 In some situations, the TURN server may be situated in the network 2670 such that it is able to send to hosts to which the client cannot 2671 directly send. This can happen, for example, if the server is 2672 located behind a firewall that allows packets from outside the 2673 firewall to be delivered to the server, but not to other hosts behind 2674 the firewall. In these situations, an attacker could send the server 2675 a Send indication with an XOR-PEER-ADDRESS attribute containing the 2676 transport address of one of the other hosts behind the firewall. If 2677 the server was to allow relaying of traffic to arbitrary peers, then 2678 this would provide a way for the attacker to attack arbitrary hosts 2679 behind the firewall. 2681 To mitigate this attack, TURN requires that the client establish a 2682 permission to a host before sending it data. Thus, an attacker can 2683 only attack hosts with which the client is already communicating, 2684 unless the attacker is able to create authenticated requests. 2685 Furthermore, the server administrator may configure the server to 2686 restrict the range of IP addresses and ports to which it will relay 2687 data. To provide even greater security, the server administrator can 2688 require that the client use (D)TLS for all communication between the 2689 client and the server. 2691 17.1.5. Impersonating a Server 2693 When a client learns a relayed address from a TURN server, it uses 2694 that relayed address in application protocols to receive traffic. 2695 Therefore, an attacker wishing to intercept or redirect that traffic 2696 might try to impersonate a TURN server and provide the client with a 2697 faked relayed address. 2699 This attack is prevented through the long-term credential mechanism, 2700 which provides message integrity for responses in addition to 2701 verifying that they came from the server. Furthermore, an attacker 2702 cannot replay old server responses as the transaction id in the STUN 2703 header prevents this. Replay attacks are further thwarted through 2704 frequent changes to the nonce value. 2706 17.1.6. Eavesdropping Traffic 2708 TURN concerns itself primarily with authentication and message 2709 integrity. Confidentiality is only a secondary concern, as TURN 2710 control messages do not include information that is particularly 2711 sensitive. The primary protocol content of the messages is the IP 2712 address of the peer. If it is important to prevent an eavesdropper 2713 on a TURN connection from learning this, TURN can be run over (D)TLS. 2715 Confidentiality for the application data relayed by TURN is best 2716 provided by the application protocol itself, since running TURN over 2717 (D)TLS does not protect application data between the server and the 2718 peer. If confidentiality of application data is important, then the 2719 application should encrypt or otherwise protect its data. For 2720 example, for real-time media, confidentiality can be provided by 2721 using SRTP. 2723 17.1.7. TURN Loop Attack 2725 An attacker might attempt to cause data packets to loop indefinitely 2726 between two TURN servers. The attack goes as follows. First, the 2727 attacker sends an Allocate request to server A, using the source 2728 address of server B. Server A will send its response to server B, and 2729 for the attack to succeed, the attacker must have the ability to 2730 either view or guess the contents of this response, so that the 2731 attacker can learn the allocated relayed transport address. The 2732 attacker then sends an Allocate request to server B, using the source 2733 address of server A. Again, the attacker must be able to view or 2734 guess the contents of the response, so it can send learn the 2735 allocated relayed transport address. Using the same spoofed source 2736 address technique, the attacker then binds a channel number on server 2737 A to the relayed transport address on server B, and similarly binds 2738 the same channel number on server B to the relayed transport address 2739 on server A. Finally, the attacker sends a ChannelData message to 2740 server A. 2742 The result is a data packet that loops from the relayed transport 2743 address on server A to the relayed transport address on server B, 2744 then from server B's transport address to server A's transport 2745 address, and then around the loop again. 2747 This attack is mitigated as follows. By requiring all requests to be 2748 authenticated and/or by randomizing the port number allocated for the 2749 relayed transport address, the server forces the attacker to either 2750 intercept or view responses sent to a third party (in this case, the 2751 other server) so that the attacker can authenticate the requests and 2752 learn the relayed transport address. Without one of these two 2753 measures, an attacker can guess the contents of the responses without 2754 needing to see them, which makes the attack much easier to perform. 2755 Furthermore, by requiring authenticated requests, the server forces 2756 the attacker to have credentials acceptable to the server, which 2757 turns this from an outsider attack into an insider attack and allows 2758 the attack to be traced back to the client initiating it. 2760 The attack can be further mitigated by imposing a per-username limit 2761 on the bandwidth used to relay data by allocations owned by that 2762 username, to limit the impact of this attack on other allocations. 2764 More mitigation can be achieved by decrementing the TTL when relaying 2765 data packets (if the underlying OS allows this). 2767 17.2. Firewall Considerations 2769 A key security consideration of TURN is that TURN should not weaken 2770 the protections afforded by firewalls deployed between a client and a 2771 TURN server. It is anticipated that TURN servers will often be 2772 present on the public Internet, and clients may often be inside 2773 enterprise networks with corporate firewalls. If TURN servers 2774 provide a 'backdoor' for reaching into the enterprise, TURN will be 2775 blocked by these firewalls. 2777 TURN servers therefore emulate the behavior of NAT devices that 2778 implement address-dependent filtering [RFC4787], a property common in 2779 many firewalls as well. When a NAT or firewall implements this 2780 behavior, packets from an outside IP address are only allowed to be 2781 sent to an internal IP address and port if the internal IP address 2782 and port had recently sent a packet to that outside IP address. TURN 2783 servers introduce the concept of permissions, which provide exactly 2784 this same behavior on the TURN server. An attacker cannot send a 2785 packet to a TURN server and expect it to be relayed towards the 2786 client, unless the client has tried to contact the attacker first. 2788 It is important to note that some firewalls have policies that are 2789 even more restrictive than address-dependent filtering. Firewalls 2790 can also be configured with address- and port-dependent filtering, or 2791 can be configured to disallow inbound traffic entirely. In these 2792 cases, if a client is allowed to connect the TURN server, 2793 communications to the client will be less restrictive than what the 2794 firewall would normally allow. 2796 17.2.1. Faked Permissions 2798 In firewalls and NAT devices, permissions are granted implicitly 2799 through the traversal of a packet from the inside of the network 2800 towards the outside peer. Thus, a permission cannot, by definition, 2801 be created by any entity except one inside the firewall or NAT. With 2802 TURN, this restriction no longer holds. Since the TURN server sits 2803 outside the firewall, at attacker outside the firewall can now send a 2804 message to the TURN server and try to create a permission for itself. 2806 This attack is prevented because all messages that create permissions 2807 (i.e., ChannelBind and CreatePermission) are authenticated. 2809 17.2.2. Blacklisted IP Addresses 2811 Many firewalls can be configured with blacklists that prevent a 2812 client behind the firewall from sending packets to, or receiving 2813 packets from, ranges of blacklisted IP addresses. This is 2814 accomplished by inspecting the source and destination addresses of 2815 packets entering and exiting the firewall, respectively. 2817 This feature is also present in TURN, since TURN servers are allowed 2818 to arbitrarily restrict the range of addresses of peers that they 2819 will relay to. 2821 17.2.3. Running Servers on Well-Known Ports 2823 A malicious client behind a firewall might try to connect to a TURN 2824 server and obtain an allocation which it then uses to run a server. 2825 For example, a client might try to run a DNS server or FTP server. 2827 This is not possible in TURN. A TURN server will never accept 2828 traffic from a peer for which the client has not installed a 2829 permission. Thus, peers cannot just connect to the allocated port in 2830 order to obtain the service. 2832 17.3. Insider Attacks 2834 In insider attacks, a client has legitimate credentials but defies 2835 the trust relationship that goes with those credentials. These 2836 attacks cannot be prevented by cryptographic means but need to be 2837 considered in the design of the protocol. 2839 17.3.1. DoS against TURN Server 2841 A client wishing to disrupt service to other clients might obtain an 2842 allocation and then flood it with traffic, in an attempt to swamp the 2843 server and prevent it from servicing other legitimate clients. This 2844 is mitigated by the recommendation that the server limit the amount 2845 of bandwidth it will relay for a given username. This won't prevent 2846 a client from sending a large amount of traffic, but it allows the 2847 server to immediately discard traffic in excess. 2849 Since each allocation uses a port number on the IP address of the 2850 TURN server, the number of allocations on a server is finite. An 2851 attacker might attempt to consume all of them by requesting a large 2852 number of allocations. This is prevented by the recommendation that 2853 the server impose a limit of the number of allocations active at a 2854 time for a given username. 2856 17.3.2. Anonymous Relaying of Malicious Traffic 2858 TURN servers provide a degree of anonymization. A client can send 2859 data to peers without revealing its own IP address. TURN servers may 2860 therefore become attractive vehicles for attackers to launch attacks 2861 against targets without fear of detection. Indeed, it is possible 2862 for a client to chain together multiple TURN servers, such that any 2863 number of relays can be used before a target receives a packet. 2865 Administrators who are worried about this attack can maintain logs 2866 that capture the actual source IP and port of the client, and perhaps 2867 even every permission that client installs. This will allow for 2868 forensic tracing to determine the original source, should it be 2869 discovered that an attack is being relayed through a TURN server. 2871 17.3.3. Manipulating Other Allocations 2873 An attacker might attempt to disrupt service to other users of the 2874 TURN server by sending Refresh requests or CreatePermission requests 2875 that (through source address spoofing) appear to be coming from 2876 another user of the TURN server. TURN prevents this by requiring 2877 that the credentials used in CreatePermission, Refresh, and 2878 ChannelBind messages match those used to create the initial 2879 allocation. Thus, the fake requests from the attacker will be 2880 rejected. 2882 17.4. Other Considerations 2884 Any relay addresses learned through an Allocate request will not 2885 operate properly with IPsec Authentication Header (AH) [RFC4302] in 2886 transport or tunnel mode. However, tunnel-mode IPsec Encapsulating 2887 Security Payload (ESP) [RFC4303] should still operate. 2889 18. IANA Considerations 2891 Since TURN is an extension to STUN [RFC5389], the methods, 2892 attributes, and error codes defined in this specification are new 2893 methods, attributes, and error codes for STUN. IANA has added these 2894 new protocol elements to the IANA registry of STUN protocol elements. 2896 The codepoints for the new STUN methods defined in this specification 2897 are listed in Section 13. 2899 The codepoints for the new STUN attributes defined in this 2900 specification are listed in Section 14. 2902 The codepoints for the new STUN error codes defined in this 2903 specification are listed in Section 15. 2905 IANA has allocated the SRV service name of "turn" for TURN over UDP 2906 or TCP, and the service name of "turns" for TURN over (D)TLS. 2908 IANA has created a registry for TURN channel numbers, initially 2909 populated as follows: 2911 o 0x0000 through 0x3FFF: Reserved and not available for use, since 2912 they conflict with the STUN header. 2914 o 0x4000 through 0x7FFF: A TURN implementation is free to use 2915 channel numbers in this range. 2917 o 0x8000 through 0xFFFF: Unassigned. 2919 Any change to this registry must be made through an IETF Standards 2920 Action. 2922 19. IAB Considerations 2924 The IAB has studied the problem of "Unilateral Self Address Fixing" 2925 (UNSAF), which is the general process by which a client attempts to 2926 determine its address in another realm on the other side of a NAT 2927 through a collaborative protocol-reflection mechanism [RFC3424]. The 2928 TURN extension is an example of a protocol that performs this type of 2929 function. The IAB has mandated that any protocols developed for this 2930 purpose document a specific set of considerations. These 2931 considerations and the responses for TURN are documented in this 2932 section. 2934 Consideration 1: Precise definition of a specific, limited-scope 2935 problem that is to be solved with the UNSAF proposal. A short-term 2936 fix should not be generalized to solve other problems. Such 2937 generalizations lead to the prolonged dependence on and usage of the 2938 supposed short-term fix -- meaning that it is no longer accurate to 2939 call it "short-term". 2941 Response: TURN is a protocol for communication between a relay (= 2942 TURN server) and its client. The protocol allows a client that is 2943 behind a NAT to obtain and use a public IP address on the relay. As 2944 a convenience to the client, TURN also allows the client to determine 2945 its server-reflexive transport address. 2947 Consideration 2: Description of an exit strategy/transition plan. 2948 The better short-term fixes are the ones that will naturally see less 2949 and less use as the appropriate technology is deployed. 2951 Response: TURN will no longer be needed once there are no longer any 2952 NATs. Unfortunately, as of the date of publication of this document, 2953 it no longer seems very likely that NATs will go away any time soon. 2954 However, the need for TURN will also decrease as the number of NATs 2955 with the mapping property of Endpoint-Independent Mapping [RFC4787] 2956 increases. 2958 Consideration 3: Discussion of specific issues that may render 2959 systems more "brittle". For example, approaches that involve using 2960 data at multiple network layers create more dependencies, increase 2961 debugging challenges, and make it harder to transition. 2963 Response: TURN is "brittle" in that it requires the NAT bindings 2964 between the client and the server to be maintained unchanged for the 2965 lifetime of the allocation. This is typically done using keep- 2966 alives. If this is not done, then the client will lose its 2967 allocation and can no longer exchange data with its peers. 2969 Consideration 4: Identify requirements for longer-term, sound 2970 technical solutions; contribute to the process of finding the right 2971 longer-term solution. 2973 Response: The need for TURN will be reduced once NATs implement the 2974 recommendations for NAT UDP behavior documented in [RFC4787]. 2975 Applications are also strongly urged to use ICE [RFC5245] to 2976 communicate with peers; though ICE uses TURN, it does so only as a 2977 last resort, and uses it in a controlled manner. 2979 Consideration 5: Discussion of the impact of the noted practical 2980 issues with existing deployed NATs and experience reports. 2982 Response: Some NATs deployed today exhibit a mapping behavior other 2983 than Endpoint-Independent mapping. These NATs are difficult to work 2984 with, as they make it difficult or impossible for protocols like ICE 2985 to use server-reflexive transport addresses on those NATs. A client 2986 behind such a NAT is often forced to use a relay protocol like TURN 2987 because "UDP hole punching" techniques [RFC5128] do not work. 2989 20. Acknowledgements 2991 The authors would like to thank the various participants in the 2992 BEHAVE working group for their many comments on this document. Marc 2993 Petit-Huguenin, Remi Denis-Courmont, Jason Fischl, Derek MacDonald, 2994 Scott Godin, Cullen Jennings, Lars Eggert, Magnus Westerlund, Benny 2995 Prijono, and Eric Rescorla have been particularly helpful, with Eric 2996 suggesting the channel allocation mechanism, Cullen suggesting an 2997 earlier version of the EVEN-PORT mechanism, and Marc spending many 2998 hours implementing the preliminary versions to look for problems. 2999 Christian Huitema was an early contributor to this document and was a 3000 co-author on the first few versions. Finally, the authors would like 3001 to thank Dan Wing for both his contributions to the text and his huge 3002 help in restarting progress on this document after work had stalled. 3004 21. References 3006 21.1. Normative References 3008 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 3009 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 3010 October 2008. 3012 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3013 Requirement Levels", BCP 14, RFC 2119, March 1997. 3015 [RFC2474] Nichols, K., Blake, S., Baker, F., and D. Black, 3016 "Definition of the Differentiated Services Field (DS 3017 Field) in the IPv4 and IPv6 Headers", RFC 2474, 3018 December 1998. 3020 [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 3021 of Explicit Congestion Notification (ECN) to IP", 3022 RFC 3168, September 2001. 3024 [RFC1122] Braden, R., "Requirements for Internet Hosts - 3025 Communication Layers", STD 3, RFC 1122, October 1989. 3027 21.2. Informative References 3029 [RFC1191] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 3030 November 1990. 3032 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 3033 September 1981. 3035 [RFC1918] Rekhter, Y., Moskowitz, R., Karrenberg, D., Groot, G., and 3036 E. Lear, "Address Allocation for Private Internets", 3037 BCP 5, RFC 1918, February 1996. 3039 [RFC3424] Daigle, L. and IAB, "IAB Considerations for UNilateral 3040 Self-Address Fixing (UNSAF) Across Network Address 3041 Translation", RFC 3424, November 2002. 3043 [RFC4787] Audet, F. and C. Jennings, "Network Address Translation 3044 (NAT) Behavioral Requirements for Unicast UDP", BCP 127, 3045 RFC 4787, January 2007. 3047 [RFC5245] Rosenberg, J., "Interactive Connectivity Establishment 3048 (ICE): A Protocol for Network Address Translator (NAT) 3049 Traversal for Offer/Answer Protocols", RFC 5245, 3050 April 2010. 3052 [RFC6062] Perreault, S. and J. Rosenberg, "Traversal Using Relays 3053 around NAT (TURN) Extensions for TCP Allocations", 3054 RFC 6062, November 2010. 3056 [RFC6156] Camarillo, G., Novo, O., and S. Perreault, "Traversal 3057 Using Relays around NAT (TURN) Extension for IPv6", 3058 RFC 6156, April 2011. 3060 [RFC6056] Larsen, M. and F. Gont, "Recommendations for Transport- 3061 Protocol Port Randomization", BCP 156, RFC 6056, 3062 January 2011. 3064 [RFC5128] Srisuresh, P., Ford, B., and D. Kegel, "State of Peer-to- 3065 Peer (P2P) Communication across Network Address 3066 Translators (NATs)", RFC 5128, March 2008. 3068 [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and 3069 L. Jones, "SOCKS Protocol Version 5", RFC 1928, 3070 March 1996. 3072 [RFC3550] Schulzrinne, H., Casner, S., Frederick, R., and V. 3073 Jacobson, "RTP: A Transport Protocol for Real-Time 3074 Applications", STD 64, RFC 3550, July 2003. 3076 [RFC3711] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. 3077 Norrman, "The Secure Real-time Transport Protocol (SRTP)", 3078 RFC 3711, March 2004. 3080 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, 3081 December 2005. 3083 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 3084 RFC 4303, December 2005. 3086 [RFC4821] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 3087 Discovery", RFC 4821, March 2007. 3089 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 3090 A., Peterson, J., Sparks, R., Handley, M., and E. 3091 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 3092 June 2002. 3094 [I-D.rosenberg-mmusic-ice-nonsip] 3095 Rosenberg, J., "Guidelines for Usage of Interactive 3096 Connectivity Establishment (ICE) by non Session 3097 Initiation Protocol (SIP) Protocols", 3098 draft-rosenberg-mmusic-ice-nonsip-01 (work in progress), 3099 July 2008. 3101 [I-D.ietf-tram-turn-server-discovery] 3102 Patil, P., Reddy, T., and D. Wing, "TURN Server Auto 3103 Discovery", draft-ietf-tram-turn-server-discovery-00 (work 3104 in progress), July 2014. 3106 [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness 3107 Requirements for Security", BCP 106, RFC 4086, June 2005. 3109 [Port-Numbers] 3110 "IANA Port Numbers Registry", 2005, 3111 . 3113 [Frag-Harmful] 3114 "Fragmentation Considered Harmful", . 3117 [Protocol-Numbers] 3118 "IANA Protocol Numbers Registry", 2005, 3119 . 3121 Authors' Addresses 3123 Tirumaleswar Reddy (editor) 3124 Cisco Systems, Inc. 3125 Cessna Business Park, Varthur Hobl 3126 Sarjapur Marathalli Outer Ring Road 3127 Bangalore, Karnataka 560103 3128 India 3130 Email: tireddy@cisco.com 3132 Alan Johnston (editor) 3133 Avaya 3134 St. Louis, MO 3135 USA 3137 Email: alan.b.johnston@gmail.com 3138 Rohan Mahy 3139 (Unaffiliated) 3141 Email: rohan@ekabal.com 3143 Philip Matthews 3144 Alcatel-Lucent 3145 600 March Road 3146 Ottawa, Ontario 3147 Canada 3149 Email: philip_matthews@magma.ca 3151 Jonathan Rosenberg 3152 jdrosen.net 3153 Edison, NJ 3154 USA 3156 Email: jdrosen@jdrosen.net 3157 URI: http://www.jdrosen.net