<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629xslt/rfc2629.dtd">
<?rfc toc='no'?>
<?rfc tocdepth='4'?>
<?rfc compact="yes"?>
<rfc category="std" ipr="trust200902" docName='draft-chenxin-behave-turn-websocket-01'>
    <front>
	<title abbrev="TURN over Websocket">
      WebSocket Protocol as a Transport for Traversal Using Relays around NAT (TURN)
	</title>
	<author initials="X" surname="Chen" fullname="Xin Chen">
	    <organization>Huawei</organization>
	    <address>
		<email>hangzhou.chenxin@huawei.com</email>
	    </address>
	</author>
	<author initials="S" surname="Garcia Murillo" fullname="Sergio Garcia Murillo">
	    <organization>Medooze</organization>
	    <address>
		<email>sergio.garcia.murillo@gmail.com</email>
	    </address>
	</author>
	<author initials="O" surname="Moskalenko" fullname="Oleg Moskalenko">
	    <organization>Yahoo</organization>
	    <address>
		<email>olegm@yahoo-inc.com</email>
	    </address>
	</author>
	<author initials="V" surname="Pascual" fullname="Victor Pascual">
	    <organization>Quobis</organization>
	    <address>
		<email>victor.pascual@quobis.com</email>
	    </address>
	</author>
	<author initials="L" surname="Miniero" fullname="Lorenzo Miniero">
	    <organization>Meetecho</organization>
	    <address>
		<email>lorenzo@meetecho.com</email>
	    </address>
	</author>
	<date year="2013" />
	<area>Transport Area</area>
	<workgroup>Behavior Engineering for Hindrance Avoidance</workgroup>
	<abstract>
	    <t>
This document defines an extension to the Traversal Using Relays around NAT (TURN)
protocol, in order to allow it to run over a WebSocket channel.
This will allow clients in restrictive networks to traverse them and
effectively exchange and relay media or data over WebSockets.
	    </t>
	</abstract>
    </front>
    <middle>
	<section title="Introduction">
	    <t>
Traversal Using Relays around NAT (TURN)
		<xref target="RFC5766"/>, which assigns a transport address allocation for
clients and relays data between the address and the clients, is an extension to the Session Traversal 
Utilities for NAT
		<xref target="RFC5389"/> protocol. TURN is used for NAT traversal in some complicated types of
NAT network by UDP-based media sessions 
		<xref target="RFC5766"/> or TCP-based media sessions
		<xref target="RFC6062"/>.
It is also used in conjunction with the Interactive Connectivity Establishment (ICE) 
		<xref target="RFC5245"/> technique.
	    </t>
	    <t>
In some particularly restrictive networks though, e.g., a web proxy or firewall that only allows HTTP traffic 
to pass through, TURN UDP-based media sessions and TCP-based media sessions do not work.
These types of networks are often deployed in corporations, prisons, hotels, airports and other locations that may need 
to limit the access, and as such legitimate users trying to set up a real-time multimedia session in
such a scenario would find themselves unable to do so. This is a known issue and in fact the RTCWEB specification,
which provides the means to realize direct interactive rich communications between two
peers by using just their web browsers, has an explicit requirement to allow such peers to use some
kind of fallback communication in HTTP-only networks, as specified in 
		<xref target="I-D.ietf-rtcweb-use-cases-and-requirements"/>(F37).
	    </t>
	    <t>
That said, this document is aimed at targeting such scenarios, and as such
defines an extension to the standard TURN protocol that allows it to run over a WebSocket
<xref target="RFC6455"/> channel.
	    </t>
	    <t>
The WebSocket <xref target="RFC6455"/> protocol enables message exchange between
clients and servers on top of a persistent TCP connection. Considering that
the initial protocol handshake makes use of HTTP <xref target="RFC2616"/> semantics,
thus allowing the WebSocket protocol to reuse existing HTTP infrastructure, this
means that a client in a restrictive network would be able to exchange media over a WebSocket. Besides
solving the HTTP fallback problem, this solution could also be easyly implemented and deployed
within the existing RTCWEB framework.
	    </t>
        <t>
