idnits 2.17.1 draft-ietf-tram-turnbis-27.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 : ---------------------------------------------------------------------------- -- 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? -- The draft header indicates that this document obsoletes RFC6156, but the abstract doesn't seem to directly say this. It does mention RFC6156 though, so this could be OK. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (June 27, 2019) is 1757 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. 'Protocol-Numbers' ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) ** Obsolete normative reference: RFC 7525 (Obsoleted by RFC 9325) == Outdated reference: A later version (-39) exists of draft-ietf-mmusic-ice-sip-sdp-36 == Outdated reference: A later version (-20) exists of draft-ietf-tram-stun-pmtud-10 == Outdated reference: A later version (-32) exists of draft-ietf-tsvwg-udp-options-07 -- Obsolete informational reference (is this intentional?): RFC 5766 (Obsoleted by RFC 8656) -- Obsolete informational reference (is this intentional?): RFC 6156 (Obsoleted by RFC 8656) -- Obsolete informational reference (is this intentional?): RFC 6824 (Obsoleted by RFC 8684) Summary: 2 errors (**), 0 flaws (~~), 4 warnings (==), 7 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 Obsoletes: 5766, 6156 (if approved) A. Johnston, Ed. 5 Intended status: Standards Track Villanova University 6 Expires: December 29, 2019 P. Matthews 7 Alcatel-Lucent 8 J. Rosenberg 9 jdrosen.net 10 June 27, 2019 12 Traversal Using Relays around NAT (TURN): Relay Extensions to Session 13 Traversal Utilities for NAT (STUN) 14 draft-ietf-tram-turnbis-27 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 other relay control protocols in that 26 it allows a client to communicate with multiple peers using a single 27 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 This document obsoletes RFC 5766 and RFC 6156. 35 Status of This Memo 37 This Internet-Draft is submitted in full conformance with the 38 provisions of BCP 78 and BCP 79. 40 Internet-Drafts are working documents of the Internet Engineering 41 Task Force (IETF). Note that other groups may also distribute 42 working documents as Internet-Drafts. The list of current Internet- 43 Drafts is at https://datatracker.ietf.org/drafts/current/. 45 Internet-Drafts are draft documents valid for a maximum of six months 46 and may be updated, replaced, or obsoleted by other documents at any 47 time. It is inappropriate to use Internet-Drafts as reference 48 material or to cite them other than as "work in progress." 49 This Internet-Draft will expire on December 29, 2019. 51 Copyright Notice 53 Copyright (c) 2019 IETF Trust and the persons identified as the 54 document authors. All rights reserved. 56 This document is subject to BCP 78 and the IETF Trust's Legal 57 Provisions Relating to IETF Documents 58 (https://trustee.ietf.org/license-info) in effect on the date of 59 publication of this document. Please review these documents 60 carefully, as they describe your rights and restrictions with respect 61 to this document. Code Components extracted from this document must 62 include Simplified BSD License text as described in Section 4.e of 63 the Trust Legal Provisions and are provided without warranty as 64 described in the Simplified BSD License. 66 Table of Contents 68 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 69 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 6 70 3. Overview of Operation . . . . . . . . . . . . . . . . . . . . 8 71 3.1. Transports . . . . . . . . . . . . . . . . . . . . . . . 11 72 3.2. Allocations . . . . . . . . . . . . . . . . . . . . . . . 12 73 3.3. Permissions . . . . . . . . . . . . . . . . . . . . . . . 14 74 3.4. Send Mechanism . . . . . . . . . . . . . . . . . . . . . 15 75 3.5. Channels . . . . . . . . . . . . . . . . . . . . . . . . 17 76 3.6. Unprivileged TURN Servers . . . . . . . . . . . . . . . . 19 77 3.7. Avoiding IP Fragmentation . . . . . . . . . . . . . . . . 19 78 3.8. RTP Support . . . . . . . . . . . . . . . . . . . . . . . 21 79 3.9. Happy Eyeballs for TURN . . . . . . . . . . . . . . . . . 21 80 4. Discovery of TURN server . . . . . . . . . . . . . . . . . . 22 81 4.1. TURN URI Scheme Semantics . . . . . . . . . . . . . . . . 22 82 5. General Behavior . . . . . . . . . . . . . . . . . . . . . . 23 83 6. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . 25 84 7. Creating an Allocation . . . . . . . . . . . . . . . . . . . 26 85 7.1. Sending an Allocate Request . . . . . . . . . . . . . . . 26 86 7.2. Receiving an Allocate Request . . . . . . . . . . . . . . 28 87 7.3. Receiving an Allocate Success Response . . . . . . . . . 33 88 7.4. Receiving an Allocate Error Response . . . . . . . . . . 34 89 8. Refreshing an Allocation . . . . . . . . . . . . . . . . . . 36 90 8.1. Sending a Refresh Request . . . . . . . . . . . . . . . . 36 91 8.2. Receiving a Refresh Request . . . . . . . . . . . . . . . 37 92 8.3. Receiving a Refresh Response . . . . . . . . . . . . . . 38 93 9. Permissions . . . . . . . . . . . . . . . . . . . . . . . . . 38 94 10. CreatePermission . . . . . . . . . . . . . . . . . . . . . . 39 95 10.1. Forming a CreatePermission Request . . . . . . . . . . . 39 96 10.2. Receiving a CreatePermission Request . . . . . . . . . . 40 97 10.3. Receiving a CreatePermission Response . . . . . . . . . 41 98 11. Send and Data Methods . . . . . . . . . . . . . . . . . . . . 41 99 11.1. Forming a Send Indication . . . . . . . . . . . . . . . 41 100 11.2. Receiving a Send Indication . . . . . . . . . . . . . . 41 101 11.3. Receiving a UDP Datagram . . . . . . . . . . . . . . . . 42 102 11.4. Receiving a Data Indication . . . . . . . . . . . . . . 43 103 11.5. Receiving an ICMP Packet . . . . . . . . . . . . . . . . 43 104 11.6. Receiving a Data Indication with an ICMP attribute . . . 44 105 12. Channels . . . . . . . . . . . . . . . . . . . . . . . . . . 44 106 12.1. Sending a ChannelBind Request . . . . . . . . . . . . . 46 107 12.2. Receiving a ChannelBind Request . . . . . . . . . . . . 47 108 12.3. Receiving a ChannelBind Response . . . . . . . . . . . . 48 109 12.4. The ChannelData Message . . . . . . . . . . . . . . . . 48 110 12.5. Sending a ChannelData Message . . . . . . . . . . . . . 49 111 12.6. Receiving a ChannelData Message . . . . . . . . . . . . 49 112 12.7. Relaying Data from the Peer . . . . . . . . . . . . . . 50 113 13. Packet Translations . . . . . . . . . . . . . . . . . . . . . 51 114 13.1. IPv4-to-IPv6 Translations . . . . . . . . . . . . . . . 51 115 13.2. IPv6-to-IPv6 Translations . . . . . . . . . . . . . . . 52 116 13.3. IPv6-to-IPv4 Translations . . . . . . . . . . . . . . . 54 117 14. UDP-to-UDP relay . . . . . . . . . . . . . . . . . . . . . . 54 118 15. TCP-to-UDP relay . . . . . . . . . . . . . . . . . . . . . . 56 119 16. UDP-to-TCP relay . . . . . . . . . . . . . . . . . . . . . . 58 120 17. STUN Methods . . . . . . . . . . . . . . . . . . . . . . . . 59 121 18. STUN Attributes . . . . . . . . . . . . . . . . . . . . . . . 59 122 18.1. CHANNEL-NUMBER . . . . . . . . . . . . . . . . . . . . . 60 123 18.2. LIFETIME . . . . . . . . . . . . . . . . . . . . . . . . 60 124 18.3. XOR-PEER-ADDRESS . . . . . . . . . . . . . . . . . . . . 61 125 18.4. DATA . . . . . . . . . . . . . . . . . . . . . . . . . . 61 126 18.5. XOR-RELAYED-ADDRESS . . . . . . . . . . . . . . . . . . 61 127 18.6. REQUESTED-ADDRESS-FAMILY . . . . . . . . . . . . . . . . 61 128 18.7. EVEN-PORT . . . . . . . . . . . . . . . . . . . . . . . 62 129 18.8. REQUESTED-TRANSPORT . . . . . . . . . . . . . . . . . . 62 130 18.9. DONT-FRAGMENT . . . . . . . . . . . . . . . . . . . . . 63 131 18.10. RESERVATION-TOKEN . . . . . . . . . . . . . . . . . . . 63 132 18.11. ADDITIONAL-ADDRESS-FAMILY . . . . . . . . . . . . . . . 63 133 18.12. ADDRESS-ERROR-CODE Attribute . . . . . . . . . . . . . . 63 134 18.13. ICMP Attribute . . . . . . . . . . . . . . . . . . . . . 64 135 19. STUN Error Response Codes . . . . . . . . . . . . . . . . . . 65 136 20. Detailed Example . . . . . . . . . . . . . . . . . . . . . . 65 137 21. Security Considerations . . . . . . . . . . . . . . . . . . . 74 138 21.1. Outsider Attacks . . . . . . . . . . . . . . . . . . . . 74 139 21.1.1. Obtaining Unauthorized Allocations . . . . . . . . . 74 140 21.1.2. Offline Dictionary Attacks . . . . . . . . . . . . . 74 141 21.1.3. Faked Refreshes and Permissions . . . . . . . . . . 75 142 21.1.4. Fake Data . . . . . . . . . . . . . . . . . . . . . 75 143 21.1.5. Impersonating a Server . . . . . . . . . . . . . . . 76 144 21.1.6. Eavesdropping Traffic . . . . . . . . . . . . . . . 76 145 21.1.7. TURN Loop Attack . . . . . . . . . . . . . . . . . . 77 146 21.2. Firewall Considerations . . . . . . . . . . . . . . . . 77 147 21.2.1. Faked Permissions . . . . . . . . . . . . . . . . . 78 148 21.2.2. Blacklisted IP Addresses . . . . . . . . . . . . . . 78 149 21.2.3. Running Servers on Well-Known Ports . . . . . . . . 79 150 21.3. Insider Attacks . . . . . . . . . . . . . . . . . . . . 79 151 21.3.1. DoS against TURN Server . . . . . . . . . . . . . . 79 152 21.3.2. Anonymous Relaying of Malicious Traffic . . . . . . 79 153 21.3.3. Manipulating Other Allocations . . . . . . . . . . . 80 154 21.4. Tunnel Amplification Attack . . . . . . . . . . . . . . 80 155 21.5. Other Considerations . . . . . . . . . . . . . . . . . . 81 156 22. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 81 157 23. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 82 158 24. Changes since RFC 5766 . . . . . . . . . . . . . . . . . . . 84 159 25. Updates to RFC 6156 . . . . . . . . . . . . . . . . . . . . . 84 160 26. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 84 161 27. References . . . . . . . . . . . . . . . . . . . . . . . . . 85 162 27.1. Normative References . . . . . . . . . . . . . . . . . . 85 163 27.2. Informative References . . . . . . . . . . . . . . . . . 87 164 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 91 166 1. Introduction 168 A host behind a NAT may wish to exchange packets with other hosts, 169 some of which may also be behind NATs. To do this, the hosts 170 involved can use "hole punching" techniques (see [RFC5128]) in an 171 attempt discover a direct communication path; that is, a 172 communication path that goes from one host to another through 173 intervening NATs and routers, but does not traverse any relays. 175 As described in [RFC5128] and [RFC4787], hole punching techniques 176 will fail if both hosts are behind NATs that are not well behaved. 177 For example, if both hosts are behind NATs that have a mapping 178 behavior of "address-dependent mapping" or "address- and port- 179 dependent mapping" (Section 4.1 in [RFC4787]), then hole punching 180 techniques generally fail. 182 When a direct communication path cannot be found, it is necessary to 183 use the services of an intermediate host that acts as a relay for the 184 packets. This relay typically sits in the public Internet and relays 185 packets between two hosts that both sit behind NATs. 187 This specification defines a protocol, called TURN, that allows a 188 host behind a NAT (called the TURN client) to request that another 189 host (called the TURN server) act as a relay. The client can arrange 190 for the server to relay packets to and from certain other hosts 191 (called peers) and can control aspects of how the relaying is done. 192 The client does this by obtaining an IP address and port on the 193 server, called the relayed transport address. When a peer sends a 194 packet to the relayed transport address, the server relays the 195 transport protocol data from the packet to the client. The client 196 knows the peer from which the transport protocol data was relayed by 197 the server. If the server receives an ICMP error packet, the server 198 also relays certain layer 3/4 header fields from the ICMP header to 199 the client. When the client sends a packet to the server, the server 200 relays the transport protocol data from the packet to the intended 201 peer using the relayed transport address as the source. 203 A client using TURN must have some way to communicate the relayed 204 transport address to its peers, and to learn each peer's IP address 205 and port (more precisely, each peer's server-reflexive transport 206 address, see Section 3). How this is done is out of the scope of the 207 TURN protocol. One way this might be done is for the client and 208 peers to exchange email messages. Another way is for the client and 209 its peers to use a special-purpose "introduction" or "rendezvous" 210 protocol (see [RFC5128] for more details). 212 If TURN is used with ICE [RFC8445], then the relayed transport 213 address and the IP addresses and ports of the peers are included in 214 the ICE candidate information that the rendezvous protocol must 215 carry. For example, if TURN and ICE are used as part of a multimedia 216 solution using SIP [RFC3261], then SIP serves the role of the 217 rendezvous protocol, carrying the ICE candidate information inside 218 the body of SIP messages [I-D.ietf-mmusic-ice-sip-sdp]. If TURN and 219 ICE are used with some other rendezvous protocol, then ICE provides 220 guidance on the services the rendezvous protocol must perform. 222 Though the use of a TURN server to enable communication between two 223 hosts behind NATs is very likely to work, it comes at a high cost to 224 the provider of the TURN server, since the server typically needs a 225 high-bandwidth connection to the Internet. As a consequence, it is 226 best to use a TURN server only when a direct communication path 227 cannot be found. When the client and a peer use ICE to determine the 228 communication path, ICE will use hole punching techniques to search 229 for a direct path first and only use a TURN server when a direct path 230 cannot be found. 232 TURN was originally invented to support multimedia sessions signaled 233 using SIP. Since SIP supports forking, TURN supports multiple peers 234 per relayed transport address; a feature not supported by other 235 approaches (e.g., SOCKS [RFC1928]). However, care has been taken to 236 make sure that TURN is suitable for other types of applications. 238 TURN was designed as one piece in the larger ICE approach to NAT 239 traversal. Implementors of TURN are urged to investigate ICE and 240 seriously consider using it for their application. However, it is 241 possible to use TURN without ICE. 243 TURN is an extension to the STUN (Session Traversal Utilities for 244 NAT) protocol [I-D.ietf-tram-stunbis]. Most, though not all, TURN 245 messages are STUN-formatted messages. A reader of this document 246 should be familiar with STUN. 248 The TURN specification was originally published as [RFC5766], which 249 was updated by [RFC6156] to add IPv6 support. This document 250 supersedes and obsoletes both [RFC5766] and [RFC6156]. 252 2. Terminology 254 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 255 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 256 document are to be interpreted as described in RFC 2119 [RFC2119]. 258 Readers are expected to be familiar with [I-D.ietf-tram-stunbis] and 259 the terms defined there. 261 The following terms are used in this document: 263 TURN: The protocol spoken between a TURN client and a TURN server. 264 It is an extension to the STUN protocol [I-D.ietf-tram-stunbis]. 265 The protocol allows a client to allocate and use a relayed 266 transport address. 268 TURN client: A STUN client that implements this specification. 270 TURN server: A STUN server that implements this specification. It 271 relays data between a TURN client and its peer(s). 273 Peer: A host with which the TURN client wishes to communicate. The 274 TURN server relays traffic between the TURN client and its 275 peer(s). The peer does not interact with the TURN server using 276 the protocol defined in this document; rather, the peer receives 277 data sent by the TURN server and the peer sends data towards the 278 TURN server. 280 Transport Address: The combination of an IP address and a port. 282 Host Transport Address: A transport address on a client or a peer. 284 Server-Reflexive Transport Address: A transport address on the 285 "external side" of a NAT. This address is allocated by the NAT to 286 correspond to a specific host transport address. 288 Relayed Transport Address: A transport address on the TURN server 289 that is used for relaying packets between the client and a peer. 290 A peer sends to this address on the TURN server, and the packet is 291 then relayed to the client. 293 TURN Server Transport Address: A transport address on the TURN 294 server that is used for sending TURN messages to the server. This 295 is the transport address that the client uses to communicate with 296 the server. 298 Peer Transport Address: The transport address of the peer as seen by 299 the server. When the peer is behind a NAT, this is the peer's 300 server-reflexive transport address. 302 Allocation: The relayed transport address granted to a client 303 through an Allocate request, along with related state, such as 304 permissions and expiration timers. 306 5-tuple: The combination (client IP address and port, server IP 307 address and port, and transport protocol (currently one of UDP, 308 TCP, DTLS/UDP or TLS/TCP) used to communicate between the client 309 and the server. The 5-tuple uniquely identifies this 310 communication stream. The 5-tuple also uniquely identifies the 311 Allocation on the server. 313 Transport Protocol: The protocols above IP that carries TURN 314 Requests, Responses, and Indications as well as providing 315 identifiable flows using a 5-tuple. In this specification, UDP 316 and TCP are defined as transport protocols, as well as their 317 combination with a security layer using DTLS and TLS respectively. 319 Channel: A channel number and associated peer transport address. 320 Once a channel number is bound to a peer's transport address, the 321 client and server can use the more bandwidth-efficient ChannelData 322 message to exchange data. 324 Permission: The IP address and transport protocol (but not the port) 325 of a peer that is permitted to send traffic to the TURN server and 326 have that traffic relayed to the TURN client. The TURN server 327 will only forward traffic to its client from peers that match an 328 existing permission. 330 Realm: A string used to describe the server or a context within the 331 server. The realm tells the client which username and password 332 combination to use to authenticate requests. 334 Nonce: A string chosen at random by the server and included in the 335 message-digest. To prevent replay attacks, the server should 336 change the nonce regularly. 338 (D)TLS: This term is used for statements that apply to both 339 Transport Layer Security [RFC8446] and Datagram Transport Layer 340 Security [RFC6347]. 342 3. Overview of Operation 344 This section gives an overview of the operation of TURN. It is non- 345 normative. 347 In a typical configuration, a TURN client is connected to a private 348 network [RFC1918] and through one or more NATs to the public 349 Internet. On the public Internet is a TURN server. Elsewhere in the 350 Internet are one or more peers with which the TURN client wishes to 351 communicate. These peers may or may not be behind one or more NATs. 352 The client uses the server as a relay to send packets to these peers 353 and to receive packets from these peers. 355 Peer A 356 Server-Reflexive +---------+ 357 Transport Address | | 358 192.0.2.150:32102 | | 359 | /| | 360 TURN | / ^| Peer A | 361 Client's Server | / || | 362 Host Transport Transport | // || | 363 Address Address | // |+---------+ 364 198.51.100.2:49721 192.0.2.15:3478 |+-+ // Peer A 365 | | ||N| / Host Transport 366 | +-+ | ||A|/ Address 367 | | | | v|T| 203.0.113.2:49582 368 | | | | /+-+ 369 +---------+| | | |+---------+ / +---------+ 370 | || |N| || | // | | 371 | TURN |v | | v| TURN |/ | | 372 | Client |----|A|----------| Server |------------------| Peer B | 373 | | | |^ | |^ ^| | 374 | | |T|| | || || | 375 +---------+ | || +---------+| |+---------+ 376 | || | | 377 | || | | 378 +-+| | | 379 | | | 380 | | | 381 Client's | Peer B 382 Server-Reflexive Relayed Transport 383 Transport Address Transport Address Address 384 192.0.2.1:7000 192.0.2.15:50000 192.0.2.210:49191 386 Figure 1 388 Figure 1 shows a typical deployment. In this figure, the TURN client 389 and the TURN server are separated by a NAT, with the client on the 390 private side and the server on the public side of the NAT. This NAT 391 is assumed to be a "bad" NAT; for example, it might have a mapping 392 property of "address-and-port-dependent mapping" (see [RFC4787]). 394 The client talks to the server from a (IP address, port) combination 395 called the client's HOST TRANSPORT ADDRESS. (The combination of an 396 IP address and port is called a TRANSPORT ADDRESS.) 398 The client sends TURN messages from its host transport address to a 399 transport address on the TURN server that is known as the TURN SERVER 400 TRANSPORT ADDRESS. The client learns the TURN server transport 401 address through some unspecified means (e.g., configuration), and 402 this address is typically used by many clients simultaneously. 404 Since the client is behind a NAT, the server sees packets from the 405 client as coming from a transport address on the NAT itself. This 406 address is known as the client's SERVER-REFLEXIVE transport address; 407 packets sent by the server to the client's server-reflexive transport 408 address will be forwarded by the NAT to the client's host transport 409 address. 411 The client uses TURN commands to create and manipulate an ALLOCATION 412 on the server. An allocation is a data structure on the server. 413 This data structure contains, amongst other things, the RELAYED 414 TRANSPORT ADDRESS for the allocation. The relayed transport address 415 is the transport address on the server that peers can use to have the 416 server relay data to the client. An allocation is uniquely 417 identified by its relayed transport address. 419 Once an allocation is created, the client can send application data 420 to the server along with an indication of to which peer the data is 421 to be sent, and the server will relay this data to the intended peer. 422 The client sends the application data to the server inside a TURN 423 message; at the server, the data is extracted from the TURN message 424 and sent to the peer in a UDP datagram. In the reverse direction, a 425 peer can send application data in a UDP datagram to the relayed 426 transport address for the allocation; the server will then 427 encapsulate this data inside a TURN message and send it to the client 428 along with an indication of which peer sent the data. Since the TURN 429 message always contains an indication of which peer the client is 430 communicating with, the client can use a single allocation to 431 communicate with multiple peers. 433 When the peer is behind a NAT, then the client must identify the peer 434 using its server-reflexive transport address rather than its host 435 transport address. For example, to send application data to Peer A 436 in the example above, the client must specify 192.0.2.150:32102 (Peer 437 A's server-reflexive transport address) rather than 203.0.113.2:49582 438 (Peer A's host transport address). 440 Each allocation on the server belongs to a single client and has 441 exactly one relayed transport address that is used only by that 442 allocation. Thus, when a packet arrives at a relayed transport 443 address on the server, the server knows for which client the data is 444 intended. 446 The client may have multiple allocations on a server at the same 447 time. 449 3.1. Transports 451 TURN, as defined in this specification, always uses UDP between the 452 server and the peer. However, this specification allows the use of 453 any one of UDP, TCP, Transport Layer Security (TLS) over TCP or 454 Datagram Transport Layer Security (DTLS) over UDP to carry the TURN 455 messages between the client and the server. 457 +----------------------------+---------------------+ 458 | TURN client to TURN server | TURN server to peer | 459 +----------------------------+---------------------+ 460 | UDP | UDP | 461 | TCP | UDP | 462 | TLS-over-TCP | UDP | 463 | DTLS-over-UDP | UDP | 464 +----------------------------+---------------------+ 466 If TCP or TLS-over-TCP is used between the client and the server, 467 then the server will convert between these transports and UDP 468 transport when relaying data to/from the peer. 470 Since this version of TURN only supports UDP between the server and 471 the peer, it is expected that most clients will prefer to use UDP 472 between the client and the server as well. That being the case, some 473 readers may wonder: Why also support TCP and TLS-over-TCP? 475 TURN supports TCP transport between the client and the server because 476 some firewalls are configured to block UDP entirely. These firewalls 477 block UDP but not TCP, in part because TCP has properties that make 478 the intention of the nodes being protected by the firewall more 479 obvious to the firewall. For example, TCP has a three-way handshake 480 that makes in clearer that the protected node really wishes to have 481 that particular connection established, while for UDP the best the 482 firewall can do is guess which flows are desired by using filtering 483 rules. Also, TCP has explicit connection teardown; while for UDP, 484 the firewall has to use timers to guess when the flow is finished. 486 TURN supports TLS-over-TCP transport and DTLS-over-UDP transport 487 between the client and the server because (D)TLS provides additional 488 security properties not provided by TURN's default digest 489 authentication; properties that some clients may wish to take 490 advantage of. In particular, (D)TLS provides a way for the client to 491 ascertain that it is talking to the correct server, and provides for 492 confidentiality of TURN control messages. If (D)TLS transport is 493 used between the TURN client and the TURN server, the cipher suites 494 discussed in Section 6.2.3 of [I-D.ietf-tram-stunbis] and the 495 guidance given in [RFC7525] MUST be followed to avoid attacks on 496 (D)TLS. TURN does not require (D)TLS because the overhead of using 497 (D)TLS is higher than that of digest authentication; for example, 498 using (D)TLS likely means that most application data will be doubly 499 encrypted (once by (D)TLS and once to ensure it is still encrypted in 500 the UDP datagram). 502 There is an extension to TURN for TCP transport between the server 503 and the peers [RFC6062]. For this reason, allocations that use UDP 504 between the server and the peers are known as UDP allocations, while 505 allocations that use TCP between the server and the peers are known 506 as TCP allocations. This specification describes only UDP 507 allocations. 509 In some applications for TURN, the client may send and receive 510 packets other than TURN packets on the host transport address it uses 511 to communicate with the server. This can happen, for example, when 512 using TURN with ICE. In these cases, the client can distinguish TURN 513 packets from other packets by examining the source address of the 514 arriving packet: those arriving from the TURN server will be TURN 515 packets. The algorithm of demultiplexing packets received from 516 multiple protocols on the host transport address is discussed in 517 [RFC7983]. 519 3.2. Allocations 521 To create an allocation on the server, the client uses an Allocate 522 transaction. The client sends an Allocate request to the server, and 523 the server replies with an Allocate success response containing the 524 allocated relayed transport address. The client can include 525 attributes in the Allocate request that describe the type of 526 allocation it desires (e.g., the lifetime of the allocation). Since 527 relaying data has security implications, the server requires that the 528 client authenticate itself, typically using STUN's long-term 529 credential mechanism or the STUN Extension for Third-Party 530 Authorization [RFC7635], to show that it is authorized to use the 531 server. 533 Once a relayed transport address is allocated, a client must keep the 534 allocation alive. To do this, the client periodically sends a 535 Refresh request to the server. TURN deliberately uses a different 536 method (Refresh rather than Allocate) for refreshes to ensure that 537 the client is informed if the allocation vanishes for some reason. 539 The frequency of the Refresh transaction is determined by the 540 lifetime of the allocation. The default lifetime of an allocation is 541 10 minutes -- this value was chosen to be long enough so that 542 refreshing is not typically a burden on the client, while expiring 543 allocations where the client has unexpectedly quit in a timely 544 manner. However, the client can request a longer lifetime in the 545 Allocate request and may modify its request in a Refresh request, and 546 the server always indicates the actual lifetime in the response. The 547 client must issue a new Refresh transaction within "lifetime" seconds 548 of the previous Allocate or Refresh transaction. Once a client no 549 longer wishes to use an allocation, it should delete the allocation 550 using a Refresh request with a requested lifetime of 0. 552 Both the server and client keep track of a value known as the 553 5-TUPLE. At the client, the 5-tuple consists of the client's host 554 transport address, the server transport address, and the transport 555 protocol used by the client to communicate with the server. At the 556 server, the 5-tuple value is the same except that the client's host 557 transport address is replaced by the client's server-reflexive 558 address, since that is the client's address as seen by the server. 560 Both the client and the server remember the 5-tuple used in the 561 Allocate request. Subsequent messages between the client and the 562 server use the same 5-tuple. In this way, the client and server know 563 which allocation is being referred to. If the client wishes to 564 allocate a second relayed transport address, it must create a second 565 allocation using a different 5-tuple (e.g., by using a different 566 client host address or port). 568 NOTE: While the terminology used in this document refers to 569 5-tuples, the TURN server can store whatever identifier it likes 570 that yields identical results. Specifically, an implementation 571 may use a file-descriptor in place of a 5-tuple to represent a TCP 572 connection. 574 TURN TURN Peer Peer 575 client server A B 576 |-- Allocate request --------------->| | | 577 | (invalid or missing credentials) | | | 578 | | | | 579 |<--------------- Allocate failure --| | | 580 | (401 Unauthenticated) | | | 581 | | | | 582 |-- Allocate request --------------->| | | 583 | (valid credentials) | | | 584 | | | | 585 |<---------- Allocate success resp --| | | 586 | (192.0.2.15:50000) | | | 587 // // // // 588 | | | | 589 |-- Refresh request ---------------->| | | 590 | | | | 591 |<----------- Refresh success resp --| | | 592 | | | | 594 Figure 2 596 In Figure 2, the client sends an Allocate request to the server with 597 invalid or missing credentials. Since the server requires that all 598 requests be authenticated using STUN's long-term credential 599 mechanism, the server rejects the request with a 401 (Unauthorized) 600 error code. The client then tries again, this time including 601 credentials. This time, the server accepts the Allocate request and 602 returns an Allocate success response containing (amongst other 603 things) the relayed transport address assigned to the allocation. 604 Sometime later, the client decides to refresh the allocation and thus 605 sends a Refresh request to the server. The refresh is accepted and 606 the server replies with a Refresh success response. 608 3.3. Permissions 610 To ease concerns amongst enterprise IT administrators that TURN could 611 be used to bypass corporate firewall security, TURN includes the 612 notion of permissions. TURN permissions mimic the address-restricted 613 filtering mechanism of NATs that comply with [RFC4787]. 615 An allocation can have zero or more permissions. Each permission 616 consists of an IP address and a lifetime. When the server receives a 617 UDP datagram on the allocation's relayed transport address, it first 618 checks the list of permissions. If the source IP address of the 619 datagram matches a permission, the application data is relayed to the 620 client, otherwise the UDP datagram is silently discarded. 622 A permission expires after 5 minutes if it is not refreshed, and 623 there is no way to explicitly delete a permission. This behavior was 624 selected to match the behavior of a NAT that complies with [RFC4787]. 626 The client can install or refresh a permission using either a 627 CreatePermission request or a ChannelBind request. Using the 628 CreatePermission request, multiple permissions can be installed or 629 refreshed with a single request -- this is important for applications 630 that use ICE. For security reasons, permissions can only be 631 installed or refreshed by transactions that can be authenticated; 632 thus, Send indications and ChannelData messages (which are used to 633 send data to peers) do not install or refresh any permissions. 635 Note that permissions are within the context of an allocation, so 636 adding or expiring a permission in one allocation does not affect 637 other allocations. 639 3.4. Send Mechanism 641 There are two mechanisms for the client and peers to exchange 642 application data using the TURN server. The first mechanism uses the 643 Send and Data methods, the second mechanism uses channels. Common to 644 both mechanisms is the ability of the client to communicate with 645 multiple peers using a single allocated relayed transport address; 646 thus, both mechanisms include a means for the client to indicate to 647 the server which peer should receive the data, and for the server to 648 indicate to the client which peer sent the data. 650 The Send mechanism uses Send and Data indications. Send indications 651 are used to send application data from the client to the server, 652 while Data indications are used to send application data from the 653 server to the client. 655 When using the Send mechanism, the client sends a Send indication to 656 the TURN server containing (a) an XOR-PEER-ADDRESS attribute 657 specifying the (server-reflexive) transport address of the peer and 658 (b) a DATA attribute holding the application data. When the TURN 659 server receives the Send indication, it extracts the application data 660 from the DATA attribute and sends it in a UDP datagram to the peer, 661 using the allocated relay address as the source address. Note that 662 there is no need to specify the relayed transport address, since it 663 is implied by the 5-tuple used for the Send indication. 665 In the reverse direction, UDP datagrams arriving at the relayed 666 transport address on the TURN server are converted into Data 667 indications and sent to the client, with the server-reflexive 668 transport address of the peer included in an XOR-PEER-ADDRESS 669 attribute and the data itself in a DATA attribute. Since the relayed 670 transport address uniquely identified the allocation, the server 671 knows which client should receive the data. 673 Some ICMP (Internet Control Message Protocol) packets arriving at the 674 relayed transport address on the TURN server may be converted into 675 Data indications and sent to the client, with the transport address 676 of the peer included in an XOR-PEER-ADDRESS attribute and the ICMP 677 type and code in a ICMP attribute. ICMP attribute forwarding always 678 uses Data indications containing the XOR-PEER-ADDRESS and ICMP 679 attributes, even when using the channel mechanism to forward UDP 680 data. 682 Send and Data indications cannot be authenticated, since the long- 683 term credential mechanism of STUN does not support authenticating 684 indications. This is not as big an issue as it might first appear, 685 since the client-to-server leg is only half of the total path to the 686 peer. Applications that want proper security should encrypt the data 687 sent between the client and a peer. 689 Because Send indications are not authenticated, it is possible for an 690 attacker to send bogus Send indications to the server, which will 691 then relay these to a peer. To partly mitigate this attack, TURN 692 requires that the client install a permission towards a peer before 693 sending data to it using a Send indication. The technique to fully 694 mitigate the attack is discussed in Section 21.1.4. 696 TURN TURN Peer Peer 697 client server A B 698 | | | | 699 |-- CreatePermission req (Peer A) -->| | | 700 |<-- CreatePermission success resp --| | | 701 | | | | 702 |--- Send ind (Peer A)-------------->| | | 703 | |=== data ===>| | 704 | | | | 705 | |<== data ====| | 706 |<-------------- Data ind (Peer A) --| | | 707 | | | | 708 | | | | 709 |--- Send ind (Peer B)-------------->| | | 710 | | dropped | | 711 | | | | 712 | |<== data ==================| 713 | dropped | | | 714 | | | | 716 Figure 3 718 In Figure 3, the client has already created an allocation and now 719 wishes to send data to its peers. The client first creates a 720 permission by sending the server a CreatePermission request 721 specifying Peer A's (server-reflexive) IP address in the XOR-PEER- 722 ADDRESS attribute; if this was not done, the server would not relay 723 data between the client and the server. The client then sends data 724 to Peer A using a Send indication; at the server, the application 725 data is extracted and forwarded in a UDP datagram to Peer A, using 726 the relayed transport address as the source transport address. When 727 a UDP datagram from Peer A is received at the relayed transport 728 address, the contents are placed into a Data indication and forwarded 729 to the client. Later, the client attempts to exchange data with Peer 730 B; however, no permission has been installed for Peer B, so the Send 731 indication from the client and the UDP datagram from the peer are 732 both dropped by the server. 734 3.5. Channels 736 For some applications (e.g., Voice over IP), the 36 bytes of overhead 737 that a Send indication or Data indication adds to the application 738 data can substantially increase the bandwidth required between the 739 client and the server. To remedy this, TURN offers a second way for 740 the client and server to associate data with a specific peer. 742 This second way uses an alternate packet format known as the 743 ChannelData message. The ChannelData message does not use the STUN 744 header used by other TURN messages, but instead has a 4-byte header 745 that includes a number known as a channel number. Each channel 746 number in use is bound to a specific peer and thus serves as a 747 shorthand for the peer's host transport address. 749 To bind a channel to a peer, the client sends a ChannelBind request 750 to the server, and includes an unbound channel number and the 751 transport address of the peer. Once the channel is bound, the client 752 can use a ChannelData message to send the server data destined for 753 the peer. Similarly, the server can relay data from that peer 754 towards the client using a ChannelData message. 756 Channel bindings last for 10 minutes unless refreshed -- this 757 lifetime was chosen to be longer than the permission lifetime. 758 Channel bindings are refreshed by sending another ChannelBind request 759 rebinding the channel to the peer. Like permissions (but unlike 760 allocations), there is no way to explicitly delete a channel binding; 761 the client must simply wait for it to time out. 763 TURN TURN Peer Peer 764 client server A B 765 | | | | 766 |-- ChannelBind req ---------------->| | | 767 | (Peer A to 0x4001) | | | 768 | | | | 769 |<---------- ChannelBind succ resp --| | | 770 | | | | 771 |-- (0x4001) data ------------------>| | | 772 | |=== data ===>| | 773 | | | | 774 | |<== data ====| | 775 |<------------------ (0x4001) data --| | | 776 | | | | 777 |--- Send ind (Peer A)-------------->| | | 778 | |=== data ===>| | 779 | | | | 780 | |<== data ====| | 781 |<------------------ (0x4001) data --| | | 782 | | | | 784 Figure 4 786 Figure 4 shows the channel mechanism in use. The client has already 787 created an allocation and now wishes to bind a channel to Peer A. To 788 do this, the client sends a ChannelBind request to the server, 789 specifying the transport address of Peer A and a channel number 790 (0x4001). After that, the client can send application data 791 encapsulated inside ChannelData messages to Peer A: this is shown as 792 "(0x4001) data" where 0x4001 is the channel number. When the 793 ChannelData message arrives at the server, the server transfers the 794 data to a UDP datagram and sends it to Peer A (which is the peer 795 bound to channel number 0x4001). 797 In the reverse direction, when Peer A sends a UDP datagram to the 798 relayed transport address, this UDP datagram arrives at the server on 799 the relayed transport address assigned to the allocation. Since the 800 UDP datagram was received from Peer A, which has a channel number 801 assigned to it, the server encapsulates the data into a ChannelData 802 message when sending the data to the client. 804 Once a channel has been bound, the client is free to intermix 805 ChannelData messages and Send indications. In the figure, the client 806 later decides to use a Send indication rather than a ChannelData 807 message to send additional data to Peer A. The client might decide 808 to do this, for example, so it can use the DONT-FRAGMENT attribute 809 (see the next section). However, once a channel is bound, the server 810 will always use a ChannelData message, as shown in the call flow. 812 Note that ChannelData messages can only be used for peers to which 813 the client has bound a channel. In the example above, Peer A has 814 been bound to a channel, but Peer B has not, so application data to 815 and from Peer B would use the Send mechanism. 817 3.6. Unprivileged TURN Servers 819 This version of TURN is designed so that the server can be 820 implemented as an application that runs in user space under commonly 821 available operating systems without requiring special privileges. 822 This design decision was made to make it easy to deploy a TURN 823 server: for example, to allow a TURN server to be integrated into a 824 peer-to-peer application so that one peer can offer NAT traversal 825 services to another peer. 827 This design decision has the following implications for data relayed 828 by a TURN server: 830 o The value of the Diffserv field may not be preserved across the 831 server; 833 o The Time to Live (TTL) field may be reset, rather than 834 decremented, across the server; 836 o The Explicit Congestion Notification (ECN) field may be reset by 837 the server; 839 o There is no end-to-end fragmentation, since the packet is re- 840 assembled at the server. 842 Future work may specify alternate TURN semantics that address these 843 limitations. 845 3.7. Avoiding IP Fragmentation 847 For reasons described in [Frag-Harmful], applications, especially 848 those sending large volumes of data, should avoid having their 849 packets fragmented. Applications using TCP can more or less ignore 850 this issue because fragmentation avoidance is now a standard part of 851 TCP, but applications using UDP (and thus any application using this 852 version of TURN) need to avoid IP fragmentation by sending 853 sufficiently small messages or use UDP fragmentation 854 [I-D.ietf-tsvwg-udp-options]. 856 The application running on the client and the peer can take one of 857 two approaches to avoid IP fragmentation until UDP fragmentation 858 support is available. The first uses messages that are limited to a 859 predetermined fixed maximum and the second relies on network feedback 860 to adapt that maximum. 862 The first approach is to avoid sending large amounts of application 863 data in the TURN messages/UDP datagrams exchanged between the client 864 and the peer. This is the approach taken by most VoIP (Voice-over- 865 IP) applications. In this approach, the application MUST assume a 866 PMTU of 1280 bytes, as IPv6 requires that every link in the Internet 867 have an MTU of 1280 octets or greater as specified in [RFC8200]. If 868 IPv4 support on legacy or otherwise unusual networks is a 869 consideration, the application MAY assume on an effective MTU of 576 870 bytes for IPv4 datagrams, as every IPv4 host must be capable of 871 receiving a packet whose length is equal to 576 bytes as discussed in 872 [RFC0791] and [RFC1122]. 874 The exact amount of application data that can be included while 875 avoiding fragmentation depends on the details of the TURN session 876 between the client and the server: whether UDP, TCP, or (D)TLS 877 transport is used, whether ChannelData messages or Send/Data 878 indications are used, and whether any additional attributes (such as 879 the DONT-FRAGMENT attribute) are included. Another factor, which is 880 hard to determine, is whether the MTU is reduced somewhere along the 881 path for other reasons, such as the use of IP-in-IP tunneling. 883 As a guideline, sending a maximum of 500 bytes of application data in 884 a single TURN message (by the client on the client-to-server leg) or 885 a UDP datagram (by the peer on the peer-to-server leg) will generally 886 avoid IP fragmentation. To further reduce the chance of 887 fragmentation, it is recommended that the client use ChannelData 888 messages when transferring significant volumes of data, since the 889 overhead of the ChannelData message is less than Send and Data 890 indications. 892 The second approach the client and peer can take to avoid 893 fragmentation is to use a path MTU discovery algorithm to determine 894 the maximum amount of application data that can be sent without 895 fragmentation. The classic path MTU discovery algorithm defined in 896 [RFC1191] may not be able to discover the MTU of the transmission 897 path between the client and the peer since: 899 - a probe packet with DF bit set to test a path for a larger MTU 900 can be dropped by routers, or 902 - ICMP error messages can be dropped by middle boxes. 904 As a result, the client and server need to use a path MTU discovery 905 algorithm that does not require ICMP messages. The Packetized Path 906 MTU Discovery algorithm defined in [RFC4821] is one such algorithm. 908 [I-D.ietf-tram-stun-pmtud] is an implementation of [RFC4821] that 909 uses STUN to discover the path MTU, and so might be a suitable 910 approach to be used in conjunction with a TURN server that supports 911 the DONT-FRAGMENT attribute. When the client includes the DONT- 912 FRAGMENT attribute in a Send indication, this tells the server to set 913 the DF bit in the resulting UDP datagram that it sends to the peer. 914 Since some servers may be unable to set the DF bit, the client should 915 also include this attribute in the Allocate request -- any server 916 that does not support the DONT-FRAGMENT attribute will indicate this 917 by rejecting the Allocate request. If the TURN server carrying out 918 packet translation from IPv4-to-IPv6 cannot get the Don't Fragment 919 (DF) bit in the IPv4 header, it MUST reject the Allocate request with 920 DONT-FRAGMENT attribute. 922 3.8. RTP Support 924 One of the envisioned uses of TURN is as a relay for clients and 925 peers wishing to exchange real-time data (e.g., voice or video) using 926 RTP. To facilitate the use of TURN for this purpose, TURN includes 927 some special support for older versions of RTP. 929 Old versions of RTP [RFC3550] required that the RTP stream be on an 930 even port number and the associated RTP Control Protocol (RTCP) 931 stream, if present, be on the next highest port. To allow clients to 932 work with peers that still require this, TURN allows the client to 933 request that the server allocate a relayed transport address with an 934 even port number, and to optionally request the server reserve the 935 next-highest port number for a subsequent allocation. 937 3.9. Happy Eyeballs for TURN 939 If an IPv4 path to reach a TURN server is found, but the TURN 940 server's IPv6 path is not working, a dual-stack TURN client can 941 experience a significant connection delay compared to an IPv4-only 942 TURN client. To overcome these connection setup problems, the TURN 943 client needs to query both A and AAAA records for the TURN server 944 specified using a domain name and try connecting to the TURN server 945 using both IPv6 and IPv4 addresses in a fashion similar to the Happy 946 Eyeballs mechanism defined in [RFC8305]. The TURN client performs 947 the following steps based on the transport protocol being used to 948 connect to the TURN server. 950 o For TCP or TLS-over-TCP, initiate TCP connection to both IP 951 address families as discussed in [RFC8305], and use the first TCP 952 connection that is established. If connections are established on 953 both IP address families then terminate the TCP connection using 954 the IP address family with lower precedence [RFC6724]. 956 o For clear text UDP, send TURN Allocate requests to both IP address 957 families as discussed in [RFC8305], without authentication 958 information. If the TURN server requires authentication, it will 959 send back a 401 unauthenticated response and the TURN client uses 960 the first UDP connection on which a 401 error response is 961 received. If a 401 error response is received from both IP 962 address families then the TURN client can silently abandon the UDP 963 connection on the IP address family with lower precedence. If the 964 TURN server does not require authentication (as described in 965 Section 9 of [RFC8155]), it is possible for both Allocate requests 966 to succeed. In this case, the TURN client sends a Refresh with 967 LIFETIME value of 0 on the allocation using the IP address family 968 with lower precedence to delete the allocation. 970 o For DTLS over UDP, initiate DTLS handshake to both IP address 971 families as discussed in [RFC8305] and use the first DTLS session 972 that is established. If the DTLS session is established on both 973 IP address families then the client sends DTLS close_notify alert 974 to terminate the DTLS session using the IP address family with 975 lower precedence. If TURN over DTLS server has been configured to 976 require a cookie exchange (Section 4.2 in [RFC6347]) and 977 HelloVerifyRequest is received from the TURN servers on both IP 978 address families then the client can silently abandon the 979 connection on the IP address family with lower precedence. 981 4. Discovery of TURN server 983 Methods of TURN server discovery, including using anycast, are 984 described in [RFC8155]. The syntax of the "turn" and "turns" URIs 985 are defined in Section 3.1 of [RFC7065]. DTLS as a transport 986 protocol for TURN is defined in [RFC7350]. 988 4.1. TURN URI Scheme Semantics 990 The "turn" and "turns" URI schemes are used to designate a TURN 991 server (also known as a relay) on Internet hosts accessible using the 992 TURN protocol. The TURN protocol supports sending messages over UDP, 993 TCP, TLS-over-TCP or DTLS-over-UDP. The "turns" URI scheme MUST be 994 used when TURN is run over TLS-over-TCP or in DTLS-over-UDP, and the 995 "turn" scheme MUST be used otherwise. The required part of 996 the "turn" URI denotes the TURN server host. The part, if 997 present, denotes the port on which the TURN server is awaiting 998 connection requests. If it is absent, the default port is 3478 for 999 both UDP and TCP. The default port for TURN over TLS and TURN over 1000 DTLS is 5349. 1002 5. General Behavior 1004 This section contains general TURN processing rules that apply to all 1005 TURN messages. 1007 TURN is an extension to STUN. All TURN messages, with the exception 1008 of the ChannelData message, are STUN-formatted messages. All the 1009 base processing rules described in [I-D.ietf-tram-stunbis] apply to 1010 STUN-formatted messages. This means that all the message-forming and 1011 message-processing descriptions in this document are implicitly 1012 prefixed with the rules of [I-D.ietf-tram-stunbis]. 1014 [I-D.ietf-tram-stunbis] specifies an authentication mechanism called 1015 the long-term credential mechanism. TURN servers and clients MUST 1016 implement this mechanism. The server MUST demand that all requests 1017 from the client be authenticated using this mechanism, or that a 1018 equally strong or stronger mechanism for client authentication is 1019 used. 1021 Note that the long-term credential mechanism applies only to requests 1022 and cannot be used to authenticate indications; thus, indications in 1023 TURN are never authenticated. If the server requires requests to be 1024 authenticated, then the server's administrator MUST choose a realm 1025 value that will uniquely identify the username and password 1026 combination that the client must use, even if the client uses 1027 multiple servers under different administrations. The server's 1028 administrator MAY choose to allocate a unique username to each 1029 client, or MAY choose to allocate the same username to more than one 1030 client (for example, to all clients from the same department or 1031 company). For each Allocate request, the server SHOULD generate a 1032 new random nonce when the allocation is first attempted following the 1033 randomness recommendations in [RFC4086] and SHOULD expire the nonce 1034 at least once every hour during the lifetime of the allocation. To 1035 indicate that the server supports [I-D.ietf-tram-stunbis], the server 1036 prepends the NONCE attribute value with the "nonce cookie" 1037 (Section 9.2 of [I-D.ietf-tram-stunbis]). 1039 All requests after the initial Allocate must use the same username as 1040 that used to create the allocation, to prevent attackers from 1041 hijacking the client's allocation. Specifically, if the server 1042 requires the use of the long-term credential mechanism, and if a non- 1043 Allocate request passes authentication under this mechanism, and if 1044 the 5-tuple identifies an existing allocation, but the request does 1045 not use the same username as used to create the allocation, then the 1046 request MUST be rejected with a 441 (Wrong Credentials) error. 1048 When a TURN message arrives at the server from the client, the server 1049 uses the 5-tuple in the message to identify the associated 1050 allocation. For all TURN messages (including ChannelData) EXCEPT an 1051 Allocate request, if the 5-tuple does not identify an existing 1052 allocation, then the message MUST either be rejected with a 437 1053 Allocation Mismatch error (if it is a request) or silently ignored 1054 (if it is an indication or a ChannelData message). A client 1055 receiving a 437 error response to a request other than Allocate MUST 1056 assume the allocation no longer exists. 1058 [I-D.ietf-tram-stunbis] defines a number of attributes, including the 1059 SOFTWARE and FINGERPRINT attributes. The client SHOULD include the 1060 SOFTWARE attribute in all Allocate and Refresh requests and MAY 1061 include it in any other requests or indications. The server SHOULD 1062 include the SOFTWARE attribute in all Allocate and Refresh responses 1063 (either success or failure) and MAY include it in other responses or 1064 indications. The client and the server MAY include the FINGERPRINT 1065 attribute in any STUN-formatted messages defined in this document. 1067 TURN does not use the backwards-compatibility mechanism described in 1068 [I-D.ietf-tram-stunbis]. 1070 TURN, as defined in this specification, supports both IPv4 and IPv6. 1071 IPv6 support in TURN includes IPv4-to-IPv6, IPv6-to-IPv6, and IPv6- 1072 to-IPv4 relaying. The REQUESTED-ADDRESS-FAMILY attribute allows a 1073 client to explicitly request the address type the TURN server will 1074 allocate (e.g., an IPv4-only node may request the TURN server to 1075 allocate an IPv6 address). The ADDITIONAL-ADDRESS-FAMILY attribute 1076 allows a client to request the server to allocate one IPv4 and one 1077 IPv6 relay address in a single Allocate request. This saves local 1078 ports on the client and reduces the number of messages sent between 1079 the client and the TURN server. 1081 By default, TURN runs on the same ports as STUN: 3478 for TURN over 1082 UDP and TCP, and 5349 for TURN over (D)TLS. However, TURN has its 1083 own set of Service Record (SRV) names: "turn" for UDP and TCP, and 1084 "turns" for (D)TLS. Either the DNS resolution procedures or the 1085 ALTERNATE-SERVER procedures, both described in Section 7, can be used 1086 to run TURN on a different port. 1088 To ensure interoperability, a TURN server MUST support the use of UDP 1089 transport between the client and the server, and SHOULD support the 1090 use of TCP, TLS-over-TCP and DTLS-over-UDP transports. 1092 When UDP or DTLS-over-UDP transport is used between the client and 1093 the server, the client will retransmit a request if it does not 1094 receive a response within a certain timeout period. Because of this, 1095 the server may receive two (or more) requests with the same 5-tuple 1096 and same transaction id. STUN requires that the server recognize 1097 this case and treat the request as idempotent (see 1099 [I-D.ietf-tram-stunbis]). Some implementations may choose to meet 1100 this requirement by remembering all received requests and the 1101 corresponding responses for 40 seconds. Other implementations may 1102 choose to reprocess the request and arrange that such reprocessing 1103 returns essentially the same response. To aid implementors who 1104 choose the latter approach (the so-called "stateless stack 1105 approach"), this specification includes some implementation notes on 1106 how this might be done. Implementations are free to choose either 1107 approach or choose some other approach that gives the same results. 1109 To mitigate either intentional or unintentional denial-of-service 1110 attacks against the server by clients with valid usernames and 1111 passwords, it is RECOMMENDED that the server impose limits on both 1112 the number of allocations active at one time for a given username and 1113 on the amount of bandwidth those allocations can use. The server 1114 should reject new allocations that would exceed the limit on the 1115 allowed number of allocations active at one time with a 486 1116 (Allocation Quota Exceeded) (see Section 7.2), and should discard 1117 application data traffic that exceeds the bandwidth quota. 1119 6. Allocations 1121 All TURN operations revolve around allocations, and all TURN messages 1122 are associated with either a single or dual allocation. An 1123 allocation conceptually consists of the following state data: 1125 o the relayed transport address or addresses; 1127 o the 5-tuple: (client's IP address, client's port, server IP 1128 address, server port, transport protocol); 1130 o the authentication information; 1132 o the time-to-expiry for each relayed transport address; 1134 o a list of permissions for each relayed transport address; 1136 o a list of channel to peer bindings for each relayed transport 1137 address. 1139 The relayed transport address is the transport address allocated by 1140 the server for communicating with peers, while the 5-tuple describes 1141 the communication path between the client and the server. On the 1142 client, the 5-tuple uses the client's host transport address; on the 1143 server, the 5-tuple uses the client's server-reflexive transport 1144 address. The relayed transport address MUST be unique across all 1145 allocations, so it can be used to uniquely identify the allocation. 1147 Both the relayed transport address and the 5-tuple MUST be unique 1148 across all allocations, so either one can be used to uniquely 1149 identify the allocation, and an allocation in this context can be 1150 either a single or dual allocation. 1152 The authentication information (e.g., username, password, realm, and 1153 nonce) is used to both verify subsequent requests and to compute the 1154 message integrity of responses. The username, realm, and nonce 1155 values are initially those used in the authenticated Allocate request 1156 that creates the allocation, though the server can change the nonce 1157 value during the lifetime of the allocation using a 438 (Stale Nonce) 1158 reply. For security reasons, the server MUST NOT store the password 1159 explicitly and MUST store the key value, which is a secure hash over 1160 the username, realm, and password (see Section 16.1.3 in 1161 [I-D.ietf-tram-stunbis]). 1163 The time-to-expiry is the time in seconds left until the allocation 1164 expires. Each Allocate or Refresh transaction sets this timer, which 1165 then ticks down towards 0. By default, each Allocate or Refresh 1166 transaction resets this timer to the default lifetime value of 600 1167 seconds (10 minutes), but the client can request a different value in 1168 the Allocate and Refresh request. Allocations can only be refreshed 1169 using the Refresh request; sending data to a peer does not refresh an 1170 allocation. When an allocation expires, the state data associated 1171 with the allocation can be freed. 1173 The list of permissions is described in Section 9 and the list of 1174 channels is described in Section 12. 1176 7. Creating an Allocation 1178 An allocation on the server is created using an Allocate transaction. 1180 7.1. Sending an Allocate Request 1182 The client forms an Allocate request as follows. 1184 The client first picks a host transport address. It is RECOMMENDED 1185 that the client pick a currently unused transport address, typically 1186 by allowing the underlying OS to pick a currently unused port. 1188 The client then picks a transport protocol that the client supports 1189 to use between the client and the server based on the transport 1190 protocols supported by the server. Since this specification only 1191 allows UDP between the server and the peers, it is RECOMMENDED that 1192 the client pick UDP unless it has a reason to use a different 1193 transport. One reason to pick a different transport would be that 1194 the client believes, either through configuration or discovery or by 1195 experiment, that it is unable to contact any TURN server using UDP. 1196 See Section 3.1 for more discussion. 1198 The client also picks a server transport address, which SHOULD be 1199 done as follows. The client uses one or more procedures described in 1200 [RFC8155] to discover a TURN server and uses the TURN server 1201 resolution mechanism defined in [RFC5928] and [RFC7350] to get a list 1202 of server transport addresses that can be tried to create a TURN 1203 allocation. 1205 The client MUST include a REQUESTED-TRANSPORT attribute in the 1206 request. This attribute specifies the transport protocol between the 1207 server and the peers (note that this is NOT the transport protocol 1208 that appears in the 5-tuple). In this specification, the REQUESTED- 1209 TRANSPORT type is always UDP. This attribute is included to allow 1210 future extensions to specify other protocols. 1212 If the client wishes to obtain a relayed transport address of a 1213 specific address type then it includes a REQUESTED-ADDRESS-FAMILY 1214 attribute in the request. This attribute indicates the specific 1215 address type the client wishes the TURN server to allocate. Clients 1216 MUST NOT include more than one REQUESTED-ADDRESS-FAMILY attribute in 1217 an Allocate request. Clients MUST NOT include a REQUESTED-ADDRESS- 1218 FAMILY attribute in an Allocate request that contains a RESERVATION- 1219 TOKEN attribute, for the reason that the server uses the previously 1220 reserved transport address corresponding to the included token and 1221 the client cannot obtain a relayed transport address of a specific 1222 address type. 1224 If the client wishes to obtain one IPv6 and one IPv4 relayed 1225 transport address then it includes an ADDITIONAL-ADDRESS-FAMILY 1226 attribute in the request. This attribute specifies that the server 1227 must allocate both address types. The attribute value in the 1228 ADDITIONAL-ADDRESS-FAMILY MUST be set to 0x02 (IPv6 address family). 1229 Clients MUST NOT include REQUESTED-ADDRESS-FAMILY and ADDITIONAL- 1230 ADDRESS-FAMILY attributes in the same request. Clients MUST NOT 1231 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1232 that contains a RESERVATION-TOKEN attribute. Clients MUST NOT 1233 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1234 that contains an EVEN-PORT attribute with the R bit set to 1. The 1235 reason behind the restriction is if EVEN-PORT with R bit set to 1 is 1236 allowed with the ADDITIONAL-ADDRESS-FAMILY attribute, two tokens will 1237 have to be returned in success response and requires changes to the 1238 way RESERVATION-TOKEN is handled. 1240 If the client wishes the server to initialize the time-to-expiry 1241 field of the allocation to some value other than the default 1242 lifetime, then it MAY include a LIFETIME attribute specifying its 1243 desired value. This is just a hint, and the server may elect to use 1244 a different value. Note that the server will ignore requests to 1245 initialize the field to less than the default value. 1247 If the client wishes to later use the DONT-FRAGMENT attribute in one 1248 or more Send indications on this allocation, then the client SHOULD 1249 include the DONT-FRAGMENT attribute in the Allocate request. This 1250 allows the client to test whether this attribute is supported by the 1251 server. 1253 If the client requires the port number of the relayed transport 1254 address be even, the client includes the EVEN-PORT attribute. If 1255 this attribute is not included, then the port can be even or odd. By 1256 setting the R bit in the EVEN-PORT attribute to 1, the client can 1257 request that the server reserve the next highest port number (on the 1258 same IP address) for a subsequent allocation. If the R bit is 0, no 1259 such request is made. 1261 The client MAY also include a RESERVATION-TOKEN attribute in the 1262 request to ask the server to use a previously reserved port for the 1263 allocation. If the RESERVATION-TOKEN attribute is included, then the 1264 client MUST omit the EVEN-PORT attribute. 1266 Once constructed, the client sends the Allocate request on the 1267 5-tuple. 1269 7.2. Receiving an Allocate Request 1271 When the server receives an Allocate request, it performs the 1272 following checks: 1274 1. The server SHOULD require that the request be authenticated. 1275 The authentication of the request is optional to allow TURN 1276 servers provided by the local or access network to accept 1277 Allocation requests from new and/or guest users in the network 1278 who do not necessarily possess long term credentials for STUN 1279 authentication and its security implications are discussed in 1280 [RFC8155]. If the request is authenticated, the authentication 1281 MUST be done using the long-term credential mechanism of 1282 [I-D.ietf-tram-stunbis] unless the client and server agree to 1283 use another mechanism through some procedure outside the scope 1284 of this document. 1286 2. The server checks if the 5-tuple is currently in use by an 1287 existing allocation. If yes, the server rejects the request 1288 with a 437 (Allocation Mismatch) error. 1290 3. The server checks if the request contains a REQUESTED-TRANSPORT 1291 attribute. If the REQUESTED-TRANSPORT attribute is not included 1292 or is malformed, the server rejects the request with a 400 (Bad 1293 Request) error. Otherwise, if the attribute is included but 1294 specifies a protocol other than UDP that is not supported by the 1295 server, the server rejects the request with a 442 (Unsupported 1296 Transport Protocol) error. 1298 4. The request may contain a DONT-FRAGMENT attribute. If it does, 1299 but the server does not support sending UDP datagrams with the 1300 DF bit set to 1 (see Section 14 and Section 15), then the server 1301 treats the DONT-FRAGMENT attribute in the Allocate request as an 1302 unknown comprehension-required attribute. 1304 5. The server checks if the request contains a RESERVATION-TOKEN 1305 attribute. If yes, and the request also contains an EVEN-PORT 1306 or REQUESTED-ADDRESS-FAMILY or ADDITIONAL-ADDRESS-FAMILY 1307 attribute, the server rejects the request with a 400 (Bad 1308 Request) error. Otherwise, it checks to see if the token is 1309 valid (i.e., the token is in range and has not expired and the 1310 corresponding relayed transport address is still available). If 1311 the token is not valid for some reason, the server rejects the 1312 request with a 508 (Insufficient Capacity) error. 1314 6. The server checks if the request contains both REQUESTED- 1315 ADDRESS-FAMILY and ADDITIONAL-ADDRESS-FAMILY attributes. If 1316 yes, then the server rejects the request with a 400 (Bad 1317 Request) error. 1319 7. If the server does not support the address family requested by 1320 the client in REQUESTED-ADDRESS-FAMILY or is disabled by local 1321 policy, it MUST generate an Allocate error response, and it MUST 1322 include an ERROR-CODE attribute with the 440 (Address Family not 1323 Supported) response code. If the REQUESTED-ADDRESS-FAMILY 1324 attribute is absent and the server does not support IPv4 address 1325 family, the server MUST include an ERROR-CODE attribute with the 1326 440 (Address Family not Supported) response code. If the 1327 REQUESTED-ADDRESS-FAMILY attribute is absent and the server 1328 supports IPv4 address family, the server MUST allocate an IPv4 1329 relayed transport address for the TURN client. 1331 8. The server checks if the request contains an EVEN-PORT attribute 1332 with the R bit set to 1. If yes, and the request also contains 1333 an ADDITIONAL-ADDRESS-FAMILY attribute, the server rejects the 1334 request with a 400 (Bad Request) error. Otherwise, the server 1335 checks if it can satisfy the request (i.e., can allocate a 1336 relayed transport address as described below). If the server 1337 cannot satisfy the request, then the server rejects the request 1338 with a 508 (Insufficient Capacity) error. 1340 9. The server checks if the request contains an ADDITIONAL-ADDRESS- 1341 FAMILY attribute. If yes, and the attribute value is 0x01 (IPv4 1342 address family), then the server rejects the request with a 400 1343 (Bad Request) error. Otherwise, the server checks if it can 1344 allocate relayed transport addresses of both address types. If 1345 the server cannot satisfy the request, then the server rejects 1346 the request with a 508 (Insufficient Capacity) error. If the 1347 server can partially meet the request, i.e. if it can only 1348 allocate one relayed transport address of a specific address 1349 type, then it includes ADDRESS-ERROR-CODE attribute in the 1350 response to inform the client the reason for partial failure of 1351 the request. The error code value signaled in the ADDRESS- 1352 ERROR-CODE attribute could be 440 (Address Family not Supported) 1353 or 508 (Insufficient Capacity). If the server can fully meet 1354 the request, then the server allocates one IPv4 and one IPv6 1355 relay address, and returns an Allocate success response 1356 containing the relayed transport addresses assigned to the dual 1357 allocation in two XOR-RELAYED-ADDRESS attributes. 1359 10. At any point, the server MAY choose to reject the request with a 1360 486 (Allocation Quota Reached) error if it feels the client is 1361 trying to exceed some locally defined allocation quota. The 1362 server is free to define this allocation quota any way it 1363 wishes, but SHOULD define it based on the username used to 1364 authenticate the request, and not on the client's transport 1365 address. 1367 11. Also at any point, the server MAY choose to reject the request 1368 with a 300 (Try Alternate) error if it wishes to redirect the 1369 client to a different server. The use of this error code and 1370 attribute follow the specification in [I-D.ietf-tram-stunbis]. 1372 If all the checks pass, the server creates the allocation. The 1373 5-tuple is set to the 5-tuple from the Allocate request, while the 1374 list of permissions and the list of channels are initially empty. 1376 The server chooses a relayed transport address for the allocation as 1377 follows: 1379 o If the request contains a RESERVATION-TOKEN attribute, the server 1380 uses the previously reserved transport address corresponding to 1381 the included token (if it is still available). Note that the 1382 reservation is a server-wide reservation and is not specific to a 1383 particular allocation, since the Allocate request containing the 1384 RESERVATION-TOKEN uses a different 5-tuple than the Allocate 1385 request that made the reservation. The 5-tuple for the Allocate 1386 request containing the RESERVATION-TOKEN attribute can be any 1387 allowed 5-tuple; it can use a different client IP address and 1388 port, a different transport protocol, and even different server IP 1389 address and port (provided, of course, that the server IP address 1390 and port are ones on which the server is listening for TURN 1391 requests). 1393 o If the request contains an EVEN-PORT attribute with the R bit set 1394 to 0, then the server allocates a relayed transport address with 1395 an even port number. 1397 o If the request contains an EVEN-PORT attribute with the R bit set 1398 to 1, then the server looks for a pair of port numbers N and N+1 1399 on the same IP address, where N is even. Port N is used in the 1400 current allocation, while the relayed transport address with port 1401 N+1 is assigned a token and reserved for a future allocation. The 1402 server MUST hold this reservation for at least 30 seconds, and MAY 1403 choose to hold longer (e.g., until the allocation with port N 1404 expires). The server then includes the token in a RESERVATION- 1405 TOKEN attribute in the success response. 1407 o Otherwise, the server allocates any available relayed transport 1408 address. 1410 In all cases, the server SHOULD only allocate ports from the range 1411 49152 - 65535 (the Dynamic and/or Private Port range [Port-Numbers]), 1412 unless the TURN server application knows, through some means not 1413 specified here, that other applications running on the same host as 1414 the TURN server application will not be impacted by allocating ports 1415 outside this range. This condition can often be satisfied by running 1416 the TURN server application on a dedicated machine and/or by 1417 arranging that any other applications on the machine allocate ports 1418 before the TURN server application starts. In any case, the TURN 1419 server SHOULD NOT allocate ports in the range 0 - 1023 (the Well- 1420 Known Port range) to discourage clients from using TURN to run 1421 standard services. 1423 NOTE: The use of randomized port assignments to avoid certain 1424 types of attacks is described in [RFC6056]. It is RECOMMENDED 1425 that a TURN server implement a randomized port assignment 1426 algorithm from [RFC6056]. This is especially applicable to 1427 servers that choose to pre-allocate a number of ports from the 1428 underlying OS and then later assign them to allocations; for 1429 example, a server may choose this technique to implement the EVEN- 1430 PORT attribute. 1432 The server determines the initial value of the time-to-expiry field 1433 as follows. If the request contains a LIFETIME attribute, then the 1434 server computes the minimum of the client's proposed lifetime and the 1435 server's maximum allowed lifetime. If this computed value is greater 1436 than the default lifetime, then the server uses the computed lifetime 1437 as the initial value of the time-to-expiry field. Otherwise, the 1438 server uses the default lifetime. It is RECOMMENDED that the server 1439 use a maximum allowed lifetime value of no more than 3600 seconds (1 1440 hour). Servers that implement allocation quotas or charge users for 1441 allocations in some way may wish to use a smaller maximum allowed 1442 lifetime (perhaps as small as the default lifetime) to more quickly 1443 remove orphaned allocations (that is, allocations where the 1444 corresponding client has crashed or terminated or the client 1445 connection has been lost for some reason). Also, note that the time- 1446 to-expiry is recomputed with each successful Refresh request, and 1447 thus the value computed here applies only until the first refresh. 1449 Once the allocation is created, the server replies with a success 1450 response. The success response contains: 1452 o An XOR-RELAYED-ADDRESS attribute containing the relayed transport 1453 address. 1455 o A LIFETIME attribute containing the current value of the time-to- 1456 expiry timer. 1458 o A RESERVATION-TOKEN attribute (if a second relayed transport 1459 address was reserved). 1461 o An XOR-MAPPED-ADDRESS attribute containing the client's IP address 1462 and port (from the 5-tuple). 1464 NOTE: The XOR-MAPPED-ADDRESS attribute is included in the response 1465 as a convenience to the client. TURN itself does not make use of 1466 this value, but clients running ICE can often need this value and 1467 can thus avoid having to do an extra Binding transaction with some 1468 STUN server to learn it. 1470 The response (either success or error) is sent back to the client on 1471 the 5-tuple. 1473 NOTE: When the Allocate request is sent over UDP, 1474 [I-D.ietf-tram-stunbis] requires that the server handle the 1475 possible retransmissions of the request so that retransmissions do 1476 not cause multiple allocations to be created. Implementations may 1477 achieve this using the so-called "stateless stack approach" as 1478 follows. To detect retransmissions when the original request was 1479 successful in creating an allocation, the server can store the 1480 transaction id that created the request with the allocation data 1481 and compare it with incoming Allocate requests on the same 1482 5-tuple. Once such a request is detected, the server can stop 1483 parsing the request and immediately generate a success response. 1484 When building this response, the value of the LIFETIME attribute 1485 can be taken from the time-to-expiry field in the allocate state 1486 data, even though this value may differ slightly from the LIFETIME 1487 value originally returned. In addition, the server may need to 1488 store an indication of any reservation token returned in the 1489 original response, so that this may be returned in any 1490 retransmitted responses. 1492 For the case where the original request was unsuccessful in 1493 creating an allocation, the server may choose to do nothing 1494 special. Note, however, that there is a rare case where the 1495 server rejects the original request but accepts the retransmitted 1496 request (because conditions have changed in the brief intervening 1497 time period). If the client receives the first failure response, 1498 it will ignore the second (success) response and believe that an 1499 allocation was not created. An allocation created in this matter 1500 will eventually timeout, since the client will not refresh it. 1501 Furthermore, if the client later retries with the same 5-tuple but 1502 different transaction id, it will receive a 437 (Allocation 1503 Mismatch), which will cause it to retry with a different 5-tuple. 1504 The server may use a smaller maximum lifetime value to minimize 1505 the lifetime of allocations "orphaned" in this manner. 1507 7.3. Receiving an Allocate Success Response 1509 If the client receives an Allocate success response, then it MUST 1510 check that the mapped address and the relayed transport address or 1511 addresses are part of an address family or families that the client 1512 understands and is prepared to handle. If these addresses are not 1513 part of an address family or families which the client is prepared to 1514 handle, then the client MUST delete the allocation (Section 8) and 1515 MUST NOT attempt to create another allocation on that server until it 1516 believes the mismatch has been fixed. 1518 Otherwise, the client creates its own copy of the allocation data 1519 structure to track what is happening on the server. In particular, 1520 the client needs to remember the actual lifetime received back from 1521 the server, rather than the value sent to the server in the request. 1522 The client must also remember the 5-tuple used for the request and 1523 the username and password it used to authenticate the request to 1524 ensure that it reuses them for subsequent messages. The client also 1525 needs to track the channels and permissions it establishes on the 1526 server. 1528 If the client receives an Allocate success response but with ADDRESS- 1529 ERROR-CODE attribute in the response and the error code value 1530 signaled in the ADDRESS-ERROR-CODE attribute is 440 (Address Family 1531 not Supported), the client MUST NOT retry its request for the 1532 rejected address type. If the client receives an ADDRESS-ERROR-CODE 1533 attribute in the response and the error code value signaled in the 1534 ADDRESS-ERROR-CODE attribute is 508 (Insufficient Capacity), the 1535 client SHOULD wait at least 1 minute before trying to request any 1536 more allocations on this server for the rejected address type. 1538 The client will probably wish to send the relayed transport address 1539 to peers (using some method not specified here) so the peers can 1540 communicate with it. The client may also wish to use the server- 1541 reflexive address it receives in the XOR-MAPPED-ADDRESS attribute in 1542 its ICE processing. 1544 7.4. Receiving an Allocate Error Response 1546 If the client receives an Allocate error response, then the 1547 processing depends on the actual error code returned: 1549 o (Request timed out): There is either a problem with the server, or 1550 a problem reaching the server with the chosen transport. The 1551 client considers the current transaction as having failed but MAY 1552 choose to retry the Allocate request using a different transport 1553 (e.g., TCP instead of UDP). 1555 o 300 (Try Alternate): The server would like the client to use the 1556 server specified in the ALTERNATE-SERVER attribute instead. The 1557 client considers the current transaction as having failed, but 1558 SHOULD try the Allocate request with the alternate server before 1559 trying any other servers (e.g., other servers discovered using the 1560 DNS resolution procedures). When trying the Allocate request with 1561 the alternate server, the client follows the ALTERNATE-SERVER 1562 procedures specified in [I-D.ietf-tram-stunbis]. 1564 o 400 (Bad Request): The server believes the client's request is 1565 malformed for some reason. The client considers the current 1566 transaction as having failed. The client MAY notify the user or 1567 operator and SHOULD NOT retry the request with this server until 1568 it believes the problem has been fixed. 1570 o 401 (Unauthorized): If the client has followed the procedures of 1571 the long-term credential mechanism and still gets this error, then 1572 the server is not accepting the client's credentials. In this 1573 case, the client considers the current transaction as having 1574 failed and SHOULD notify the user or operator. The client SHOULD 1575 NOT send any further requests to this server until it believes the 1576 problem has been fixed. 1578 o 403 (Forbidden): The request is valid, but the server is refusing 1579 to perform it, likely due to administrative restrictions. The 1580 client considers the current transaction as having failed. The 1581 client MAY notify the user or operator and SHOULD NOT retry the 1582 same request with this server until it believes the problem has 1583 been fixed. 1585 o 420 (Unknown Attribute): If the client included a DONT-FRAGMENT 1586 attribute in the request and the server rejected the request with 1587 a 420 error code and listed the DONT-FRAGMENT attribute in the 1588 UNKNOWN-ATTRIBUTES attribute in the error response, then the 1589 client now knows that the server does not support the DONT- 1590 FRAGMENT attribute. The client considers the current transaction 1591 as having failed but MAY choose to retry the Allocate request 1592 without the DONT-FRAGMENT attribute. 1594 o 437 (Allocation Mismatch): This indicates that the client has 1595 picked a 5-tuple that the server sees as already in use. One way 1596 this could happen is if an intervening NAT assigned a mapped 1597 transport address that was used by another client that recently 1598 crashed. The client considers the current transaction as having 1599 failed. The client SHOULD pick another client transport address 1600 and retry the Allocate request (using a different transaction id). 1601 The client SHOULD try three different client transport addresses 1602 before giving up on this server. Once the client gives up on the 1603 server, it SHOULD NOT try to create another allocation on the 1604 server for 2 minutes. 1606 o 438 (Stale Nonce): See the procedures for the long-term credential 1607 mechanism [I-D.ietf-tram-stunbis]. 1609 o 440 (Address Family not Supported): The server does not support 1610 the address family requested by the client. If the client 1611 receives an Allocate error response with the 440 (Unsupported 1612 Address Family) error code, the client MUST NOT retry the request. 1614 o 441 (Wrong Credentials): The client should not receive this error 1615 in response to a Allocate request. The client MAY notify the user 1616 or operator and SHOULD NOT retry the same request with this server 1617 until it believes the problem has been fixed. 1619 o 442 (Unsupported Transport Address): The client should not receive 1620 this error in response to a request for a UDP allocation. The 1621 client MAY notify the user or operator and SHOULD NOT reattempt 1622 the request with this server until it believes the problem has 1623 been fixed. 1625 o 486 (Allocation Quota Reached): The server is currently unable to 1626 create any more allocations with this username. The client 1627 considers the current transaction as having failed. The client 1628 SHOULD wait at least 1 minute before trying to create any more 1629 allocations on the server. 1631 o 508 (Insufficient Capacity): The server has no more relayed 1632 transport addresses available, or has none with the requested 1633 properties, or the one that was reserved is no longer available. 1634 The client considers the current operation as having failed. If 1635 the client is using either the EVEN-PORT or the RESERVATION-TOKEN 1636 attribute, then the client MAY choose to remove or modify this 1637 attribute and try again immediately. Otherwise, the client SHOULD 1638 wait at least 1 minute before trying to create any more 1639 allocations on this server. 1641 An unknown error response MUST be handled as described in 1642 [I-D.ietf-tram-stunbis]. 1644 8. Refreshing an Allocation 1646 A Refresh transaction can be used to either (a) refresh an existing 1647 allocation and update its time-to-expiry or (b) delete an existing 1648 allocation. 1650 If a client wishes to continue using an allocation, then the client 1651 MUST refresh it before it expires. It is suggested that the client 1652 refresh the allocation roughly 1 minute before it expires. If a 1653 client no longer wishes to use an allocation, then it SHOULD 1654 explicitly delete the allocation. A client MAY refresh an allocation 1655 at any time for other reasons. 1657 8.1. Sending a Refresh Request 1659 If the client wishes to immediately delete an existing allocation, it 1660 includes a LIFETIME attribute with a value of 0. All other forms of 1661 the request refresh the allocation. 1663 When refreshing a dual allocation, the client includes REQUESTED- 1664 ADDRESS-FAMILY attribute indicating the address family type that 1665 should be refreshed. If no REQUESTED-ADDRESS-FAMILY is included then 1666 the request should be treated as applying to all current allocations. 1667 The client MUST only include family types it previously allocated and 1668 has not yet deleted. This process can also be used to delete an 1669 allocation of a specific address type, by setting the lifetime of 1670 that refresh request to 0. Deleting a single allocation destroys any 1671 permissions or channels associated with that particular allocation; 1672 it MUST NOT affect any permissions or channels associated with 1673 allocations for the other address family. 1675 The Refresh transaction updates the time-to-expiry timer of an 1676 allocation. If the client wishes the server to set the time-to- 1677 expiry timer to something other than the default lifetime, it 1678 includes a LIFETIME attribute with the requested value. The server 1679 then computes a new time-to-expiry value in the same way as it does 1680 for an Allocate transaction, with the exception that a requested 1681 lifetime of 0 causes the server to immediately delete the allocation. 1683 8.2. Receiving a Refresh Request 1685 When the server receives a Refresh request, it processes the request 1686 as per Section 5 plus the specific rules mentioned here. 1688 If the server receives a Refresh Request with a REQUESTED-ADDRESS- 1689 FAMILY attribute and the attribute value does not match the address 1690 family of the allocation, the server MUST reply with a 443 (Peer 1691 Address Family Mismatch) Refresh error response. 1693 The server computes a value called the "desired lifetime" as follows: 1694 if the request contains a LIFETIME attribute and the attribute value 1695 is 0, then the "desired lifetime" is 0. Otherwise, if the request 1696 contains a LIFETIME attribute, then the server computes the minimum 1697 of the client's requested lifetime and the server's maximum allowed 1698 lifetime. If this computed value is greater than the default 1699 lifetime, then the "desired lifetime" is the computed value. 1700 Otherwise, the "desired lifetime" is the default lifetime. 1702 Subsequent processing depends on the "desired lifetime" value: 1704 o If the "desired lifetime" is 0, then the request succeeds and the 1705 allocation is deleted. 1707 o If the "desired lifetime" is non-zero, then the request succeeds 1708 and the allocation's time-to-expiry is set to the "desired 1709 lifetime". 1711 If the request succeeds, then the server sends a success response 1712 containing: 1714 o A LIFETIME attribute containing the current value of the time-to- 1715 expiry timer. 1717 NOTE: A server need not do anything special to implement 1718 idempotency of Refresh requests over UDP using the "stateless 1719 stack approach". Retransmitted Refresh requests with a non-zero 1720 "desired lifetime" will simply refresh the allocation. A 1721 retransmitted Refresh request with a zero "desired lifetime" will 1722 cause a 437 (Allocation Mismatch) response if the allocation has 1723 already been deleted, but the client will treat this as equivalent 1724 to a success response (see below). 1726 8.3. Receiving a Refresh Response 1728 If the client receives a success response to its Refresh request with 1729 a non-zero lifetime, it updates its copy of the allocation data 1730 structure with the time-to-expiry value contained in the response. 1731 If the client receives a 437 (Allocation Mismatch) error response to 1732 its request to refresh the allocation, it should consider the 1733 allocation no longer exists. If the client receives a 438 (Stale 1734 Nonce) error to its request to refresh the allocation, it should 1735 reattempt the request with the new nonce value. 1737 If the client receives a 437 (Allocation Mismatch) error response to 1738 a request to delete the allocation, then the allocation no longer 1739 exists and it should consider its request as having effectively 1740 succeeded. 1742 9. Permissions 1744 For each allocation, the server keeps a list of zero or more 1745 permissions. Each permission consists of an IP address and an 1746 associated time-to-expiry. While a permission exists, all peers 1747 using the IP address in the permission are allowed to send data to 1748 the client. The time-to-expiry is the number of seconds until the 1749 permission expires. Within the context of an allocation, a 1750 permission is uniquely identified by its associated IP address. 1752 By sending either CreatePermission requests or ChannelBind requests, 1753 the client can cause the server to install or refresh a permission 1754 for a given IP address. This causes one of two things to happen: 1756 o If no permission for that IP address exists, then a permission is 1757 created with the given IP address and a time-to-expiry equal to 1758 Permission Lifetime. 1760 o If a permission for that IP address already exists, then the time- 1761 to-expiry for that permission is reset to Permission Lifetime. 1763 The Permission Lifetime MUST be 300 seconds (= 5 minutes). 1765 Each permission's time-to-expiry decreases down once per second until 1766 it reaches 0; at which point, the permission expires and is deleted. 1768 CreatePermission and ChannelBind requests may be freely intermixed on 1769 a permission. A given permission may be initially installed and/or 1770 refreshed with a CreatePermission request, and then later refreshed 1771 with a ChannelBind request, or vice versa. 1773 When a UDP datagram arrives at the relayed transport address for the 1774 allocation, the server extracts the source IP address from the IP 1775 header. The server then compares this address with the IP address 1776 associated with each permission in the list of permissions for the 1777 allocation. Note that only addresses are compared and port numbers 1778 are not considered. If no match is found, relaying is not permitted, 1779 and the server silently discards the UDP datagram. If an exact match 1780 is found, the permission check is considered to have succeeded and 1781 the server continues to process the UDP datagram as specified 1782 elsewhere (Section 11.3). 1784 The permissions for one allocation are totally unrelated to the 1785 permissions for a different allocation. If an allocation expires, 1786 all its permissions expire with it. 1788 NOTE: Though TURN permissions expire after 5 minutes, many NATs 1789 deployed at the time of publication expire their UDP bindings 1790 considerably faster. Thus, an application using TURN will 1791 probably wish to send some sort of keep-alive traffic at a much 1792 faster rate. Applications using ICE should follow the keep-alive 1793 guidelines of ICE [RFC8445], and applications not using ICE are 1794 advised to do something similar. 1796 10. CreatePermission 1798 TURN supports two ways for the client to install or refresh 1799 permissions on the server. This section describes one way: the 1800 CreatePermission request. 1802 A CreatePermission request may be used in conjunction with either the 1803 Send mechanism in Section 11 or the Channel mechanism in Section 12. 1805 10.1. Forming a CreatePermission Request 1807 The client who wishes to install or refresh one or more permissions 1808 can send a CreatePermission request to the server. 1810 When forming a CreatePermission request, the client MUST include at 1811 least one XOR-PEER-ADDRESS attribute, and MAY include more than one 1812 such attribute. The IP address portion of each XOR-PEER-ADDRESS 1813 attribute contains the IP address for which a permission should be 1814 installed or refreshed. The port portion of each XOR-PEER-ADDRESS 1815 attribute will be ignored and can be any arbitrary value. The 1816 various XOR-PEER-ADDRESS attributes MAY appear in any order. The 1817 client MUST only include XOR-PEER-ADDRESS attributes with addresses 1818 of the same address family as that of the relayed transport address 1819 for the allocation. For dual allocations obtained using the 1820 ADDITIONAL-ADDRESS-FAMILY attribute, the client MAY include XOR-PEER- 1821 ADDRESS attributes with addresses of IPv4 and IPv6 address families. 1823 10.2. Receiving a CreatePermission Request 1825 When the server receives the CreatePermission request, it processes 1826 as per Section 5 plus the specific rules mentioned here. 1828 The message is checked for validity. The CreatePermission request 1829 MUST contain at least one XOR-PEER-ADDRESS attribute and MAY contain 1830 multiple such attributes. If no such attribute exists, or if any of 1831 these attributes are invalid, then a 400 (Bad Request) error is 1832 returned. If the request is valid, but the server is unable to 1833 satisfy the request due to some capacity limit or similar, then a 508 1834 (Insufficient Capacity) error is returned. 1836 If an XOR-PEER-ADDRESS attribute contains an address of an address 1837 family that is not the same as that of a relayed transport address 1838 for the allocation, the server MUST generate an error response with 1839 the 443 (Peer Address Family Mismatch) response code. 1841 The server MAY impose restrictions on the IP address allowed in the 1842 XOR-PEER-ADDRESS attribute -- if a value is not allowed, the server 1843 rejects the request with a 403 (Forbidden) error. 1845 If the message is valid and the server is capable of carrying out the 1846 request, then the server installs or refreshes a permission for the 1847 IP address contained in each XOR-PEER-ADDRESS attribute as described 1848 in Section 9. The port portion of each attribute is ignored and may 1849 be any arbitrary value. 1851 The server then responds with a CreatePermission success response. 1852 There are no mandatory attributes in the success response. 1854 NOTE: A server need not do anything special to implement 1855 idempotency of CreatePermission requests over UDP using the 1856 "stateless stack approach". Retransmitted CreatePermission 1857 requests will simply refresh the permissions. 1859 10.3. Receiving a CreatePermission Response 1861 If the client receives a valid CreatePermission success response, 1862 then the client updates its data structures to indicate that the 1863 permissions have been installed or refreshed. 1865 11. Send and Data Methods 1867 TURN supports two mechanisms for sending and receiving data from 1868 peers. This section describes the use of the Send and Data 1869 mechanisms, while Section 12 describes the use of the Channel 1870 mechanism. 1872 11.1. Forming a Send Indication 1874 The client can use a Send indication to pass data to the server for 1875 relaying to a peer. A client may use a Send indication even if a 1876 channel is bound to that peer. However, the client MUST ensure that 1877 there is a permission installed for the IP address of the peer to 1878 which the Send indication is being sent; this prevents a third party 1879 from using a TURN server to send data to arbitrary destinations. 1881 When forming a Send indication, the client MUST include an XOR-PEER- 1882 ADDRESS attribute and a DATA attribute. The XOR-PEER-ADDRESS 1883 attribute contains the transport address of the peer to which the 1884 data is to be sent, and the DATA attribute contains the actual 1885 application data to be sent to the peer. 1887 The client MAY include a DONT-FRAGMENT attribute in the Send 1888 indication if it wishes the server to set the DF bit on the UDP 1889 datagram sent to the peer. 1891 11.2. Receiving a Send Indication 1893 When the server receives a Send indication, it processes as per 1894 Section 5 plus the specific rules mentioned here. 1896 The message is first checked for validity. The Send indication MUST 1897 contain both an XOR-PEER-ADDRESS attribute and a DATA attribute. If 1898 one of these attributes is missing or invalid, then the message is 1899 discarded. Note that the DATA attribute is allowed to contain zero 1900 bytes of data. 1902 The Send indication may also contain the DONT-FRAGMENT attribute. If 1903 the server is unable to set the DF bit on outgoing UDP datagrams when 1904 this attribute is present, then the server acts as if the DONT- 1905 FRAGMENT attribute is an unknown comprehension-required attribute 1906 (and thus the Send indication is discarded). 1908 The server also checks that there is a permission installed for the 1909 IP address contained in the XOR-PEER-ADDRESS attribute. If no such 1910 permission exists, the message is discarded. Note that a Send 1911 indication never causes the server to refresh the permission. 1913 The server MAY impose restrictions on the IP address and port values 1914 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1915 allowed, the server silently discards the Send indication. 1917 If everything is OK, then the server forms a UDP datagram as follows: 1919 o the source transport address is the relayed transport address of 1920 the allocation, where the allocation is determined by the 5-tuple 1921 on which the Send indication arrived; 1923 o the destination transport address is taken from the XOR-PEER- 1924 ADDRESS attribute; 1926 o the data following the UDP header is the contents of the value 1927 field of the DATA attribute. 1929 The handling of the DONT-FRAGMENT attribute (if present), is 1930 described in Section 14 and Section 15. 1932 The resulting UDP datagram is then sent to the peer. 1934 11.3. Receiving a UDP Datagram 1936 When the server receives a UDP datagram at a currently allocated 1937 relayed transport address, the server looks up the allocation 1938 associated with the relayed transport address. The server then 1939 checks to see whether the set of permissions for the allocation allow 1940 the relaying of the UDP datagram as described in Section 9. 1942 If relaying is permitted, then the server checks if there is a 1943 channel bound to the peer that sent the UDP datagram (see 1944 Section 12). If a channel is bound, then processing proceeds as 1945 described in Section 12.7. 1947 If relaying is permitted but no channel is bound to the peer, then 1948 the server forms and sends a Data indication. The Data indication 1949 MUST contain both an XOR-PEER-ADDRESS and a DATA attribute. The DATA 1950 attribute is set to the value of the 'data octets' field from the 1951 datagram, and the XOR-PEER-ADDRESS attribute is set to the source 1952 transport address of the received UDP datagram. The Data indication 1953 is then sent on the 5-tuple associated with the allocation. 1955 11.4. Receiving a Data Indication 1957 When the client receives a Data indication, it checks that the Data 1958 indication contains an XOR-PEER-ADDRESS attribute, and discards the 1959 indication if it does not. The client SHOULD also check that the 1960 XOR-PEER-ADDRESS attribute value contains an IP address with which 1961 the client believes there is an active permission, and discard the 1962 Data indication otherwise. 1964 NOTE: The latter check protects the client against an attacker who 1965 somehow manages to trick the server into installing permissions 1966 not desired by the client. 1968 If the XOR-PEER-ADDRESS is present and valid, the client checks that 1969 the Data indication contains either a DATA attribute or an ICMP 1970 attribute and discards the indication if it does not. Note that a 1971 DATA attribute is allowed to contain zero bytes of data. Processing 1972 of Data indications with an ICMP attribute is described in 1973 Section 11.6. 1975 If the Data indication passes the above checks, the client delivers 1976 the data octets inside the DATA attribute to the application, along 1977 with an indication that they were received from the peer whose 1978 transport address is given by the XOR-PEER-ADDRESS attribute. 1980 11.5. Receiving an ICMP Packet 1982 When the server receives an ICMP packet, the server verifies that the 1983 type is either 3 or 11 for an ICMPv4 [RFC0792] packet or either 1, 2, 1984 or 3 for an ICMPv6 [RFC4443] packet. It also verifies that the IP 1985 packet in the ICMP packet payload contains a UDP header. If either 1986 of these conditions fail, then the ICMP packet is silently dropped. 1988 The server looks up the allocation whose relayed transport address 1989 corresponds to the encapsulated packet's source IP address and UDP 1990 port. If no such allocation exists, the packet is silently dropped. 1991 The server then checks to see whether the set of permissions for the 1992 allocation allows the relaying of the ICMP packet. For ICMP packets, 1993 the source IP address MUST NOT be checked against the permissions 1994 list as it would be for UDP packets. Instead, the server extracts 1995 the destination IP address from the encapsulated IP header. The 1996 server then compares this address with the IP address associated with 1997 each permission in the list of permissions for the allocation. If no 1998 match is found, relaying is not permitted, and the server silently 1999 discards the ICMP packet. Note that only addresses are compared and 2000 port numbers are not considered. 2002 If relaying is permitted then the server forms and sends a Data 2003 indication. The Data indication MUST contain both an XOR-PEER- 2004 ADDRESS and an ICMP attribute. The ICMP attribute is set to the 2005 value of the type and code fields from the ICMP packet. The IP 2006 address portion of XOR-PEER-ADDRESS attribute is set to the 2007 destination IP address in the encapsulated IP header. At the time of 2008 writing of this specification, Socket APIs on some operating systems 2009 do not deliver the destination port in the encapsulated UDP header to 2010 applications without superuser privileges. If destination port in 2011 the encapsulated UDP header is available to the server then the port 2012 portion of XOR-PEER-ADDRESS attribute is set to the destination port 2013 otherwise the port portion is set to 0. The Data indication is then 2014 sent on the 5-tuple associated with the allocation. 2016 11.6. Receiving a Data Indication with an ICMP attribute 2018 When the client receives a Data indication with an ICMP attribute, it 2019 checks that the Data indication contains an XOR-PEER-ADDRESS 2020 attribute, and discards the indication if it does not. The client 2021 SHOULD also check that the XOR-PEER-ADDRESS attribute value contains 2022 an IP address with an active permission, and discard the Data 2023 indication otherwise. 2025 If the Data indication passes the above checks, the client signals 2026 the application of the error condition, along with an indication that 2027 it was received from the peer whose transport address is given by the 2028 XOR-PEER-ADDRESS attribute. The application can make sense of the 2029 meaning of the type and code values in the ICMP attribute by using 2030 the family field in the XOR-PEER-ADDRESS attribute. 2032 12. Channels 2034 Channels provide a way for the client and server to send application 2035 data using ChannelData messages, which have less overhead than Send 2036 and Data indications. 2038 The ChannelData message (see Section 12.4) starts with a two-byte 2039 field that carries the channel number. The values of this field are 2040 allocated as follows: 2042 0x0000 through 0x3FFF: These values can never be used for channel 2043 numbers. 2045 0x4000 through 0x4FFF: These values are the allowed channel 2046 numbers (4096 possible values). 2048 0x5000-0xFFFF: Reserved (For DTLS-SRTP multiplexing collision 2049 avoidance, see [RFC7983]. 2051 According to [RFC7983], ChannelData messages can be distinguished 2052 from other multiplexed protocols by examining the first byte of the 2053 message: 2055 +------------+------------------------------+ 2056 | [0..3] | STUN | 2057 | | | 2058 +-------------------------------------------+ 2059 | [16..19] | ZRTP | 2060 | | | 2061 +-------------------------------------------+ 2062 | [20..63] | DTLS | 2063 | | | 2064 +-------------------------------------------+ 2065 | [64..79] | TURN Channel | 2066 | | | 2067 +-------------------------------------------+ 2068 | [128..191] | RTP/RTCP | 2069 | | | 2070 +-------------------------------------------+ 2071 | Others | Reserved, MUST be dropped | 2072 | | and an alert MAY be logged | 2073 +-------------------------------------------+ 2075 Figure 5 2077 Reserved values may be used in the future by other protocols. When 2078 the client uses channel binding, it MUST comply with the 2079 demultiplexing scheme discussed above. 2081 Channel bindings are always initiated by the client. The client can 2082 bind a channel to a peer at any time during the lifetime of the 2083 allocation. The client may bind a channel to a peer before 2084 exchanging data with it, or after exchanging data with it (using Send 2085 and Data indications) for some time, or may choose never to bind a 2086 channel to it. The client can also bind channels to some peers while 2087 not binding channels to other peers. 2089 Channel bindings are specific to an allocation, so that the use of a 2090 channel number or peer transport address in a channel binding in one 2091 allocation has no impact on their use in a different allocation. If 2092 an allocation expires, all its channel bindings expire with it. 2094 A channel binding consists of: 2096 o a channel number; 2098 o a transport address (of the peer); and 2099 o A time-to-expiry timer. 2101 Within the context of an allocation, a channel binding is uniquely 2102 identified either by the channel number or by the peer's transport 2103 address. Thus, the same channel cannot be bound to two different 2104 transport addresses, nor can the same transport address be bound to 2105 two different channels. 2107 A channel binding lasts for 10 minutes unless refreshed. Refreshing 2108 the binding (by the server receiving a ChannelBind request rebinding 2109 the channel to the same peer) resets the time-to-expiry timer back to 2110 10 minutes. 2112 When the channel binding expires, the channel becomes unbound. Once 2113 unbound, the channel number can be bound to a different transport 2114 address, and the transport address can be bound to a different 2115 channel number. To prevent race conditions, the client MUST wait 5 2116 minutes after the channel binding expires before attempting to bind 2117 the channel number to a different transport address or the transport 2118 address to a different channel number. 2120 When binding a channel to a peer, the client SHOULD be prepared to 2121 receive ChannelData messages on the channel from the server as soon 2122 as it has sent the ChannelBind request. Over UDP, it is possible for 2123 the client to receive ChannelData messages from the server before it 2124 receives a ChannelBind success response. 2126 In the other direction, the client MAY elect to send ChannelData 2127 messages before receiving the ChannelBind success response. Doing 2128 so, however, runs the risk of having the ChannelData messages dropped 2129 by the server if the ChannelBind request does not succeed for some 2130 reason (e.g., packet lost if the request is sent over UDP, or the 2131 server being unable to fulfill the request). A client that wishes to 2132 be safe should either queue the data or use Send indications until 2133 the channel binding is confirmed. 2135 12.1. Sending a ChannelBind Request 2137 A channel binding is created or refreshed using a ChannelBind 2138 transaction. A ChannelBind transaction also creates or refreshes a 2139 permission towards the peer (see Section 9). 2141 To initiate the ChannelBind transaction, the client forms a 2142 ChannelBind request. The channel to be bound is specified in a 2143 CHANNEL-NUMBER attribute, and the peer's transport address is 2144 specified in an XOR-PEER-ADDRESS attribute. Section 12.2 describes 2145 the restrictions on these attributes. The client MUST only include 2146 an XOR-PEER-ADDRESS attribute with an address of the same address 2147 family as that of a relayed transport address for the allocation. 2149 Rebinding a channel to the same transport address that it is already 2150 bound to provides a way to refresh a channel binding and the 2151 corresponding permission without sending data to the peer. Note 2152 however, that permissions need to be refreshed more frequently than 2153 channels. 2155 12.2. Receiving a ChannelBind Request 2157 When the server receives a ChannelBind request, it processes as per 2158 Section 5 plus the specific rules mentioned here. 2160 The server checks the following: 2162 o The request contains both a CHANNEL-NUMBER and an XOR-PEER-ADDRESS 2163 attribute; 2165 o The channel number is in the range 0x4000 through 0x4FFF 2166 (inclusive); 2168 o The channel number is not currently bound to a different transport 2169 address (same transport address is OK); 2171 o The transport address is not currently bound to a different 2172 channel number. 2174 o If the XOR-PEER-ADDRESS attribute contains an address of an 2175 address family that is not the same as that of a relayed transport 2176 address for the allocation, the server MUST generate an error 2177 response with the 443 (Peer Address Family Mismatch) response 2178 code. 2180 If any of these tests fail, the server replies with a 400 (Bad 2181 Request) error. 2183 The server MAY impose restrictions on the IP address and port values 2184 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 2185 allowed, the server rejects the request with a 403 (Forbidden) error. 2187 If the request is valid, but the server is unable to fulfill the 2188 request due to some capacity limit or similar, the server replies 2189 with a 508 (Insufficient Capacity) error. 2191 Otherwise, the server replies with a ChannelBind success response. 2192 There are no required attributes in a successful ChannelBind 2193 response. 2195 If the server can satisfy the request, then the server creates or 2196 refreshes the channel binding using the channel number in the 2197 CHANNEL-NUMBER attribute and the transport address in the XOR-PEER- 2198 ADDRESS attribute. The server also installs or refreshes a 2199 permission for the IP address in the XOR-PEER-ADDRESS attribute as 2200 described in Section 9. 2202 NOTE: A server need not do anything special to implement 2203 idempotency of ChannelBind requests over UDP using the "stateless 2204 stack approach". Retransmitted ChannelBind requests will simply 2205 refresh the channel binding and the corresponding permission. 2206 Furthermore, the client must wait 5 minutes before binding a 2207 previously bound channel number or peer address to a different 2208 channel, eliminating the possibility that the transaction would 2209 initially fail but succeed on a retransmission. 2211 12.3. Receiving a ChannelBind Response 2213 When the client receives a ChannelBind success response, it updates 2214 its data structures to record that the channel binding is now active. 2215 It also updates its data structures to record that the corresponding 2216 permission has been installed or refreshed. 2218 If the client receives a ChannelBind failure response that indicates 2219 that the channel information is out-of-sync between the client and 2220 the server (e.g., an unexpected 400 "Bad Request" response), then it 2221 is RECOMMENDED that the client immediately delete the allocation and 2222 start afresh with a new allocation. 2224 12.4. The ChannelData Message 2226 The ChannelData message is used to carry application data between the 2227 client and the server. It has the following format: 2229 0 1 2 3 2230 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 2231 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2232 | Channel Number | Length | 2233 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2234 | | 2235 / Application Data / 2236 / / 2237 | | 2238 | +-------------------------------+ 2239 | | 2240 +-------------------------------+ 2241 The Channel Number field specifies the number of the channel on which 2242 the data is traveling, and thus the address of the peer that is 2243 sending or is to receive the data. 2245 The Length field specifies the length in bytes of the application 2246 data field (i.e., it does not include the size of the ChannelData 2247 header). Note that 0 is a valid length. 2249 The Application Data field carries the data the client is trying to 2250 send to the peer, or that the peer is sending to the client. 2252 12.5. Sending a ChannelData Message 2254 Once a client has bound a channel to a peer, then when the client has 2255 data to send to that peer it may use either a ChannelData message or 2256 a Send indication; that is, the client is not obligated to use the 2257 channel when it exists and may freely intermix the two message types 2258 when sending data to the peer. The server, on the other hand, MUST 2259 use the ChannelData message if a channel has been bound to the peer. 2260 The server uses a Data indication to signal the XOR-PEER-ADDRESS and 2261 ICMP attributes to the client even if a channel has been bound to the 2262 peer. 2264 The fields of the ChannelData message are filled in as described in 2265 Section 12.4. 2267 Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to 2268 a multiple of four bytes in order to ensure the alignment of 2269 subsequent messages. The padding is not reflected in the length 2270 field of the ChannelData message, so the actual size of a ChannelData 2271 message (including padding) is (4 + Length) rounded up to the nearest 2272 multiple of 4. Over UDP, the padding is not required but MAY be 2273 included. 2275 The ChannelData message is then sent on the 5-tuple associated with 2276 the allocation. 2278 12.6. Receiving a ChannelData Message 2280 The receiver of the ChannelData message uses the first byte to 2281 distinguish it from other multiplexed protocols, as described in 2282 Figure 5. If the message uses a value in the reserved range (0x5000 2283 through 0xFFFF), then the message is silently discarded. 2285 If the ChannelData message is received in a UDP datagram, and if the 2286 UDP datagram is too short to contain the claimed length of the 2287 ChannelData message (i.e., the UDP header length field value is less 2288 than the ChannelData header length field value + 4 + 8), then the 2289 message is silently discarded. 2291 If the ChannelData message is received over TCP or over TLS-over-TCP, 2292 then the actual length of the ChannelData message is as described in 2293 Section 12.5. 2295 If the ChannelData message is received on a channel that is not bound 2296 to any peer, then the message is silently discarded. 2298 On the client, it is RECOMMENDED that the client discard the 2299 ChannelData message if the client believes there is no active 2300 permission towards the peer. On the server, the receipt of a 2301 ChannelData message MUST NOT refresh either the channel binding or 2302 the permission towards the peer. 2304 On the server, if no errors are detected, the server relays the 2305 application data to the peer by forming a UDP datagram as follows: 2307 o the source transport address is the relayed transport address of 2308 the allocation, where the allocation is determined by the 5-tuple 2309 on which the ChannelData message arrived; 2311 o the destination transport address is the transport address to 2312 which the channel is bound; 2314 o the data following the UDP header is the contents of the data 2315 field of the ChannelData message. 2317 The resulting UDP datagram is then sent to the peer. Note that if 2318 the Length field in the ChannelData message is 0, then there will be 2319 no data in the UDP datagram, but the UDP datagram is still formed and 2320 sent. 2322 12.7. Relaying Data from the Peer 2324 When the server receives a UDP datagram on the relayed transport 2325 address associated with an allocation, the server processes it as 2326 described in Section 11.3. If that section indicates that a 2327 ChannelData message should be sent (because there is a channel bound 2328 to the peer that sent to the UDP datagram), then the server forms and 2329 sends a ChannelData message as described in Section 12.5. 2331 When the server receives an ICMP packet, the server processes it as 2332 described in Section 11.5. A Data indication MUST be sent regardless 2333 of whether there is a channel bound to the peer that was the 2334 destination of the UDP datagram that triggered the reception of the 2335 ICMP packet. 2337 13. Packet Translations 2339 This section addresses IPv4-to-IPv6, IPv6-to-IPv4, and IPv6-to-IPv6 2340 translations. Requirements for translation of the IP addresses and 2341 port numbers of the packets are described above. The following 2342 sections specify how to translate other header fields. 2344 As discussed in Section 3.6, translations in TURN are designed so 2345 that a TURN server can be implemented as an application that runs in 2346 user space under commonly available operating systems and that does 2347 not require special privileges. The translations specified in the 2348 following sections follow this principle. 2350 The descriptions below have two parts: a preferred behavior and an 2351 alternate behavior. The server SHOULD implement the preferred 2352 behavior. Otherwise, the server MUST implement the alternate 2353 behavior and MUST NOT do anything else for the reasons detailed in 2354 [RFC7915]. The TURN server solely relies on the DF bit in the IPv4 2355 header and Fragmentation header in IPv6 header to handle 2356 fragmentation and does not rely on the DONT-FRAGMENT attribute. 2358 13.1. IPv4-to-IPv6 Translations 2360 Time to Live (TTL) field 2362 Preferred Behavior: As specified in Section 4 of [RFC7915]. 2364 Alternate Behavior: Set the outgoing value to the default for 2365 outgoing packets. 2367 Traffic Class 2369 Preferred behavior: As specified in Section 4 of [RFC7915]. 2371 Alternate behavior: The TURN server sets the Traffic Class to the 2372 default value for outgoing packets. 2374 Flow Label 2376 Preferred behavior: The TURN server can use the 5-tuple of relayed 2377 transport address, peer transport address and UDP protocol number 2378 to identify each flow, generate and set the flow label value in 2379 the IPv6 packet as discussed in Section 3 of [RFC6437]. If the 2380 TURN server is incapable of generating the flow label value from 2381 the IPv6 packet's 5-tuple, it sets the Flow label to 0. 2383 Alternate behavior: The TURN server sets the Flow label to the 2384 default value of zero for outgoing packets. 2386 Hop Limit 2388 Preferred behavior: As specified in Section 4 of [RFC7915]. 2390 Alternate behavior: The TURN server sets the Hop Limit to the 2391 default value for outgoing packets. 2393 Fragmentation 2395 Preferred behavior: As specified in Section 4 of [RFC7915]. 2397 Alternate behavior: The TURN server assembles incoming fragments. 2398 The TURN server follows its default behavior to send outgoing 2399 packets. 2401 For both preferred and alternate behavior, the DONT-FRAGMENT 2402 attribute MUST be ignored by the server. 2404 Extension Headers 2406 Preferred behavior: The outgoing packet uses the system defaults 2407 for IPv6 extension headers, with the exception of the 2408 Fragmentation header as described above. 2410 Alternate behavior: Same as preferred. 2412 13.2. IPv6-to-IPv6 Translations 2414 Flow Label 2416 The TURN server should consider that it is handling two different 2417 IPv6 flows. Therefore, the Flow label [RFC6437] SHOULD NOT be copied 2418 as part of the translation. 2420 Preferred behavior: The TURN server can use the 5-tuple of relayed 2421 transport address, peer transport address and UDP protocol number 2422 to identify each flow, generate and set the flow label value in 2423 the IPv6 packet as discussed in Section 3 of [RFC6437]. If the 2424 TURN server is incapable of generating the flow label value from 2425 the IPv6 packet's 5-tuple, it sets the Flow label to 0. 2427 Alternate behavior: The TURN server sets the Flow label to the 2428 default value of zero for outgoing packets. 2430 Hop Limit 2431 Preferred behavior: The TURN server acts as a regular router with 2432 respect to decrementing the Hop Limit and generating an ICMPv6 2433 error if it reaches zero. 2435 Alternate behavior: The TURN server sets the Hop Limit to the 2436 default value for outgoing packets. 2438 Fragmentation 2440 Preferred behavior: If the incoming packet did not include a 2441 Fragment header and the outgoing packet size does not exceed the 2442 outgoing link's MTU, the TURN server sends the outgoing packet 2443 without a Fragment header. 2445 If the incoming packet did not include a Fragment header and the 2446 outgoing packet size exceeds the outgoing link's MTU, the TURN 2447 server drops the outgoing packet and send an ICMP message of type 2448 2 code 0 ("Packet too big") to the sender of the incoming packet. 2449 If the packet is being sent to the peer, the TURN server reduces 2450 the MTU reported in the ICMP message by 48 bytes to allow room for 2451 the overhead of a Data indication. 2453 If the incoming packet included a Fragment header and the outgoing 2454 packet size (with a Fragment header included) does not exceed the 2455 outgoing link's MTU, the TURN server sends the outgoing packet 2456 with a Fragment header. The TURN server sets the fields of the 2457 Fragment header as appropriate for a packet originating from the 2458 server. 2460 If the incoming packet included a Fragment header and the outgoing 2461 packet size exceeds the outgoing link's MTU, the TURN server MUST 2462 fragment the outgoing packet into fragments of no more than 1280 2463 bytes. The TURN server sets the fields of the Fragment header as 2464 appropriate for a packet originating from the server. 2466 Alternate behavior: The TURN server assembles incoming fragments. 2467 The TURN server follows its default behavior to send outgoing 2468 packets. 2470 For both preferred and alternate behavior, the DONT-FRAGMENT 2471 attribute MUST be ignored by the server. 2473 Extension Headers 2475 Preferred behavior: The outgoing packet uses the system defaults 2476 for IPv6 extension headers, with the exception of the 2477 Fragmentation header as described above. 2479 Alternate behavior: Same as preferred. 2481 13.3. IPv6-to-IPv4 Translations 2483 Type of Service and Precedence 2485 Preferred behavior: As specified in Section 5 of [RFC7915]. 2487 Alternate behavior: The TURN server sets the Type of Service and 2488 Precedence to the default value for outgoing packets. 2490 Time to Live 2492 Preferred behavior: As specified in Section 5 of [RFC7915]. 2494 Alternate behavior: The TURN server sets the Time to Live to the 2495 default value for outgoing packets. 2497 Fragmentation 2499 Preferred behavior: As specified in Section 5 of [RFC7915]. 2500 Additionally, when the outgoing packet's size exceeds the outgoing 2501 link's MTU, the TURN server needs to generate an ICMP error 2502 (ICMPv6 Packet Too Big) reporting the MTU size. If the packet is 2503 being sent to the peer, the TURN server SHOULD reduce the MTU 2504 reported in the ICMP message by 48 bytes to allow room for the 2505 overhead of a Data indication. 2507 Alternate behavior: The TURN server assembles incoming fragments. 2508 The TURN server follows its default behavior to send outgoing 2509 packets. 2511 For both preferred and alternate behavior, the DONT-FRAGMENT 2512 attribute MUST be ignored by the server. 2514 14. UDP-to-UDP relay 2516 This section describes how the server sets various fields in the IP 2517 header for UDP-to-UDP relay from the client to the peer or vice 2518 versa. The descriptions in this section apply: (a) when the server 2519 sends a UDP datagram to the peer, or (b) when the server sends a Data 2520 indication or ChannelData message to the client over UDP transport. 2521 The descriptions in this section do not apply to TURN messages sent 2522 over TCP or TLS transport from the server to the client. 2524 The descriptions below have two parts: a preferred behavior and an 2525 alternate behavior. The server SHOULD implement the preferred 2526 behavior, but if that is not possible for a particular field, then it 2527 SHOULD implement the alternative behavior. 2529 Differentiated Services Code Point (DSCP) field [RFC2474] 2531 Preferred Behavior: Set the outgoing value to the incoming value, 2532 unless the server includes a differentiated services classifier 2533 and marker [RFC2474]. 2535 Alternate Behavior: Set the outgoing value to a fixed value, which 2536 by default is Best Effort unless configured otherwise. 2538 In both cases, if the server is immediately adjacent to a 2539 differentiated services classifier and marker, then DSCP MAY be 2540 set to any arbitrary value in the direction towards the 2541 classifier. 2543 Explicit Congestion Notification (ECN) field [RFC3168] 2545 Preferred Behavior: Set the outgoing value to the incoming value. 2546 The server may perform Active Queue Management, in which case it 2547 SHOULD behave as a ECN aware router [RFC3168] and can mark traffic 2548 with Congestion Experienced (CE) instead of dropping the packet. 2549 The use of ECT(1) is subject to experimental usage [RFC8311]. 2551 Alternate Behavior: Set the outgoing value to Not-ECT (=0b00). 2553 IPv4 Fragmentation fields 2555 Preferred Behavior: When the server sends a packet to a peer in 2556 response to a Send indication containing the DONT-FRAGMENT 2557 attribute, then set the outgoing UDP packet to not fragment. In 2558 all other cases when sending an outgoing packet containing 2559 application data (e.g., Data indication, ChannelData message, or 2560 DONT-FRAGMENT attribute not included in the Send indication), copy 2561 the DF bit from the DF bit of the incoming packet that contained 2562 the application data. 2564 Set the other fragmentation fields (Identification, More 2565 Fragments, Fragment Offset) as appropriate for a packet 2566 originating from the server. 2568 Alternate Behavior: As described in the Preferred Behavior, except 2569 always assume the incoming DF bit is 0. 2571 In both the Preferred and Alternate Behaviors, the resulting 2572 packet may be too large for the outgoing link. If this is the 2573 case, then the normal fragmentation rules apply [RFC1122]. 2575 IPv4 Options 2577 Preferred Behavior: The outgoing packet uses the system defaults 2578 for IPv4 options. 2580 Alternate Behavior: Same as preferred. 2582 15. TCP-to-UDP relay 2584 This section describes how the server sets various fields in the IP 2585 header for TCP-to-UDP relay from the client to the peer. The 2586 descriptions in this section apply when the server sends a UDP 2587 datagram to the peer. Note that the server does not perform per- 2588 packet translation for TCP-to-UDP relaying. 2590 TCP multi-path [RFC6824] is not supported by this version of TURN 2591 because TCP multi-path is not used by both SIP and WebRTC protocols 2592 [RFC7478] for media and non-media data. TCP connection between the 2593 TURN client and server can use TCP-AO [RFC5925] but UDP does not 2594 provide a similar type of authentication until UDP supports a similar 2595 authentication option [I-D.ietf-tsvwg-udp-options]. Even if both 2596 TCP-AO and UDP authentication would be used between TURN client and 2597 server, it would not change the end-to-end security properties of the 2598 UDP payload being relayed. Therefore applications using TURN will 2599 need to secure their application data end-to-end appropriately, e.g., 2600 SRTP for RTP applications. Note that TCP-AO option obsoletes TCP MD5 2601 option. Unlike UDP, TCP without the TCP Fast Open extension 2602 [RFC7413] does not support 0-RTT session resumption. The TCP user 2603 timeout [RFC5482] equivalent for application data relayed by the TURN 2604 is the use of RTP control protocol (RTCP). As a reminder, RTCP is a 2605 fundamental and integral part of RTP. 2607 The descriptions below have two parts: a preferred behavior and an 2608 alternate behavior. The server SHOULD implement the preferred 2609 behavior, but if that is not possible for a particular field, then it 2610 SHOULD implement the alternative behavior. 2612 For the UDP datagram sent to the peer based on Send Indication or 2613 ChannelData message arriving at the TURN server over a TCP Transport, 2614 the server sets various fields in the IP header as follows: 2616 Differentiated Services Code Point (DSCP) field [RFC2474] 2617 Preferred Behavior: The TCP connection can only use a single DSCP 2618 code point so inter flow differentiation is not possible, see 2619 Section 5.1 of [RFC7657]. The server sets the outgoing value to 2620 the DSCP code point used by the TCP connection, unless the server 2621 includes a differentiated services classifier and marker 2622 [RFC2474]. 2624 Alternate Behavior: Set the outgoing value to a fixed value, which 2625 by default is Best Effort unless configured otherwise. 2627 In both cases, if the server is immediately adjacent to a 2628 differentiated services classifier and marker, then DSCP MAY be 2629 set to any arbitrary value in the direction towards the 2630 classifier. 2632 Explicit Congestion Notification (ECN) field [RFC3168] 2634 Preferred Behavior: No mechanism is defined to indicate what ECN 2635 value should be used for the outgoing UDP datagrams of an 2636 allocation, therefore set the outgoing value to Not-ECT (=0b00). 2638 Alternate Behavior: Same as preferred. 2640 IPv4 Fragmentation fields 2642 Preferred Behavior: When the server sends a packet to a peer in 2643 response to a Send indication containing the DONT-FRAGMENT 2644 attribute, then set the outgoing UDP packet to not fragment. In 2645 all other cases when sending an outgoing UDP packet containing 2646 application data (e.g., Data indication, ChannelData message, or 2647 DONT-FRAGMENT attribute not included in the Send indication), set 2648 the DF bit in the outgoing IP header to 0. 2650 Alternate Behavior: Same as preferred. 2652 IPv6 Fragmentation fields 2654 Preferred Behavior: If the TCP traffic arrives over IPv6, the 2655 server relies on the presence of DON'T-FRAGMENT attribute in the 2656 send indication to set the outgoing UDP packet to not fragment. 2658 Alternate Behavior: Same as preferred. 2660 IPv4 Options 2661 Preferred Behavior: The outgoing packet uses the system defaults 2662 for IPv4 options. 2664 Alternate Behavior: Same as preferred. 2666 16. UDP-to-TCP relay 2668 This section describes how the server sets various fields in the IP 2669 header for UDP-to-TCP relay from the peer to the client. The 2670 descriptions in this section apply when the server sends a Data 2671 indication or ChannelData message to the client over TCP or TLS 2672 transport. Note that the server does not perform per-packet 2673 translation for UDP-to-TCP relaying. 2675 The descriptions below have two parts: a preferred behavior and an 2676 alternate behavior. The server SHOULD implement the preferred 2677 behavior, but if that is not possible for a particular field, then it 2678 SHOULD implement the alternative behavior. 2680 The TURN server sets IP header fields in the TCP packets on a per- 2681 connection basis for the TCP connection as follows: 2683 Differentiated Services Code Point (DSCP) field [RFC2474] 2685 Preferred Behavior: Ignore the incoming DSCP value. When TCP is 2686 used between the client and the server, a single DSCP should be 2687 used for all traffic on that TCP connection. Note, TURN/ICE 2688 occurs before application data is exchanged. 2690 Alternate Behavior: Same as preferred. 2692 Explicit Congestion Notification (ECN) field [RFC3168] 2694 Preferred Behavior: Ignore, ECN signals are dropped in the TURN 2695 server for the incoming UDP datagrams from the peer. 2697 Alternate Behavior: Same as preferred. 2699 Fragmentation 2701 Preferred Behavior: Any fragmented packets are reassembled in the 2702 server and then forwarded to the client over the TCP connection. 2703 ICMP messages resulting from the UDP datagrams sent to the peer 2704 MUST be forwarded to the client using TURN's mechanism for 2705 relevant ICMP types and codes. 2707 Alternate Behavior: Same as preferred. 2709 Extension Headers 2711 Preferred behavior: The outgoing packet uses the system defaults 2712 for IPv6 extension headers. 2714 Alternate behavior: Same as preferred. 2716 IPv4 Options 2718 Preferred Behavior: The outgoing packet uses the system defaults 2719 for IPv4 options. 2721 Alternate Behavior: Same as preferred. 2723 17. STUN Methods 2725 This section lists the codepoints for the STUN methods defined in 2726 this specification. See elsewhere in this document for the semantics 2727 of these methods. 2729 0x003 : Allocate (only request/response semantics defined) 2730 0x004 : Refresh (only request/response semantics defined) 2731 0x006 : Send (only indication semantics defined) 2732 0x007 : Data (only indication semantics defined) 2733 0x008 : CreatePermission (only request/response semantics defined 2734 0x009 : ChannelBind (only request/response semantics defined) 2736 18. STUN Attributes 2737 This STUN extension defines the following attributes: 2739 0x000C: CHANNEL-NUMBER 2740 0x000D: LIFETIME 2741 0x0010: Reserved (was BANDWIDTH) 2742 0x0012: XOR-PEER-ADDRESS 2743 0x0013: DATA 2744 0x0016: XOR-RELAYED-ADDRESS 2745 0x0017: REQUESTED-ADDRESS-FAMILY 2746 0x0018: EVEN-PORT 2747 0x0019: REQUESTED-TRANSPORT 2748 0x001A: DONT-FRAGMENT 2749 0x0021: Reserved (was TIMER-VAL) 2750 0x0022: RESERVATION-TOKEN 2751 TBD-CA: ADDITIONAL-ADDRESS-FAMILY 2752 TBD-CA: ADDRESS-ERROR-CODE 2753 TBD-CA: ICMP 2755 Some of these attributes have lengths that are not multiples of 4. 2756 By the rules of STUN, any attribute whose length is not a multiple of 2757 4 bytes MUST be immediately followed by 1 to 3 padding bytes to 2758 ensure the next attribute (if any) would start on a 4-byte boundary 2759 (see [I-D.ietf-tram-stunbis]). 2761 18.1. CHANNEL-NUMBER 2763 The CHANNEL-NUMBER attribute contains the number of the channel. The 2764 value portion of this attribute is 4 bytes long and consists of a 2765 16-bit unsigned integer, followed by a two-octet RFFU (Reserved For 2766 Future Use) field, which MUST be set to 0 on transmission and MUST be 2767 ignored on reception. 2769 0 1 2 3 2770 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 2771 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2772 | Channel Number | RFFU = 0 | 2773 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2775 18.2. LIFETIME 2777 The LIFETIME attribute represents the duration for which the server 2778 will maintain an allocation in the absence of a refresh. The TURN 2779 client can include the LIFETIME attribute with the desired lifetime 2780 in Allocate and Refresh requests. The value portion of this 2781 attribute is 4-bytes long and consists of a 32-bit unsigned integral 2782 value representing the number of seconds remaining until expiration. 2784 18.3. XOR-PEER-ADDRESS 2786 The XOR-PEER-ADDRESS specifies the address and port of the peer as 2787 seen from the TURN server. (For example, the peer's server-reflexive 2788 transport address if the peer is behind a NAT.) It is encoded in the 2789 same way as XOR-MAPPED-ADDRESS [I-D.ietf-tram-stunbis]. 2791 18.4. DATA 2793 The DATA attribute is present in all Send and Data indications. The 2794 value portion of this attribute is variable length and consists of 2795 the application data (that is, the data that would immediately follow 2796 the UDP header if the data was been sent directly between the client 2797 and the peer). The application data is equivalent to the "UDP user 2798 data" and does not include the "surplus area" defined in Section 4 of 2799 [I-D.ietf-tsvwg-udp-options]. If the length of this attribute is not 2800 a multiple of 4, then padding must be added after this attribute. 2802 18.5. XOR-RELAYED-ADDRESS 2804 The XOR-RELAYED-ADDRESS is present in Allocate responses. It 2805 specifies the address and port that the server allocated to the 2806 client. It is encoded in the same way as XOR-MAPPED-ADDRESS 2807 [I-D.ietf-tram-stunbis]. 2809 18.6. REQUESTED-ADDRESS-FAMILY 2811 This attribute is used in Allocate and Refresh requests to specify 2812 the address type requested by the client. The value of this 2813 attribute is 4 bytes with the following format: 2815 0 1 2 3 2816 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 2817 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2818 | Family | Reserved | 2819 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2821 Family: there are two values defined for this field and specified in 2822 [I-D.ietf-tram-stunbis], Section 14.1: 0x01 for IPv4 addresses and 2823 0x02 for IPv6 addresses. 2825 Reserved: at this point, the 24 bits in the Reserved field MUST be 2826 set to zero by the client and MUST be ignored by the server. 2828 18.7. EVEN-PORT 2830 This attribute allows the client to request that the port in the 2831 relayed transport address be even, and (optionally) that the server 2832 reserve the next-higher port number. The value portion of this 2833 attribute is 1 byte long. Its format is: 2835 0 2836 0 1 2 3 4 5 6 7 2837 +-+-+-+-+-+-+-+-+ 2838 |R| RFFU | 2839 +-+-+-+-+-+-+-+-+ 2841 The value contains a single 1-bit flag: 2843 R: If 1, the server is requested to reserve the next-higher port 2844 number (on the same IP address) for a subsequent allocation. If 2845 0, no such reservation is requested. 2847 RFFU: Reserved For Future Use. 2849 The other 7 bits of the attribute's value must be set to zero on 2850 transmission and ignored on reception. 2852 Since the length of this attribute is not a multiple of 4, padding 2853 must immediately follow this attribute. 2855 18.8. REQUESTED-TRANSPORT 2857 This attribute is used by the client to request a specific transport 2858 protocol for the allocated transport address. The value of this 2859 attribute is 4 bytes with the following format: 2861 0 1 2 3 2862 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 2863 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2864 | Protocol | RFFU | 2865 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2867 The Protocol field specifies the desired protocol. The codepoints 2868 used in this field are taken from those allowed in the Protocol field 2869 in the IPv4 header and the NextHeader field in the IPv6 header 2870 [Protocol-Numbers]. This specification only allows the use of 2871 codepoint 17 (User Datagram Protocol). 2873 The RFFU field MUST be set to zero on transmission and MUST be 2874 ignored on reception. It is reserved for future uses. 2876 18.9. DONT-FRAGMENT 2878 This attribute is used by the client to request that the server set 2879 the DF (Don't Fragment) bit in the IP header when relaying the 2880 application data onward to the peer, and for determining the server 2881 capability in Allocate requests. This attribute has no value part 2882 and thus the attribute length field is 0. 2884 18.10. RESERVATION-TOKEN 2886 The RESERVATION-TOKEN attribute contains a token that uniquely 2887 identifies a relayed transport address being held in reserve by the 2888 server. The server includes this attribute in a success response to 2889 tell the client about the token, and the client includes this 2890 attribute in a subsequent Allocate request to request the server use 2891 that relayed transport address for the allocation. 2893 The attribute value is 8 bytes and contains the token value. 2895 18.11. ADDITIONAL-ADDRESS-FAMILY 2897 This attribute is used by clients to request the allocation of a IPv4 2898 and IPv6 address type from a server. It is encoded in the same way 2899 as REQUESTED-ADDRESS-FAMILY Section 18.6. The ADDITIONAL-ADDRESS- 2900 FAMILY attribute MAY be present in Allocate request. The attribute 2901 value of 0x02 (IPv6 address) is the only valid value in Allocate 2902 request. 2904 18.12. ADDRESS-ERROR-CODE Attribute 2906 This attribute is used by servers to signal the reason for not 2907 allocating the requested address family. The value portion of this 2908 attribute is variable length with the following format: 2910 0 1 2 3 2911 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 2912 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2913 | Family | Reserved |Class| Number | 2914 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2915 | Reason Phrase (variable) .. 2916 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2918 Family: there are two values defined for this field and specified in 2919 [I-D.ietf-tram-stunbis], Section 14.1: 0x01 for IPv4 addresses and 2920 0x02 for IPv6 addresses. 2922 Reserved: at this point, the 13 bits in the Reserved field MUST be 2923 set to zero by the client and MUST be ignored by the server. 2925 Class: The Class represents the hundreds digit of the error code and 2926 is defined in section 14.8 of [I-D.ietf-tram-stunbis]. 2928 Number: this 8-bit field contains the reason server cannot allocate 2929 one of the requested address types. The error code values could 2930 be either 440 (unsupported address family) or 508 (insufficient 2931 capacity). The number representation is defined in section 14.8 2932 of [I-D.ietf-tram-stunbis]. 2934 Reason Phrase: The recommended reason phrases for error codes 440 2935 and 508 are explained in Section 19. The reason phrase MUST be a 2936 UTF-8 [RFC3629] encoded sequence of less than 128 characters 2937 (which can be as long as 509 bytes when encoding them or 763 bytes 2938 when decoding them). 2940 18.13. ICMP Attribute 2942 This attribute is used by servers to signal the reason an UDP packet 2943 was dropped. The following is the format of the ICMP attribute. 2945 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 2946 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2947 | Reserved | ICMP Type | ICMP Code | 2948 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2949 | Error Data | 2950 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2952 Reserved: This field MUST be set to 0 when sent, and MUST be ignored 2953 when received. 2955 ICMP Type: The field contains the value in the ICMP type. Its 2956 interpretation depends whether the ICMP was received over IPv4 or 2957 IPv6. 2959 ICMP Code: The field contains the value in the ICMP code. Its 2960 interpretation depends whether the ICMP was received over IPv4 or 2961 IPv6. 2963 Error Data: This field size is 4 bytes long. If the ICMPv6 type is 2964 2 (Packet Too Big Message) or ICMPv4 type is 3 ( Destination 2965 Unreachable) and Code is 4 (fragmentation needed and DF set), the 2966 Error Data field will be set to the Maximum Transmission Unit of 2967 the next-hop link (Section 3.2 of [RFC4443]) and Section 4 of 2969 [RFC1191]). For other ICMPv6 types and ICMPv4 types and codes, 2970 Error Data field MUST be set to zero. 2972 19. STUN Error Response Codes 2974 This document defines the following error response codes: 2976 403 (Forbidden): The request was valid but cannot be performed due 2977 to administrative or similar restrictions. 2979 437 (Allocation Mismatch): A request was received by the server that 2980 requires an allocation to be in place, but no allocation exists, 2981 or a request was received that requires no allocation, but an 2982 allocation exists. 2984 440 (Address Family not Supported): The server does not support the 2985 address family requested by the client. 2987 441 (Wrong Credentials): The credentials in the (non-Allocate) 2988 request do not match those used to create the allocation. 2990 442 (Unsupported Transport Protocol): The Allocate request asked the 2991 server to use a transport protocol between the server and the peer 2992 that the server does not support. NOTE: This does NOT refer to 2993 the transport protocol used in the 5-tuple. 2995 443 (Peer Address Family Mismatch). A peer address is part of a 2996 different address family than that of the relayed transport 2997 address of the allocation. 2999 486 (Allocation Quota Reached): No more allocations using this 3000 username can be created at the present time. 3002 508 (Insufficient Capacity): The server is unable to carry out the 3003 request due to some capacity limit being reached. In an Allocate 3004 response, this could be due to the server having no more relayed 3005 transport addresses available at that time, having none with the 3006 requested properties, or the one that corresponds to the specified 3007 reservation token is not available. 3009 20. Detailed Example 3011 This section gives an example of the use of TURN, showing in detail 3012 the contents of the messages exchanged. The example uses the network 3013 diagram shown in the Overview (Figure 1). 3015 For each message, the attributes included in the message and their 3016 values are shown. For convenience, values are shown in a human- 3017 readable format rather than showing the actual octets; for example, 3018 "XOR-RELAYED-ADDRESS=192.0.2.15:9000" shows that the XOR-RELAYED- 3019 ADDRESS attribute is included with an address of 192.0.2.15 and a 3020 port of 9000, here the address and port are shown before the xor-ing 3021 is done. For attributes with string-like values (e.g., 3022 SOFTWARE="Example client, version 1.03" and 3023 NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda"), the value of the attribute 3024 is shown in quotes for readability, but these quotes do not appear in 3025 the actual value. 3027 TURN TURN Peer Peer 3028 client server A B 3029 | | | | 3030 |--- Allocate request -------------->| | | 3031 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 3032 | SOFTWARE="Example client, version 1.03" | | 3033 | LIFETIME=3600 (1 hour) | | | 3034 | REQUESTED-TRANSPORT=17 (UDP) | | | 3035 | DONT-FRAGMENT | | | 3036 | | | | 3037 |<-- Allocate error response --------| | | 3038 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 3039 | SOFTWARE="Example server, version 1.17" | | 3040 | ERROR-CODE=401 (Unauthorized) | | | 3041 | REALM="example.com" | | | 3042 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3043 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 3044 | | | | 3045 |--- Allocate request -------------->| | | 3046 | Transaction-Id=0xC271E932AD7446A32C234492 | | 3047 | SOFTWARE="Example client 1.03" | | | 3048 | LIFETIME=3600 (1 hour) | | | 3049 | REQUESTED-TRANSPORT=17 (UDP) | | | 3050 | DONT-FRAGMENT | | | 3051 | USERNAME="George" | | | 3052 | REALM="example.com" | | | 3053 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3054 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 3055 | PASSWORD-ALGORITHM=SHA256 | | | 3056 | MESSAGE-INTEGRITY=... | | | 3057 | MESSAGE-INTEGRITY-SHA256=... | | | 3058 | | | | 3059 |<-- Allocate success response ------| | | 3060 | Transaction-Id=0xC271E932AD7446A32C234492 | | 3061 | SOFTWARE="Example server, version 1.17" | | 3062 | LIFETIME=1200 (20 minutes) | | | 3063 | XOR-RELAYED-ADDRESS=192.0.2.15:50000 | | 3064 | XOR-MAPPED-ADDRESS=192.0.2.1:7000 | | 3065 | MESSAGE-INTEGRITY=... | | | 3067 The client begins by selecting a host transport address to use for 3068 the TURN session; in this example, the client has selected 3069 198.51.100.2:49721 as shown in Figure 1. The client then sends an 3070 Allocate request to the server at the server transport address. The 3071 client randomly selects a 96-bit transaction id of 3072 0xA56250D3F17ABE679422DE85 for this transaction; this is encoded in 3073 the transaction id field in the fixed header. The client includes a 3074 SOFTWARE attribute that gives information about the client's 3075 software; here the value is "Example client, version 1.03" to 3076 indicate that this is version 1.03 of something called the Example 3077 client. The client includes the LIFETIME attribute because it wishes 3078 the allocation to have a longer lifetime than the default of 10 3079 minutes; the value of this attribute is 3600 seconds, which 3080 corresponds to 1 hour. The client must always include a REQUESTED- 3081 TRANSPORT attribute in an Allocate request and the only value allowed 3082 by this specification is 17, which indicates UDP transport between 3083 the server and the peers. The client also includes the DONT-FRAGMENT 3084 attribute because it wishes to use the DONT-FRAGMENT attribute later 3085 in Send indications; this attribute consists of only an attribute 3086 header, there is no value part. We assume the client has not 3087 recently interacted with the server, thus the client does not include 3088 USERNAME, USERHASH, REALM, NONCE, PASSWORD-ALGORITHMS, PASSWORD- 3089 ALGORITHM, MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 attribute. 3090 Finally, note that the order of attributes in a message is arbitrary 3091 (except for the MESSAGE-INTEGRITY, MESSAGE-INTEGRITY-SHA256 and 3092 FINGERPRINT attributes) and the client could have used a different 3093 order. 3095 Servers require any request to be authenticated. Thus, when the 3096 server receives the initial Allocate request, it rejects the request 3097 because the request does not contain the authentication attributes. 3098 Following the procedures of the long-term credential mechanism of 3099 STUN [I-D.ietf-tram-stunbis], the server includes an ERROR-CODE 3100 attribute with a value of 401 (Unauthorized), a REALM attribute that 3101 specifies the authentication realm used by the server (in this case, 3102 the server's domain "example.com"), and a nonce value in a NONCE 3103 attribute. The NONCE attribute starts with the "nonce cookie" with 3104 the STUN Security Feature "Password algorithm" bit set to 1. The 3105 server includes a PASSWORD-ALGORITHMS attribute that specifies the 3106 list of algorithms that the server can use to derive the long-term 3107 password. If the server sets the STUN Security Feature "Username 3108 anonymity" bit to 1 then the client uses the USERHASH attribute 3109 instead of the USERNAME attribute in the Allocate request to 3110 anonymise the username. The server also includes a SOFTWARE 3111 attribute that gives information about the server's software. 3113 The client, upon receipt of the 401 error, re-attempts the Allocate 3114 request, this time including the authentication attributes. The 3115 client selects a new transaction id, and then populates the new 3116 Allocate request with the same attributes as before. The client 3117 includes a USERNAME attribute and uses the realm value received from 3118 the server to help it determine which value to use; here the client 3119 is configured to use the username "George" for the realm 3120 "example.com". The client includes the PASSWORD-ALGORITHM attribute 3121 indicating the algorithm that the server must use to derive the long- 3122 term password. The client also includes the REALM and NONCE 3123 attributes, which are just copied from the 401 error response. 3124 Finally, the client includes MESSAGE-INTEGRITY and MESSAGE-INTEGRITY- 3125 SHA256 attributes as the last attributes in the message, whose values 3126 are Hashed Message Authentication Code - Secure Hash Algorithm 1 3127 (HMAC-SHA1) hash and Hashed Message Authentication Code - Secure Hash 3128 Algorithm 2 (HMAC-SHA2) hash over the contents of the message (shown 3129 as just "..." above); this HMAC-SHA1 and HMAC-SHA2 computation 3130 includes a password value. Thus, an attacker cannot compute the 3131 message integrity value without somehow knowing the secret password. 3133 The server, upon receipt of the authenticated Allocate request, 3134 checks that everything is OK, then creates an allocation. The server 3135 replies with an Allocate success response. The server includes a 3136 LIFETIME attribute giving the lifetime of the allocation; here, the 3137 server has reduced the client's requested 1-hour lifetime to just 20 3138 minutes, because this particular server doesn't allow lifetimes 3139 longer than 20 minutes. The server includes an XOR-RELAYED-ADDRESS 3140 attribute whose value is the relayed transport address of the 3141 allocation. The server includes an XOR-MAPPED-ADDRESS attribute 3142 whose value is the server-reflexive address of the client; this value 3143 is not used otherwise in TURN but is returned as a convenience to the 3144 client. The server includes either a MESSAGE-INTEGRITY or MESSAGE- 3145 INTEGRITY-SHA256 attribute to authenticate the response and to ensure 3146 its integrity; note that the response does not contain the USERNAME, 3147 REALM, and NONCE attributes. The server also includes a SOFTWARE 3148 attribute. 3150 TURN TURN Peer Peer 3151 client server A B 3152 |--- CreatePermission request ------>| | | 3153 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 3154 | XOR-PEER-ADDRESS=192.0.2.150:0 | | | 3155 | USERNAME="George" | | | 3156 | REALM="example.com" | | | 3157 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3158 | MESSAGE-INTEGRITY=... | | | 3159 | | | | 3160 |<-- CreatePermission success resp.--| | | 3161 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 3162 | MESSAGE-INTEGRITY=... | | | 3164 The client then creates a permission towards Peer A in preparation 3165 for sending it some application data. This is done through a 3166 CreatePermission request. The XOR-PEER-ADDRESS attribute contains 3167 the IP address for which a permission is established (the IP address 3168 of peer A); note that the port number in the attribute is ignored 3169 when used in a CreatePermission request, and here it has been set to 3170 0; also, note how the client uses Peer A's server-reflexive IP 3171 address and not its (private) host address. The client uses the same 3172 username, realm, and nonce values as in the previous request on the 3173 allocation. Though it is allowed to do so, the client has chosen not 3174 to include a SOFTWARE attribute in this request. 3176 The server receives the CreatePermission request, creates the 3177 corresponding permission, and then replies with a CreatePermission 3178 success response. Like the client, the server chooses not to include 3179 the SOFTWARE attribute in its reply. Again, note how success 3180 responses contain a MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256 3181 attribute (assuming the server uses the long-term credential 3182 mechanism), but no USERNAME, REALM, and NONCE attributes. 3184 TURN TURN Peer Peer 3185 client server A B 3186 |--- Send indication --------------->| | | 3187 | Transaction-Id=0x1278E9ACA2711637EF7D3328 | | 3188 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 3189 | DONT-FRAGMENT | | | 3190 | DATA=... | | | 3191 | |-- UDP dgm ->| | 3192 | | data=... | | 3193 | | | | 3194 | |<- UDP dgm --| | 3195 | | data=... | | 3196 |<-- Data indication ----------------| | | 3197 | Transaction-Id=0x8231AE8F9242DA9FF287FEFF | | 3198 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 3199 | DATA=... | | | 3201 The client now sends application data to Peer A using a Send 3202 indication. Peer A's server-reflexive transport address is specified 3203 in the XOR-PEER-ADDRESS attribute, and the application data (shown 3204 here as just "...") is specified in the DATA attribute. The client 3205 is doing a form of path MTU discovery at the application layer and 3206 thus specifies (by including the DONT-FRAGMENT attribute) that the 3207 server should set the DF bit in the UDP datagram to send to the peer. 3208 Indications cannot be authenticated using the long-term credential 3209 mechanism of STUN, so no MESSAGE-INTEGRITY or MESSAGE-INTEGRITY- 3210 SHA256 attribute is included in the message. An application wishing 3211 to ensure that its data is not altered or forged must integrity- 3212 protect its data at the application level. 3214 Upon receipt of the Send indication, the server extracts the 3215 application data and sends it in a UDP datagram to Peer A, with the 3216 relayed transport address as the source transport address of the 3217 datagram, and with the DF bit set as requested. Note that, had the 3218 client not previously established a permission for Peer A's server- 3219 reflexive IP address, then the server would have silently discarded 3220 the Send indication instead. 3222 Peer A then replies with its own UDP datagram containing application 3223 data. The datagram is sent to the relayed transport address on the 3224 server. When this arrives, the server creates a Data indication 3225 containing the source of the UDP datagram in the XOR-PEER-ADDRESS 3226 attribute, and the data from the UDP datagram in the DATA attribute. 3227 The resulting Data indication is then sent to the client. 3229 TURN TURN Peer Peer 3230 client server A B 3231 |--- ChannelBind request ----------->| | | 3232 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 3233 | CHANNEL-NUMBER=0x4000 | | | 3234 | XOR-PEER-ADDRESS=192.0.2.210:49191 | | 3235 | USERNAME="George" | | | 3236 | REALM="example.com" | | | 3237 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3238 | MESSAGE-INTEGRITY=... | | | 3239 | | | | 3240 |<-- ChannelBind success response ---| | | 3241 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 3242 | MESSAGE-INTEGRITY=... | | | 3244 The client now binds a channel to Peer B, specifying a free channel 3245 number (0x4000) in the CHANNEL-NUMBER attribute, and Peer B's 3246 transport address in the XOR-PEER-ADDRESS attribute. As before, the 3247 client re-uses the username, realm, and nonce from its last request 3248 in the message. 3250 Upon receipt of the request, the server binds the channel number to 3251 the peer, installs a permission for Peer B's IP address, and then 3252 replies with ChannelBind success response. 3254 TURN TURN Peer Peer 3255 client server A B 3256 |--- ChannelData ------------------->| | | 3257 | Channel-number=0x4000 |--- UDP datagram --------->| 3258 | Data=... | Data=... | 3259 | | | | 3260 | |<-- UDP datagram ----------| 3261 | | Data=... | | 3262 |<-- ChannelData --------------------| | | 3263 | Channel-number=0x4000 | | | 3264 | Data=... | | | 3266 The client now sends a ChannelData message to the server with data 3267 destined for Peer B. The ChannelData message is not a STUN message, 3268 and thus has no transaction id. Instead, it has only three fields: a 3269 channel number, data, and data length; here the channel number field 3270 is 0x4000 (the channel the client just bound to Peer B). When the 3271 server receives the ChannelData message, it checks that the channel 3272 is currently bound (which it is) and then sends the data onward to 3273 Peer B in a UDP datagram, using the relayed transport address as the 3274 source transport address and 192.0.2.210:49191 (the value of the XOR- 3275 PEER-ADDRESS attribute in the ChannelBind request) as the destination 3276 transport address. 3278 Later, Peer B sends a UDP datagram back to the relayed transport 3279 address. This causes the server to send a ChannelData message to the 3280 client containing the data from the UDP datagram. The server knows 3281 to which client to send the ChannelData message because of the 3282 relayed transport address at which the UDP datagram arrived, and 3283 knows to use channel 0x4000 because this is the channel bound to 3284 192.0.2.210:49191. Note that if there had not been any channel 3285 number bound to that address, the server would have used a Data 3286 indication instead. 3288 TURN TURN Peer Peer 3289 client server A B 3290 |--- ChannelBind request ----------->| | | 3291 | Transaction-Id=0xE5913A8F46091637EF7D3328 | | 3292 | CHANNEL-NUMBER=0x4000 | | | 3293 | XOR-PEER-ADDRESS=192.0.2.210:49191 | | 3294 | USERNAME="George" | | | 3295 | REALM="example.com" | | | 3296 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3297 | MESSAGE-INTEGRITY=... | | | 3298 | | | | 3299 |<-- ChannelBind success response ---| | | 3300 | Transaction-Id=0xE5913A8F46091637EF7D3328 | | 3301 | MESSAGE-INTEGRITY=... | | | 3303 The channel binding lasts for 10 minutes unless refreshed. The TURN 3304 client refreshes the binding by sending ChannelBind request rebinding 3305 the channel to the same peer (Peer B's IP address). The server 3306 processes the ChannelBind request, rebinds the channel to the same 3307 peer and resets the time-to-expiry timer back to 10 minutes. 3309 TURN TURN Peer Peer 3310 client server A B 3311 |--- Refresh request --------------->| | | 3312 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 3313 | SOFTWARE="Example client 1.03" | | | 3314 | USERNAME="George" | | | 3315 | REALM="example.com" | | | 3316 | NONCE="obMatJos2AAABadl7W7PeDU4hKE72jda" | | 3317 | MESSAGE-INTEGRITY=... | | | 3318 | | | | 3319 |<-- Refresh error response ---------| | | 3320 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 3321 | SOFTWARE="Example server, version 1.17" | | 3322 | ERROR-CODE=438 (Stale Nonce) | | | 3323 | REALM="example.com" | | | 3324 | NONCE="obMatJos2AAABnpSw1Xw239bBwGYhjN" | | 3325 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 3326 | | | | 3327 |--- Refresh request --------------->| | | 3328 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 3329 | SOFTWARE="Example client 1.03" | | | 3330 | USERNAME="George" | | | 3331 | REALM="example.com" | | | 3332 | NONCE="obMatJos2AAABnpSw1Xw239bBwGYhjNj" | | 3333 | PASSWORD-ALGORITHMS=MD5 and SHA256 | | 3334 | PASSWORD-ALGORITHM=SHA256 | | | 3335 | MESSAGE-INTEGRITY=... | | | 3336 | | | | 3337 |<-- Refresh success response -------| | | 3338 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 3339 | SOFTWARE="Example server, version 1.17" | | 3340 | LIFETIME=600 (10 minutes) | | | 3342 Sometime before the 20 minute lifetime is up, the client refreshes 3343 the allocation. This is done using a Refresh request. As before, 3344 the client includes the latest username, realm, and nonce values in 3345 the request. The client also includes the SOFTWARE attribute, 3346 following the recommended practice of always including this attribute 3347 in Allocate and Refresh messages. When the server receives the 3348 Refresh request, it notices that the nonce value has expired, and so 3349 replies with 438 (Stale Nonce) error given a new nonce value. The 3350 client then reattempts the request, this time with the new nonce 3351 value. This second attempt is accepted, and the server replies with 3352 a success response. Note that the client did not include a LIFETIME 3353 attribute in the request, so the server refreshes the allocation for 3354 the default lifetime of 10 minutes (as can be seen by the LIFETIME 3355 attribute in the success response). 3357 21. Security Considerations 3359 This section considers attacks that are possible in a TURN 3360 deployment, and discusses how they are mitigated by mechanisms in the 3361 protocol or recommended practices in the implementation. 3363 Most of the attacks on TURN are mitigated by the server requiring 3364 requests be authenticated. Thus, this specification requires the use 3365 of authentication. The mandatory-to-implement mechanism is the long- 3366 term credential mechanism of STUN. Other authentication mechanisms 3367 of equal or stronger security properties may be used. However, it is 3368 important to ensure that they can be invoked in an inter-operable 3369 way. 3371 21.1. Outsider Attacks 3373 Outsider attacks are ones where the attacker has no credentials in 3374 the system, and is attempting to disrupt the service seen by the 3375 client or the server. 3377 21.1.1. Obtaining Unauthorized Allocations 3379 An attacker might wish to obtain allocations on a TURN server for any 3380 number of nefarious purposes. A TURN server provides a mechanism for 3381 sending and receiving packets while cloaking the actual IP address of 3382 the client. This makes TURN servers an attractive target for 3383 attackers who wish to use it to mask their true identity. 3385 An attacker might also wish to simply utilize the services of a TURN 3386 server without paying for them. Since TURN services require 3387 resources from the provider, it is anticipated that their usage will 3388 come with a cost. 3390 These attacks are prevented using the long-term credential mechanism, 3391 which allows the TURN server to determine the identity of the 3392 requestor and whether the requestor is allowed to obtain the 3393 allocation. 3395 21.1.2. Offline Dictionary Attacks 3397 The long-term credential mechanism used by TURN is subject to offline 3398 dictionary attacks. An attacker that is capable of eavesdropping on 3399 a message exchange between a client and server can determine the 3400 password by trying a number of candidate passwords and seeing if one 3401 of them is correct. This attack works when the passwords are low 3402 entropy, such as a word from the dictionary. This attack can be 3403 mitigated by using strong passwords with large entropy. In 3404 situations where even stronger mitigation is required, (D)TLS 3405 transport between the client and the server can be used. 3407 21.1.3. Faked Refreshes and Permissions 3409 An attacker might wish to attack an active allocation by sending it a 3410 Refresh request with an immediate expiration, in order to delete it 3411 and disrupt service to the client. This is prevented by 3412 authentication of refreshes. Similarly, an attacker wishing to send 3413 CreatePermission requests to create permissions to undesirable 3414 destinations is prevented from doing so through authentication. The 3415 motivations for such an attack are described in Section 21.2. 3417 21.1.4. Fake Data 3419 An attacker might wish to send data to the client or the peer, as if 3420 they came from the peer or client, respectively. To do that, the 3421 attacker can send the client a faked Data Indication or ChannelData 3422 message, or send the TURN server a faked Send Indication or 3423 ChannelData message. 3425 Since indications and ChannelData messages are not authenticated, 3426 this attack is not prevented by TURN. However, this attack is 3427 generally present in IP-based communications and is not substantially 3428 worsened by TURN. Consider a normal, non-TURN IP session between 3429 hosts A and B. An attacker can send packets to B as if they came 3430 from A by sending packets towards A with a spoofed IP address of B. 3431 This attack requires the attacker to know the IP addresses of A and 3432 B. With TURN, an attacker wishing to send packets towards a client 3433 using a Data indication needs to know its IP address (and port), the 3434 IP address and port of the TURN server, and the IP address and port 3435 of the peer (for inclusion in the XOR-PEER-ADDRESS attribute). To 3436 send a fake ChannelData message to a client, an attacker needs to 3437 know the IP address and port of the client, the IP address and port 3438 of the TURN server, and the channel number. This particular 3439 combination is mildly more guessable than in the non-TURN case. 3441 These attacks are more properly mitigated by application-layer 3442 authentication techniques. In the case of real-time traffic, usage 3443 of SRTP [RFC3711] prevents these attacks. 3445 In some situations, the TURN server may be situated in the network 3446 such that it is able to send to hosts to which the client cannot 3447 directly send. This can happen, for example, if the server is 3448 located behind a firewall that allows packets from outside the 3449 firewall to be delivered to the server, but not to other hosts behind 3450 the firewall. In these situations, an attacker could send the server 3451 a Send indication with an XOR-PEER-ADDRESS attribute containing the 3452 transport address of one of the other hosts behind the firewall. If 3453 the server was to allow relaying of traffic to arbitrary peers, then 3454 this would provide a way for the attacker to attack arbitrary hosts 3455 behind the firewall. 3457 To mitigate this attack, TURN requires that the client establish a 3458 permission to a host before sending it data. Thus, an attacker can 3459 only attack hosts with which the client is already communicating, 3460 unless the attacker is able to create authenticated requests. 3461 Furthermore, the server administrator may configure the server to 3462 restrict the range of IP addresses and ports to which it will relay 3463 data. To provide even greater security, the server administrator can 3464 require that the client use (D)TLS for all communication between the 3465 client and the server. 3467 21.1.5. Impersonating a Server 3469 When a client learns a relayed address from a TURN server, it uses 3470 that relayed address in application protocols to receive traffic. 3471 Therefore, an attacker wishing to intercept or redirect that traffic 3472 might try to impersonate a TURN server and provide the client with a 3473 faked relayed address. 3475 This attack is prevented through the long-term credential mechanism, 3476 which provides message integrity for responses in addition to 3477 verifying that they came from the server. Furthermore, an attacker 3478 cannot replay old server responses as the transaction id in the STUN 3479 header prevents this. Replay attacks are further thwarted through 3480 frequent changes to the nonce value. 3482 21.1.6. Eavesdropping Traffic 3484 TURN concerns itself primarily with authentication and message 3485 integrity. Confidentiality is only a secondary concern, as TURN 3486 control messages do not include information that is particularly 3487 sensitive. The primary protocol content of the messages is the IP 3488 address of the peer. If it is important to prevent an eavesdropper 3489 on a TURN connection from learning this, TURN can be run over (D)TLS. 3491 Confidentiality for the application data relayed by TURN is best 3492 provided by the application protocol itself, since running TURN over 3493 (D)TLS does not protect application data between the server and the 3494 peer. If confidentiality of application data is important, then the 3495 application should encrypt or otherwise protect its data. For 3496 example, for real-time media, confidentiality can be provided by 3497 using SRTP. 3499 21.1.7. TURN Loop Attack 3501 An attacker might attempt to cause data packets to loop indefinitely 3502 between two TURN servers. The attack goes as follows. First, the 3503 attacker sends an Allocate request to server A, using the source 3504 address of server B. Server A will send its response to server B, 3505 and for the attack to succeed, the attacker must have the ability to 3506 either view or guess the contents of this response, so that the 3507 attacker can learn the allocated relayed transport address. The 3508 attacker then sends an Allocate request to server B, using the source 3509 address of server A. Again, the attacker must be able to view or 3510 guess the contents of the response, so it can send learn the 3511 allocated relayed transport address. Using the same spoofed source 3512 address technique, the attacker then binds a channel number on server 3513 A to the relayed transport address on server B, and similarly binds 3514 the same channel number on server B to the relayed transport address 3515 on server A. Finally, the attacker sends a ChannelData message to 3516 server A. 3518 The result is a data packet that loops from the relayed transport 3519 address on server A to the relayed transport address on server B, 3520 then from server B's transport address to server A's transport 3521 address, and then around the loop again. 3523 This attack is mitigated as follows. By requiring all requests to be 3524 authenticated and/or by randomizing the port number allocated for the 3525 relayed transport address, the server forces the attacker to either 3526 intercept or view responses sent to a third party (in this case, the 3527 other server) so that the attacker can authenticate the requests and 3528 learn the relayed transport address. Without one of these two 3529 measures, an attacker can guess the contents of the responses without 3530 needing to see them, which makes the attack much easier to perform. 3531 Furthermore, by requiring authenticated requests, the server forces 3532 the attacker to have credentials acceptable to the server, which 3533 turns this from an outsider attack into an insider attack and allows 3534 the attack to be traced back to the client initiating it. 3536 The attack can be further mitigated by imposing a per-username limit 3537 on the bandwidth used to relay data by allocations owned by that 3538 username, to limit the impact of this attack on other allocations. 3539 More mitigation can be achieved by decrementing the TTL when relaying 3540 data packets (if the underlying OS allows this). 3542 21.2. Firewall Considerations 3544 A key security consideration of TURN is that TURN should not weaken 3545 the protections afforded by firewalls deployed between a client and a 3546 TURN server. It is anticipated that TURN servers will often be 3547 present on the public Internet, and clients may often be inside 3548 enterprise networks with corporate firewalls. If TURN servers 3549 provide a 'backdoor' for reaching into the enterprise, TURN will be 3550 blocked by these firewalls. 3552 TURN servers therefore emulate the behavior of NAT devices that 3553 implement address-dependent filtering [RFC4787], a property common in 3554 many firewalls as well. When a NAT or firewall implements this 3555 behavior, packets from an outside IP address are only allowed to be 3556 sent to an internal IP address and port if the internal IP address 3557 and port had recently sent a packet to that outside IP address. TURN 3558 servers introduce the concept of permissions, which provide exactly 3559 this same behavior on the TURN server. An attacker cannot send a 3560 packet to a TURN server and expect it to be relayed towards the 3561 client, unless the client has tried to contact the attacker first. 3563 It is important to note that some firewalls have policies that are 3564 even more restrictive than address-dependent filtering. Firewalls 3565 can also be configured with address- and port-dependent filtering, or 3566 can be configured to disallow inbound traffic entirely. In these 3567 cases, if a client is allowed to connect the TURN server, 3568 communications to the client will be less restrictive than what the 3569 firewall would normally allow. 3571 21.2.1. Faked Permissions 3573 In firewalls and NAT devices, permissions are granted implicitly 3574 through the traversal of a packet from the inside of the network 3575 towards the outside peer. Thus, a permission cannot, by definition, 3576 be created by any entity except one inside the firewall or NAT. With 3577 TURN, this restriction no longer holds. Since the TURN server sits 3578 outside the firewall, at attacker outside the firewall can now send a 3579 message to the TURN server and try to create a permission for itself. 3581 This attack is prevented because all messages that create permissions 3582 (i.e., ChannelBind and CreatePermission) are authenticated. 3584 21.2.2. Blacklisted IP Addresses 3586 Many firewalls can be configured with blacklists that prevent a 3587 client behind the firewall from sending packets to, or receiving 3588 packets from, ranges of blacklisted IP addresses. This is 3589 accomplished by inspecting the source and destination addresses of 3590 packets entering and exiting the firewall, respectively. 3592 This feature is also present in TURN, since TURN servers are allowed 3593 to arbitrarily restrict the range of addresses of peers that they 3594 will relay to. 3596 21.2.3. Running Servers on Well-Known Ports 3598 A malicious client behind a firewall might try to connect to a TURN 3599 server and obtain an allocation which it then uses to run a server. 3600 For example, a client might try to run a DNS server or FTP server. 3602 This is not possible in TURN. A TURN server will never accept 3603 traffic from a peer for which the client has not installed a 3604 permission. Thus, peers cannot just connect to the allocated port in 3605 order to obtain the service. 3607 21.3. Insider Attacks 3609 In insider attacks, a client has legitimate credentials but defies 3610 the trust relationship that goes with those credentials. These 3611 attacks cannot be prevented by cryptographic means but need to be 3612 considered in the design of the protocol. 3614 21.3.1. DoS against TURN Server 3616 A client wishing to disrupt service to other clients might obtain an 3617 allocation and then flood it with traffic, in an attempt to swamp the 3618 server and prevent it from servicing other legitimate clients. This 3619 is mitigated by the recommendation that the server limit the amount 3620 of bandwidth it will relay for a given username. This won't prevent 3621 a client from sending a large amount of traffic, but it allows the 3622 server to immediately discard traffic in excess. 3624 Since each allocation uses a port number on the IP address of the 3625 TURN server, the number of allocations on a server is finite. An 3626 attacker might attempt to consume all of them by requesting a large 3627 number of allocations. This is prevented by the recommendation that 3628 the server impose a limit of the number of allocations active at a 3629 time for a given username. 3631 21.3.2. Anonymous Relaying of Malicious Traffic 3633 TURN servers provide a degree of anonymization. A client can send 3634 data to peers without revealing its own IP address. TURN servers may 3635 therefore become attractive vehicles for attackers to launch attacks 3636 against targets without fear of detection. Indeed, it is possible 3637 for a client to chain together multiple TURN servers, such that any 3638 number of relays can be used before a target receives a packet. 3640 Administrators who are worried about this attack can maintain logs 3641 that capture the actual source IP and port of the client, and perhaps 3642 even every permission that client installs. This will allow for 3643 forensic tracing to determine the original source, should it be 3644 discovered that an attack is being relayed through a TURN server. 3646 21.3.3. Manipulating Other Allocations 3648 An attacker might attempt to disrupt service to other users of the 3649 TURN server by sending Refresh requests or CreatePermission requests 3650 that (through source address spoofing) appear to be coming from 3651 another user of the TURN server. TURN prevents this by requiring 3652 that the credentials used in CreatePermission, Refresh, and 3653 ChannelBind messages match those used to create the initial 3654 allocation. Thus, the fake requests from the attacker will be 3655 rejected. 3657 21.4. Tunnel Amplification Attack 3659 An attacker might attempt to cause data packets to loop numerous 3660 times between a TURN server and a tunnel between IPv4 and IPv6. The 3661 attack goes as follows. 3663 Suppose an attacker knows that a tunnel endpoint will forward 3664 encapsulated packets from a given IPv6 address (this doesn't 3665 necessarily need to be the tunnel endpoint's address). Suppose he 3666 then spoofs two packets from this address: 3668 1. An Allocate request asking for a v4 address, and 3670 2. A ChannelBind request establishing a channel to the IPv4 address 3671 of the tunnel endpoint 3673 Then he has set up an amplification attack: 3675 o The TURN server will re-encapsulate IPv6 UDP data in v4 and send 3676 it to the tunnel endpoint 3678 o The tunnel endpoint will de-encapsulate packets from the v4 3679 interface and send them to v6 3681 So if the attacker sends a packet of the following form... 3683 IPv6: src=2001:DB8:1::1 dst=2001:DB8::2 3684 UDP: 3685 TURN: 3686 IPv6: src=2001:DB8:1::1 dst=2001:DB8::2 3687 UDP: 3688 TURN: 3689 IPv6: src=2001:DB8:1::1 dst=2001:DB8::2 3690 UDP: 3691 TURN: 3692 ... 3694 Then the TURN server and the tunnel endpoint will send it back and 3695 forth until the last TURN header is consumed, at which point the TURN 3696 server will send an empty packet, which the tunnel endpoint will 3697 drop. 3699 The amplification potential here is limited by the MTU, so it's not 3700 huge: IPv6+UDP+TURN takes 334 bytes, so a four-to-one amplification 3701 out of a 1500-byte packet is possible. But the attacker could still 3702 increase traffic volume by sending multiple packets or by 3703 establishing multiple channels spoofed from different addresses 3704 behind the same tunnel endpoint. 3706 The attack is mitigated as follows. It is RECOMMENDED that TURN 3707 servers not accept allocation or channel binding requests from 3708 addresses known to be tunneled, and that they not forward data to 3709 such addresses. In particular, a TURN server MUST NOT accept Teredo 3710 or 6to4 addresses in these requests. 3712 21.5. Other Considerations 3714 Any relay addresses learned through an Allocate request will not 3715 operate properly with IPsec Authentication Header (AH) [RFC4302] in 3716 transport or tunnel mode. However, tunnel-mode IPsec Encapsulating 3717 Security Payload (ESP) [RFC4303] should still operate. 3719 22. IANA Considerations 3721 [Paragraphs in braces should be removed by the RFC Editor upon 3722 publication] 3724 The codepoints for the STUN methods defined in this specification are 3725 listed in Section 17. [IANA is requested to update the reference 3726 from [RFC5766] to RFC-to-be for the STUN methods listed in 3727 Section 17.] 3729 The codepoints for the STUN attributes defined in this specification 3730 are listed in Section 18. [IANA is requested to update the reference 3731 from [RFC5766] to RFC-to-be for the STUN attributes CHANNEL-NUMBER, 3732 LIFETIME, Reserved (was BANDWIDTH), XOR-PEER-ADDRESS, DATA, XOR- 3733 RELAYED-ADDRESS, REQUESTED-ADDRESS-FAMILY, EVEN-PORT, REQUESTED- 3734 TRANSPORT, DONT-FRAGMENT, Reserved (was TIMER-VAL) and RESERVATION- 3735 TOKEN listed in Section 18.] 3737 [The ADDITIONAL-ADDRESS-FAMILY, ADDRESS-ERROR-CODE and ICMP 3738 attributes requires that IANA allocate a value in the "STUN 3739 attributes Registry" from the comprehension-optional range 3740 (0x8000-0xFFFF), to be replaced for TBD-CA throughout this document] 3742 The codepoints for the STUN error codes defined in this specification 3743 are listed in Section 19. [IANA is requested to update the reference 3744 from [RFC5766] to RFC-to-be for the STUN error codes listed in 3745 Section 19.] 3747 IANA has allocated the SRV service name of "turn" for TURN over UDP 3748 or TCP, and the service name of "turns" for TURN over (D)TLS. 3750 IANA has created a registry for TURN channel numbers, initially 3751 populated as follows: 3753 o 0x0000 through 0x3FFF: Reserved and not available for use, since 3754 they conflict with the STUN header. 3756 o 0x4000 through 0x4FFF: A TURN implementation is free to use 3757 channel numbers in this range. 3759 o 0x5000 through 0xFFFF: Unassigned. 3761 Any change to this registry must be made through an IETF Standards 3762 Action. 3764 23. IAB Considerations 3766 The IAB has studied the problem of "Unilateral Self Address Fixing" 3767 (UNSAF), which is the general process by which a client attempts to 3768 determine its address in another realm on the other side of a NAT 3769 through a collaborative protocol-reflection mechanism [RFC3424]. The 3770 TURN extension is an example of a protocol that performs this type of 3771 function. The IAB has mandated that any protocols developed for this 3772 purpose document a specific set of considerations. These 3773 considerations and the responses for TURN are documented in this 3774 section. 3776 Consideration 1: Precise definition of a specific, limited-scope 3777 problem that is to be solved with the UNSAF proposal. A short-term 3778 fix should not be generalized to solve other problems. Such 3779 generalizations lead to the prolonged dependence on and usage of the 3780 supposed short-term fix -- meaning that it is no longer accurate to 3781 call it "short-term". 3783 Response: TURN is a protocol for communication between a relay (= 3784 TURN server) and its client. The protocol allows a client that is 3785 behind a NAT to obtain and use a public IP address on the relay. As 3786 a convenience to the client, TURN also allows the client to determine 3787 its server-reflexive transport address. 3789 Consideration 2: Description of an exit strategy/transition plan. 3790 The better short-term fixes are the ones that will naturally see less 3791 and less use as the appropriate technology is deployed. 3793 Response: TURN will no longer be needed once there are no longer any 3794 NATs. Unfortunately, as of the date of publication of this document, 3795 it no longer seems very likely that NATs will go away any time soon. 3796 However, the need for TURN will also decrease as the number of NATs 3797 with the mapping property of Endpoint-Independent Mapping [RFC4787] 3798 increases. 3800 Consideration 3: Discussion of specific issues that may render 3801 systems more "brittle". For example, approaches that involve using 3802 data at multiple network layers create more dependencies, increase 3803 debugging challenges, and make it harder to transition. 3805 Response: TURN is "brittle" in that it requires the NAT bindings 3806 between the client and the server to be maintained unchanged for the 3807 lifetime of the allocation. This is typically done using keep- 3808 alives. If this is not done, then the client will lose its 3809 allocation and can no longer exchange data with its peers. 3811 Consideration 4: Identify requirements for longer-term, sound 3812 technical solutions; contribute to the process of finding the right 3813 longer-term solution. 3815 Response: The need for TURN will be reduced once NATs implement the 3816 recommendations for NAT UDP behavior documented in [RFC4787]. 3817 Applications are also strongly urged to use ICE [RFC8445] to 3818 communicate with peers; though ICE uses TURN, it does so only as a 3819 last resort, and uses it in a controlled manner. 3821 Consideration 5: Discussion of the impact of the noted practical 3822 issues with existing deployed NATs and experience reports. 3824 Response: Some NATs deployed today exhibit a mapping behavior other 3825 than Endpoint-Independent mapping. These NATs are difficult to work 3826 with, as they make it difficult or impossible for protocols like ICE 3827 to use server-reflexive transport addresses on those NATs. A client 3828 behind such a NAT is often forced to use a relay protocol like TURN 3829 because "UDP hole punching" techniques [RFC5128] do not work. 3831 24. Changes since RFC 5766 3833 This section lists the major changes in the TURN protocol from the 3834 original [RFC5766] specification. 3836 o IPv6 support. 3838 o REQUESTED-ADDRESS-FAMILY attribute. 3840 o Description of the tunnel amplification attack. 3842 o DTLS support. 3844 o Add support for receiving ICMP packets. 3846 o Updates PMTUD. 3848 o Discovery of TURN server. 3850 o TURN URI Scheme Semantics. 3852 o Happy Eyeballs for TURN. 3854 o Align with the changes in STUNbis. 3856 25. Updates to RFC 6156 3858 This section lists the major updates to [RFC6156] in this 3859 specification. 3861 o ADDITIONAL-ADDRESS-FAMILY, AND ADDRESS-ERR-CODE attributes. 3863 o 440 (Address Family not Supported) and 443 (Peer Address Family 3864 Mismatch) responses. 3866 o More details on packet translation. 3868 o TCP-to-UDP and UDP-to-TCP relaying. 3870 26. Acknowledgements 3872 Most of the text in this note comes from the original TURN 3873 specification, [RFC5766]. The authors would like to thank Rohan Mahy 3874 co-author of original TURN specification and everyone who had 3875 contributed to that document. The authors would also like to 3876 acknowledge that this document inherits material from [RFC6156]. 3878 Thanks to Justin Uberti, Pal Martinsen, Oleg Moskalenko, Aijun Wang 3879 and Simon Perreault for their help on the ADDITIONAL-ADDRESS-FAMILY 3880 mechanism. Authors would like to thank Gonzalo Salgueiro, Simon 3881 Perreault, Jonathan Lennox, Brandon Williams, Karl Stahl, Noriyuki 3882 Torii, Nils Ohlmeier, Dan Wing, Vijay Gurbani, Joseph Touch, Justin 3883 Uberti and Oleg Moskalenko for comments and review. The authors 3884 would like to thank Marc for his contributions to the text. 3886 Special thanks to Magnus Westerlund for the detailed AD review. 3888 27. References 3890 27.1. Normative References 3892 [I-D.ietf-tram-stunbis] 3893 Petit-Huguenin, M., Salgueiro, G., Rosenberg, J., Wing, 3894 D., Mahy, R., and P. Matthews, "Session Traversal 3895 Utilities for NAT (STUN)", draft-ietf-tram-stunbis-21 3896 (work in progress), March 2019. 3898 [Protocol-Numbers] 3899 "IANA Protocol Numbers Registry", 2005, 3900 . 3902 [RFC0792] Postel, J., "Internet Control Message Protocol", STD 5, 3903 RFC 792, DOI 10.17487/RFC0792, September 1981, 3904 . 3906 [RFC1122] Braden, R., Ed., "Requirements for Internet Hosts - 3907 Communication Layers", STD 3, RFC 1122, 3908 DOI 10.17487/RFC1122, October 1989, 3909 . 3911 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3912 Requirement Levels", BCP 14, RFC 2119, 3913 DOI 10.17487/RFC2119, March 1997, 3914 . 3916 [RFC2474] Nichols, K., Blake, S., Baker, F., and D. Black, 3917 "Definition of the Differentiated Services Field (DS 3918 Field) in the IPv4 and IPv6 Headers", RFC 2474, 3919 DOI 10.17487/RFC2474, December 1998, 3920 . 3922 [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 3923 of Explicit Congestion Notification (ECN) to IP", 3924 RFC 3168, DOI 10.17487/RFC3168, September 2001, 3925 . 3927 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 3928 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 3929 2003, . 3931 [RFC4443] Conta, A., Deering, S., and M. Gupta, Ed., "Internet 3932 Control Message Protocol (ICMPv6) for the Internet 3933 Protocol Version 6 (IPv6) Specification", STD 89, 3934 RFC 4443, DOI 10.17487/RFC4443, March 2006, 3935 . 3937 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 3938 Security Version 1.2", RFC 6347, DOI 10.17487/RFC6347, 3939 January 2012, . 3941 [RFC6437] Amante, S., Carpenter, B., Jiang, S., and J. Rajahalme, 3942 "IPv6 Flow Label Specification", RFC 6437, 3943 DOI 10.17487/RFC6437, November 2011, 3944 . 3946 [RFC6724] Thaler, D., Ed., Draves, R., Matsumoto, A., and T. Chown, 3947 "Default Address Selection for Internet Protocol Version 6 3948 (IPv6)", RFC 6724, DOI 10.17487/RFC6724, September 2012, 3949 . 3951 [RFC7065] Petit-Huguenin, M., Nandakumar, S., Salgueiro, G., and P. 3952 Jones, "Traversal Using Relays around NAT (TURN) Uniform 3953 Resource Identifiers", RFC 7065, DOI 10.17487/RFC7065, 3954 November 2013, . 3956 [RFC7350] Petit-Huguenin, M. and G. Salgueiro, "Datagram Transport 3957 Layer Security (DTLS) as Transport for Session Traversal 3958 Utilities for NAT (STUN)", RFC 7350, DOI 10.17487/RFC7350, 3959 August 2014, . 3961 [RFC7525] Sheffer, Y., Holz, R., and P. Saint-Andre, 3962 "Recommendations for Secure Use of Transport Layer 3963 Security (TLS) and Datagram Transport Layer Security 3964 (DTLS)", BCP 195, RFC 7525, DOI 10.17487/RFC7525, May 3965 2015, . 3967 [RFC7915] Bao, C., Li, X., Baker, F., Anderson, T., and F. Gont, 3968 "IP/ICMP Translation Algorithm", RFC 7915, 3969 DOI 10.17487/RFC7915, June 2016, 3970 . 3972 [RFC8200] Deering, S. and R. Hinden, "Internet Protocol, Version 6 3973 (IPv6) Specification", STD 86, RFC 8200, 3974 DOI 10.17487/RFC8200, July 2017, 3975 . 3977 [RFC8305] Schinazi, D. and T. Pauly, "Happy Eyeballs Version 2: 3978 Better Connectivity Using Concurrency", RFC 8305, 3979 DOI 10.17487/RFC8305, December 2017, 3980 . 3982 [RFC8446] Rescorla, E., "The Transport Layer Security (TLS) Protocol 3983 Version 1.3", RFC 8446, DOI 10.17487/RFC8446, August 2018, 3984 . 3986 27.2. Informative References 3988 [Frag-Harmful] 3989 "Fragmentation Considered Harmful", . 3992 [I-D.ietf-mmusic-ice-sip-sdp] 3993 Petit-Huguenin, M., Nandakumar, S., and A. Keranen, 3994 "Session Description Protocol (SDP) Offer/Answer 3995 procedures for Interactive Connectivity Establishment 3996 (ICE)", draft-ietf-mmusic-ice-sip-sdp-36 (work in 3997 progress), June 2019. 3999 [I-D.ietf-tram-stun-pmtud] 4000 Petit-Huguenin, M. and G. Salgueiro, "Path MTU Discovery 4001 Using Session Traversal Utilities for NAT (STUN)", draft- 4002 ietf-tram-stun-pmtud-10 (work in progress), September 4003 2018. 4005 [I-D.ietf-tsvwg-udp-options] 4006 Touch, J., "Transport Options for UDP", draft-ietf-tsvwg- 4007 udp-options-07 (work in progress), March 2019. 4009 [Port-Numbers] 4010 "IANA Port Numbers Registry", 2005, 4011 . 4013 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, 4014 DOI 10.17487/RFC0791, September 1981, 4015 . 4017 [RFC1191] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 4018 DOI 10.17487/RFC1191, November 1990, 4019 . 4021 [RFC1918] Rekhter, Y., Moskowitz, B., Karrenberg, D., de Groot, G., 4022 and E. Lear, "Address Allocation for Private Internets", 4023 BCP 5, RFC 1918, DOI 10.17487/RFC1918, February 1996, 4024 . 4026 [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and 4027 L. Jones, "SOCKS Protocol Version 5", RFC 1928, 4028 DOI 10.17487/RFC1928, March 1996, 4029 . 4031 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 4032 A., Peterson, J., Sparks, R., Handley, M., and E. 4033 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 4034 DOI 10.17487/RFC3261, June 2002, 4035 . 4037 [RFC3424] Daigle, L., Ed. and IAB, "IAB Considerations for 4038 UNilateral Self-Address Fixing (UNSAF) Across Network 4039 Address Translation", RFC 3424, DOI 10.17487/RFC3424, 4040 November 2002, . 4042 [RFC3550] Schulzrinne, H., Casner, S., Frederick, R., and V. 4043 Jacobson, "RTP: A Transport Protocol for Real-Time 4044 Applications", STD 64, RFC 3550, DOI 10.17487/RFC3550, 4045 July 2003, . 4047 [RFC3711] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. 4048 Norrman, "The Secure Real-time Transport Protocol (SRTP)", 4049 RFC 3711, DOI 10.17487/RFC3711, March 2004, 4050 . 4052 [RFC4086] Eastlake 3rd, D., Schiller, J., and S. Crocker, 4053 "Randomness Requirements for Security", BCP 106, RFC 4086, 4054 DOI 10.17487/RFC4086, June 2005, 4055 . 4057 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, 4058 DOI 10.17487/RFC4302, December 2005, 4059 . 4061 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 4062 RFC 4303, DOI 10.17487/RFC4303, December 2005, 4063 . 4065 [RFC4787] Audet, F., Ed. and C. Jennings, "Network Address 4066 Translation (NAT) Behavioral Requirements for Unicast 4067 UDP", BCP 127, RFC 4787, DOI 10.17487/RFC4787, January 4068 2007, . 4070 [RFC4821] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4071 Discovery", RFC 4821, DOI 10.17487/RFC4821, March 2007, 4072 . 4074 [RFC5128] Srisuresh, P., Ford, B., and D. Kegel, "State of Peer-to- 4075 Peer (P2P) Communication across Network Address 4076 Translators (NATs)", RFC 5128, DOI 10.17487/RFC5128, March 4077 2008, . 4079 [RFC5482] Eggert, L. and F. Gont, "TCP User Timeout Option", 4080 RFC 5482, DOI 10.17487/RFC5482, March 2009, 4081 . 4083 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 4084 Relays around NAT (TURN): Relay Extensions to Session 4085 Traversal Utilities for NAT (STUN)", RFC 5766, 4086 DOI 10.17487/RFC5766, April 2010, 4087 . 4089 [RFC5925] Touch, J., Mankin, A., and R. Bonica, "The TCP 4090 Authentication Option", RFC 5925, DOI 10.17487/RFC5925, 4091 June 2010, . 4093 [RFC5928] Petit-Huguenin, M., "Traversal Using Relays around NAT 4094 (TURN) Resolution Mechanism", RFC 5928, 4095 DOI 10.17487/RFC5928, August 2010, 4096 . 4098 [RFC6056] Larsen, M. and F. Gont, "Recommendations for Transport- 4099 Protocol Port Randomization", BCP 156, RFC 6056, 4100 DOI 10.17487/RFC6056, January 2011, 4101 . 4103 [RFC6062] Perreault, S., Ed. and J. Rosenberg, "Traversal Using 4104 Relays around NAT (TURN) Extensions for TCP Allocations", 4105 RFC 6062, DOI 10.17487/RFC6062, November 2010, 4106 . 4108 [RFC6156] Camarillo, G., Novo, O., and S. Perreault, Ed., "Traversal 4109 Using Relays around NAT (TURN) Extension for IPv6", 4110 RFC 6156, DOI 10.17487/RFC6156, April 2011, 4111 . 4113 [RFC6824] Ford, A., Raiciu, C., Handley, M., and O. Bonaventure, 4114 "TCP Extensions for Multipath Operation with Multiple 4115 Addresses", RFC 6824, DOI 10.17487/RFC6824, January 2013, 4116 . 4118 [RFC7413] Cheng, Y., Chu, J., Radhakrishnan, S., and A. Jain, "TCP 4119 Fast Open", RFC 7413, DOI 10.17487/RFC7413, December 2014, 4120 . 4122 [RFC7478] Holmberg, C., Hakansson, S., and G. Eriksson, "Web Real- 4123 Time Communication Use Cases and Requirements", RFC 7478, 4124 DOI 10.17487/RFC7478, March 2015, 4125 . 4127 [RFC7635] Reddy, T., Patil, P., Ravindranath, R., and J. Uberti, 4128 "Session Traversal Utilities for NAT (STUN) Extension for 4129 Third-Party Authorization", RFC 7635, 4130 DOI 10.17487/RFC7635, August 2015, 4131 . 4133 [RFC7657] Black, D., Ed. and P. Jones, "Differentiated Services 4134 (Diffserv) and Real-Time Communication", RFC 7657, 4135 DOI 10.17487/RFC7657, November 2015, 4136 . 4138 [RFC7983] Petit-Huguenin, M. and G. Salgueiro, "Multiplexing Scheme 4139 Updates for Secure Real-time Transport Protocol (SRTP) 4140 Extension for Datagram Transport Layer Security (DTLS)", 4141 RFC 7983, DOI 10.17487/RFC7983, September 2016, 4142 . 4144 [RFC8155] Patil, P., Reddy, T., and D. Wing, "Traversal Using Relays 4145 around NAT (TURN) Server Auto Discovery", RFC 8155, 4146 DOI 10.17487/RFC8155, April 2017, 4147 . 4149 [RFC8311] Black, D., "Relaxing Restrictions on Explicit Congestion 4150 Notification (ECN) Experimentation", RFC 8311, 4151 DOI 10.17487/RFC8311, January 2018, 4152 . 4154 [RFC8445] Keranen, A., Holmberg, C., and J. Rosenberg, "Interactive 4155 Connectivity Establishment (ICE): A Protocol for Network 4156 Address Translator (NAT) Traversal", RFC 8445, 4157 DOI 10.17487/RFC8445, July 2018, 4158 . 4160 Authors' Addresses 4162 Tirumaleswar Reddy (editor) 4163 McAfee, Inc. 4164 Embassy Golf Link Business Park 4165 Bangalore, Karnataka 560071 4166 India 4168 Email: kondtir@gmail.com 4170 Alan Johnston (editor) 4171 Villanova University 4172 Villanova, PA 4173 USA 4175 Email: alan.b.johnston@gmail.com 4177 Philip Matthews 4178 Alcatel-Lucent 4179 600 March Road 4180 Ottawa, Ontario 4181 Canada 4183 Email: philip_matthews@magma.ca 4185 Jonathan Rosenberg 4186 jdrosen.net 4187 Edison, NJ 4188 USA 4190 Email: jdrosen@jdrosen.net 4191 URI: http://www.jdrosen.net