idnits 2.17.1 draft-ietf-tram-turnbis-11.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 (June 1, 2017) is 2519 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 667, but not defined ** Obsolete normative reference: RFC 5389 (Obsoleted by RFC 8489) ** Obsolete normative reference: RFC 6145 (Obsoleted by RFC 7915) ** Obsolete normative reference: RFC 3697 (Obsoleted by RFC 6437) == Outdated reference: A later version (-21) exists of draft-ietf-tram-stunbis-12 ** Obsolete normative reference: RFC 6555 (Obsoleted by RFC 8305) ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) -- 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 (-20) exists of draft-ietf-tram-stun-pmtud-05 -- Obsolete informational reference (is this intentional?): RFC 5766 (Obsoleted by RFC 8656) Summary: 5 errors (**), 0 flaws (~~), 5 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 TRAM WG T. Reddy, Ed. 3 Internet-Draft McAfee 4 Intended status: Standards Track A. Johnston, Ed. 5 Expires: December 3, 2017 Unaffiliated 6 P. Matthews 7 Alcatel-Lucent 8 J. Rosenberg 9 jdrosen.net 10 June 1, 2017 12 Traversal Using Relays around NAT (TURN): Relay Extensions to Session 13 Traversal Utilities for NAT (STUN) 14 draft-ietf-tram-turnbis-11 16 Abstract 18 If a host is located behind a NAT, then in certain situations it can 19 be impossible for that host to communicate directly with other hosts 20 (peers). In these situations, it is necessary for the host to use 21 the services of an intermediate node that acts as a communication 22 relay. This specification defines a protocol, called TURN (Traversal 23 Using Relays around NAT), that allows the host to control the 24 operation of the relay and to exchange packets with its peers using 25 the relay. TURN differs from some other relay control protocols in 26 that it allows a client to communicate with multiple peers using a 27 single relay address. 29 The TURN protocol was designed to be used as part of the ICE 30 (Interactive Connectivity Establishment) approach to NAT traversal, 31 though it also can be used without ICE. 33 Status of This Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at http://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on December 3, 2017. 50 Copyright Notice 52 Copyright (c) 2017 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 68 2. Overview of Operation . . . . . . . . . . . . . . . . . . . . 6 69 2.1. Transports . . . . . . . . . . . . . . . . . . . . . . . 8 70 2.2. Allocations . . . . . . . . . . . . . . . . . . . . . . . 9 71 2.3. Permissions . . . . . . . . . . . . . . . . . . . . . . . 11 72 2.4. Send Mechanism . . . . . . . . . . . . . . . . . . . . . 12 73 2.5. Channels . . . . . . . . . . . . . . . . . . . . . . . . 14 74 2.6. Unprivileged TURN Servers . . . . . . . . . . . . . . . . 16 75 2.7. Avoiding IP Fragmentation . . . . . . . . . . . . . . . . 16 76 2.8. RTP Support . . . . . . . . . . . . . . . . . . . . . . . 18 77 2.9. Discovery of TURN server . . . . . . . . . . . . . . . . 18 78 2.9.1. TURN URI Scheme Semantics . . . . . . . . . . . . . . 18 79 2.10. Happy Eyeballs for TURN . . . . . . . . . . . . . . . . . 18 80 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 19 81 4. General Behavior . . . . . . . . . . . . . . . . . . . . . . 21 82 5. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . 23 83 6. Creating an Allocation . . . . . . . . . . . . . . . . . . . 25 84 6.1. Sending an Allocate Request . . . . . . . . . . . . . . . 25 85 6.2. Receiving an Allocate Request . . . . . . . . . . . . . . 26 86 6.3. Receiving an Allocate Success Response . . . . . . . . . 31 87 6.4. Receiving an Allocate Error Response . . . . . . . . . . 32 88 7. Refreshing an Allocation . . . . . . . . . . . . . . . . . . 34 89 7.1. Sending a Refresh Request . . . . . . . . . . . . . . . . 34 90 7.2. Receiving a Refresh Request . . . . . . . . . . . . . . . 35 91 7.3. Receiving a Refresh Response . . . . . . . . . . . . . . 35 92 8. Permissions . . . . . . . . . . . . . . . . . . . . . . . . . 36 93 9. CreatePermission . . . . . . . . . . . . . . . . . . . . . . 37 94 9.1. Forming a CreatePermission Request . . . . . . . . . . . 37 95 9.2. Receiving a CreatePermission Request . . . . . . . . . . 37 96 9.3. Receiving a CreatePermission Response . . . . . . . . . . 38 97 10. Send and Data Methods . . . . . . . . . . . . . . . . . . . . 38 98 10.1. Forming a Send Indication . . . . . . . . . . . . . . . 38 99 10.2. Receiving a Send Indication . . . . . . . . . . . . . . 39 100 10.3. Receiving a UDP Datagram . . . . . . . . . . . . . . . . 40 101 10.4. Receiving a Data Indication with DATA attribute . . . . 40 102 10.5. Receiving an ICMP Packet . . . . . . . . . . . . . . . . 41 103 10.6. Receiving a Data Indication with an ICMP attribute . . . 41 104 11. Channels . . . . . . . . . . . . . . . . . . . . . . . . . . 42 105 11.1. Sending a ChannelBind Request . . . . . . . . . . . . . 44 106 11.2. Receiving a ChannelBind Request . . . . . . . . . . . . 44 107 11.3. Receiving a ChannelBind Response . . . . . . . . . . . . 45 108 11.4. The ChannelData Message . . . . . . . . . . . . . . . . 46 109 11.5. Sending a ChannelData Message . . . . . . . . . . . . . 46 110 11.6. Receiving a ChannelData Message . . . . . . . . . . . . 47 111 11.7. Relaying Data from the Peer . . . . . . . . . . . . . . 48 112 12. Packet Translations . . . . . . . . . . . . . . . . . . . . . 48 113 12.1. IPv4-to-IPv6 Translations . . . . . . . . . . . . . . . 48 114 12.2. IPv6-to-IPv6 Translations . . . . . . . . . . . . . . . 49 115 12.3. IPv6-to-IPv4 Translations . . . . . . . . . . . . . . . 50 116 13. IP Header Fields . . . . . . . . . . . . . . . . . . . . . . 51 117 14. New STUN Methods . . . . . . . . . . . . . . . . . . . . . . 53 118 15. New STUN Attributes . . . . . . . . . . . . . . . . . . . . . 53 119 15.1. CHANNEL-NUMBER . . . . . . . . . . . . . . . . . . . . . 54 120 15.2. LIFETIME . . . . . . . . . . . . . . . . . . . . . . . . 54 121 15.3. XOR-PEER-ADDRESS . . . . . . . . . . . . . . . . . . . . 54 122 15.4. DATA . . . . . . . . . . . . . . . . . . . . . . . . . . 54 123 15.5. XOR-RELAYED-ADDRESS . . . . . . . . . . . . . . . . . . 54 124 15.6. REQUESTED-ADDRESS-FAMILY . . . . . . . . . . . . . . . . 55 125 15.7. EVEN-PORT . . . . . . . . . . . . . . . . . . . . . . . 55 126 15.8. REQUESTED-TRANSPORT . . . . . . . . . . . . . . . . . . 56 127 15.9. DONT-FRAGMENT . . . . . . . . . . . . . . . . . . . . . 56 128 15.10. RESERVATION-TOKEN . . . . . . . . . . . . . . . . . . . 56 129 15.11. ADDITIONAL-ADDRESS-FAMILY . . . . . . . . . . . . . . . 57 130 15.12. ADDRESS-ERROR-CODE Attribute . . . . . . . . . . . . . . 57 131 15.13. ICMP Attribute . . . . . . . . . . . . . . . . . . . . . 58 132 16. New STUN Error Response Codes . . . . . . . . . . . . . . . . 58 133 17. Detailed Example . . . . . . . . . . . . . . . . . . . . . . 59 134 18. Security Considerations . . . . . . . . . . . . . . . . . . . 67 135 18.1. Outsider Attacks . . . . . . . . . . . . . . . . . . . . 67 136 18.1.1. Obtaining Unauthorized Allocations . . . . . . . . . 67 137 18.1.2. Offline Dictionary Attacks . . . . . . . . . . . . . 67 138 18.1.3. Faked Refreshes and Permissions . . . . . . . . . . 68 139 18.1.4. Fake Data . . . . . . . . . . . . . . . . . . . . . 68 140 18.1.5. Impersonating a Server . . . . . . . . . . . . . . . 69 141 18.1.6. Eavesdropping Traffic . . . . . . . . . . . . . . . 69 142 18.1.7. TURN Loop Attack . . . . . . . . . . . . . . . . . . 70 143 18.2. Firewall Considerations . . . . . . . . . . . . . . . . 70 144 18.2.1. Faked Permissions . . . . . . . . . . . . . . . . . 71 145 18.2.2. Blacklisted IP Addresses . . . . . . . . . . . . . . 71 146 18.2.3. Running Servers on Well-Known Ports . . . . . . . . 72 147 18.3. Insider Attacks . . . . . . . . . . . . . . . . . . . . 72 148 18.3.1. DoS against TURN Server . . . . . . . . . . . . . . 72 149 18.3.2. Anonymous Relaying of Malicious Traffic . . . . . . 72 150 18.3.3. Manipulating Other Allocations . . . . . . . . . . . 73 151 18.4. Tunnel Amplification Attack . . . . . . . . . . . . . . 73 152 18.5. Other Considerations . . . . . . . . . . . . . . . . . . 74 153 19. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 74 154 20. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 75 155 21. Changes since RFC 5766 . . . . . . . . . . . . . . . . . . . 77 156 22. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 77 157 23. References . . . . . . . . . . . . . . . . . . . . . . . . . 77 158 23.1. Normative References . . . . . . . . . . . . . . . . . . 77 159 23.2. Informative References . . . . . . . . . . . . . . . . . 79 160 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 82 162 1. Introduction 164 A host behind a NAT may wish to exchange packets with other hosts, 165 some of which may also be behind NATs. To do this, the hosts 166 involved can use "hole punching" techniques (see [RFC5128]) in an 167 attempt discover a direct communication path; that is, a 168 communication path that goes from one host to another through 169 intervening NATs and routers, but does not traverse any relays. 171 As described in [RFC5128] and [RFC4787], hole punching techniques 172 will fail if both hosts are behind NATs that are not well behaved. 173 For example, if both hosts are behind NATs that have a mapping 174 behavior of "address-dependent mapping" or "address- and port- 175 dependent mapping", then hole punching techniques generally fail. 177 When a direct communication path cannot be found, it is necessary to 178 use the services of an intermediate host that acts as a relay for the 179 packets. This relay typically sits in the public Internet and relays 180 packets between two hosts that both sit behind NATs. 182 This specification defines a protocol, called TURN, that allows a 183 host behind a NAT (called the TURN client) to request that another 184 host (called the TURN server) act as a relay. The client can arrange 185 for the server to relay packets to and from certain other hosts 186 (called peers) and can control aspects of how the relaying is done. 187 The client does this by obtaining an IP address and port on the 188 server, called the relayed transport address. When a peer sends a 189 packet to the relayed transport address, the server relays the packet 190 to the client. When the client sends a data packet to the server, 191 the server relays it to the appropriate peer using the relayed 192 transport address as the source. 194 A client using TURN must have some way to communicate the relayed 195 transport address to its peers, and to learn each peer's IP address 196 and port (more precisely, each peer's server-reflexive transport 197 address, see Section 2). How this is done is out of the scope of the 198 TURN protocol. One way this might be done is for the client and 199 peers to exchange email messages. Another way is for the client and 200 its peers to use a special-purpose "introduction" or "rendezvous" 201 protocol (see [RFC5128] for more details). 203 If TURN is used with ICE [RFC5245], then the relayed transport 204 address and the IP addresses and ports of the peers are included in 205 the ICE candidate information that the rendezvous protocol must 206 carry. For example, if TURN and ICE are used as part of a multimedia 207 solution using SIP [RFC3261], then SIP serves the role of the 208 rendezvous protocol, carrying the ICE candidate information inside 209 the body of SIP messages. If TURN and ICE are used with some other 210 rendezvous protocol, then [I-D.rosenberg-mmusic-ice-nonsip] provides 211 guidance on the services the rendezvous protocol must perform. 213 Though the use of a TURN server to enable communication between two 214 hosts behind NATs is very likely to work, it comes at a high cost to 215 the provider of the TURN server, since the server typically needs a 216 high-bandwidth connection to the Internet . As a consequence, it is 217 best to use a TURN server only when a direct communication path 218 cannot be found. When the client and a peer use ICE to determine the 219 communication path, ICE will use hole punching techniques to search 220 for a direct path first and only use a TURN server when a direct path 221 cannot be found. 223 TURN was originally invented to support multimedia sessions signaled 224 using SIP. Since SIP supports forking, TURN supports multiple peers 225 per relayed transport address; a feature not supported by other 226 approaches (e.g., SOCKS [RFC1928]). However, care has been taken to 227 make sure that TURN is suitable for other types of applications. 229 TURN was designed as one piece in the larger ICE approach to NAT 230 traversal. Implementors of TURN are urged to investigate ICE and 231 seriously consider using it for their application. However, it is 232 possible to use TURN without ICE. 234 TURN is an extension to the STUN (Session Traversal Utilities for 235 NAT) protocol [RFC5389]. Most, though not all, TURN messages are 236 STUN-formatted messages. A reader of this document should be 237 familiar with STUN. 239 2. Overview of Operation 241 This section gives an overview of the operation of TURN. It is non- 242 normative. 244 In a typical configuration, a TURN client is connected to a private 245 network [RFC1918] and through one or more NATs to the public 246 Internet. On the public Internet is a TURN server. Elsewhere in the 247 Internet are one or more peers with which the TURN client wishes to 248 communicate. These peers may or may not be behind one or more NATs. 249 The client uses the server as a relay to send packets to these peers 250 and to receive packets from these peers. 252 Peer A 253 Server-Reflexive +---------+ 254 Transport Address | | 255 192.0.2.150:32102 | | 256 | /| | 257 TURN | / ^| Peer A | 258 Client's Server | / || | 259 Host Transport Transport | // || | 260 Address Address | // |+---------+ 261 10.1.1.2:49721 192.0.2.15:3478 |+-+ // Peer A 262 | | ||N| / Host Transport 263 | +-+ | ||A|/ Address 264 | | | | v|T| 192.168.100.2:49582 265 | | | | /+-+ 266 +---------+| | | |+---------+ / +---------+ 267 | || |N| || | // | | 268 | TURN |v | | v| TURN |/ | | 269 | Client |----|A|----------| Server |------------------| Peer B | 270 | | | |^ | |^ ^| | 271 | | |T|| | || || | 272 +---------+ | || +---------+| |+---------+ 273 | || | | 274 | || | | 275 +-+| | | 276 | | | 277 | | | 278 Client's | Peer B 279 Server-Reflexive Relayed Transport 280 Transport Address Transport Address Address 281 192.0.2.1:7000 192.0.2.15:50000 192.0.2.210:49191 283 Figure 1 285 Figure 1 shows a typical deployment. In this figure, the TURN client 286 and the TURN server are separated by a NAT, with the client on the 287 private side and the server on the public side of the NAT. This NAT 288 is assumed to be a "bad" NAT; for example, it might have a mapping 289 property of "address-and-port-dependent mapping" (see [RFC4787]). 291 The client talks to the server from a (IP address, port) combination 292 called the client's HOST TRANSPORT ADDRESS. (The combination of an 293 IP address and port is called a TRANSPORT ADDRESS.) 295 The client sends TURN messages from its host transport address to a 296 transport address on the TURN server that is known as the TURN SERVER 297 TRANSPORT ADDRESS. The client learns the TURN server transport 298 address through some unspecified means (e.g., configuration), and 299 this address is typically used by many clients simultaneously. 301 Since the client is behind a NAT, the server sees packets from the 302 client as coming from a transport address on the NAT itself. This 303 address is known as the client's SERVER-REFLEXIVE transport address; 304 packets sent by the server to the client's server-reflexive transport 305 address will be forwarded by the NAT to the client's host transport 306 address. 308 The client uses TURN commands to create and manipulate an ALLOCATION 309 on the server. An allocation is a data structure on the server. 310 This data structure contains, amongst other things, the RELAYED 311 TRANSPORT ADDRESS for the allocation. The relayed transport address 312 is the transport address on the server that peers can use to have the 313 server relay data to the client. An allocation is uniquely 314 identified by its relayed transport address. 316 Once an allocation is created, the client can send application data 317 to the server along with an indication of to which peer the data is 318 to be sent, and the server will relay this data to the appropriate 319 peer. The client sends the application data to the server inside a 320 TURN message; at the server, the data is extracted from the TURN 321 message and sent to the peer in a UDP datagram. In the reverse 322 direction, a peer can send application data in a UDP datagram to the 323 relayed transport address for the allocation; the server will then 324 encapsulate this data inside a TURN message and send it to the client 325 along with an indication of which peer sent the data. Since the TURN 326 message always contains an indication of which peer the client is 327 communicating with, the client can use a single allocation to 328 communicate with multiple peers. 330 When the peer is behind a NAT, then the client must identify the peer 331 using its server-reflexive transport address rather than its host 332 transport address. For example, to send application data to Peer A 333 in the example above, the client must specify 192.0.2.150:32102 (Peer 334 A's server-reflexive transport address) rather than 335 192.168.100.2:49582 (Peer A's host transport address). 337 Each allocation on the server belongs to a single client and has 338 exactly one relayed transport address that is used only by that 339 allocation. Thus, when a packet arrives at a relayed transport 340 address on the server, the server knows for which client the data is 341 intended. 343 The client may have multiple allocations on a server at the same 344 time. 346 2.1. Transports 348 TURN, as defined in this specification, always uses UDP between the 349 server and the peer. However, this specification allows the use of 350 any one of UDP, TCP, Transport Layer Security (TLS) over TCP or 351 Datagram Transport Layer Security (DTLS) over UDP to carry the TURN 352 messages between the client and the server. 354 +----------------------------+---------------------+ 355 | TURN client to TURN server | TURN server to peer | 356 +----------------------------+---------------------+ 357 | UDP | UDP | 358 | TCP | UDP | 359 | TLS-over-TCP | UDP | 360 | DTLS-over-UDP | UDP | 361 +----------------------------+---------------------+ 363 If TCP or TLS-over-TCP is used between the client and the server, 364 then the server will convert between these transports and UDP 365 transport when relaying data to/from the peer. 367 Since this version of TURN only supports UDP between the server and 368 the peer, it is expected that most clients will prefer to use UDP 369 between the client and the server as well. That being the case, some 370 readers may wonder: Why also support TCP and TLS-over-TCP? 372 TURN supports TCP transport between the client and the server because 373 some firewalls are configured to block UDP entirely. These firewalls 374 block UDP but not TCP, in part because TCP has properties that make 375 the intention of the nodes being protected by the firewall more 376 obvious to the firewall. For example, TCP has a three-way handshake 377 that makes in clearer that the protected node really wishes to have 378 that particular connection established, while for UDP the best the 379 firewall can do is guess which flows are desired by using filtering 380 rules. Also, TCP has explicit connection teardown; while for UDP, 381 the firewall has to use timers to guess when the flow is finished. 383 TURN supports TLS-over-TCP transport and DTLS-over-UDP transport 384 between the client and the server because (D)TLS provides additional 385 security properties not provided by TURN's default digest 386 authentication; properties that some clients may wish to take 387 advantage of. In particular, (D)TLS provides a way for the client to 388 ascertain that it is talking to the correct server, and provides for 389 confidentiality of TURN control messages. TURN does not require 390 (D)TLS because the overhead of using (D)TLS is higher than that of 391 digest authentication; for example, using (D)TLS likely means that 392 most application data will be doubly encrypted (once by (D)TLS and 393 once to ensure it is still encrypted in the UDP datagram). 395 There is an extension to TURN for TCP transport between the server 396 and the peers [RFC6062]. For this reason, allocations that use UDP 397 between the server and the peers are known as UDP allocations, while 398 allocations that use TCP between the server and the peers are known 399 as TCP allocations. This specification describes only UDP 400 allocations. 402 In some applications for TURN, the client may send and receive 403 packets other than TURN packets on the host transport address it uses 404 to communicate with the server. This can happen, for example, when 405 using TURN with ICE. In these cases, the client can distinguish TURN 406 packets from other packets by examining the source address of the 407 arriving packet: those arriving from the TURN server will be TURN 408 packets. 410 2.2. Allocations 412 To create an allocation on the server, the client uses an Allocate 413 transaction. The client sends an Allocate request to the server, and 414 the server replies with an Allocate success response containing the 415 allocated relayed transport address. The client can include 416 attributes in the Allocate request that describe the type of 417 allocation it desires (e.g., the lifetime of the allocation). Since 418 relaying data has security implications, the server requires that the 419 client authenticate itself, typically using STUN's long-term 420 credential mechanism, to show that it is authorized to use the 421 server. 423 Once a relayed transport address is allocated, a client must keep the 424 allocation alive. To do this, the client periodically sends a 425 Refresh request to the server. TURN deliberately uses a different 426 method (Refresh rather than Allocate) for refreshes to ensure that 427 the client is informed if the allocation vanishes for some reason. 429 The frequency of the Refresh transaction is determined by the 430 lifetime of the allocation. The default lifetime of an allocation is 431 10 minutes -- this value was chosen to be long enough so that 432 refreshing is not typically a burden on the client, while expiring 433 allocations where the client has unexpectedly quit in a timely 434 manner. However, the client can request a longer lifetime in the 435 Allocate request and may modify its request in a Refresh request, and 436 the server always indicates the actual lifetime in the response. The 437 client must issue a new Refresh transaction within "lifetime" seconds 438 of the previous Allocate or Refresh transaction. Once a client no 439 longer wishes to use an allocation, it should delete the allocation 440 using a Refresh request with a requested lifetime of 0. 442 Both the server and client keep track of a value known as the 443 5-TUPLE. At the client, the 5-tuple consists of the client's host 444 transport address, the server transport address, and the transport 445 protocol used by the client to communicate with the server. At the 446 server, the 5-tuple value is the same except that the client's host 447 transport address is replaced by the client's server-reflexive 448 address, since that is the client's address as seen by the server. 450 Both the client and the server remember the 5-tuple used in the 451 Allocate request. Subsequent messages between the client and the 452 server use the same 5-tuple. In this way, the client and server know 453 which allocation is being referred to. If the client wishes to 454 allocate a second relayed transport address, it must create a second 455 allocation using a different 5-tuple (e.g., by using a different 456 client host address or port). 458 NOTE: While the terminology used in this document refers to 459 5-tuples, the TURN server can store whatever identifier it likes 460 that yields identical results. Specifically, an implementation 461 may use a file-descriptor in place of a 5-tuple to represent a TCP 462 connection. 464 TURN TURN Peer Peer 465 client server A B 466 |-- Allocate request --------------->| | | 467 | | | | 468 |<--------------- Allocate failure --| | | 469 | (401 Unauthenticated) | | | 470 | | | | 471 |-- Allocate request --------------->| | | 472 | | | | 473 |<---------- Allocate success resp --| | | 474 | (192.0.2.15:50000) | | | 475 // // // // 476 | | | | 477 |-- Refresh request ---------------->| | | 478 | | | | 479 |<----------- Refresh success resp --| | | 480 | | | | 482 Figure 2 484 In Figure 2, the client sends an Allocate request to the server 485 without credentials. Since the server requires that all requests be 486 authenticated using STUN's long-term credential mechanism, the server 487 rejects the request with a 401 (Unauthorized) error code. The client 488 then tries again, this time including credentials (not shown). This 489 time, the server accepts the Allocate request and returns an Allocate 490 success response containing (amongst other things) the relayed 491 transport address assigned to the allocation. Sometime later, the 492 client decides to refresh the allocation and thus sends a Refresh 493 request to the server. The refresh is accepted and the server 494 replies with a Refresh success response. 496 2.3. Permissions 498 To ease concerns amongst enterprise IT administrators that TURN could 499 be used to bypass corporate firewall security, TURN includes the 500 notion of permissions. TURN permissions mimic the address-restricted 501 filtering mechanism of NATs that comply with [RFC4787]. 503 An allocation can have zero or more permissions. Each permission 504 consists of an IP address and a lifetime. When the server receives a 505 UDP datagram on the allocation's relayed transport address, it first 506 checks the list of permissions. If the source IP address of the 507 datagram matches a permission, the application data is relayed to the 508 client, otherwise the UDP datagram is silently discarded. 510 A permission expires after 5 minutes if it is not refreshed, and 511 there is no way to explicitly delete a permission. This behavior was 512 selected to match the behavior of a NAT that complies with [RFC4787]. 514 The client can install or refresh a permission using either a 515 CreatePermission request or a ChannelBind request. Using the 516 CreatePermission request, multiple permissions can be installed or 517 refreshed with a single request -- this is important for applications 518 that use ICE. For security reasons, permissions can only be 519 installed or refreshed by transactions that can be authenticated; 520 thus, Send indications and ChannelData messages (which are used to 521 send data to peers) do not install or refresh any permissions. 523 Note that permissions are within the context of an allocation, so 524 adding or expiring a permission in one allocation does not affect 525 other allocations. 527 2.4. Send Mechanism 529 There are two mechanisms for the client and peers to exchange 530 application data using the TURN server. The first mechanism uses the 531 Send and Data methods, the second way uses channels. Common to both 532 ways is the ability of the client to communicate with multiple peers 533 using a single allocated relayed transport address; thus, both ways 534 include a means for the client to indicate to the server which peer 535 should receive the data, and for the server to indicate to the client 536 which peer sent the data. 538 The Send mechanism uses Send and Data indications. Send indications 539 are used to send application data from the client to the server, 540 while Data indications are used to send application data from the 541 server to the client. 543 When using the Send mechanism, the client sends a Send indication to 544 the TURN server containing (a) an XOR-PEER-ADDRESS attribute 545 specifying the (server-reflexive) transport address of the peer and 546 (b) a DATA attribute holding the application data. When the TURN 547 server receives the Send indication, it extracts the application data 548 from the DATA attribute and sends it in a UDP datagram to the peer, 549 using the allocated relay address as the source address. Note that 550 there is no need to specify the relayed transport address, since it 551 is implied by the 5-tuple used for the Send indication. 553 In the reverse direction, UDP datagrams arriving at the relayed 554 transport address on the TURN server are converted into Data 555 indications and sent to the client, with the server-reflexive 556 transport address of the peer included in an XOR-PEER-ADDRESS 557 attribute and the data itself in a DATA attribute. Since the relayed 558 transport address uniquely identified the allocation, the server 559 knows which client should receive the data. 561 Some ICMP (Internet Control Message Protocol) packets arriving at the 562 relayed transport address on the TURN server may be converted into 563 Data indications and sent to the client, with the transport address 564 of the peer included in an XOR-PEER-ADDRESS attribute and the ICMP 565 type and code in a ICMP attribute. Data indications containing the 566 XOR-PEER-ADDRESS and ICMP attribute are also sent when using the 567 channel mechanism. 569 Send and Data indications cannot be authenticated, since the long- 570 term credential mechanism of STUN does not support authenticating 571 indications. This is not as big an issue as it might first appear, 572 since the client-to-server leg is only half of the total path to the 573 peer. Applications that want proper security should encrypt the data 574 sent between the client and a peer. 576 Because Send indications are not authenticated, it is possible for an 577 attacker to send bogus Send indications to the server, which will 578 then relay these to a peer. To partly mitigate this attack, TURN 579 requires that the client install a permission towards a peer before 580 sending data to it using a Send indication. 582 TURN TURN Peer Peer 583 client server A B 584 | | | | 585 |-- CreatePermission req (Peer A) -->| | | 586 |<-- CreatePermission success resp --| | | 587 | | | | 588 |--- Send ind (Peer A)-------------->| | | 589 | |=== data ===>| | 590 | | | | 591 | |<== data ====| | 592 |<-------------- Data ind (Peer A) --| | | 593 | | | | 594 | | | | 595 |--- Send ind (Peer B)-------------->| | | 596 | | dropped | | 597 | | | | 598 | |<== data ==================| 599 | dropped | | | 600 | | | | 602 Figure 3 604 In Figure 3, the client has already created an allocation and now 605 wishes to send data to its peers. The client first creates a 606 permission by sending the server a CreatePermission request 607 specifying Peer A's (server-reflexive) IP address in the XOR-PEER- 608 ADDRESS attribute; if this was not done, the server would not relay 609 data between the client and the server. The client then sends data 610 to Peer A using a Send indication; at the server, the application 611 data is extracted and forwarded in a UDP datagram to Peer A, using 612 the relayed transport address as the source transport address. When 613 a UDP datagram from Peer A is received at the relayed transport 614 address, the contents are placed into a Data indication and forwarded 615 to the client. Later, the client attempts to exchange data with Peer 616 B; however, no permission has been installed for Peer B, so the Send 617 indication from the client and the UDP datagram from the peer are 618 both dropped by the server. 620 2.5. Channels 622 For some applications (e.g., Voice over IP), the 36 bytes of overhead 623 that a Send indication or Data indication adds to the application 624 data can substantially increase the bandwidth required between the 625 client and the server. To remedy this, TURN offers a second way for 626 the client and server to associate data with a specific peer. 628 This second way uses an alternate packet format known as the 629 ChannelData message. The ChannelData message does not use the STUN 630 header used by other TURN messages, but instead has a 4-byte header 631 that includes a number known as a channel number. Each channel 632 number in use is bound to a specific peer and thus serves as a 633 shorthand for the peer's host transport address. 635 To bind a channel to a peer, the client sends a ChannelBind request 636 to the server, and includes an unbound channel number and the 637 transport address of the peer. Once the channel is bound, the client 638 can use a ChannelData message to send the server data destined for 639 the peer. Similarly, the server can relay data from that peer 640 towards the client using a ChannelData message. 642 Channel bindings last for 10 minutes unless refreshed -- this 643 lifetime was chosen to be longer than the permission lifetime. 644 Channel bindings are refreshed by sending another ChannelBind request 645 rebinding the channel to the peer. Like permissions (but unlike 646 allocations), there is no way to explicitly delete a channel binding; 647 the client must simply wait for it to time out. 649 TURN TURN Peer Peer 650 client server A B 651 | | | | 652 |-- ChannelBind req ---------------->| | | 653 | (Peer A to 0x4001) | | | 654 | | | | 655 |<---------- ChannelBind succ resp --| | | 656 | | | | 657 |-- [0x4001] data ------------------>| | | 658 | |=== data ===>| | 659 | | | | 660 | |<== data ====| | 661 |<------------------ [0x4001] data --| | | 662 | | | | 663 |--- Send ind (Peer A)-------------->| | | 664 | |=== data ===>| | 665 | | | | 666 | |<== data ====| | 667 |<------------------ [0x4001] data --| | | 668 | | | | 670 Figure 4 672 Figure 4 shows the channel mechanism in use. The client has already 673 created an allocation and now wishes to bind a channel to Peer A. To 674 do this, the client sends a ChannelBind request to the server, 675 specifying the transport address of Peer A and a channel number 676 (0x4001). After that, the client can send application data 677 encapsulated inside ChannelData messages to Peer A: this is shown as 678 "[0x4001] data" where 0x4001 is the channel number. When the 679 ChannelData message arrives at the server, the server transfers the 680 data to a UDP datagram and sends it to Peer A (which is the peer 681 bound to channel number 0x4001). 683 In the reverse direction, when Peer A sends a UDP datagram to the 684 relayed transport address, this UDP datagram arrives at the server on 685 the relayed transport address assigned to the allocation. Since the 686 UDP datagram was received from Peer A, which has a channel number 687 assigned to it, the server encapsulates the data into a ChannelData 688 message when sending the data to the client. 690 Once a channel has been bound, the client is free to intermix 691 ChannelData messages and Send indications. In the figure, the client 692 later decides to use a Send indication rather than a ChannelData 693 message to send additional data to Peer A. The client might decide 694 to do this, for example, so it can use the DONT-FRAGMENT attribute 695 (see the next section). However, once a channel is bound, the server 696 will always use a ChannelData message, as shown in the call flow. 698 Note that ChannelData messages can only be used for peers to which 699 the client has bound a channel. In the example above, Peer A has 700 been bound to a channel, but Peer B has not, so application data to 701 and from Peer B would use the Send mechanism. 703 2.6. Unprivileged TURN Servers 705 This version of TURN is designed so that the server can be 706 implemented as an application that runs in user space under commonly 707 available operating systems without requiring special privileges. 708 This design decision was made to make it easy to deploy a TURN 709 server: for example, to allow a TURN server to be integrated into a 710 peer-to-peer application so that one peer can offer NAT traversal 711 services to another peer. 713 This design decision has the following implications for data relayed 714 by a TURN server: 716 o The value of the Diffserv field may not be preserved across the 717 server; 719 o The Time to Live (TTL) field may be reset, rather than 720 decremented, across the server; 722 o The Explicit Congestion Notification (ECN) field may be reset by 723 the server; 725 o There is no end-to-end fragmentation, since the packet is re- 726 assembled at the server. 728 Future work may specify alternate TURN semantics that address these 729 limitations. 731 2.7. Avoiding IP Fragmentation 733 For reasons described in [Frag-Harmful], applications, especially 734 those sending large volumes of data, should try hard to avoid having 735 their packets fragmented. Applications using TCP can more or less 736 ignore this issue because fragmentation avoidance is now a standard 737 part of TCP, but applications using UDP (and thus any application 738 using this version of TURN) must handle fragmentation avoidance 739 themselves. 741 The application running on the client and the peer can take one of 742 two approaches to avoid IP fragmentation. 744 The first approach is to avoid sending large amounts of application 745 data in the TURN messages/UDP datagrams exchanged between the client 746 and the peer. This is the approach taken by most VoIP (Voice-over- 747 IP) applications. In this approach, the application exploits the 748 fact that the IP specification [RFC0791] specifies that IP packets up 749 to 576 bytes should never need to be fragmented. 751 The exact amount of application data that can be included while 752 avoiding fragmentation depends on the details of the TURN session 753 between the client and the server: whether UDP, TCP, or (D)TLS 754 transport is used, whether ChannelData messages or Send/Data 755 indications are used, and whether any additional attributes (such as 756 the DONT-FRAGMENT attribute) are included. Another factor, which is 757 hard to determine, is whether the MTU is reduced somewhere along the 758 path for other reasons, such as the use of IP-in-IP tunneling. 760 As a guideline, sending a maximum of 500 bytes of application data in 761 a single TURN message (by the client on the client-to-server leg) or 762 a UDP datagram (by the peer on the peer-to-server leg) will generally 763 avoid IP fragmentation. To further reduce the chance of 764 fragmentation, it is recommended that the client use ChannelData 765 messages when transferring significant volumes of data, since the 766 overhead of the ChannelData message is less than Send and Data 767 indications. 769 The second approach the client and peer can take to avoid 770 fragmentation is to use a path MTU discovery algorithm to determine 771 the maximum amount of application data that can be sent without 772 fragmentation. The classic path MTU discovery algorithm defined in 773 [RFC1191] may not be able to discover the MTU of the transmission 774 path between the client and the peer since: 776 - a probe packet with DF bit set to test a path for a larger MTU 777 can be dropped by routers, or 779 - ICMP error messages can be dropped by middle boxes. 781 As a result, the client and server need to use a path MTU discovery 782 algorithm that does not require ICMP messages. The Packetized Path 783 MTU Discovery algorithm defined in [RFC4821] is one such algorithm. 785 [I-D.ietf-tram-stun-pmtud] is an implementation of [RFC4821] that is 786 using STUN to discover the PMTUD, and so may be a suitable approach 787 to be used in conjunction with a TURN server, together with the DONT- 788 FRAGMENT attribute. When the client includes the DONT-FRAGMENT 789 attribute in a Send indication, this tells the server to set the DF 790 bit in the resulting UDP datagram that it sends to the peer. Since 791 some servers may be unable to set the DF bit, the client should also 792 include this attribute in the Allocate request -- any server that 793 does not support the DONT-FRAGMENT attribute will indicate this by 794 rejecting the Allocate request. 796 2.8. RTP Support 798 One of the envisioned uses of TURN is as a relay for clients and 799 peers wishing to exchange real-time data (e.g., voice or video) using 800 RTP. To facilitate the use of TURN for this purpose, TURN includes 801 some special support for older versions of RTP. 803 Old versions of RTP [RFC3550] required that the RTP stream be on an 804 even port number and the associated RTP Control Protocol (RTCP) 805 stream, if present, be on the next highest port. To allow clients to 806 work with peers that still require this, TURN allows the client to 807 request that the server allocate a relayed transport address with an 808 even port number, and to optionally request the server reserve the 809 next-highest port number for a subsequent allocation. 811 2.9. Discovery of TURN server 813 Methods of TURN server discovery, including using anycast, are 814 described in [RFC8155]. The syntax of the "turn" and "turn" URIs are 815 defined in Section 3.1 of [RFC7065]. 817 2.9.1. TURN URI Scheme Semantics 819 The "turn" and "turns" URI schemes are used to designate a TURN 820 server (also known as a relay) on Internet hosts accessible using the 821 TURN protocol. The TURN protocol supports sending messages over UDP, 822 TCP, TLS-over-TCP or DTLS-over-UDP. The "turns" URI scheme MUST be 823 used when TURN is run over TLS-over-TCP or in DTLS-over-UDP, and the 824 "turn" scheme MUST be used otherwise. The required part of 825 the "turn" URI denotes the TURN server host. The part, if 826 present, denotes the port on which the TURN server is awaiting 827 connection requests. If it is absent, the default port is 3478 for 828 both UDP and TCP. The default port for TURN over TLS and TURN over 829 DTLS is 5349. 831 2.10. Happy Eyeballs for TURN 833 If an IPv4 path to reach a TURN server is found, but the TURN 834 server's IPv6 path is not working, a dual-stack TURN client can 835 experience a significant connection delay compared to an IPv4-only 836 TURN client. To overcome these connection setup problems, the TURN 837 client MUST query both A and AAAA records for the TURN server 838 specified using a domain name and try connecting to the TURN server 839 using both IPv6 and IPv4 addresses in a fashion similar to the Happy 840 Eyeballs mechanism defined in [RFC6555]. The TURN client performs 841 the following steps based on the transport protocol being used to 842 connect to the TURN server. 844 o For TCP, initiate TCP connection to both IP address families as 845 discussed in [RFC6555], and use the first TCP connection that is 846 established. If connections are established on both IP address 847 families then terminate the TCP connection using the IP address 848 family with lower precedence [RFC6724]. 850 o For clear text UDP, send TURN Allocate requests to both IP address 851 families as discussed in [RFC6555], without authentication 852 information. If the TURN server requires authentication, it will 853 send back a 401 unauthenticated response and the TURN client uses 854 the first UDP connection on which a 401 error response is 855 received. If a 401 error response is received from both IP 856 address families then the TURN client can silently abandon the UDP 857 connection on the IP address family with lower precedence. If the 858 TURN server does not require authentication (as described in 859 Section 9 of [RFC8155]), it is possible for both Allocate requests 860 to succeed. In this case, the TURN client sends a Refresh with 861 LIFETIME value of 0 on the allocation using the IP address family 862 with lower precedence to delete the allocation. 864 o For DTLS over UDP, initiate DTLS handshake to both IP address 865 families as discussed in [RFC6555] and use the first DTLS session 866 that is established. If the DTLS session is established on both 867 IP addresses families then the client sends DTLS close_notify 868 alert to terminate the DTLS session using the IP address family 869 with lower precedence. If TURN over DTLS server has been 870 configured to require a cookie exchange (Section 4.2 in [RFC6347]) 871 and HelloVerifyRequest is received from the TURN servers on both 872 IP addresses families then the client can silently abandon the 873 connection on the IP address family with lower precedence. 875 3. Terminology 877 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 878 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 879 document are to be interpreted as described in RFC 2119 [RFC2119]. 881 Readers are expected to be familiar with [RFC5389] and the terms 882 defined there. 884 The following terms are used in this document: 886 TURN: The protocol spoken between a TURN client and a TURN server. 887 It is an extension to the STUN protocol [RFC5389]. The protocol 888 allows a client to allocate and use a relayed transport address. 890 TURN client: A STUN client that implements this specification. 892 TURN server: A STUN server that implements this specification. It 893 relays data between a TURN client and its peer(s). 895 Peer: A host with which the TURN client wishes to communicate. The 896 TURN server relays traffic between the TURN client and its 897 peer(s). The peer does not interact with the TURN server using 898 the protocol defined in this document; rather, the peer receives 899 data sent by the TURN server and the peer sends data towards the 900 TURN server. 902 Transport Address: The combination of an IP address and a port. 904 Host Transport Address: A transport address on a client or a peer. 906 Server-Reflexive Transport Address: A transport address on the 907 "public side" of a NAT. This address is allocated by the NAT to 908 correspond to a specific host transport address. 910 Relayed Transport Address: A transport address on the TURN server 911 that is used for relaying packets between the client and a peer. 912 A peer sends to this address on the TURN server, and the packet is 913 then relayed to the client. 915 TURN Server Transport Address: A transport address on the TURN 916 server that is used for sending TURN messages to the server. This 917 is the transport address that the client uses to communicate with 918 the server. 920 Peer Transport Address: The transport address of the peer as seen by 921 the server. When the peer is behind a NAT, this is the peer's 922 server-reflexive transport address. 924 Allocation: The relayed transport address granted to a client 925 through an Allocate request, along with related state, such as 926 permissions and expiration timers. 928 5-tuple: The combination (client IP address and port, server IP 929 address and port, and transport protocol (currently one of UDP, 930 TCP, or (D)TLS)) used to communicate between the client and the 931 server. The 5-tuple uniquely identifies this communication 932 stream. The 5-tuple also uniquely identifies the Allocation on 933 the server. 935 Channel: A channel number and associated peer transport address. 936 Once a channel number is bound to a peer's transport address, the 937 client and server can use the more bandwidth-efficient ChannelData 938 message to exchange data. 940 Permission: The IP address and transport protocol (but not the port) 941 of a peer that is permitted to send traffic to the TURN server and 942 have that traffic relayed to the TURN client. The TURN server 943 will only forward traffic to its client from peers that match an 944 existing permission. 946 Realm: A string used to describe the server or a context within the 947 server. The realm tells the client which username and password 948 combination to use to authenticate requests. 950 Nonce: A string chosen at random by the server and included in the 951 message-digest. To prevent reply attacks, the server should 952 change the nonce regularly. 954 4. General Behavior 956 This section contains general TURN processing rules that apply to all 957 TURN messages. 959 TURN is an extension to STUN. All TURN messages, with the exception 960 of the ChannelData message, are STUN-formatted messages. All the 961 base processing rules described in [RFC5389] apply to STUN-formatted 962 messages. This means that all the message-forming and message- 963 processing descriptions in this document are implicitly prefixed with 964 the rules of [RFC5389]. 966 [RFC5389] specifies an authentication mechanism called the long-term 967 credential mechanism. TURN servers and clients MUST implement this 968 mechanism. The server MUST demand that all requests from the client 969 be authenticated using this mechanism, or that a equally strong or 970 stronger mechanism for client authentication is used. 972 Note that the long-term credential mechanism applies only to requests 973 and cannot be used to authenticate indications; thus, indications in 974 TURN are never authenticated. If the server requires requests to be 975 authenticated, then the server's administrator MUST choose a realm 976 value that will uniquely identify the username and password 977 combination that the client must use, even if the client uses 978 multiple servers under different administrations. The server's 979 administrator MAY choose to allocate a unique username to each 980 client, or MAY choose to allocate the same username to more than one 981 client (for example, to all clients from the same department or 982 company). For each allocation, the server SHOULD generate a new 983 random nonce when the allocation is first attempted following the 984 randomness recommendations in [RFC4086] and SHOULD expire the nonce 985 at least once every hour during the lifetime of the allocation. 987 All requests after the initial Allocate must use the same username as 988 that used to create the allocation, to prevent attackers from 989 hijacking the client's allocation. Specifically, if the server 990 requires the use of the long-term credential mechanism, and if a non- 991 Allocate request passes authentication under this mechanism, and if 992 the 5-tuple identifies an existing allocation, but the request does 993 not use the same username as used to create the allocation, then the 994 request MUST be rejected with a 441 (Wrong Credentials) error. 996 When a TURN message arrives at the server from the client, the server 997 uses the 5-tuple in the message to identify the associated 998 allocation. For all TURN messages (including ChannelData) EXCEPT an 999 Allocate request, if the 5-tuple does not identify an existing 1000 allocation, then the message MUST either be rejected with a 437 1001 Allocation Mismatch error (if it is a request) or silently ignored 1002 (if it is an indication or a ChannelData message). A client 1003 receiving a 437 error response to a request other than Allocate MUST 1004 assume the allocation no longer exists. 1006 [RFC5389] defines a number of attributes, including the SOFTWARE and 1007 FINGERPRINT attributes. The client SHOULD include the SOFTWARE 1008 attribute in all Allocate and Refresh requests and MAY include it in 1009 any other requests or indications. The server SHOULD include the 1010 SOFTWARE attribute in all Allocate and Refresh responses (either 1011 success or failure) and MAY include it in other responses or 1012 indications. The client and the server MAY include the FINGERPRINT 1013 attribute in any STUN-formatted messages defined in this document. 1015 TURN does not use the backwards-compatibility mechanism described in 1016 [RFC5389]. 1018 TURN, as defined in this specification, supports both IPv4 and IPv6. 1019 IPv6 support in TURN includes IPv4-to-IPv6, IPv6-to-IPv6, and IPv6- 1020 to-IPv4 relaying. The REQUESTED-ADDRESS-FAMILY attribute allows a 1021 client to explicitly request the address type the TURN server will 1022 allocate (e.g., an IPv4-only node may request the TURN server to 1023 allocate an IPv6 address). The ADDITIONAL-ADDRESS-FAMILY attribute 1024 allows a client to request the server to allocate one IPv4 and one 1025 IPv6 relay address in a single Allocate request. This saves local 1026 ports on the client and reduces the number of messages sent between 1027 the client and the TURN server. 1029 By default, TURN runs on the same ports as STUN: 3478 for TURN over 1030 UDP and TCP, and 5349 for TURN over (D)TLS. However, TURN has its 1031 own set of Service Record (SRV) names: "turn" for UDP and TCP, and 1032 "turns" for (D)TLS. Either the SRV procedures or the ALTERNATE- 1033 SERVER procedures, both described in Section 6, can be used to run 1034 TURN on a different port. 1036 To ensure interoperability, a TURN server MUST support the use of UDP 1037 transport between the client and the server, and SHOULD support the 1038 use of TCP and (D)TLS transport. 1040 When UDP transport is used between the client and the server, the 1041 client will retransmit a request if it does not receive a response 1042 within a certain timeout period. Because of this, the server may 1043 receive two (or more) requests with the same 5-tuple and same 1044 transaction id. STUN requires that the server recognize this case 1045 and treat the request as idempotent (see [RFC5389]). Some 1046 implementations may choose to meet this requirement by remembering 1047 all received requests and the corresponding responses for 40 seconds. 1048 Other implementations may choose to reprocess the request and arrange 1049 that such reprocessing returns essentially the same response. To aid 1050 implementors who choose the latter approach (the so-called "stateless 1051 stack approach"), this specification includes some implementation 1052 notes on how this might be done. Implementations are free to choose 1053 either approach or choose some other approach that gives the same 1054 results. 1056 When TCP transport is used between the client and the server, it is 1057 possible that a bit error will cause a length field in a TURN packet 1058 to become corrupted, causing the receiver to lose synchronization 1059 with the incoming stream of TURN messages. A client or server that 1060 detects a long sequence of invalid TURN messages over TCP transport 1061 SHOULD close the corresponding TCP connection to help the other end 1062 detect this situation more rapidly. 1064 To mitigate either intentional or unintentional denial-of-service 1065 attacks against the server by clients with valid usernames and 1066 passwords, it is RECOMMENDED that the server impose limits on both 1067 the number of allocations active at one time for a given username and 1068 on the amount of bandwidth those allocations can use. The server 1069 should reject new allocations that would exceed the limit on the 1070 allowed number of allocations active at one time with a 486 1071 (Allocation Quota Exceeded) (see Section 6.2), and should discard 1072 application data traffic that exceeds the bandwidth quota. 1074 5. Allocations 1076 All TURN operations revolve around allocations, and all TURN messages 1077 are associated with an allocation. An allocation conceptually 1078 consists of the following state data: 1080 o the relayed transport address; 1082 o the 5-tuple: (client's IP address, client's port, server IP 1083 address, server port, transport protocol); 1085 o the authentication information; 1087 o the time-to-expiry; 1089 o a list of permissions; 1091 o a list of channel to peer bindings. 1093 The relayed transport address is the transport address allocated by 1094 the server for communicating with peers, while the 5-tuple describes 1095 the communication path between the client and the server. On the 1096 client, the 5-tuple uses the client's host transport address; on the 1097 server, the 5-tuple uses the client's server-reflexive transport 1098 address. 1100 Both the relayed transport address and the 5-tuple MUST be unique 1101 across all allocations, so either one can be used to uniquely 1102 identify the allocation. 1104 The authentication information (e.g., username, password, realm, and 1105 nonce) is used to both verify subsequent requests and to compute the 1106 message integrity of responses. The username, realm, and nonce 1107 values are initially those used in the authenticated Allocate request 1108 that creates the allocation, though the server can change the nonce 1109 value during the lifetime of the allocation using a 438 (Stale Nonce) 1110 reply. Note that, rather than storing the password explicitly, for 1111 security reasons, it may be desirable for the server to store the key 1112 value, which is an secure hash over the username, realm, and password 1113 (see [I-D.ietf-tram-stunbis]). 1115 The time-to-expiry is the time in seconds left until the allocation 1116 expires. Each Allocate or Refresh transaction sets this timer, which 1117 then ticks down towards 0. By default, each Allocate or Refresh 1118 transaction resets this timer to the default lifetime value of 600 1119 seconds (10 minutes), but the client can request a different value in 1120 the Allocate and Refresh request. Allocations can only be refreshed 1121 using the Refresh request; sending data to a peer does not refresh an 1122 allocation. When an allocation expires, the state data associated 1123 with the allocation can be freed. 1125 The list of permissions is described in Section 8 and the list of 1126 channels is described in Section 11. 1128 6. Creating an Allocation 1130 An allocation on the server is created using an Allocate transaction. 1132 6.1. Sending an Allocate Request 1134 The client forms an Allocate request as follows. 1136 The client first picks a host transport address. It is RECOMMENDED 1137 that the client pick a currently unused transport address, typically 1138 by allowing the underlying OS to pick a currently unused port for a 1139 new socket. 1141 The client then picks a transport protocol to use between the client 1142 and the server. The transport protocol MUST be one of UDP, TCP, TLS- 1143 over-TCP or DTLS-over-UDP. Since this specification only allows UDP 1144 between the server and the peers, it is RECOMMENDED that the client 1145 pick UDP unless it has a reason to use a different transport. One 1146 reason to pick a different transport would be that the client 1147 believes, either through configuration or by experiment, that it is 1148 unable to contact any TURN server using UDP. See Section 2.1 for 1149 more discussion. 1151 The client also picks a server transport address, which SHOULD be 1152 done as follows. The client uses the procedures described in 1153 [RFC8155] to discover a TURN server and TURN server resolution 1154 mechanism defined in [RFC5928] to get a list of server transport 1155 addresses that can be tried to create a TURN allocation. 1157 The client MUST include a REQUESTED-TRANSPORT attribute in the 1158 request. This attribute specifies the transport protocol between the 1159 server and the peers (note that this is NOT the transport protocol 1160 that appears in the 5-tuple). In this specification, the REQUESTED- 1161 TRANSPORT type is always UDP. This attribute is included to allow 1162 future extensions to specify other protocols. 1164 If the client wishes to obtain a relayed transport address of a 1165 specific address type then it includes a REQUESTED-ADDRESS-FAMILY 1166 attribute in the request. This attribute indicates the specific 1167 address type the client wishes the TURN server to allocate. Clients 1168 MUST NOT include more than one REQUESTED-ADDRESS-FAMILY attribute in 1169 an Allocate request. Clients MUST NOT include a REQUESTED-ADDRESS- 1170 FAMILY attribute in an Allocate request that contains a RESERVATION- 1171 TOKEN attribute, for the reasons outlined in [RFC6156]. 1173 If the client wishes to obtain one IPv6 and one IPv4 relayed 1174 transport addresses then it includes an ADDITIONAL-ADDRESS-FAMILY 1175 attribute in the request. This attribute specifies that the server 1176 must allocate both address types. The attribute value in the 1177 ADDITIONAL-ADDRESS-FAMILY MUST be set to 0x02 (IPv6 address family). 1178 Clients MUST NOT include REQUESTED-ADDRESS-FAMILY and ADDITIONAL- 1179 ADDRESS-FAMILY attributes in the same request. Clients MUST NOT 1180 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1181 that contains a RESERVATION-TOKEN attribute. Clients MUST NOT 1182 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1183 that contains a EVEN-PORT attribute with the R bit set to 1. 1185 If the client wishes the server to initialize the time-to-expiry 1186 field of the allocation to some value other than the default 1187 lifetime, then it MAY include a LIFETIME attribute specifying its 1188 desired value. This is just a hint, and the server may elect to use 1189 a different value. Note that the server will ignore requests to 1190 initialize the field to less than the default value. 1192 If the client wishes to later use the DONT-FRAGMENT attribute in one 1193 or more Send indications on this allocation, then the client SHOULD 1194 include the DONT-FRAGMENT attribute in the Allocate request. This 1195 allows the client to test whether this attribute is supported by the 1196 server. 1198 If the client requires the port number of the relayed transport 1199 address be even, the client includes the EVEN-PORT attribute. If 1200 this attribute is not included, then the port can be even or odd. By 1201 setting the R bit in the EVEN-PORT attribute to 1, the client can 1202 request that the server reserve the next highest port number (on the 1203 same IP address) for a subsequent allocation. If the R bit is 0, no 1204 such request is made. 1206 The client MAY also include a RESERVATION-TOKEN attribute in the 1207 request to ask the server to use a previously reserved port for the 1208 allocation. If the RESERVATION-TOKEN attribute is included, then the 1209 client MUST omit the EVEN-PORT attribute. 1211 Once constructed, the client sends the Allocate request on the 1212 5-tuple. 1214 6.2. Receiving an Allocate Request 1216 When the server receives an Allocate request, it performs the 1217 following checks: 1219 1. The server MUST require that the request be authenticated. This 1220 authentication MUST be done using the long-term credential 1221 mechanism of [RFC5389] unless the client and server agree to use 1222 another mechanism through some procedure outside the scope of 1223 this document. 1225 2. The server checks if the 5-tuple is currently in use by an 1226 existing allocation. If yes, the server rejects the request 1227 with a 437 (Allocation Mismatch) error. 1229 3. The server checks if the request contains a REQUESTED-TRANSPORT 1230 attribute. If the REQUESTED-TRANSPORT attribute is not included 1231 or is malformed, the server rejects the request with a 400 (Bad 1232 Request) error. Otherwise, if the attribute is included but 1233 specifies a protocol other that UDP, the server rejects the 1234 request with a 442 (Unsupported Transport Protocol) error. 1236 4. The request may contain a DONT-FRAGMENT attribute. If it does, 1237 but the server does not support sending UDP datagrams with the 1238 DF bit set to 1 (see Section 13), then the server treats the 1239 DONT-FRAGMENT attribute in the Allocate request as an unknown 1240 comprehension-required attribute. 1242 5. The server checks if the request contains a RESERVATION-TOKEN 1243 attribute. If yes, and the request also contains an EVEN-PORT 1244 or REQUESTED-ADDRESS-FAMILY or ADDITIONAL-ADDRESS-FAMILY 1245 attribute, the server rejects the request with a 400 (Bad 1246 Request) error. Otherwise, it checks to see if the token is 1247 valid (i.e., the token is in range and has not expired and the 1248 corresponding relayed transport address is still available). If 1249 the token is not valid for some reason, the server rejects the 1250 request with a 508 (Insufficient Capacity) error. 1252 6. The server checks if the request contains both REQUESTED- 1253 ADDRESS-FAMILY and ADDITIONAL-ADDRESS-FAMILY attributes, then 1254 the server rejects the request with a 400 (Bad Request) error. 1256 7. If the server does not support the address family requested by 1257 the client in REQUESTED-ADDRESS-FAMILY or is disabled by local 1258 policy, it MUST generate an Allocate error response, and it MUST 1259 include an ERROR-CODE attribute with the 440 (Address Family not 1260 Supported) response code. If the REQUESTED-ADDRESS-FAMILY 1261 attribute is absent, the server MUST allocate an IPv4 relayed 1262 transport address for the TURN client. 1264 8. The server checks if the request contains an EVEN-PORT attribute 1265 with the R bit set to 1. If yes, and the request also contains 1266 an ADDITIONAL- ADDRESS-FAMILY attribute, the server rejects the 1267 request with a 400 (Bad Request) error. Otherwise, the server 1268 checks if it can satisfy the request (i.e., can allocate a 1269 relayed transport address as described below). If the server 1270 cannot satisfy the request, then the server rejects the request 1271 with a 508 (Insufficient Capacity) error. 1273 9. The server checks if the request contains an ADDITIONAL-ADDRESS- 1274 FAMILY attribute. If yes, and the attribute value is 0x01 (IPv4 1275 address family), then the server rejects the request with a 400 1276 (Bad Request) error. Otherwise, and the server checks if it can 1277 allocate relayed transport addresses of both address types. If 1278 the server cannot satisfy the request, then the server rejects 1279 the request with a 508 (Insufficient Capacity) error. If the 1280 server can partially meet the request, i.e. if it can only 1281 allocate one relayed transport address of a specific address 1282 type, then it includes ADDRESS-ERROR-CODE attribute in the 1283 response to inform the client the reason for partial failure of 1284 the request. The error code value signaled in the ADDRESS- 1285 ERROR-CODE attribute could be 440 (Address Family not Supported) 1286 or 508 (Insufficient Capacity). 1288 10. At any point, the server MAY choose to reject the request with a 1289 486 (Allocation Quota Reached) error if it feels the client is 1290 trying to exceed some locally defined allocation quota. The 1291 server is free to define this allocation quota any way it 1292 wishes, but SHOULD define it based on the username used to 1293 authenticate the request, and not on the client's transport 1294 address. 1296 11. Also at any point, the server MAY choose to reject the request 1297 with a 300 (Try Alternate) error if it wishes to redirect the 1298 client to a different server. The use of this error code and 1299 attribute follow the specification in [RFC5389]. 1301 If all the checks pass, the server creates the allocation. The 1302 5-tuple is set to the 5-tuple from the Allocate request, while the 1303 list of permissions and the list of channels are initially empty. 1305 The server chooses a relayed transport address for the allocation as 1306 follows: 1308 o If the request contains a RESERVATION-TOKEN attribute, the server 1309 uses the previously reserved transport address corresponding to 1310 the included token (if it is still available). Note that the 1311 reservation is a server-wide reservation and is not specific to a 1312 particular allocation, since the Allocate request containing the 1313 RESERVATION-TOKEN uses a different 5-tuple than the Allocate 1314 request that made the reservation. The 5-tuple for the Allocate 1315 request containing the RESERVATION-TOKEN attribute can be any 1316 allowed 5-tuple; it can use a different client IP address and 1317 port, a different transport protocol, and even different server IP 1318 address and port (provided, of course, that the server IP address 1319 and port are ones on which the server is listening for TURN 1320 requests). 1322 o If the request contains an EVEN-PORT attribute with the R bit set 1323 to 0, then the server allocates a relayed transport address with 1324 an even port number. 1326 o If the request contains an EVEN-PORT attribute with the R bit set 1327 to 1, then the server looks for a pair of port numbers N and N+1 1328 on the same IP address, where N is even. Port N is used in the 1329 current allocation, while the relayed transport address with port 1330 N+1 is assigned a token and reserved for a future allocation. The 1331 server MUST hold this reservation for at least 30 seconds, and MAY 1332 choose to hold longer (e.g., until the allocation with port N 1333 expires). The server then includes the token in a RESERVATION- 1334 TOKEN attribute in the success response. 1336 o Otherwise, the server allocates any available relayed transport 1337 address. 1339 In all cases, the server SHOULD only allocate ports from the range 1340 49152 - 65535 (the Dynamic and/or Private Port range [Port-Numbers]), 1341 unless the TURN server application knows, through some means not 1342 specified here, that other applications running on the same host as 1343 the TURN server application will not be impacted by allocating ports 1344 outside this range. This condition can often be satisfied by running 1345 the TURN server application on a dedicated machine and/or by 1346 arranging that any other applications on the machine allocate ports 1347 before the TURN server application starts. In any case, the TURN 1348 server SHOULD NOT allocate ports in the range 0 - 1023 (the Well- 1349 Known Port range) to discourage clients from using TURN to run 1350 standard services. 1352 NOTE: The use of randomized port assignments to avoid certain 1353 types of attacks is described in [RFC6056]. It is RECOMMENDED 1354 that a TURN server implement a randomized port assignment 1355 algorithm from [RFC6056]. This is especially applicable to 1356 servers that choose to pre-allocate a number of ports from the 1357 underlying OS and then later assign them to allocations; for 1358 example, a server may choose this technique to implement the EVEN- 1359 PORT attribute. 1361 The server determines the initial value of the time-to-expiry field 1362 as follows. If the request contains a LIFETIME attribute, then the 1363 server computes the minimum of the client's proposed lifetime and the 1364 server's maximum allowed lifetime. If this computed value is greater 1365 than the default lifetime, then the server uses the computed lifetime 1366 as the initial value of the time-to-expiry field. Otherwise, the 1367 server uses the default lifetime. It is RECOMMENDED that the server 1368 use a maximum allowed lifetime value of no more than 3600 seconds (1 1369 hour). Servers that implement allocation quotas or charge users for 1370 allocations in some way may wish to use a smaller maximum allowed 1371 lifetime (perhaps as small as the default lifetime) to more quickly 1372 remove orphaned allocations (that is, allocations where the 1373 corresponding client has crashed or terminated or the client 1374 connection has been lost for some reason). Also, note that the time- 1375 to-expiry is recomputed with each successful Refresh request, and 1376 thus the value computed here applies only until the first refresh. 1378 Once the allocation is created, the server replies with a success 1379 response. The success response contains: 1381 o An XOR-RELAYED-ADDRESS attribute containing the relayed transport 1382 address. 1384 o A LIFETIME attribute containing the current value of the time-to- 1385 expiry timer. 1387 o A RESERVATION-TOKEN attribute (if a second relayed transport 1388 address was reserved). 1390 o An XOR-MAPPED-ADDRESS attribute containing the client's IP address 1391 and port (from the 5-tuple). 1393 NOTE: The XOR-MAPPED-ADDRESS attribute is included in the response 1394 as a convenience to the client. TURN itself does not make use of 1395 this value, but clients running ICE can often need this value and 1396 can thus avoid having to do an extra Binding transaction with some 1397 STUN server to learn it. 1399 The response (either success or error) is sent back to the client on 1400 the 5-tuple. 1402 NOTE: When the Allocate request is sent over UDP, section 7.3.1 of 1403 [RFC5389] requires that the server handle the possible 1404 retransmissions of the request so that retransmissions do not 1405 cause multiple allocations to be created. Implementations may 1406 achieve this using the so-called "stateless stack approach" as 1407 follows. To detect retransmissions when the original request was 1408 successful in creating an allocation, the server can store the 1409 transaction id that created the request with the allocation data 1410 and compare it with incoming Allocate requests on the same 1411 5-tuple. Once such a request is detected, the server can stop 1412 parsing the request and immediately generate a success response. 1413 When building this response, the value of the LIFETIME attribute 1414 can be taken from the time-to-expiry field in the allocate state 1415 data, even though this value may differ slightly from the LIFETIME 1416 value originally returned. In addition, the server may need to 1417 store an indication of any reservation token returned in the 1418 original response, so that this may be returned in any 1419 retransmitted responses. 1421 For the case where the original request was unsuccessful in 1422 creating an allocation, the server may choose to do nothing 1423 special. Note, however, that there is a rare case where the 1424 server rejects the original request but accepts the retransmitted 1425 request (because conditions have changed in the brief intervening 1426 time period). If the client receives the first failure response, 1427 it will ignore the second (success) response and believe that an 1428 allocation was not created. An allocation created in this matter 1429 will eventually timeout, since the client will not refresh it. 1430 Furthermore, if the client later retries with the same 5-tuple but 1431 different transaction id, it will receive a 437 (Allocation 1432 Mismatch), which will cause it to retry with a different 5-tuple. 1433 The server may use a smaller maximum lifetime value to minimize 1434 the lifetime of allocations "orphaned" in this manner. 1436 6.3. Receiving an Allocate Success Response 1438 If the client receives an Allocate success response, then it MUST 1439 check that the mapped address and the relayed transport address are 1440 part of an address family that the client understands and is prepared 1441 to handle. If these two addresses are not part of an address family 1442 which the client is prepared to handle, then the client MUST delete 1443 the allocation (Section 7) and MUST NOT attempt to create another 1444 allocation on that server until it believes the mismatch has been 1445 fixed. 1447 Otherwise, the client creates its own copy of the allocation data 1448 structure to track what is happening on the server. In particular, 1449 the client needs to remember the actual lifetime received back from 1450 the server, rather than the value sent to the server in the request. 1451 The client must also remember the 5-tuple used for the request and 1452 the username and password it used to authenticate the request to 1453 ensure that it reuses them for subsequent messages. The client also 1454 needs to track the channels and permissions it establishes on the 1455 server. 1457 The client will probably wish to send the relayed transport address 1458 to peers (using some method not specified here) so the peers can 1459 communicate with it. The client may also wish to use the server- 1460 reflexive address it receives in the XOR-MAPPED-ADDRESS attribute in 1461 its ICE processing. 1463 6.4. Receiving an Allocate Error Response 1465 If the client receives an Allocate error response, then the 1466 processing depends on the actual error code returned: 1468 o (Request timed out): There is either a problem with the server, or 1469 a problem reaching the server with the chosen transport. The 1470 client considers the current transaction as having failed but MAY 1471 choose to retry the Allocate request using a different transport 1472 (e.g., TCP instead of UDP). 1474 o 300 (Try Alternate): The server would like the client to use the 1475 server specified in the ALTERNATE-SERVER attribute instead. The 1476 client considers the current transaction as having failed, but 1477 SHOULD try the Allocate request with the alternate server before 1478 trying any other servers (e.g., other servers discovered using the 1479 SRV procedures). When trying the Allocate request with the 1480 alternate server, the client follows the ALTERNATE-SERVER 1481 procedures specified in [RFC5389]. 1483 o 400 (Bad Request): The server believes the client's request is 1484 malformed for some reason. The client considers the current 1485 transaction as having failed. The client MAY notify the user or 1486 operator and SHOULD NOT retry the request with this server until 1487 it believes the problem has been fixed. 1489 o 401 (Unauthorized): If the client has followed the procedures of 1490 the long-term credential mechanism and still gets this error, then 1491 the server is not accepting the client's credentials. In this 1492 case, the client considers the current transaction as having 1493 failed and SHOULD notify the user or operator. The client SHOULD 1494 NOT send any further requests to this server until it believes the 1495 problem has been fixed. 1497 o 403 (Forbidden): The request is valid, but the server is refusing 1498 to perform it, likely due to administrative restrictions. The 1499 client considers the current transaction as having failed. The 1500 client MAY notify the user or operator and SHOULD NOT retry the 1501 same request with this server until it believes the problem has 1502 been fixed. 1504 o 420 (Unknown Attribute): If the client included a DONT-FRAGMENT 1505 attribute in the request and the server rejected the request with 1506 a 420 error code and listed the DONT-FRAGMENT attribute in the 1507 UNKNOWN-ATTRIBUTES attribute in the error response, then the 1508 client now knows that the server does not support the DONT- 1509 FRAGMENT attribute. The client considers the current transaction 1510 as having failed but MAY choose to retry the Allocate request 1511 without the DONT-FRAGMENT attribute. 1513 o 437 (Allocation Mismatch): This indicates that the client has 1514 picked a 5-tuple that the server sees as already in use. One way 1515 this could happen is if an intervening NAT assigned a mapped 1516 transport address that was used by another client that recently 1517 crashed. The client considers the current transaction as having 1518 failed. The client SHOULD pick another client transport address 1519 and retry the Allocate request (using a different transaction id). 1520 The client SHOULD try three different client transport addresses 1521 before giving up on this server. Once the client gives up on the 1522 server, it SHOULD NOT try to create another allocation on the 1523 server for 2 minutes. 1525 o 438 (Stale Nonce): See the procedures for the long-term credential 1526 mechanism [RFC5389]. 1528 o 440 (Address Family not Supported): The server does not support 1529 the address family requested by the client. If the client 1530 receives an Allocate error response with the 440 (Unsupported 1531 Address Family) error code, the client MUST NOT retry the request. 1533 o 441 (Wrong Credentials): The client should not receive this error 1534 in response to a Allocate request. The client MAY notify the user 1535 or operator and SHOULD NOT retry the same request with this server 1536 until it believes the problem has been fixed. 1538 o 442 (Unsupported Transport Address): The client should not receive 1539 this error in response to a request for a UDP allocation. The 1540 client MAY notify the user or operator and SHOULD NOT reattempt 1541 the request with this server until it believes the problem has 1542 been fixed. 1544 o 486 (Allocation Quota Reached): The server is currently unable to 1545 create any more allocations with this username. The client 1546 considers the current transaction as having failed. The client 1547 SHOULD wait at least 1 minute before trying to create any more 1548 allocations on the server. 1550 o 508 (Insufficient Capacity): The server has no more relayed 1551 transport addresses available, or has none with the requested 1552 properties, or the one that was reserved is no longer available. 1553 The client considers the current operation as having failed. If 1554 the client is using either the EVEN-PORT or the RESERVATION-TOKEN 1555 attribute, then the client MAY choose to remove or modify this 1556 attribute and try again immediately. Otherwise, the client SHOULD 1557 wait at least 1 minute before trying to create any more 1558 allocations on this server. 1560 An unknown error response MUST be handled as described in [RFC5389]. 1562 7. Refreshing an Allocation 1564 A Refresh transaction can be used to either (a) refresh an existing 1565 allocation and update its time-to-expiry or (b) delete an existing 1566 allocation. 1568 If a client wishes to continue using an allocation, then the client 1569 MUST refresh it before it expires. It is suggested that the client 1570 refresh the allocation roughly 1 minute before it expires. If a 1571 client no longer wishes to use an allocation, then it SHOULD 1572 explicitly delete the allocation. A client MAY refresh an allocation 1573 at any time for other reasons. 1575 7.1. Sending a Refresh Request 1577 If the client wishes to immediately delete an existing allocation, it 1578 includes a LIFETIME attribute with a value of 0. All other forms of 1579 the request refresh the allocation. 1581 When refreshing a dual allocation, the client includes REQUESTED- 1582 ADDRESS-FAMILY attribute indicating the address family type that 1583 should be refreshed. If no REQUESTED-ADDRESS-FAMILY is included then 1584 the request should be treated as applying to all current allocations. 1585 The client MUST only include family types it previously allocated and 1586 has not yet deleted. This process can also be used to delete an 1587 allocation of a specific address type, by setting the lifetime of 1588 that refresh request to 0. Deleting a single allocation destroys any 1589 permissions or channels associated with that particular allocation; 1590 it MUST NOT affect any permissions or channels associated with 1591 allocations for the other address family. 1593 The Refresh transaction updates the time-to-expiry timer of an 1594 allocation. If the client wishes the server to set the time-to- 1595 expiry timer to something other than the default lifetime, it 1596 includes a LIFETIME attribute with the requested value. The server 1597 then computes a new time-to-expiry value in the same way as it does 1598 for an Allocate transaction, with the exception that a requested 1599 lifetime of 0 causes the server to immediately delete the allocation. 1601 7.2. Receiving a Refresh Request 1603 When the server receives a Refresh request, it processes it as per 1604 Section 4 plus the specific rules mentioned here. 1606 If the server receives a Refresh Request with an REQUESTED-ADDRESS- 1607 FAMILY attribute and the attribute value does not match the address 1608 family of the allocation, the server MUST reply with a 443 (Peer 1609 Address Family Mismatch) Refresh error response. 1611 The server computes a value called the "desired lifetime" as follows: 1612 if the request contains a LIFETIME attribute and the attribute value 1613 is 0, then the "desired lifetime" is 0. Otherwise, if the request 1614 contains a LIFETIME attribute, then the server computes the minimum 1615 of the client's requested lifetime and the server's maximum allowed 1616 lifetime. If this computed value is greater than the default 1617 lifetime, then the "desired lifetime" is the computed value. 1618 Otherwise, the "desired lifetime" is the default lifetime. 1620 Subsequent processing depends on the "desired lifetime" value: 1622 o If the "desired lifetime" is 0, then the request succeeds and the 1623 allocation is deleted. 1625 o If the "desired lifetime" is non-zero, then the request succeeds 1626 and the allocation's time-to-expiry is set to the "desired 1627 lifetime". 1629 If the request succeeds, then the server sends a success response 1630 containing: 1632 o A LIFETIME attribute containing the current value of the time-to- 1633 expiry timer. 1635 NOTE: A server need not do anything special to implement 1636 idempotency of Refresh requests over UDP using the "stateless 1637 stack approach". Retransmitted Refresh requests with a non-zero 1638 "desired lifetime" will simply refresh the allocation. A 1639 retransmitted Refresh request with a zero "desired lifetime" will 1640 cause a 437 (Allocation Mismatch) response if the allocation has 1641 already been deleted, but the client will treat this as equivalent 1642 to a success response (see below). 1644 7.3. Receiving a Refresh Response 1646 If the client receives a success response to its Refresh request with 1647 a non-zero lifetime, it updates its copy of the allocation data 1648 structure with the time-to-expiry value contained in the response. 1650 If the client receives a 437 (Allocation Mismatch) error response to 1651 a request to delete the allocation, then the allocation no longer 1652 exists and it should consider its request as having effectively 1653 succeeded. 1655 8. Permissions 1657 For each allocation, the server keeps a list of zero or more 1658 permissions. Each permission consists of an IP address and an 1659 associated time-to-expiry. While a permission exists, all peers 1660 using the IP address in the permission are allowed to send data to 1661 the client. The time-to-expiry is the number of seconds until the 1662 permission expires. Within the context of an allocation, a 1663 permission is uniquely identified by its associated IP address. 1665 By sending either CreatePermission requests or ChannelBind requests, 1666 the client can cause the server to install or refresh a permission 1667 for a given IP address. This causes one of two things to happen: 1669 o If no permission for that IP address exists, then a permission is 1670 created with the given IP address and a time-to-expiry equal to 1671 Permission Lifetime. 1673 o If a permission for that IP address already exists, then the time- 1674 to-expiry for that permission is reset to Permission Lifetime. 1676 The Permission Lifetime MUST be 300 seconds (= 5 minutes). 1678 Each permission's time-to-expiry decreases down once per second until 1679 it reaches 0; at which point, the permission expires and is deleted. 1681 CreatePermission and ChannelBind requests may be freely intermixed on 1682 a permission. A given permission may be initially installed and/or 1683 refreshed with a CreatePermission request, and then later refreshed 1684 with a ChannelBind request, or vice versa. 1686 When a UDP datagram arrives at the relayed transport address for the 1687 allocation, the server extracts the source IP address from the IP 1688 header. The server then compares this address with the IP address 1689 associated with each permission in the list of permissions for the 1690 allocation. If no match is found, relaying is not permitted, and the 1691 server silently discards the UDP datagram. If an exact match is 1692 found, then the permission check is considered to have succeeded and 1693 the server continues to process the UDP datagram as specified 1694 elsewhere (Section 10.3). Note that only addresses are compared and 1695 port numbers are not considered. 1697 The permissions for one allocation are totally unrelated to the 1698 permissions for a different allocation. If an allocation expires, 1699 all its permissions expire with it. 1701 NOTE: Though TURN permissions expire after 5 minutes, many NATs 1702 deployed at the time of publication expire their UDP bindings 1703 considerably faster. Thus, an application using TURN will 1704 probably wish to send some sort of keep-alive traffic at a much 1705 faster rate. Applications using ICE should follow the keep-alive 1706 guidelines of ICE [RFC5245], and applications not using ICE are 1707 advised to do something similar. 1709 9. CreatePermission 1711 TURN supports two ways for the client to install or refresh 1712 permissions on the server. This section describes one way: the 1713 CreatePermission request. 1715 A CreatePermission request may be used in conjunction with either the 1716 Send mechanism in Section 10 or the Channel mechanism in Section 11. 1718 9.1. Forming a CreatePermission Request 1720 The client who wishes to install or refresh one or more permissions 1721 can send a CreatePermission request to the server. 1723 When forming a CreatePermission request, the client MUST include at 1724 least one XOR-PEER-ADDRESS attribute, and MAY include more than one 1725 such attribute. The IP address portion of each XOR-PEER-ADDRESS 1726 attribute contains the IP address for which a permission should be 1727 installed or refreshed. The port portion of each XOR-PEER-ADDRESS 1728 attribute will be ignored and can be any arbitrary value. The 1729 various XOR-PEER-ADDRESS attributes can appear in any order. The 1730 client MUST only include XOR-PEER-ADDRESS attributes with addresses 1731 of the same address family as that of the relayed transport address 1732 for the allocation. For dual allocations obtained using the 1733 ADDITIONAL-FAMILY-ADDRESS attribute, the client can include XOR-PEER- 1734 ADDRESS attributes with addresses of IPv4 and IPv6 address families. 1736 9.2. Receiving a CreatePermission Request 1738 When the server receives the CreatePermission request, it processes 1739 as per Section 4 plus the specific rules mentioned here. 1741 The message is checked for validity. The CreatePermission request 1742 MUST contain at least one XOR-PEER-ADDRESS attribute and MAY contain 1743 multiple such attributes. If no such attribute exists, or if any of 1744 these attributes are invalid, then a 400 (Bad Request) error is 1745 returned. If the request is valid, but the server is unable to 1746 satisfy the request due to some capacity limit or similar, then a 508 1747 (Insufficient Capacity) error is returned. 1749 If an XOR-PEER-ADDRESS attribute contains an address of an address 1750 family that is not the same as that of the relayed transport address 1751 for the allocation, the server MUST generate an error response with 1752 the 443 (Peer Address Family Mismatch) response code. 1754 The server MAY impose restrictions on the IP address allowed in the 1755 XOR-PEER-ADDRESS attribute -- if a value is not allowed, the server 1756 rejects the request with a 403 (Forbidden) error. 1758 If the message is valid and the server is capable of carrying out the 1759 request, then the server installs or refreshes a permission for the 1760 IP address contained in each XOR-PEER-ADDRESS attribute as described 1761 in Section 8. The port portion of each attribute is ignored and may 1762 be any arbitrary value. 1764 The server then responds with a CreatePermission success response. 1765 There are no mandatory attributes in the success response. 1767 NOTE: A server need not do anything special to implement 1768 idempotency of CreatePermission requests over UDP using the 1769 "stateless stack approach". Retransmitted CreatePermission 1770 requests will simply refresh the permissions. 1772 9.3. Receiving a CreatePermission Response 1774 If the client receives a valid CreatePermission success response, 1775 then the client updates its data structures to indicate that the 1776 permissions have been installed or refreshed. 1778 10. Send and Data Methods 1780 TURN supports two mechanisms for sending and receiving data from 1781 peers. This section describes the use of the Send and Data 1782 mechanisms, while Section 11 describes the use of the Channel 1783 mechanism. 1785 10.1. Forming a Send Indication 1787 The client can use a Send indication to pass data to the server for 1788 relaying to a peer. A client may use a Send indication even if a 1789 channel is bound to that peer. However, the client MUST ensure that 1790 there is a permission installed for the IP address of the peer to 1791 which the Send indication is being sent; this prevents a third party 1792 from using a TURN server to send data to arbitrary destinations. 1794 When forming a Send indication, the client MUST include an XOR-PEER- 1795 ADDRESS attribute and a DATA attribute. The XOR-PEER-ADDRESS 1796 attribute contains the transport address of the peer to which the 1797 data is to be sent, and the DATA attribute contains the actual 1798 application data to be sent to the peer. 1800 The client MAY include a DONT-FRAGMENT attribute in the Send 1801 indication if it wishes the server to set the DF bit on the UDP 1802 datagram sent to the peer. 1804 10.2. Receiving a Send Indication 1806 When the server receives a Send indication, it processes as per 1807 Section 4 plus the specific rules mentioned here. 1809 The message is first checked for validity. The Send indication MUST 1810 contain both an XOR-PEER-ADDRESS attribute and a DATA attribute. If 1811 one of these attributes is missing or invalid, then the message is 1812 discarded. Note that the DATA attribute is allowed to contain zero 1813 bytes of data. 1815 The Send indication may also contain the DONT-FRAGMENT attribute. If 1816 the server is unable to set the DF bit on outgoing UDP datagrams when 1817 this attribute is present, then the server acts as if the DONT- 1818 FRAGMENT attribute is an unknown comprehension-required attribute 1819 (and thus the Send indication is discarded). 1821 The server also checks that there is a permission installed for the 1822 IP address contained in the XOR-PEER-ADDRESS attribute. If no such 1823 permission exists, the message is discarded. Note that a Send 1824 indication never causes the server to refresh the permission. 1826 The server MAY impose restrictions on the IP address and port values 1827 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1828 allowed, the server silently discards the Send indication. 1830 If everything is OK, then the server forms a UDP datagram as follows: 1832 o the source transport address is the relayed transport address of 1833 the allocation, where the allocation is determined by the 5-tuple 1834 on which the Send indication arrived; 1836 o the destination transport address is taken from the XOR-PEER- 1837 ADDRESS attribute; 1839 o the data following the UDP header is the contents of the value 1840 field of the DATA attribute. 1842 The handling of the DONT-FRAGMENT attribute (if present), is 1843 described in Section 13. 1845 The resulting UDP datagram is then sent to the peer. 1847 10.3. Receiving a UDP Datagram 1849 When the server receives a UDP datagram at a currently allocated 1850 relayed transport address, the server looks up the allocation 1851 associated with the relayed transport address. The server then 1852 checks to see whether the set of permissions for the allocation allow 1853 the relaying of the UDP datagram as described in Section 8. 1855 If relaying is permitted, then the server checks if there is a 1856 channel bound to the peer that sent the UDP datagram (see 1857 Section 11). If a channel is bound, then processing proceeds as 1858 described in Section 11.7. 1860 If relaying is permitted but no channel is bound to the peer, then 1861 the server forms and sends a Data indication. The Data indication 1862 MUST contain both an XOR-PEER-ADDRESS and a DATA attribute. The DATA 1863 attribute is set to the value of the 'data octets' field from the 1864 datagram, and the XOR-PEER-ADDRESS attribute is set to the source 1865 transport address of the received UDP datagram. The Data indication 1866 is then sent on the 5-tuple associated with the allocation. 1868 10.4. Receiving a Data Indication with DATA attribute 1870 When the client receives a Data indication with DATA attribute, it 1871 checks that the Data indication contains an XOR-PEER-ADDRESS 1872 attribute, and discards the indication if it does not. The client 1873 SHOULD also check that the XOR-PEER-ADDRESS attribute value contains 1874 an IP address with which the client believes there is an active 1875 permission, and discard the Data indication otherwise. Note that the 1876 DATA attribute is allowed to contain zero bytes of data. 1878 NOTE: The latter check protects the client against an attacker who 1879 somehow manages to trick the server into installing permissions 1880 not desired by the client. 1882 If the Data indication passes the above checks, the client delivers 1883 the data octets inside the DATA attribute to the application, along 1884 with an indication that they were received from the peer whose 1885 transport address is given by the XOR-PEER-ADDRESS attribute. 1887 10.5. Receiving an ICMP Packet 1889 When the server receives an ICMP packet, the server verifies that the 1890 type is either 3, 11 or 12 for an ICMPv4 [RFC0792] packet or either 1891 1, 2, or 3 for an ICMPv6 [RFC4443] packet. It also verifies that the 1892 IP packet in the ICMP packet payload contains a UDP header. If 1893 either of these conditions fail, then the ICMP packet is silently 1894 dropped. 1896 The server looks up the allocation whose relayed transport address 1897 corresponds to the encapsulated packet's source IP address and UDP 1898 port. If no such allocation exists, the packet is silently dropped. 1899 The server then checks to see whether the set of permissions for the 1900 allocation allows the relaying of the ICMP packet. For ICMP packets, 1901 the source IP address MUST NOT be checked against the permissions 1902 list as it would be for UDP packets. Instead, the server extracts 1903 the destination IP address from the encapsulated IP header. The 1904 server then compares this address with the IP address associated with 1905 each permission in the list of permissions for the allocation. If no 1906 match is found, relaying is not permitted, and the server silently 1907 discards the ICMP packet. Note that only addresses are compared and 1908 port numbers are not considered. 1910 If relaying is permitted then the server forms and sends a Data 1911 indication. The Data indication MUST contain both an XOR-PEER- 1912 ADDRESS and an ICMP attribute. The ICMP attribute is set to the 1913 value of the type and code fields from the ICMP packet. The IP 1914 address portion of XOR-PEER-ADDRESS attribute is set to the 1915 destination IP address in the encapsulated IP header. At the time of 1916 writing of this specification, Socket APIs on some operating systems 1917 do not deliver the destination port in the encapsulated UDP header to 1918 applications without superuser privileges. If destination port in 1919 the encapsulated UDP header is available to the server then the port 1920 portion of XOR-PEER-ADDRESS attribute is set to the destination port 1921 otherwise the port portion is set to 0. The Data indication is then 1922 sent on the 5-tuple associated with the allocation. 1924 10.6. Receiving a Data Indication with an ICMP attribute 1926 When the client receives a Data indication with an ICMP attribute, it 1927 checks that the Data indication contains an XOR-PEER-ADDRESS 1928 attribute, and discards the indication if it does not. The client 1929 SHOULD also check that the XOR-PEER-ADDRESS attribute value contains 1930 an IP address with an active permission, and discard the Data 1931 indication otherwise. 1933 If the Data indication passes the above checks, the client signals 1934 the application of the error condition, along with an indication that 1935 it was received from the peer whose transport address is given by the 1936 XOR-PEER-ADDRESS attribute. The application can make sense of the 1937 meaning of the type and code values in the ICMP attribute by using 1938 the family field in the XOR-PEER-ADDRESS attribute. 1940 11. Channels 1942 Channels provide a way for the client and server to send application 1943 data using ChannelData messages, which have less overhead than Send 1944 and Data indications. 1946 The ChannelData message (see Section 11.4) starts with a two-byte 1947 field that carries the channel number. The values of this field are 1948 allocated as follows: 1950 0x0000 through 0x3FFF: These values can never be used for channel 1951 numbers. 1953 0x4000 through 0x7FFF: These values are the allowed channel 1954 numbers (16,384 possible values). 1956 0x8000 through 0xFFFF: These values are reserved for future use. 1958 Because of this division, ChannelData messages can be distinguished 1959 from STUN-formatted messages (e.g., Allocate request, Send 1960 indication, etc.) by examining the first two bits of the message: 1962 0b00: STUN-formatted message (since the first two bits of a STUN- 1963 formatted message are always zero). 1965 0b01: ChannelData message (since the channel number is the first 1966 field in the ChannelData message and channel numbers fall in the 1967 range 0x4000 - 0x7FFF). 1969 0b10: Reserved 1971 0b11: Reserved 1973 The reserved values may be used in the future to extend the range of 1974 channel numbers. Thus, an implementation MUST NOT assume that a TURN 1975 message always starts with a 0 bit. 1977 Channel bindings are always initiated by the client. The client can 1978 bind a channel to a peer at any time during the lifetime of the 1979 allocation. The client may bind a channel to a peer before 1980 exchanging data with it, or after exchanging data with it (using Send 1981 and Data indications) for some time, or may choose never to bind a 1982 channel to it. The client can also bind channels to some peers while 1983 not binding channels to other peers. 1985 Channel bindings are specific to an allocation, so that the use of a 1986 channel number or peer transport address in a channel binding in one 1987 allocation has no impact on their use in a different allocation. If 1988 an allocation expires, all its channel bindings expire with it. 1990 A channel binding consists of: 1992 o a channel number; 1994 o a transport address (of the peer); and 1996 o A time-to-expiry timer. 1998 Within the context of an allocation, a channel binding is uniquely 1999 identified either by the channel number or by the peer's transport 2000 address. Thus, the same channel cannot be bound to two different 2001 transport addresses, nor can the same transport address be bound to 2002 two different channels. 2004 A channel binding lasts for 10 minutes unless refreshed. Refreshing 2005 the binding (by the server receiving a ChannelBind request rebinding 2006 the channel to the same peer) resets the time-to-expiry timer back to 2007 10 minutes. 2009 When the channel binding expires, the channel becomes unbound. Once 2010 unbound, the channel number can be bound to a different transport 2011 address, and the transport address can be bound to a different 2012 channel number. To prevent race conditions, the client MUST wait 5 2013 minutes after the channel binding expires before attempting to bind 2014 the channel number to a different transport address or the transport 2015 address to a different channel number. 2017 When binding a channel to a peer, the client SHOULD be prepared to 2018 receive ChannelData messages on the channel from the server as soon 2019 as it has sent the ChannelBind request. Over UDP, it is possible for 2020 the client to receive ChannelData messages from the server before it 2021 receives a ChannelBind success response. 2023 In the other direction, the client MAY elect to send ChannelData 2024 messages before receiving the ChannelBind success response. Doing 2025 so, however, runs the risk of having the ChannelData messages dropped 2026 by the server if the ChannelBind request does not succeed for some 2027 reason (e.g., packet lost if the request is sent over UDP, or the 2028 server being unable to fulfill the request). A client that wishes to 2029 be safe should either queue the data or use Send indications until 2030 the channel binding is confirmed. 2032 11.1. Sending a ChannelBind Request 2034 A channel binding is created or refreshed using a ChannelBind 2035 transaction. A ChannelBind transaction also creates or refreshes a 2036 permission towards the peer (see Section 8). 2038 To initiate the ChannelBind transaction, the client forms a 2039 ChannelBind request. The channel to be bound is specified in a 2040 CHANNEL-NUMBER attribute, and the peer's transport address is 2041 specified in an XOR-PEER-ADDRESS attribute. Section 11.2 describes 2042 the restrictions on these attributes. The client MUST only include 2043 an XOR-PEER-ADDRESS attribute with an address of the same address 2044 family as that of the relayed transport address for the allocation. 2046 Rebinding a channel to the same transport address that it is already 2047 bound to provides a way to refresh a channel binding and the 2048 corresponding permission without sending data to the peer. Note 2049 however, that permissions need to be refreshed more frequently than 2050 channels. 2052 11.2. Receiving a ChannelBind Request 2054 When the server receives a ChannelBind request, it processes as per 2055 Section 4 plus the specific rules mentioned here. 2057 The server checks the following: 2059 o The request contains both a CHANNEL-NUMBER and an XOR-PEER-ADDRESS 2060 attribute; 2062 o The channel number is in the range 0x4000 through 0x7FFE 2063 (inclusive); 2065 o The channel number is not currently bound to a different transport 2066 address (same transport address is OK); 2068 o The transport address is not currently bound to a different 2069 channel number. 2071 o If the XOR-PEER-ADDRESS attribute contains an address of an 2072 address family that is not the same as that of the relayed 2073 transport address for the allocation, the server MUST generate an 2074 error response with the 443 (Peer Address Family Mismatch) 2075 response code. 2077 If any of these tests fail, the server replies with a 400 (Bad 2078 Request) error. 2080 The server MAY impose restrictions on the IP address and port values 2081 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 2082 allowed, the server rejects the request with a 403 (Forbidden) error. 2084 If the request is valid, but the server is unable to fulfill the 2085 request due to some capacity limit or similar, the server replies 2086 with a 508 (Insufficient Capacity) error. 2088 Otherwise, the server replies with a ChannelBind success response. 2089 There are no required attributes in a successful ChannelBind 2090 response. 2092 If the server can satisfy the request, then the server creates or 2093 refreshes the channel binding using the channel number in the 2094 CHANNEL-NUMBER attribute and the transport address in the XOR-PEER- 2095 ADDRESS attribute. The server also installs or refreshes a 2096 permission for the IP address in the XOR-PEER-ADDRESS attribute as 2097 described in Section 8. 2099 NOTE: A server need not do anything special to implement 2100 idempotency of ChannelBind requests over UDP using the "stateless 2101 stack approach". Retransmitted ChannelBind requests will simply 2102 refresh the channel binding and the corresponding permission. 2103 Furthermore, the client must wait 5 minutes before binding a 2104 previously bound channel number or peer address to a different 2105 channel, eliminating the possibility that the transaction would 2106 initially fail but succeed on a retransmission. 2108 11.3. Receiving a ChannelBind Response 2110 When the client receives a ChannelBind success response, it updates 2111 its data structures to record that the channel binding is now active. 2112 It also updates its data structures to record that the corresponding 2113 permission has been installed or refreshed. 2115 If the client receives a ChannelBind failure response that indicates 2116 that the channel information is out-of-sync between the client and 2117 the server (e.g., an unexpected 400 "Bad Request" response), then it 2118 is RECOMMENDED that the client immediately delete the allocation and 2119 start afresh with a new allocation. 2121 11.4. The ChannelData Message 2123 The ChannelData message is used to carry application data between the 2124 client and the server. It has the following format: 2126 0 1 2 3 2127 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 2128 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2129 | Channel Number | Length | 2130 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2131 | | 2132 / Application Data / 2133 / / 2134 | | 2135 | +-------------------------------+ 2136 | | 2137 +-------------------------------+ 2139 The Channel Number field specifies the number of the channel on which 2140 the data is traveling, and thus the address of the peer that is 2141 sending or is to receive the data. 2143 The Length field specifies the length in bytes of the application 2144 data field (i.e., it does not include the size of the ChannelData 2145 header). Note that 0 is a valid length. 2147 The Application Data field carries the data the client is trying to 2148 send to the peer, or that the peer is sending to the client. 2150 11.5. Sending a ChannelData Message 2152 Once a client has bound a channel to a peer, then when the client has 2153 data to send to that peer it may use either a ChannelData message or 2154 a Send indication; that is, the client is not obligated to use the 2155 channel when it exists and may freely intermix the two message types 2156 when sending data to the peer. The server, on the other hand, MUST 2157 use the ChannelData message if a channel has been bound to the peer. 2158 The server uses a Data indication to signal the XOR-PEER-ADDRESS and 2159 ICMP attributes to the client even if a channel has been bound to the 2160 peer. 2162 The fields of the ChannelData message are filled in as described in 2163 Section 11.4. 2165 Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to 2166 a multiple of four bytes in order to ensure the alignment of 2167 subsequent messages. The padding is not reflected in the length 2168 field of the ChannelData message, so the actual size of a ChannelData 2169 message (including padding) is (4 + Length) rounded up to the nearest 2170 multiple of 4. Over UDP, the padding is not required but MAY be 2171 included. 2173 The ChannelData message is then sent on the 5-tuple associated with 2174 the allocation. 2176 11.6. Receiving a ChannelData Message 2178 The receiver of the ChannelData message uses the first two bits to 2179 distinguish it from STUN-formatted messages, as described above. If 2180 the message uses a value in the reserved range (0x8000 through 2181 0xFFFF), then the message is silently discarded. 2183 If the ChannelData message is received in a UDP datagram, and if the 2184 UDP datagram is too short to contain the claimed length of the 2185 ChannelData message (i.e., the UDP header length field value is less 2186 than the ChannelData header length field value + 4 + 8), then the 2187 message is silently discarded. 2189 If the ChannelData message is received over TCP or over TLS-over-TCP, 2190 then the actual length of the ChannelData message is as described in 2191 Section 11.5. 2193 If the ChannelData message is received on a channel that is not bound 2194 to any peer, then the message is silently discarded. 2196 On the client, it is RECOMMENDED that the client discard the 2197 ChannelData message if the client believes there is no active 2198 permission towards the peer. On the server, the receipt of a 2199 ChannelData message MUST NOT refresh either the channel binding or 2200 the permission towards the peer. 2202 On the server, if no errors are detected, the server relays the 2203 application data to the peer by forming a UDP datagram as follows: 2205 o the source transport address is the relayed transport address of 2206 the allocation, where the allocation is determined by the 5-tuple 2207 on which the ChannelData message arrived; 2209 o the destination transport address is the transport address to 2210 which the channel is bound; 2212 o the data following the UDP header is the contents of the data 2213 field of the ChannelData message. 2215 The resulting UDP datagram is then sent to the peer. Note that if 2216 the Length field in the ChannelData message is 0, then there will be 2217 no data in the UDP datagram, but the UDP datagram is still formed and 2218 sent. 2220 11.7. Relaying Data from the Peer 2222 When the server receives a UDP datagram on the relayed transport 2223 address associated with an allocation, the server processes it as 2224 described in Section 10.3. If that section indicates that a 2225 ChannelData message should be sent (because there is a channel bound 2226 to the peer that sent to the UDP datagram), then the server forms and 2227 sends a ChannelData message as described in Section 11.5. 2229 When the server receives an ICMP packet, the server processes it as 2230 described in Section 10.5. A Data indication MUST be sent regardless 2231 if there is a channel bound to the peer that was the destination of 2232 the UDP datagram that triggered the reception of the ICMP packet. 2234 12. Packet Translations 2236 As discussed in Section 2.6, translations in TURN are designed so 2237 that a TURN server can be implemented as an application that runs in 2238 userland under commonly available operating systems and that does not 2239 require special privileges. The translations specified in the 2240 following sections follow this principle. 2242 The descriptions below have two parts: a preferred behavior and an 2243 alternate behavior. The server SHOULD implement the preferred 2244 behavior. Otherwise, the server MUST implement the alternate 2245 behavior and MUST NOT do anything else for the reasons detailed in 2246 [RFC6145]. 2248 12.1. IPv4-to-IPv6 Translations 2250 Traffic Class 2252 Preferred behavior: As specified in Section 4 of [RFC6145]. 2254 Alternate behavior: The relay sets the Traffic Class to the 2255 default value for outgoing packets. 2257 Flow Label 2259 Preferred behavior: The relay sets the Flow label to 0. The relay 2260 can choose to set the Flow label to a different value if it 2261 supports the IPv6 Flow Label field[RFC3697]. 2263 Alternate behavior: the relay sets the Flow label to the default 2264 value for outgoing packets. 2266 Hop Limit 2268 Preferred behavior: As specified in Section 4 of [RFC6145]. 2270 Alternate behavior: The relay sets the Hop Limit to the default 2271 value for outgoing packets. 2273 Fragmentation 2275 Preferred behavior: As specified in Section 4 of [RFC6145]. 2277 Alternate behavior: The relay assembles incoming fragments. The 2278 relay follows its default behavior to send outgoing packets. 2280 For both preferred and alternate behavior, the DONT-FRAGMENT 2281 attribute MUST be ignored by the server. 2283 Extension Headers 2285 Preferred behavior: The relay sends outgoing packet without any 2286 IPv6 extension headers, with the exception of the Fragmentation 2287 header as described above. 2289 Alternate behavior: Same as preferred. 2291 12.2. IPv6-to-IPv6 Translations 2293 Flow Label 2295 The relay should consider that it is handling two different IPv6 2296 flows. Therefore, the Flow label [RFC3697] SHOULD NOT be copied as 2297 part of the translation. 2299 Preferred behavior: The relay sets the Flow label to 0. The relay 2300 can choose to set the Flow label to a different value if it 2301 supports the IPv6 Flow Label field[RFC3697]. 2303 Alternate behavior: The relay sets the Flow label to the default 2304 value for outgoing packets. 2306 Hop Limit 2308 Preferred behavior: The relay acts as a regular router with 2309 respect to decrementing the Hop Limit and generating an ICMPv6 2310 error if it reaches zero. 2312 Alternate behavior: The relay sets the Hop Limit to the default 2313 value for outgoing packets. 2315 Fragmentation 2317 Preferred behavior: If the incoming packet did not include a 2318 Fragment header and the outgoing packet size does not exceed the 2319 outgoing link's MTU, the relay sends the outgoing packet without a 2320 Fragment header. 2322 If the incoming packet did not include a Fragment header and the 2323 outgoing packet size exceeds the outgoing link's MTU, the relay 2324 drops the outgoing packet and send an ICMP message of type 2 code 2325 0 ("Packet too big") to the sender of the incoming packet. If 2326 the packet is being sent to the peer, the relay reduces the MTU 2327 reported in the ICMP message by 48 bytes to allow room for the 2328 overhead of a Data indication. 2330 If the incoming packet included a Fragment header and the outgoing 2331 packet size (with a Fragment header included) does not exceed the 2332 outgoing link's MTU, the relay sends the outgoing packet with a 2333 Fragment header. The relay sets the fields of the Fragment header 2334 as appropriate for a packet originating from the server. 2336 If the incoming packet included a Fragment header and the outgoing 2337 packet size exceeds the outgoing link's MTU, the relay MUST 2338 fragment the outgoing packet into fragments of no more than 1280 2339 bytes. The relay sets the fields of the Fragment header as 2340 appropriate for a packet originating from the server. 2342 Alternate behavior: The relay assembles incoming fragments. The 2343 relay follows its default behavior to send outgoing packets. 2345 For both preferred and alternate behavior, the DONT-FRAGMENT 2346 attribute MUST be ignored by the server. 2348 Extension Headers 2350 Preferred behavior: The relay sends outgoing packet without any 2351 IPv6 extension headers, with the exception of the Fragmentation 2352 header as described above. 2354 Alternate behavior: Same as preferred. 2356 12.3. IPv6-to-IPv4 Translations 2358 Type of Service and Precedence 2360 Preferred behavior: As specified in Section 5 of [RFC6145]. 2362 Alternate behavior: The relay sets the Type of Service and 2363 Precedence to the default value for outgoing packets. 2365 Time to Live 2367 Preferred behavior: As specified in Section 5 of [RFC6145]. 2369 Alternate behavior: The relay sets the Time to Live to the default 2370 value for outgoing packets. 2372 Fragmentation 2374 Preferred behavior: As specified in Section 5 of [RFC6145]. 2375 Additionally, when the outgoing packet's size exceeds the 2376 outgoing link's MTU, the relay needs to generate an ICMP error 2377 (ICMPv6 Packet Too Big) reporting the MTU size. If the packet is 2378 being sent to the peer, the relay SHOULD reduce the MTU reported 2379 in the ICMP message by 48 bytes to allow room for the overhead of 2380 a Data indication. 2382 Alternate behavior: The relay assembles incoming fragments. The 2383 relay follows its default behavior to send outgoing packets. 2385 For both preferred and alternate behavior, the DONT-FRAGMENT 2386 attribute MUST be ignored by the server. 2388 13. IP Header Fields 2390 This section describes how the server sets various fields in the IP 2391 header when relaying between the client and the peer or vice versa. 2392 The descriptions in this section apply: (a) when the server sends a 2393 UDP datagram to the peer, or (b) when the server sends a Data 2394 indication or ChannelData message to the client over UDP transport. 2395 The descriptions in this section do not apply to TURN messages sent 2396 over TCP or TLS transport from the server to the client. 2398 The descriptions below have two parts: a preferred behavior and an 2399 alternate behavior. The server SHOULD implement the preferred 2400 behavior, but if that is not possible for a particular field, then it 2401 SHOULD implement the alternative behavior. 2403 Time to Live (TTL) field 2405 Preferred Behavior: If the incoming value is 0, then the drop the 2406 incoming packet. Otherwise, set the outgoing Time to Live/Hop 2407 Count to one less than the incoming value. 2409 Alternate Behavior: Set the outgoing value to the default for 2410 outgoing packets. 2412 Differentiated Services Code Point (DSCP) field [RFC2474] 2414 Preferred Behavior: Set the outgoing value to the incoming value, 2415 unless the server includes a differentiated services classifier 2416 and marker [RFC2474]. 2418 Alternate Behavior: Set the outgoing value to a fixed value, which 2419 by default is Best Effort unless configured otherwise. 2421 In both cases, if the server is immediately adjacent to a 2422 differentiated services classifier and marker, then DSCP MAY be 2423 set to any arbitrary value in the direction towards the 2424 classifier. 2426 Explicit Congestion Notification (ECN) field [RFC3168] 2428 Preferred Behavior: Set the outgoing value to the incoming value, 2429 UNLESS the server is doing Active Queue Management, the incoming 2430 ECN field is ECT(1) (=0b01) or ECT(0) (=0b10), and the server 2431 wishes to indicate that congestion has been experienced, in which 2432 case set the outgoing value to CE (=0b11). 2434 Alternate Behavior: Set the outgoing value to Not-ECT (=0b00). 2436 IPv4 Fragmentation fields 2438 Preferred Behavior: When the server sends a packet to a peer in 2439 response to a Send indication containing the DONT-FRAGMENT 2440 attribute, then set the DF bit in the outgoing IP header to 1. In 2441 all other cases when sending an outgoing packet containing 2442 application data (e.g., Data indication, ChannelData message, or 2443 DONT-FRAGMENT attribute not included in the Send indication), copy 2444 the DF bit from the DF bit of the incoming packet that contained 2445 the application data. 2447 Set the other fragmentation fields (Identification, More 2448 Fragments, Fragment Offset) as appropriate for a packet 2449 originating from the server. 2451 Alternate Behavior: As described in the Preferred Behavior, except 2452 always assume the incoming DF bit is 0. 2454 In both the Preferred and Alternate Behaviors, the resulting 2455 packet may be too large for the outgoing link. If this is the 2456 case, then the normal fragmentation rules apply [RFC1122]. 2458 IPv4 Options 2460 Preferred Behavior: The outgoing packet is sent without any IPv4 2461 options. 2463 Alternate Behavior: Same as preferred. 2465 14. New STUN Methods 2467 This section lists the codepoints for the new STUN methods defined in 2468 this specification. See elsewhere in this document for the semantics 2469 of these new methods. 2471 0x003 : Allocate (only request/response semantics defined) 2472 0x004 : Refresh (only request/response semantics defined) 2473 0x006 : Send (only indication semantics defined) 2474 0x007 : Data (only indication semantics defined) 2475 0x008 : CreatePermission (only request/response semantics defined 2476 0x009 : ChannelBind (only request/response semantics defined) 2478 15. New STUN Attributes 2480 This STUN extension defines the following new attributes: 2482 0x000C: CHANNEL-NUMBER 2483 0x000D: LIFETIME 2484 0x0010: Reserved (was BANDWIDTH) 2485 0x0012: XOR-PEER-ADDRESS 2486 0x0013: DATA 2487 0x0016: XOR-RELAYED-ADDRESS 2488 0x0017: REQUESTED-ADDRESS-FAMILY 2489 0x0018: EVEN-PORT 2490 0x0019: REQUESTED-TRANSPORT 2491 0x001A: DONT-FRAGMENT 2492 0x0021: Reserved (was TIMER-VAL) 2493 0x0022: RESERVATION-TOKEN 2494 TBD-CA: ADDITIONAL-ADDRESS-FAMILY 2495 TBD-CA: ADDRESS-ERROR-CODE 2496 TBD-CA: ICMP 2498 Some of these attributes have lengths that are not multiples of 4. 2499 By the rules of STUN, any attribute whose length is not a multiple of 2500 4 bytes MUST be immediately followed by 1 to 3 padding bytes to 2501 ensure the next attribute (if any) would start on a 4-byte boundary 2502 (see [RFC5389]). 2504 15.1. CHANNEL-NUMBER 2506 The CHANNEL-NUMBER attribute contains the number of the channel. The 2507 value portion of this attribute is 4 bytes long and consists of a 2508 16-bit unsigned integer, followed by a two-octet RFFU (Reserved For 2509 Future Use) field, which MUST be set to 0 on transmission and MUST be 2510 ignored on reception. 2512 0 1 2 3 2513 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 2514 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2515 | Channel Number | RFFU = 0 | 2516 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2518 15.2. LIFETIME 2520 The LIFETIME attribute represents the duration for which the server 2521 will maintain an allocation in the absence of a refresh. The value 2522 portion of this attribute is 4-bytes long and consists of a 32-bit 2523 unsigned integral value representing the number of seconds remaining 2524 until expiration. 2526 15.3. XOR-PEER-ADDRESS 2528 The XOR-PEER-ADDRESS specifies the address and port of the peer as 2529 seen from the TURN server. (For example, the peer's server-reflexive 2530 transport address if the peer is behind a NAT.) It is encoded in the 2531 same way as XOR-MAPPED-ADDRESS [RFC5389]. 2533 15.4. DATA 2535 The DATA attribute is present in all Send and Data indications. The 2536 value portion of this attribute is variable length and consists of 2537 the application data (that is, the data that would immediately follow 2538 the UDP header if the data was been sent directly between the client 2539 and the peer). If the length of this attribute is not a multiple of 2540 4, then padding must be added after this attribute. 2542 15.5. XOR-RELAYED-ADDRESS 2544 The XOR-RELAYED-ADDRESS is present in Allocate responses. It 2545 specifies the address and port that the server allocated to the 2546 client. It is encoded in the same way as XOR-MAPPED-ADDRESS 2547 [RFC5389]. 2549 15.6. REQUESTED-ADDRESS-FAMILY 2551 This attribute is used by clients to request the allocation of a 2552 specific address type from a server. The following is the format of 2553 the REQUESTED-ADDRESS-FAMILY attribute. Note that TURN attributes 2554 are TLV (Type-Length-Value) encoded, with a 16-bit type, a 16-bit 2555 length, and a variable-length value. 2557 0 1 2 3 2558 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 2559 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2560 | Type | Length | 2561 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2562 | Family | Reserved | 2563 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2565 Type: the type of the REQUESTED-ADDRESS-FAMILY attribute is 0x0017. 2566 As specified in [RFC5389], attributes with values between 0x0000 2567 and 0x7FFF are comprehension-required, which means that the client 2568 or server cannot successfully process the message unless it 2569 understands the attribute. 2571 Length: this 16-bit field contains the length of the attribute in 2572 bytes. The length of this attribute is 4 bytes. 2574 Family: there are two values defined for this field and specified in 2575 [RFC5389], Section 15.1: 0x01 for IPv4 addresses and 0x02 for IPv6 2576 addresses. 2578 Reserved: at this point, the 24 bits in the Reserved field MUST be 2579 set to zero by the client and MUST be ignored by the server. 2581 The REQUEST-ADDRESS-TYPE attribute MAY only be present in Allocate 2582 requests. 2584 15.7. EVEN-PORT 2586 This attribute allows the client to request that the port in the 2587 relayed transport address be even, and (optionally) that the server 2588 reserve the next-higher port number. The value portion of this 2589 attribute is 1 byte long. Its format is: 2591 0 2592 0 1 2 3 4 5 6 7 2593 +-+-+-+-+-+-+-+-+ 2594 |R| RFFU | 2595 +-+-+-+-+-+-+-+-+ 2597 The value contains a single 1-bit flag: 2599 R: If 1, the server is requested to reserve the next-higher port 2600 number (on the same IP address) for a subsequent allocation. If 2601 0, no such reservation is requested. 2603 The other 7 bits of the attribute's value must be set to zero on 2604 transmission and ignored on reception. 2606 Since the length of this attribute is not a multiple of 4, padding 2607 must immediately follow this attribute. 2609 15.8. REQUESTED-TRANSPORT 2611 This attribute is used by the client to request a specific transport 2612 protocol for the allocated transport address. The value of this 2613 attribute is 4 bytes with the following format: 2615 0 1 2 3 2616 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 2617 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2618 | Protocol | RFFU | 2619 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2621 The Protocol field specifies the desired protocol. The codepoints 2622 used in this field are taken from those allowed in the Protocol field 2623 in the IPv4 header and the NextHeader field in the IPv6 header 2624 [Protocol-Numbers]. This specification only allows the use of 2625 codepoint 17 (User Datagram Protocol). 2627 The RFFU field MUST be set to zero on transmission and MUST be 2628 ignored on reception. It is reserved for future uses. 2630 15.9. DONT-FRAGMENT 2632 This attribute is used by the client to request that the server set 2633 the DF (Don't Fragment) bit in the IP header when relaying the 2634 application data onward to the peer. This attribute has no value 2635 part and thus the attribute length field is 0. 2637 15.10. RESERVATION-TOKEN 2639 The RESERVATION-TOKEN attribute contains a token that uniquely 2640 identifies a relayed transport address being held in reserve by the 2641 server. The server includes this attribute in a success response to 2642 tell the client about the token, and the client includes this 2643 attribute in a subsequent Allocate request to request the server use 2644 that relayed transport address for the allocation. 2646 The attribute value is 8 bytes and contains the token value. 2648 15.11. ADDITIONAL-ADDRESS-FAMILY 2650 This attribute is used by clients to request the allocation of a IPv4 2651 and IPv6 address type from a server. It is encoded in the same way 2652 as REQUESTED-ADDRESS-FAMILY Section 15.6. The ADDITIONAL-ADDRESS- 2653 FAMILY attribute MAY be present in Allocate request. The attribute 2654 value of 0x02 (IPv6 address) is the only valid value in Allocate 2655 request. 2657 15.12. ADDRESS-ERROR-CODE Attribute 2659 This attribute is used by servers to signal the reason for not 2660 allocating the requested address family. The following is the format 2661 of the ADDRESS-ERROR-CODE attribute. 2663 0 1 2 3 2664 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 2665 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2666 | Type | Length | 2667 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2668 | Family | Rsvd |Class| Number | 2669 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2670 | Reason Phrase (variable) .. 2671 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2673 Type: the type of the ADDRESS-ERROR-CODE attribute is TBD-CA. As 2674 specified in [RFC5389], attributes with values between 0x8000 and 2675 0xFFFF are comprehension-optional, which means that the client or 2676 server can safely ignore the attribute if they don't understand 2677 it. 2679 Length: this 16-bit field contains the length of the attribute in 2680 bytes. 2682 Family: there are two values defined for this field and specified in 2683 [RFC5389], Section 15.1: 0x01 for IPv4 addresses and 0x02 for IPv6 2684 addresses. 2686 Reserved: at this point, the 13 bits in the Reserved field MUST be 2687 set to zero by the client and MUST be ignored by the server. 2689 Class: The Class represents the hundreds digit of the error code and 2690 is defined in section 15.6 of [RFC5389]. 2692 Number: this 8-bit field contains the reason server cannot allocate 2693 one of the requested address types. The error code values could 2694 be either 440 (unsupported address family) or 508 (insufficient 2695 capacity). The number representation is defined in section 15.6 2696 of [RFC5389]. 2698 Reason Phrase: The recommended reason phrases for error codes 440 2699 and 508 are explained in Section 16. 2701 The ADDRESS-ERROR-CODE attribute MAY only be present in Allocate 2702 responses. 2704 15.13. ICMP Attribute 2706 This attribute is used by servers to signal the reason an UDP packet 2707 was dropped. The following is the format of the ICMP attribute. 2709 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 2710 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2711 | Reserved | Type | Code | 2712 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2714 Reserved: This field MUST be set to 0 when sent, and MUST be ignored 2715 when received. 2717 Type: The field contains the value in the ICMP type. Its 2718 interpretation depends whether the ICMP was received over IPv4 or 2719 IPv6. 2721 Code: The field contains the value in the ICMP code. Its 2722 interpretation depends whether the ICMP was received over IPv4 or 2723 IPv6. 2725 16. New STUN Error Response Codes 2727 This document defines the following new error response codes: 2729 403 (Forbidden): The request was valid but cannot be performed due 2730 to administrative or similar restrictions. 2732 437 (Allocation Mismatch): A request was received by the server that 2733 requires an allocation to be in place, but no allocation exists, 2734 or a request was received that requires no allocation, but an 2735 allocation exists. 2737 440 (Address Family not Supported): The server does not support the 2738 address family requested by the client. 2740 441 (Wrong Credentials): The credentials in the (non-Allocate) 2741 request do not match those used to create the allocation. 2743 442 (Unsupported Transport Protocol): The Allocate request asked the 2744 server to use a transport protocol between the server and the peer 2745 that the server does not support. NOTE: This does NOT refer to 2746 the transport protocol used in the 5-tuple. 2748 443 (Peer Address Family Mismatch). A peer address is part of a 2749 different address family than that of the relayed transport 2750 address of the allocation. 2752 486 (Allocation Quota Reached): No more allocations using this 2753 username can be created at the present time. 2755 508 (Insufficient Capacity): The server is unable to carry out the 2756 request due to some capacity limit being reached. In an Allocate 2757 response, this could be due to the server having no more relayed 2758 transport addresses available at that time, having none with the 2759 requested properties, or the one that corresponds to the specified 2760 reservation token is not available. 2762 17. Detailed Example 2764 This section gives an example of the use of TURN, showing in detail 2765 the contents of the messages exchanged. The example uses the network 2766 diagram shown in the Overview (Figure 1). 2768 For each message, the attributes included in the message and their 2769 values are shown. For convenience, values are shown in a human- 2770 readable format rather than showing the actual octets; for example, 2771 "XOR-RELAYED-ADDRESS=192.0.2.15:9000" shows that the XOR-RELAYED- 2772 ADDRESS attribute is included with an address of 192.0.2.15 and a 2773 port of 9000, here the address and port are shown before the xor-ing 2774 is done. For attributes with string-like values (e.g., 2775 SOFTWARE="Example client, version 1.03" and 2776 NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda"), the value of the attribute 2777 is shown in quotes for readability, but these quotes do not appear in 2778 the actual value. 2780 TURN TURN Peer Peer 2781 client server A B 2782 | | | | 2783 |--- Allocate request -------------->| | | 2784 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2785 | SOFTWARE="Example client, version 1.03" | | 2786 | LIFETIME=3600 (1 hour) | | | 2787 | REQUESTED-TRANSPORT=17 (UDP) | | | 2788 | DONT-FRAGMENT | | | 2789 | | | | 2790 |<-- Allocate error response --------| | | 2791 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2792 | SOFTWARE="Example server, version 1.17" | | 2793 | ERROR-CODE=401 (Unauthorized) | | | 2794 | REALM="example.com" | | | 2795 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 2796 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 2797 | | | | 2798 |--- Allocate request -------------->| | | 2799 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2800 | SOFTWARE="Example client 1.03" | | | 2801 | LIFETIME=3600 (1 hour) | | | 2802 | REQUESTED-TRANSPORT=17 (UDP) | | | 2803 | DONT-FRAGMENT | | | 2804 | USERNAME="George" | | | 2805 | REALM="example.com" | | | 2806 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 2807 | PASSWORD-ALGORITHM=SHA256 | | | 2808 | MESSAGE-INTEGRITY=... | | | 2809 | MESSAGE-INTEGRITY-SHA256=... | | | 2810 | | | | 2811 |<-- Allocate success response ------| | | 2812 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2813 | SOFTWARE="Example server, version 1.17" | | 2814 | LIFETIME=1200 (20 minutes) | | | 2815 | XOR-RELAYED-ADDRESS=192.0.2.15:50000 | | 2816 | XOR-MAPPED-ADDRESS=192.0.2.1:7000 | | 2817 | MESSAGE-INTEGRITY=... | | | 2819 The client begins by selecting a host transport address to use for 2820 the TURN session; in this example, the client has selected 2821 10.1.1.2:49721 as shown in Figure 1. The client then sends an 2822 Allocate request to the server at the server transport address. The 2823 client randomly selects a 96-bit transaction id of 2824 0xA56250D3F17ABE679422DE85 for this transaction; this is encoded in 2825 the transaction id field in the fixed header. The client includes a 2826 SOFTWARE attribute that gives information about the client's 2827 software; here the value is "Example client, version 1.03" to 2828 indicate that this is version 1.03 of something called the Example 2829 client. The client includes the LIFETIME attribute because it wishes 2830 the allocation to have a longer lifetime than the default of 10 2831 minutes; the value of this attribute is 3600 seconds, which 2832 corresponds to 1 hour. The client must always include a REQUESTED- 2833 TRANSPORT attribute in an Allocate request and the only value allowed 2834 by this specification is 17, which indicates UDP transport between 2835 the server and the peers. The client also includes the DONT-FRAGMENT 2836 attribute because it wishes to use the DONT-FRAGMENT attribute later 2837 in Send indications; this attribute consists of only an attribute 2838 header, there is no value part. We assume the client has not 2839 recently interacted with the server, thus the client does not include 2840 USERNAME, USERHASH, REALM, NONCE, PASSWORD-ALGORITHMS, PASSWORD- 2841 ALGORITHM, MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute. 2842 Finally, note that the order of attributes in a message is arbitrary 2843 (except for the MESSAGE-INTEGRITY, MESSAGE-INTEGRITY-SHA256 and 2844 FINGERPRINT attributes) and the client could have used a different 2845 order. 2847 Servers require any request to be authenticated. Thus, when the 2848 server receives the initial Allocate request, it rejects the request 2849 because the request does not contain the authentication attributes. 2850 Following the procedures of the long-term credential mechanism of 2851 STUN [RFC5389], the server includes an ERROR-CODE attribute with a 2852 value of 401 (Unauthorized), a REALM attribute that specifies the 2853 authentication realm used by the server (in this case, the server's 2854 domain "example.com"), and a nonce value in a NONCE attribute. The 2855 NONCE attribute starts with the "nonce cookie" with the STUN Security 2856 Feature "Password algorithm" bit set to 1. The server includes a 2857 PASSWORD-ALGORITHMS attribute that specifies the list of algorithms 2858 that the server can use to derive the long-term password. If the 2859 server sets the STUN Security Feature "Username anonymity" bit to 1 2860 then the client uses the USERHASH attribute instead of the USERNAME 2861 attribute in the Allocate request to anonymise the username. The 2862 server also includes a SOFTWARE attribute that gives information 2863 about the server's software. 2865 The client, upon receipt of the 401 error, re-attempts the Allocate 2866 request, this time including the authentication attributes. The 2867 client selects a new transaction id, and then populates the new 2868 Allocate request with the same attributes as before. The client 2869 includes a USERNAME attribute and uses the realm value received from 2870 the server to help it determine which value to use; here the client 2871 is configured to use the username "George" for the realm 2872 "example.com". The client includes the PASSWORD-ALGORITHM attribute 2873 indicating the algorithm that the server must use to derive the long- 2874 term password. The client also includes the REALM and NONCE 2875 attributes, which are just copied from the 401 error response. 2877 Finally, the client includes MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 2878 SHA256 attributes as the last attributes in the message, whose values 2879 are Hashed Message Authentication Code - Secure Hash Algorithm 1 2880 (HMAC-SHA1) hash and Hashed Message Authentication Code - Secure Hash 2881 Algorithm 2 (HMAC-SHA2) hash over the contents of the message (shown 2882 as just "..." above); this HMAC-SHA1 and HMAC-SHA2 computation 2883 includes a password value. Thus, an attacker cannot compute the 2884 message integrity value without somehow knowing the secret password. 2886 The server, upon receipt of the authenticated Allocate request, 2887 checks that everything is OK, then creates an allocation. The server 2888 replies with an Allocate success response. The server includes a 2889 LIFETIME attribute giving the lifetime of the allocation; here, the 2890 server has reduced the client's requested 1-hour lifetime to just 20 2891 minutes, because this particular server doesn't allow lifetimes 2892 longer than 20 minutes. The server includes an XOR-RELAYED-ADDRESS 2893 attribute whose value is the relayed transport address of the 2894 allocation. The server includes an XOR-MAPPED-ADDRESS attribute 2895 whose value is the server-reflexive address of the client; this value 2896 is not used otherwise in TURN but is returned as a convenience to the 2897 client. The server includes either a MESSAGE-INTEGRITY or MESSAGE- 2898 INTEGRITY-SHA256 attribute to authenticate the response and to ensure 2899 its integrity; note that the response does not contain the USERNAME, 2900 REALM, and NONCE attributes. The server also includes a SOFTWARE 2901 attribute. 2903 TURN TURN Peer Peer 2904 client server A B 2905 |--- CreatePermission request ------>| | | 2906 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2907 | XOR-PEER-ADDRESS=192.0.2.150:0 | | | 2908 | USERNAME="George" | | | 2909 | REALM="example.com" | | | 2910 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 2911 | MESSAGE-INTEGRITY=... | | | 2912 | | | | 2913 |<-- CreatePermission success resp.--| | | 2914 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2915 | MESSAGE-INTEGRITY=... | | | 2917 The client then creates a permission towards Peer A in preparation 2918 for sending it some application data. This is done through a 2919 CreatePermission request. The XOR-PEER-ADDRESS attribute contains 2920 the IP address for which a permission is established (the IP address 2921 of peer A); note that the port number in the attribute is ignored 2922 when used in a CreatePermission request, and here it has been set to 2923 0; also, note how the client uses Peer A's server-reflexive IP 2924 address and not its (private) host address. The client uses the same 2925 username, realm, and nonce values as in the previous request on the 2926 allocation. Though it is allowed to do so, the client has chosen not 2927 to include a SOFTWARE attribute in this request. 2929 The server receives the CreatePermission request, creates the 2930 corresponding permission, and then replies with a CreatePermission 2931 success response. Like the client, the server chooses not to include 2932 the SOFTWARE attribute in its reply. Again, note how success 2933 responses contain a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 2934 attribute (assuming the server uses the long-term credential 2935 mechanism), but no USERNAME, REALM, and NONCE attributes. 2937 TURN TURN Peer Peer 2938 client server A B 2939 |--- Send indication --------------->| | | 2940 | Transaction-Id=0x1278E9ACA2711637EF7D3328 | | 2941 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2942 | DONT-FRAGMENT | | | 2943 | DATA=... | | | 2944 | |-- UDP dgm ->| | 2945 | | data=... | | 2946 | | | | 2947 | |<- UDP dgm --| | 2948 | | data=... | | 2949 |<-- Data indication ----------------| | | 2950 | Transaction-Id=0x8231AE8F9242DA9FF287FEFF | | 2951 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2952 | DATA=... | | | 2954 The client now sends application data to Peer A using a Send 2955 indication. Peer A's server-reflexive transport address is specified 2956 in the XOR-PEER-ADDRESS attribute, and the application data (shown 2957 here as just "...") is specified in the DATA attribute. The client 2958 is doing a form of path MTU discovery at the application layer and 2959 thus specifies (by including the DONT-FRAGMENT attribute) that the 2960 server should set the DF bit in the UDP datagram to send to the peer. 2961 Indications cannot be authenticated using the long-term credential 2962 mechanism of STUN, so no MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 2963 SHA256 attribute is included in the message. An application wishing 2964 to ensure that its data is not altered or forged must integrity- 2965 protect its data at the application level. 2967 Upon receipt of the Send indication, the server extracts the 2968 application data and sends it in a UDP datagram to Peer A, with the 2969 relayed transport address as the source transport address of the 2970 datagram, and with the DF bit set as requested. Note that, had the 2971 client not previously established a permission for Peer A's server- 2972 reflexive IP address, then the server would have silently discarded 2973 the Send indication instead. 2975 Peer A then replies with its own UDP datagram containing application 2976 data. The datagram is sent to the relayed transport address on the 2977 server. When this arrives, the server creates a Data indication 2978 containing the source of the UDP datagram in the XOR-PEER-ADDRESS 2979 attribute, and the data from the UDP datagram in the DATA attribute. 2980 The resulting Data indication is then sent to the client. 2982 TURN TURN Peer Peer 2983 client server A B 2984 |--- ChannelBind request ----------->| | | 2985 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2986 | CHANNEL-NUMBER=0x4000 | | | 2987 | XOR-PEER-ADDRESS=192.0.2.210:49191 | | 2988 | USERNAME="George" | | | 2989 | REALM="example.com" | | | 2990 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 2991 | MESSAGE-INTEGRITY=... | | | 2992 | | | | 2993 |<-- ChannelBind success response ---| | | 2994 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2995 | MESSAGE-INTEGRITY=... | | | 2997 The client now binds a channel to Peer B, specifying a free channel 2998 number (0x4000) in the CHANNEL-NUMBER attribute, and Peer B's 2999 transport address in the XOR-PEER-ADDRESS attribute. As before, the 3000 client re-uses the username, realm, and nonce from its last request 3001 in the message. 3003 Upon receipt of the request, the server binds the channel number to 3004 the peer, installs a permission for Peer B's IP address, and then 3005 replies with ChannelBind success response. 3007 TURN TURN Peer Peer 3008 client server A B 3009 |--- ChannelData ------------------->| | | 3010 | Channel-number=0x4000 |--- UDP datagram --------->| 3011 | Data=... | Data=... | 3012 | | | | 3013 | |<-- UDP datagram ----------| 3014 | | Data=... | | 3015 |<-- ChannelData --------------------| | | 3016 | Channel-number=0x4000 | | | 3017 | Data=... | | | 3019 The client now sends a ChannelData message to the server with data 3020 destined for Peer B. The ChannelData message is not a STUN message, 3021 and thus has no transaction id. Instead, it has only three fields: a 3022 channel number, data, and data length; here the channel number field 3023 is 0x4000 (the channel the client just bound to Peer B). When the 3024 server receives the ChannelData message, it checks that the channel 3025 is currently bound (which it is) and then sends the data onward to 3026 Peer B in a UDP datagram, using the relayed transport address as the 3027 source transport address and 192.0.2.210:49191 (the value of the XOR- 3028 PEER-ADDRESS attribute in the ChannelBind request) as the destination 3029 transport address. 3031 Later, Peer B sends a UDP datagram back to the relayed transport 3032 address. This causes the server to send a ChannelData message to the 3033 client containing the data from the UDP datagram. The server knows 3034 to which client to send the ChannelData message because of the 3035 relayed transport address at which the UDP datagram arrived, and 3036 knows to use channel 0x4000 because this is the channel bound to 3037 192.0.2.210:49191. Note that if there had not been any channel 3038 number bound to that address, the server would have used a Data 3039 indication instead. 3041 TURN TURN Peer Peer 3042 client server A B 3043 |--- Refresh request --------------->| | | 3044 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 3045 | SOFTWARE="Example client 1.03" | | | 3046 | USERNAME="George" | | | 3047 | REALM="example.com" | | | 3048 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3049 | MESSAGE-INTEGRITY=... | | | 3050 | | | | 3051 |<-- Refresh error response ---------| | | 3052 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 3053 | SOFTWARE="Example server, version 1.17" | | 3054 | ERROR-CODE=438 (Stale Nonce) | | | 3055 | REALM="example.com" | | | 3056 | NONCE="obMatJos2AAABnpSw1Xw239bBwGYhjN" | | 3057 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 3058 | | | | 3059 |--- Refresh request --------------->| | | 3060 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 3061 | SOFTWARE="Example client 1.03" | | | 3062 | USERNAME="George" | | | 3063 | REALM="example.com" | | | 3064 | NONCE="obMatJos2AAABnpSw1Xw239bBwGYhjNj" | | 3065 | PASSWORD-ALGORITHM=SHA256 | | | 3066 | MESSAGE-INTEGRITY=... | | | 3067 | | | | 3068 |<-- Refresh success response -------| | | 3069 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 3070 | SOFTWARE="Example server, version 1.17" | | 3071 | LIFETIME=600 (10 minutes) | | | 3073 Sometime before the 20 minute lifetime is up, the client refreshes 3074 the allocation. This is done using a Refresh request. As before, 3075 the client includes the latest username, realm, and nonce values in 3076 the request. The client also includes the SOFTWARE attribute, 3077 following the recommended practice of always including this attribute 3078 in Allocate and Refresh messages. When the server receives the 3079 Refresh request, it notices that the nonce value has expired, and so 3080 replies with 438 (Stale Nonce) error given a new nonce value. The 3081 client then reattempts the request, this time with the new nonce 3082 value. This second attempt is accepted, and the server replies with 3083 a success response. Note that the client did not include a LIFETIME 3084 attribute in the request, so the server refreshes the allocation for 3085 the default lifetime of 10 minutes (as can be seen by the LIFETIME 3086 attribute in the success response). 3088 18. Security Considerations 3090 This section considers attacks that are possible in a TURN 3091 deployment, and discusses how they are mitigated by mechanisms in the 3092 protocol or recommended practices in the implementation. 3094 Most of the attacks on TURN are mitigated by the server requiring 3095 requests be authenticated. Thus, this specification requires the use 3096 of authentication. The mandatory-to-implement mechanism is the long- 3097 term credential mechanism of STUN. Other authentication mechanisms 3098 of equal or stronger security properties may be used. However, it is 3099 important to ensure that they can be invoked in an inter-operable 3100 way. 3102 18.1. Outsider Attacks 3104 Outsider attacks are ones where the attacker has no credentials in 3105 the system, and is attempting to disrupt the service seen by the 3106 client or the server. 3108 18.1.1. Obtaining Unauthorized Allocations 3110 An attacker might wish to obtain allocations on a TURN server for any 3111 number of nefarious purposes. A TURN server provides a mechanism for 3112 sending and receiving packets while cloaking the actual IP address of 3113 the client. This makes TURN servers an attractive target for 3114 attackers who wish to use it to mask their true identity. 3116 An attacker might also wish to simply utilize the services of a TURN 3117 server without paying for them. Since TURN services require 3118 resources from the provider, it is anticipated that their usage will 3119 come with a cost. 3121 These attacks are prevented using the long-term credential mechanism, 3122 which allows the TURN server to determine the identity of the 3123 requestor and whether the requestor is allowed to obtain the 3124 allocation. 3126 18.1.2. Offline Dictionary Attacks 3128 The long-term credential mechanism used by TURN is subject to offline 3129 dictionary attacks. An attacker that is capable of eavesdropping on 3130 a message exchange between a client and server can determine the 3131 password by trying a number of candidate passwords and seeing if one 3132 of them is correct. This attack works when the passwords are low 3133 entropy, such as a word from the dictionary. This attack can be 3134 mitigated by using strong passwords with large entropy. In 3135 situations where even stronger mitigation is required, (D)TLS 3136 transport between the client and the server can be used. 3138 18.1.3. Faked Refreshes and Permissions 3140 An attacker might wish to attack an active allocation by sending it a 3141 Refresh request with an immediate expiration, in order to delete it 3142 and disrupt service to the client. This is prevented by 3143 authentication of refreshes. Similarly, an attacker wishing to send 3144 CreatePermission requests to create permissions to undesirable 3145 destinations is prevented from doing so through authentication. The 3146 motivations for such an attack are described in Section 18.2. 3148 18.1.4. Fake Data 3150 An attacker might wish to send data to the client or the peer, as if 3151 they came from the peer or client, respectively. To do that, the 3152 attacker can send the client a faked Data Indication or ChannelData 3153 message, or send the TURN server a faked Send Indication or 3154 ChannelData message. 3156 Since indications and ChannelData messages are not authenticated, 3157 this attack is not prevented by TURN. However, this attack is 3158 generally present in IP-based communications and is not substantially 3159 worsened by TURN. Consider a normal, non-TURN IP session between 3160 hosts A and B. An attacker can send packets to B as if they came 3161 from A by sending packets towards A with a spoofed IP address of B. 3162 This attack requires the attacker to know the IP addresses of A and 3163 B. With TURN, an attacker wishing to send packets towards a client 3164 using a Data indication needs to know its IP address (and port), the 3165 IP address and port of the TURN server, and the IP address and port 3166 of the peer (for inclusion in the XOR-PEER-ADDRESS attribute). To 3167 send a fake ChannelData message to a client, an attacker needs to 3168 know the IP address and port of the client, the IP address and port 3169 of the TURN server, and the channel number. This particular 3170 combination is mildly more guessable than in the non-TURN case. 3172 These attacks are more properly mitigated by application-layer 3173 authentication techniques. In the case of real-time traffic, usage 3174 of SRTP [RFC3711] prevents these attacks. 3176 In some situations, the TURN server may be situated in the network 3177 such that it is able to send to hosts to which the client cannot 3178 directly send. This can happen, for example, if the server is 3179 located behind a firewall that allows packets from outside the 3180 firewall to be delivered to the server, but not to other hosts behind 3181 the firewall. In these situations, an attacker could send the server 3182 a Send indication with an XOR-PEER-ADDRESS attribute containing the 3183 transport address of one of the other hosts behind the firewall. If 3184 the server was to allow relaying of traffic to arbitrary peers, then 3185 this would provide a way for the attacker to attack arbitrary hosts 3186 behind the firewall. 3188 To mitigate this attack, TURN requires that the client establish a 3189 permission to a host before sending it data. Thus, an attacker can 3190 only attack hosts with which the client is already communicating, 3191 unless the attacker is able to create authenticated requests. 3192 Furthermore, the server administrator may configure the server to 3193 restrict the range of IP addresses and ports to which it will relay 3194 data. To provide even greater security, the server administrator can 3195 require that the client use (D)TLS for all communication between the 3196 client and the server. 3198 18.1.5. Impersonating a Server 3200 When a client learns a relayed address from a TURN server, it uses 3201 that relayed address in application protocols to receive traffic. 3202 Therefore, an attacker wishing to intercept or redirect that traffic 3203 might try to impersonate a TURN server and provide the client with a 3204 faked relayed address. 3206 This attack is prevented through the long-term credential mechanism, 3207 which provides message integrity for responses in addition to 3208 verifying that they came from the server. Furthermore, an attacker 3209 cannot replay old server responses as the transaction id in the STUN 3210 header prevents this. Replay attacks are further thwarted through 3211 frequent changes to the nonce value. 3213 18.1.6. Eavesdropping Traffic 3215 TURN concerns itself primarily with authentication and message 3216 integrity. Confidentiality is only a secondary concern, as TURN 3217 control messages do not include information that is particularly 3218 sensitive. The primary protocol content of the messages is the IP 3219 address of the peer. If it is important to prevent an eavesdropper 3220 on a TURN connection from learning this, TURN can be run over (D)TLS. 3222 Confidentiality for the application data relayed by TURN is best 3223 provided by the application protocol itself, since running TURN over 3224 (D)TLS does not protect application data between the server and the 3225 peer. If confidentiality of application data is important, then the 3226 application should encrypt or otherwise protect its data. For 3227 example, for real-time media, confidentiality can be provided by 3228 using SRTP. 3230 18.1.7. TURN Loop Attack 3232 An attacker might attempt to cause data packets to loop indefinitely 3233 between two TURN servers. The attack goes as follows. First, the 3234 attacker sends an Allocate request to server A, using the source 3235 address of server B. Server A will send its response to server B, 3236 and for the attack to succeed, the attacker must have the ability to 3237 either view or guess the contents of this response, so that the 3238 attacker can learn the allocated relayed transport address. The 3239 attacker then sends an Allocate request to server B, using the source 3240 address of server A. Again, the attacker must be able to view or 3241 guess the contents of the response, so it can send learn the 3242 allocated relayed transport address. Using the same spoofed source 3243 address technique, the attacker then binds a channel number on server 3244 A to the relayed transport address on server B, and similarly binds 3245 the same channel number on server B to the relayed transport address 3246 on server A. Finally, the attacker sends a ChannelData message to 3247 server A. 3249 The result is a data packet that loops from the relayed transport 3250 address on server A to the relayed transport address on server B, 3251 then from server B's transport address to server A's transport 3252 address, and then around the loop again. 3254 This attack is mitigated as follows. By requiring all requests to be 3255 authenticated and/or by randomizing the port number allocated for the 3256 relayed transport address, the server forces the attacker to either 3257 intercept or view responses sent to a third party (in this case, the 3258 other server) so that the attacker can authenticate the requests and 3259 learn the relayed transport address. Without one of these two 3260 measures, an attacker can guess the contents of the responses without 3261 needing to see them, which makes the attack much easier to perform. 3262 Furthermore, by requiring authenticated requests, the server forces 3263 the attacker to have credentials acceptable to the server, which 3264 turns this from an outsider attack into an insider attack and allows 3265 the attack to be traced back to the client initiating it. 3267 The attack can be further mitigated by imposing a per-username limit 3268 on the bandwidth used to relay data by allocations owned by that 3269 username, to limit the impact of this attack on other allocations. 3270 More mitigation can be achieved by decrementing the TTL when relaying 3271 data packets (if the underlying OS allows this). 3273 18.2. Firewall Considerations 3275 A key security consideration of TURN is that TURN should not weaken 3276 the protections afforded by firewalls deployed between a client and a 3277 TURN server. It is anticipated that TURN servers will often be 3278 present on the public Internet, and clients may often be inside 3279 enterprise networks with corporate firewalls. If TURN servers 3280 provide a 'backdoor' for reaching into the enterprise, TURN will be 3281 blocked by these firewalls. 3283 TURN servers therefore emulate the behavior of NAT devices that 3284 implement address-dependent filtering [RFC4787], a property common in 3285 many firewalls as well. When a NAT or firewall implements this 3286 behavior, packets from an outside IP address are only allowed to be 3287 sent to an internal IP address and port if the internal IP address 3288 and port had recently sent a packet to that outside IP address. TURN 3289 servers introduce the concept of permissions, which provide exactly 3290 this same behavior on the TURN server. An attacker cannot send a 3291 packet to a TURN server and expect it to be relayed towards the 3292 client, unless the client has tried to contact the attacker first. 3294 It is important to note that some firewalls have policies that are 3295 even more restrictive than address-dependent filtering. Firewalls 3296 can also be configured with address- and port-dependent filtering, or 3297 can be configured to disallow inbound traffic entirely. In these 3298 cases, if a client is allowed to connect the TURN server, 3299 communications to the client will be less restrictive than what the 3300 firewall would normally allow. 3302 18.2.1. Faked Permissions 3304 In firewalls and NAT devices, permissions are granted implicitly 3305 through the traversal of a packet from the inside of the network 3306 towards the outside peer. Thus, a permission cannot, by definition, 3307 be created by any entity except one inside the firewall or NAT. With 3308 TURN, this restriction no longer holds. Since the TURN server sits 3309 outside the firewall, at attacker outside the firewall can now send a 3310 message to the TURN server and try to create a permission for itself. 3312 This attack is prevented because all messages that create permissions 3313 (i.e., ChannelBind and CreatePermission) are authenticated. 3315 18.2.2. Blacklisted IP Addresses 3317 Many firewalls can be configured with blacklists that prevent a 3318 client behind the firewall from sending packets to, or receiving 3319 packets from, ranges of blacklisted IP addresses. This is 3320 accomplished by inspecting the source and destination addresses of 3321 packets entering and exiting the firewall, respectively. 3323 This feature is also present in TURN, since TURN servers are allowed 3324 to arbitrarily restrict the range of addresses of peers that they 3325 will relay to. 3327 18.2.3. Running Servers on Well-Known Ports 3329 A malicious client behind a firewall might try to connect to a TURN 3330 server and obtain an allocation which it then uses to run a server. 3331 For example, a client might try to run a DNS server or FTP server. 3333 This is not possible in TURN. A TURN server will never accept 3334 traffic from a peer for which the client has not installed a 3335 permission. Thus, peers cannot just connect to the allocated port in 3336 order to obtain the service. 3338 18.3. Insider Attacks 3340 In insider attacks, a client has legitimate credentials but defies 3341 the trust relationship that goes with those credentials. These 3342 attacks cannot be prevented by cryptographic means but need to be 3343 considered in the design of the protocol. 3345 18.3.1. DoS against TURN Server 3347 A client wishing to disrupt service to other clients might obtain an 3348 allocation and then flood it with traffic, in an attempt to swamp the 3349 server and prevent it from servicing other legitimate clients. This 3350 is mitigated by the recommendation that the server limit the amount 3351 of bandwidth it will relay for a given username. This won't prevent 3352 a client from sending a large amount of traffic, but it allows the 3353 server to immediately discard traffic in excess. 3355 Since each allocation uses a port number on the IP address of the 3356 TURN server, the number of allocations on a server is finite. An 3357 attacker might attempt to consume all of them by requesting a large 3358 number of allocations. This is prevented by the recommendation that 3359 the server impose a limit of the number of allocations active at a 3360 time for a given username. 3362 18.3.2. Anonymous Relaying of Malicious Traffic 3364 TURN servers provide a degree of anonymization. A client can send 3365 data to peers without revealing its own IP address. TURN servers may 3366 therefore become attractive vehicles for attackers to launch attacks 3367 against targets without fear of detection. Indeed, it is possible 3368 for a client to chain together multiple TURN servers, such that any 3369 number of relays can be used before a target receives a packet. 3371 Administrators who are worried about this attack can maintain logs 3372 that capture the actual source IP and port of the client, and perhaps 3373 even every permission that client installs. This will allow for 3374 forensic tracing to determine the original source, should it be 3375 discovered that an attack is being relayed through a TURN server. 3377 18.3.3. Manipulating Other Allocations 3379 An attacker might attempt to disrupt service to other users of the 3380 TURN server by sending Refresh requests or CreatePermission requests 3381 that (through source address spoofing) appear to be coming from 3382 another user of the TURN server. TURN prevents this by requiring 3383 that the credentials used in CreatePermission, Refresh, and 3384 ChannelBind messages match those used to create the initial 3385 allocation. Thus, the fake requests from the attacker will be 3386 rejected. 3388 18.4. Tunnel Amplification Attack 3390 An attacker might attempt to cause data packets to loop numerous 3391 times between a TURN server and a tunnel between IPv4 and IPv6. The 3392 attack goes as follows. 3394 Suppose an attacker knows that a tunnel endpoint will forward 3395 encapsulated packets from a given IPv6 address (this doesn't 3396 necessarily need to be the tunnel endpoint's address). Suppose he 3397 then spoofs two packets from this address: 3399 1. An Allocate request asking for a v4 address, and 3401 2. A ChannelBind request establishing a channel to the IPv4 address 3402 of the tunnel endpoint 3404 Then he has set up an amplification attack: 3406 o The TURN relay will re-encapsulate IPv6 UDP data in v4 and send it 3407 to the tunnel endpoint 3409 o The tunnel endpoint will de-encapsulate packets from the v4 3410 interface and send them to v6 3412 So if the attacker sends a packet of the following form... 3414 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3415 UDP: 3416 TURN: 3417 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3418 UDP: 3419 TURN: 3420 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3421 UDP: 3422 TURN: 3423 ... 3425 Then the TURN relay and the tunnel endpoint will send it back and 3426 forth until the last TURN header is consumed, at which point the TURN 3427 relay will send an empty packet, which the tunnel endpoint will drop. 3429 The amplification potential here is limited by the MTU, so it's not 3430 huge: IPv6+UDP+TURN takes 334 bytes, so a four-to-one amplification 3431 out of a 1500-byte packet is possible. But the attacker could still 3432 increase traffic volume by sending multiple packets or by 3433 establishing multiple channels spoofed from different addresses 3434 behind the same tunnel endpoint. 3436 The attack is mitigated as follows. It is RECOMMENDED that TURN 3437 relays not accept allocation or channel binding requests from 3438 addresses known to be tunneled, and that they not forward data to 3439 such addresses. In particular, a TURN relay MUST NOT accept Teredo 3440 or 6to4 addresses in these requests. 3442 18.5. Other Considerations 3444 Any relay addresses learned through an Allocate request will not 3445 operate properly with IPsec Authentication Header (AH) [RFC4302] in 3446 transport or tunnel mode. However, tunnel-mode IPsec Encapsulating 3447 Security Payload (ESP) [RFC4303] should still operate. 3449 19. IANA Considerations 3451 Since TURN is an extension to STUN [RFC5389], the methods, 3452 attributes, and error codes defined in this specification are new 3453 methods, attributes, and error codes for STUN. IANA has added these 3454 new protocol elements to the IANA registry of STUN protocol elements. 3456 The codepoints for the new STUN methods defined in this specification 3457 are listed in Section 14. 3459 The codepoints for the new STUN attributes defined in this 3460 specification are listed in Section 15. 3462 The codepoints for the new STUN error codes defined in this 3463 specification are listed in Section 16. 3465 IANA has allocated the SRV service name of "turn" for TURN over UDP 3466 or TCP, and the service name of "turns" for TURN over (D)TLS. 3468 IANA has created a registry for TURN channel numbers, initially 3469 populated as follows: 3471 o 0x0000 through 0x3FFF: Reserved and not available for use, since 3472 they conflict with the STUN header. 3474 o 0x4000 through 0x7FFF: A TURN implementation is free to use 3475 channel numbers in this range. 3477 o 0x8000 through 0xFFFF: Unassigned. 3479 Any change to this registry must be made through an IETF Standards 3480 Action. 3482 [Paragraphs in braces should be removed by the RFC Editor upon 3483 publication] 3485 [The ADDITIONAL-ADDRESS-FAMILY, ADDRESS-ERROR-CODE and ICMP 3486 attributes requires that IANA allocate a value in the "STUN 3487 attributes Registry" from the comprehension- optional range 3488 (0x8000-0xFFFF), to be replaced for TBD-CA throughout this document] 3490 [The SendErr method requires that IANA allocate a value in the "STUN 3491 Methods Registry" from the range (0x000-0x7FF), to be replaced for 3492 TBD-DA throughout this document] 3494 20. IAB Considerations 3496 The IAB has studied the problem of "Unilateral Self Address Fixing" 3497 (UNSAF), which is the general process by which a client attempts to 3498 determine its address in another realm on the other side of a NAT 3499 through a collaborative protocol-reflection mechanism [RFC3424]. The 3500 TURN extension is an example of a protocol that performs this type of 3501 function. The IAB has mandated that any protocols developed for this 3502 purpose document a specific set of considerations. These 3503 considerations and the responses for TURN are documented in this 3504 section. 3506 Consideration 1: Precise definition of a specific, limited-scope 3507 problem that is to be solved with the UNSAF proposal. A short-term 3508 fix should not be generalized to solve other problems. Such 3509 generalizations lead to the prolonged dependence on and usage of the 3510 supposed short-term fix -- meaning that it is no longer accurate to 3511 call it "short-term". 3513 Response: TURN is a protocol for communication between a relay (= 3514 TURN server) and its client. The protocol allows a client that is 3515 behind a NAT to obtain and use a public IP address on the relay. As 3516 a convenience to the client, TURN also allows the client to determine 3517 its server-reflexive transport address. 3519 Consideration 2: Description of an exit strategy/transition plan. 3520 The better short-term fixes are the ones that will naturally see less 3521 and less use as the appropriate technology is deployed. 3523 Response: TURN will no longer be needed once there are no longer any 3524 NATs. Unfortunately, as of the date of publication of this document, 3525 it no longer seems very likely that NATs will go away any time soon. 3526 However, the need for TURN will also decrease as the number of NATs 3527 with the mapping property of Endpoint-Independent Mapping [RFC4787] 3528 increases. 3530 Consideration 3: Discussion of specific issues that may render 3531 systems more "brittle". For example, approaches that involve using 3532 data at multiple network layers create more dependencies, increase 3533 debugging challenges, and make it harder to transition. 3535 Response: TURN is "brittle" in that it requires the NAT bindings 3536 between the client and the server to be maintained unchanged for the 3537 lifetime of the allocation. This is typically done using keep- 3538 alives. If this is not done, then the client will lose its 3539 allocation and can no longer exchange data with its peers. 3541 Consideration 4: Identify requirements for longer-term, sound 3542 technical solutions; contribute to the process of finding the right 3543 longer-term solution. 3545 Response: The need for TURN will be reduced once NATs implement the 3546 recommendations for NAT UDP behavior documented in [RFC4787]. 3547 Applications are also strongly urged to use ICE [RFC5245] to 3548 communicate with peers; though ICE uses TURN, it does so only as a 3549 last resort, and uses it in a controlled manner. 3551 Consideration 5: Discussion of the impact of the noted practical 3552 issues with existing deployed NATs and experience reports. 3554 Response: Some NATs deployed today exhibit a mapping behavior other 3555 than Endpoint-Independent mapping. These NATs are difficult to work 3556 with, as they make it difficult or impossible for protocols like ICE 3557 to use server-reflexive transport addresses on those NATs. A client 3558 behind such a NAT is often forced to use a relay protocol like TURN 3559 because "UDP hole punching" techniques [RFC5128] do not work. 3561 21. Changes since RFC 5766 3563 This section lists the major changes in the TURN protocol from the 3564 original [RFC5766] specification. 3566 o IPv6 support. 3568 o REQUESTED-ADDRESS-FAMILY, ADDITIONAL-ADDRESS-FAMILY, AND ADDRESS- 3569 ERRR-CODE attributes. 3571 o 440 (Address Family not Supported) and 443 (Peer Address Family 3572 Mismatch) responses. 3574 o Description of the tunnel amplification attack. 3576 o DTLS support. 3578 o More details on packet translations. 3580 o Add support for receiving ICMP packets. 3582 o Updates PMTUD. 3584 22. Acknowledgements 3586 Most of the text in this note comes from the original TURN 3587 specification, [RFC5766]. The authors would like to thank Rohan Mahy 3588 co-author of orginal TURN specification and everyone who had 3589 contributed to that document. 3591 Thanks to Justin Uberti, Pal Martinsen, Oleg Moskalenko, Aijun Wang 3592 and Simon Perreault for their help on SSODA mechanism. Authors would 3593 like to thank Gonzalo Salgueiro, Simon Perreault, Jonathan Lennox and 3594 Oleg Moskalenko for comments and review. The authors would like to 3595 thank Marc for his contributions to the text. 3597 23. References 3599 23.1. Normative References 3601 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 3602 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 3603 DOI 10.17487/RFC5389, October 2008, 3604 . 3606 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3607 Requirement Levels", BCP 14, RFC 2119, 3608 DOI 10.17487/RFC2119, March 1997, 3609 . 3611 [RFC2474] Nichols, K., Blake, S., Baker, F., and D. Black, 3612 "Definition of the Differentiated Services Field (DS 3613 Field) in the IPv4 and IPv6 Headers", RFC 2474, 3614 DOI 10.17487/RFC2474, December 1998, 3615 . 3617 [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 3618 of Explicit Congestion Notification (ECN) to IP", 3619 RFC 3168, DOI 10.17487/RFC3168, September 2001, 3620 . 3622 [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - 3623 Communication Layers", STD 3, RFC 1122, 3624 DOI 10.17487/RFC1122, October 1989, 3625 . 3627 [RFC6145] Li, X., Bao, C., and F. Baker, "IP/ICMP Translation 3628 Algorithm", RFC 6145, DOI 10.17487/RFC6145, April 2011, 3629 . 3631 [RFC3697] Rajahalme, J., Conta, A., Carpenter, B., and S. Deering, 3632 "IPv6 Flow Label Specification", RFC 3697, 3633 DOI 10.17487/RFC3697, March 2004, 3634 . 3636 [RFC7065] Petit-Huguenin, M., Nandakumar, S., Salgueiro, G., and P. 3637 Jones, "Traversal Using Relays around NAT (TURN) Uniform 3638 Resource Identifiers", RFC 7065, DOI 10.17487/RFC7065, 3639 November 2013, . 3641 [RFC0792] Postel, J., "Internet Control Message Protocol", STD 5, 3642 RFC 792, DOI 10.17487/RFC0792, September 1981, 3643 . 3645 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 3646 Control Message Protocol (ICMPv6) for the Internet 3647 Protocol Version 6 (IPv6) Specification", RFC 4443, 3648 DOI 10.17487/RFC4443, March 2006, 3649 . 3651 [I-D.ietf-tram-stunbis] 3652 Petit-Huguenin, M., Salgueiro, G., Rosenberg, J., Wing, 3653 D., Mahy, R., and P. Matthews, "Session Traversal 3654 Utilities for NAT (STUN)", draft-ietf-tram-stunbis-12 3655 (work in progress), March 2017. 3657 [RFC6724] Thaler, D., Ed., Draves, R., Matsumoto, A., and T. Chown, 3658 "Default Address Selection for Internet Protocol Version 6 3659 (IPv6)", RFC 6724, DOI 10.17487/RFC6724, September 2012, 3660 . 3662 [RFC6555] Wing, D. and A. Yourtchenko, "Happy Eyeballs: Success with 3663 Dual-Stack Hosts", RFC 6555, DOI 10.17487/RFC6555, April 3664 2012, . 3666 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 3667 Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, 3668 January 2012, . 3670 23.2. Informative References 3672 [RFC1191] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 3673 DOI 10.17487/RFC1191, November 1990, 3674 . 3676 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 3677 DOI 10.17487/RFC0791, September 1981, 3678 . 3680 [RFC1918] Rekhter, Y., Moskowitz, B., Karrenberg, D., de Groot, G., 3681 and E. Lear, "Address Allocation for Private Internets", 3682 BCP 5, RFC 1918, DOI 10.17487/RFC1918, February 1996, 3683 . 3685 [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations for 3686 UNilateral Self-Address Fixing (UNSAF) Across Network 3687 Address Translation", RFC 3424, DOI 10.17487/RFC3424, 3688 November 2002, . 3690 [RFC4787] Audet, F., Ed. and C. Jennings, "Network Address 3691 Translation (NAT) Behavioral Requirements for Unicast 3692 UDP", BCP 127, RFC 4787, DOI 10.17487/RFC4787, January 3693 2007, . 3695 [RFC5245] Rosenberg, J., "Interactive Connectivity Establishment 3696 (ICE): A Protocol for Network Address Translator (NAT) 3697 Traversal for Offer/Answer Protocols", RFC 5245, 3698 DOI 10.17487/RFC5245, April 2010, 3699 . 3701 [RFC6062] Perreault, S., Ed. and J. Rosenberg, "Traversal Using 3702 Relays around NAT (TURN) Extensions for TCP Allocations", 3703 RFC 6062, DOI 10.17487/RFC6062, November 2010, 3704 . 3706 [RFC6156] Camarillo, G., Novo, O., and S. Perreault, Ed., "Traversal 3707 Using Relays around NAT (TURN) Extension for IPv6", 3708 RFC 6156, DOI 10.17487/RFC6156, April 2011, 3709 . 3711 [RFC6056] Larsen, M. and F. Gont, "Recommendations for Transport- 3712 Protocol Port Randomization", BCP 156, RFC 6056, 3713 DOI 10.17487/RFC6056, January 2011, 3714 . 3716 [RFC5128] Srisuresh, P., Ford, B., and D. Kegel, "State of Peer-to- 3717 Peer (P2P) Communication across Network Address 3718 Translators (NATs)", RFC 5128, DOI 10.17487/RFC5128, March 3719 2008, . 3721 [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and 3722 L. Jones, "SOCKS Protocol Version 5", RFC 1928, 3723 DOI 10.17487/RFC1928, March 1996, 3724 . 3726 [RFC3550] Schulzrinne, H., Casner, S., Frederick, R., and V. 3727 Jacobson, "RTP: A Transport Protocol for Real-Time 3728 Applications", STD 64, RFC 3550, DOI 10.17487/RFC3550, 3729 July 2003, . 3731 [RFC3711] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. 3732 Norrman, "The Secure Real-time Transport Protocol (SRTP)", 3733 RFC 3711, DOI 10.17487/RFC3711, March 2004, 3734 . 3736 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, 3737 DOI 10.17487/RFC4302, December 2005, 3738 . 3740 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 3741 RFC 4303, DOI 10.17487/RFC4303, December 2005, 3742 . 3744 [RFC4821] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 3745 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 3746 . 3748 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 3749 A., Peterson, J., Sparks, R., Handley, M., and E. 3750 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 3751 DOI 10.17487/RFC3261, June 2002, 3752 . 3754 [I-D.rosenberg-mmusic-ice-nonsip] 3755 Rosenberg, J., "Guidelines for Usage of Interactive 3756 Connectivity Establishment (ICE) by non Session Initiation 3757 Protocol (SIP) Protocols", draft-rosenberg-mmusic-ice- 3758 nonsip-01 (work in progress), July 2008. 3760 [I-D.ietf-tram-stun-pmtud] 3761 Petit-Huguenin, M. and G. Salgueiro, "Path MTU Discovery 3762 Using Session Traversal Utilities for NAT (STUN)", draft- 3763 ietf-tram-stun-pmtud-05 (work in progress), February 2017. 3765 [RFC8155] Patil, P., Reddy, T., and D. Wing, "Traversal Using Relays 3766 around NAT (TURN) Server Auto Discovery", RFC 8155, 3767 DOI 10.17487/RFC8155, April 2017, 3768 . 3770 [RFC4086] Eastlake 3rd, D., Schiller, J., and S. Crocker, 3771 "Randomness Requirements for Security", BCP 106, RFC 4086, 3772 DOI 10.17487/RFC4086, June 2005, 3773 . 3775 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 3776 Relays around NAT (TURN): Relay Extensions to Session 3777 Traversal Utilities for NAT (STUN)", RFC 5766, 3778 DOI 10.17487/RFC5766, April 2010, 3779 . 3781 [RFC5928] Petit-Huguenin, M., "Traversal Using Relays around NAT 3782 (TURN) Resolution Mechanism", RFC 5928, 3783 DOI 10.17487/RFC5928, August 2010, 3784 . 3786 [Port-Numbers] 3787 "IANA Port Numbers Registry", 2005, 3788 . 3790 [Frag-Harmful] 3791 "Fragmentation Considered Harmful", . 3794 [Protocol-Numbers] 3795 "IANA Protocol Numbers Registry", 2005, 3796 . 3798 Authors' Addresses 3800 Tirumaleswar Reddy (editor) 3801 McAfee, Inc. 3802 Embassy Golf Link Business Park 3803 Bangalore, Karnataka 560071 3804 India 3806 Email: kondtir@gmail.com 3808 Alan Johnston (editor) 3809 Unaffiliated 3810 Bellevue, WA 3811 USA 3813 Email: alan.b.johnston@gmail.com 3815 Philip Matthews 3816 Alcatel-Lucent 3817 600 March Road 3818 Ottawa, Ontario 3819 Canada 3821 Email: philip_matthews@magma.ca 3823 Jonathan Rosenberg 3824 jdrosen.net 3825 Edison, NJ 3826 USA 3828 Email: jdrosen@jdrosen.net 3829 URI: http://www.jdrosen.net