For what concerns the impact of such an extensions on the interaction with legacy peers making use of
the services provided by a TURN server, the connection between the server and such
peers would still be based on UDP as <xref target="RFC5766"/> or TCP as
<xref target="RFC6062"/> in a seamless and transparent fashion.
	    </t>

	    <figure>
		<artwork><![CDATA[
          +----------------------------+---------------------+
          | TURN client to TURN server | TURN server to peer |
          +----------------------------+---------------------+
          |    WebSocket over TCP/TLS  |         UDP         |
          |                            |         TCP         |
          +----------------------------+---------------------+]]>
		</artwork>
	    </figure>
	</section>
	<section title="Terminology">
	    <t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in
		<xref target="RFC2119"/>.
	    </t>
	</section>
	<section title="Deployment Topology">
	    <t>
Within the context of real-time multimedia
communications and considering a scenario that involves two peers, an HTTP fallback mechanism may 
fall in basically three different network topologies:
	    </t>

	    <section title="A topology whereas only one of the involved peers needs HTTP fallback for communication">

		<figure anchor="websocket-to-udp-tcp">
		    <artwork><![CDATA[
                        +-------------+
                        |             |
         +--------------+ TURN Server +----------------+
         |    WS/WSS    |             |    UDP/TCP     |
         |              +-------------+                |
         |                                             |
         |                                             |
     +---+---+                                     +---+---+
     | Alice |                                     |  Bob  |
     +-------+                                     +-------+]]></artwork>
		</figure>
		<t>
In
		    <xref target="websocket-to-udp-tcp"/>,  only one involved peer (Alice) is in a restrained network,
which means Alice needs to make use of a WebSocket connection to traverse the firewall and/or proxy. 
The situation for Bob is better, he could connect to the TURN server by UDP or TCP using the existing mechanisms.
		</t>
		<t>
When Alice wants to communicate with Bob, she needs to request a UDP or TCP allocation in the WebSocket server 
for Bob, which is then transferred to the WebSocket channel. The WebSocket server will receive the request 
and handle it like a TURN server. The processing of TURN messages is exactly the same as TURN UDP and TURN TCP,
and the WebSocket server will also allocate a UDP or TCP relay address for Bob. The application data 
between Alice and Bob will be packaged and relayed to each other by the WebSocket server.
		</t>
	    </section>
	    <section title="A topology whereas both the involved peers need HTTP fallback for communication,
using two different intermediaries">
		<figure anchor="websocket-to-udp-tcp-to-websocket">
		    <artwork><![CDATA[
              +-------------+         +-------------+
              |             |         |             |
     +--------+ TURN Server +---------+ TURN Server +---------+
     | WS/WSS |             | UDP/TCP |             | WS/WSS  |
     |        +-------------+         +-------------+         |
     |                                                        |
     |                                                        |
 +---+---+                                                +---+---+
 | Alice |                                                |  Bob  |
 +-------+                                                +-------+]]></artwork>
		</figure>
		<t>
In <xref target="websocket-to-udp-tcp-to-websocket"/>, both Alice and Bob are in restrictive
networks, so both need a fallback mechanism. In this slightly more complex scenario,
both Alice and Bob each have been configred to refer to different WebSocket servers.
In this scenario, Alice and Bob need to request the TURN allocation in their own
WebSocket server using a WebSocket connection.
		</t>
		<t>
Again, just as before the processing of TURN messages
is exactly the same as TURN UDP and TURN TCP. The only difference with previous sceneario is that, in this case,
the involved WebSocket server have to relay the application data to each other by either UDP, TCP or
other existing ways, using the existing TURN mechanics for the purpose.
		</t>
		<t>
It is of course suggested that Alice and Bob allocate the same type of transport address, 
so that their reference WebSocket server could connect to each other by this address directly.
		</t>

		<t>
