1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-18 07:15:07 -05:00
xeps/xep-0046.xml

217 lines
7.9 KiB
XML
Raw Normal View History

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM "xep.ent">
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
<title>DTCP</title>
<abstract>Direct TCP connection between two Jabber entities.</abstract>
&LEGALNOTICE;
<number>0046</number>
<status>Retracted</status>
<type>Standards Track</type>
<sig>Standards</sig>
2016-12-26 10:02:53 -05:00
<dependencies/>
<supersedes/>
2017-01-01 15:08:18 -05:00
<supersededby><spec>XEP-0065</spec></supersededby>
<shortname>None</shortname>
<author>
<firstname>Justin</firstname>
<surname>Karneges</surname>
<email>justin@affinix.com</email>
<jid>justin@andbit.net</jid>
</author>
<revision>
<version>0.8</version>
<date>2003-04-11</date>
<initials>psa</initials>
<remark>At the request of the author, changed status to Retracted.</remark>
</revision>
<revision>
<version>0.7</version>
<date>2002-12-10</date>
<initials>jk</initials>
<remark>Remove 'comment' block</remark>
</revision>
<revision>
<version>0.6</version>
<date>2002-12-02</date>
<initials>jk</initials>
<remark>Simplification of the document</remark>
</revision>
<revision>
<version>0.5</version>
<date>2002-11-19</date>
<initials>jk</initials>
<remark>Changed handshake and namespace, merged active/passive</remark>
</revision>
<revision>
<version>0.4</version>
<date>2002-10-10</date>
<initials>jk</initials>
<remark>Change to 'comment' block</remark>
</revision>
<revision>
<version>0.3</version>
<date>2002-09-18</date>
<initials>jk</initials>
<remark>Support for SSL</remark>
</revision>
<revision>
<version>0.2</version>
<date>2002-09-18</date>
<initials>jk</initials>
<remark>Simplified things.</remark>
</revision>
<revision>
<version>0.1</version>
<date>2002-09-12</date>
<initials>jk</initials>
<remark>Initial version.</remark>
</revision>
</header>
<section1 topic='Introduction'>
<p>There are cases where it would be more optimal for clients to exchange data directly with each other rather than through the server. DTCP specifies a method for establishing a direct TCP socket connection between two entities, so that a reliable bytestream can be created out-of-band.</p>
</section1>
<section1 topic='Requirements'>
<p>The following design goals are considered:</p>
<ul>
<li>The protocol should be reasonably effective in scenarios involving NAT and/or firewalls.<note>DTCP works in situations where at least one client can accept incoming connections.</note></li>
<li>It should be reasonably secure.</li>
<li>Establishing a connection should be fast.</li>
<li>The protocol should be simple.</li>
</ul>
</section1>
<section1 topic='Implementation'>
<section2 topic='Requesting a DTCP connection'>
<p>Say you wish to initiate a DTCP session with Joe:</p>
<example caption='Requesting a DTCP session'><![CDATA[
<iq type="set" id="dtcp_1" to="joe@blow.com/Home">
<query xmlns="http://jabber.org/protocol/dtcp">
<key>c7b5ea3f</key>
<host>192.168.0.32:8000</host>
<host>63.110.44.12:8000</host>
</query>
</iq>
]]></example>
<p>The 'key' given is a unique key for Joe to use when referencing this session with you. If a 'host' element is present, then you are indicating that you can be reached at the given "host:port". Multiple hosts may be specified, but Joe cannot be expected to act on more than three of them.</p>
<example caption='Success response'><![CDATA[
<iq type="result" id="dtcp_1" from="joe@blow.com/Home">
<query xmlns="http://jabber.org/protocol/dtcp">
<key>a1b2c3d4</key>
<host>192.168.0.33:8000</host>
</query>
</iq>
]]></example>
<p>The success response is in exactly the same format as the request. As before, Joe cannot expect you to act on more than three hosts. The 'key' is a unique key from Joe that you will use when referring to the session with him.</p>
<example caption='Error response'><![CDATA[
<iq type="error" id="dtcp_1" from="joe@blow.com/Home">
<error code="501">DTCP not supported</error>
</iq>
]]></example>
<p>Or he may send an error.</p>
</section2>
<section2 topic='Establishing the TCP connection'>
<p>If you received a success response, then the next step is to form the TCP connection. Each entity should have a list of hosts (between 0-3 inclusive) and key of the other. With this information, they should each try to establish a direct connection with the hosts provided. When these connections take place is implementation dependent. Clients may choose to connect to all provided hosts at once, and both clients may even end up connecting to each other simultaneously. Clients may delay between connections, etc. As such, clients that are listening for connections should be prepared for anything.</p>
<p>The procedure ends when either a successful DTCP connection is formed (and all other TCP connections discarded), or when both entities have given up. An entity gives up when it is no longer trying to connect to any hosts. This is done by sending an additional iq-error packet, with the key of the other entity:</p>
<example><![CDATA[
<iq type="error" to="joe@blow.com/Home">
<query xmlns="http://jabber.org/protocol/dtcp">
<key>a1b2c3d4</key>
</query>
<error code="503">Could not connect to any of the hosts.</error>
</iq>
]]></example>
<p>If an entity was not provided any hosts, then it is assumed that he has given up and this packet need not be sent.</p>
</section2>
<section2 topic='The handshake'>
<p>For a given host, a TCP socket connection is established. Once connected, the connecting client must send a command across the channel. Each command is a line of text terminated by the ASCII linefeed character (0x0A).</p>
<example caption='Command format'>
[command]:[argument]&lt;LF&gt;
</example>
<p>Some commands may have an argument, which is placed on the same line and separated by a colon character. If there is no argument, then the colon need not be present.</p>
<p>The serving client should keep the connection open after responding to a command, even if it resulted in an error, in case the connecting client wishes to try another command.</p>
<section3 topic='SSL/TLS'>
<p>If you want an encrypted channel, then it must be requested using the 'starttls' command</p>
<example>
starttls&lt;LF&gt;
</example>
<p>If successful, the serving client should send back:</p>
<example>
ok&lt;LF&gt;
</example>
<p>This means that the serving client supports SSL and the connecting client should begin the SSL/TLS negotiation. After this, further data sent/received over the channel should be in encrypted form.</p>
<p>Or the serving client might report an error:</p>
<example>
error&lt;LF&gt;
</example>
<p>This means SSL is not supported by the serving client.</p>
</section3>
<section3 topic='Authenticating'>
<p>To complete the DTCP connection, the connecting client must authenticate with the serving client. This is done by exchanging keys. First, the connecting client sends the serving client's key:</p>
<example>
key:a1b2c3d4&lt;LF&gt;
</example>
<p>If the serving client recognizes the key, then it should respond by sending the connecting client's key:</p>
<example>
ok:c7b5ea3f&lt;LF&gt;
</example>
<p>Or the serving client might report an error:</p>
<example>
error&lt;LF&gt;
</example>
<p>On success, there may be one more step necessary. If the connecting client is also the original requestor of the DTCP connection (ie, he did the iq-set), then he must send the following "ack":</p>
<example>
ok&lt;LF&gt;
</example>
<p>This gives the final say to the requestor, to prevent any sort of race-condition due to the clients contacting each other at the same time. If the serving client is the requestor, then this extra "ack" is NOT needed and must NOT be sent.</p>
<p>At this point, the channel is established. No further commands may be issued, as the TCP connection is now for application data only.</p>
</section3>
</section2>
</section1>
</xep>