The scenario would of course be simpler in case the TURN servers
depicted in the figure above happen to be the same TURN server, i.e.,
if Alice and Bob both referred to the same server. In that case, it
may be possible to relay the data internally instead of using an UDP/TCP connection.
		</t>
		<figure anchor="websocket-to-websocket">
		    <artwork><![CDATA[
                         +-------------+
                         |             |
            +------------+ TURN Server +-----------+
            |  WS/WSS    |             |  WS/WSS   |
            |            +-------------+           |
            |                                      |
            |                                      |
        +---+---+                              +---+---+
        | Alice |                              |  Bob  |
        +-------+                              +-------+]]></artwork>
		</figure>
		<t>
However, this is an implementation decision, not affecting the
TURN clients interaction with the TURN server and it will not be covered in detail within this specification.
</t>
	    </section>
	</section>
	<section title="The WebSocket TURN Sub-Protocol" anchor="the_websocket_TURN_subprotocol">

	    <t>
The term WebSocket sub-protocol refers to an application-level
protocol layered on top of a WebSocket connection. This document
specifies the WebSocket TURN sub-protocol for carrying TURN requests
and responses through a WebSocket connection.
		</t>

	    <section title="Handshake" anchor="handshake">

		<t>
The TURN Client and TURN Server negotiate usage of the WebSocket
TURN sub-protocol during the WebSocket handshake procedure as defined in section 1.3 of
<xref target="RFC6455"/>. The Client MUST include the value
"turn" in the Sec-WebSocket-Protocol header in its handshake request.
The 101 reply from the Server MUST contain "turn" in its corresponding Sec-WebSocket-Protocol header.
		</t>
		<t>
Also, the TURN WebSocket Client shall set the Origin header if
the TURN connection is createad in a Web context as defined in
    <xref target="RFC6454"/>. Particularly, for WebRTC, the Origin
    header shall be set to the value of the URI of the HTML page creating the PeerConnection.
		</t>
		<t>
Below is an example of a WebSocket handshake in which the Client
requests the WebSocket TURN sub-protocol support from the Server:
		    <figure>
			<artwork><![CDATA[
  GET / HTTP/1.1
  Host: TURN-ws.example.com
  Upgrade: websocket
  Connection: Upgrade
  Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
  Origin: http://www.example.com
  Sec-WebSocket-Protocol: turn
  Sec-WebSocket-Version: 13
]]>
			</artwork>
		    </figure>
		</t>

		<t>
The handshake response from the Server accepting the WebSocket TURN sub-protocol would look as follows:
		    <figure>
			<artwork><![CDATA[
  HTTP/1.1 101 Switching Protocols
  Upgrade: websocket
  Connection: Upgrade
  Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
  Sec-WebSocket-Protocol: turn
]]>
			</artwork>
		    </figure>
		</t>

		<t>
Once the negotiation has been completed, the WebSocket connection
is established and can be used for the transport of TURN requests and
responses. The WebSocket messages transmitted over this connection
MUST conform to the negotiated WebSocket sub-protocol.
		</t>

	    </section>

	    <section title="TURN message framing" anchor="TURN_framing">
		<t>
TURN messages shall be transported in unfragmented binary frames (FIN:1,opcode:%x2).
		</t>
		<t>
The WebSocket frame data shall be a valid TURN packet, so the
length of the payload of the WebSocket frame shall be lower than the maximum size allowed (2^16 bytes) for a TURN request or response as defined in <xref target="RFC5766"/>.
		</t>
		<t>
TURN client using TURN over WebSockets should follow the
		recommendations in section 2.7 of <xref target="RFC5766"/>
		"Avoiding IP Fragmentation" when sending application data on
		the client-to-server-leg as messages could be relied over a UDP connection to the peer client.
</t>
	    </section>

    
	    <section title="TURN Allocation">
		<t>
This document extends both <xref target="RFC5766"/> (TURN UDP relay) and
<xref target="RFC6062"/> (TURN TCP relay) with a new type of client-to-server
 connection, i.e. WebSocket. For TURN allocations, WebSocket is a type of
TCP client-to-server connection and is subject to all TURN TCP considerations.
		</t>
		<t>
This specification strictly follows the allocation definition in section 5
in <xref target="RFC5766"/>. In the 5-tuple, the transport address is always
TCP, of course, when WebSockets are used. All definitions in the
section 5 of <xref target="RFC5766"/> are applicable to the WebSockets TURN connections.
		</t>
	    </section>
	    <section title="TURN Operation">
		<t>
The operation of the client, server and peer is the same as TURN UDP and TURN TCP,
with the difference consisting in the new connection channel - WebSocket. 
		</t>
		
	    </section>
	    <section title="TURN and TURNS URI WebSocket Transport Parameter" anchor="turn_uri_transport_parameter">

		<t>
This document defines the value "ws" as a transport parameter value for a TURN and TURNS URI
<xref target="I-D.petithuguenin-behave-turn-uris"/> to be
contacted using the TURN WebSocket sub-protocol as transport.
		</t>
		<t>
The "turns" URI scheme MUST be used when TURN is run over
Secure Websockets (WebSockets over TLS) and the "turn" scheme MUST be used otherwise.
		</t>
		<t>
The updated augmented BNF (Backus-Naur Form) for this parameter
is the following (the original BNF for this parameter can be found in
		    <xref target="I-D.petithuguenin-behave-turn-uris"/>):
		    <figure>
			<artwork><![CDATA[
  transport     = "udp" / "tcp" / "ws"  / transport-ext
  ]]>
			</artwork>
		    </figure>
		</t>

	    </section>
	    <section title="Impact on ICE candidates and SDP signalling" anchor="ICE_SDP_impact">
		   <t>
This specification does not have any impact on ICE. In fact, all the related candidates would be allocated
at the TURN sever, and as such no modifications are needed in the SDP signaling in order to support the TURN over WebSockets operation.
		   </t>
	    </section>

	</section>
	<section title="IANA Considerations">
	    <t>
RFC Editor Note: Please set the RFC number assigned for this
document in the sub-sections below and remove this note.
</t>

	    <section title="Registration of the WebSocket TURN Sub-Protocol">
		<t>
This specification requests IANA to register the WebSocket TURN
sub-protocol under the "WebSocket Subprotocol Name" Registry with the following data:
		    <list style="hanging">
			<t hangText="Subprotocol Identifier:">turn</t>
			<t hangText="Subprotocol Common Name:">WebSocket Transport for TURN</t>
			<t hangText="Subprotocol Definition:">TBD: this document</t>
		    </list>
		</t>
	    </section>

	</section>
	<section title="Security Considerations">
	    <t>
TBD.
	    </t>
	</section>
	<!-- Changelog -->
	<section title="Change Summary" anchor="sec-changes">
	
		<t>Note to RFC Editor:  Please remove this whole section.</t>

		<t>
The following are the major changes between the
00 and the 01 versions of the draft:
		</t>
		<t>
			<list style="symbols">
				<t>Removal of multiplexing and references to BCFP and other non related protocols</t>
				<t>Websocket TURN sub protocol specification</t>
				<t>TURN message framing inside Websocket</t>
				<t>Extension to turn and turns URI</t>
				<t>Impact analisys on ice candidates SDP negotiation</t>
			</list>
		</t>
	</section>
	<section title="Acknowledgements">
	    <t>
Paul Kyzivat helped with the formatting of this draft.
	    </t>
	</section>
    </middle>

    <back>
	<references title="Normative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5766.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6062.xml"?>
	</references>
	<references title="Informative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5245.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5389.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6455.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6454.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2616.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml3/reference.I-D.draft-petithuguenin-behave-turn-uris-06.xml"?>
      <?rfc include="http://xml.resource.org/public/rfc/bibxml3/reference.I-D.draft-ietf-rtcweb-use-cases-and-requirements-11.xml"?>
	</references>


    </back>
</rfc>
