<?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.3 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?rfc toc="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>

<rfc ipr="trust200902" docName="draft-olteanu-socks-6-00" category="exp">

  <front>
    <title abbrev="SOCKS 6">SOCKS Protocol Version 6</title>

    <author initials="V." surname="Olteanu" fullname="Vladimir Olteanu">
      <organization>University Politehnica of Bucharest</organization>
      <address>
        <email>vladimir.olteanu@cs.pub.ro</email>
      </address>
    </author>
    <author initials="D." surname="Niculescu" fullname="Dragos Niculescu">
      <organization>University Politehnica of Bucharest</organization>
      <address>
        <email>dragos.niculescu@cs.pub.ro</email>
      </address>
    </author>

    <date year="2017" month="June" day="28"/>

    <area>Internet</area>
    <workgroup>Internet Area Working Group</workgroup>
    <keyword>Internet-Draft</keyword>

    <abstract>


<t>The SOCKS protocol is used primarily to proxy TCP connections to
arbitrary destinations via the use of a proxy server. Under the
latest version of the protocol (version 5), it takes 2 RTTs (or 3, if
authentication is used) before data can flow between the client and
the server.</t>

<t>This memo proposes SOCKS version 6, which reduces the number of RTTs
used, takes full advantage of TCP Fast Open, and adds support for
0-RTT authentication.</t>



    </abstract>


  </front>

<middle>

<section anchor="intro" title="Introduction">

<t>Versions 4 and 5 <xref target="RFC1928"></xref> of the SOCKS protocol were developed
two decades ago and are in widespread use for
circuit level gateways or as circumvention tools, and enjoy wide support and usage
from various software, such as web browsers, SSH clients, and
proxifiers. However, their design needs an update in order to
take advantage of the new features of transport protocols, such as TCP
Fast Open <xref target="RFC7413"></xref>, or to better assist newer transport protocols, such
as MPTCP <xref target="RFC6824"></xref>.</t>

<t>One of the main issues faced by SOCKS version 5 is that, when taking into account  
 the TCP handshake, method negotiation, authentication, connection request and grant, 
 it may take up to 5 RTTs for a data exchange to take place at the 
 application layer. This is especially costly in networks with a large 
 delay at the access layer, such as 3G, 4G, or satelite.</t>

<t>The desire to reduce the number of RTTs manifests itself in
 the design of newer security protocols. TLS version 1.3
 <xref target="I-D.ietf-tls-tls13"></xref> defines a zero round trip (0-RTT) handshake mode
 for connections if the client and server had previously communicated.</t>

<t>TCP Fast Open <xref target="RFC7413"></xref> is a TCP option that allows TCP to send data
in the SYN and receive a response in the first ACK, and aims at obtaining a data 
response in one RTT. The SOCKS protocol needs to concern itself with at 
least two TFO deployment scenarios: First, when TFO is available end-to-end 
(at the client, at the proxy, and at the server); second,
when TFO is active between the client and 
the proxy, but not at the server.</t>

<t>This document describes the SOCKS protocol version 6. The key improvements over SOCKS version 5 are:</t>

<t><list style="symbols">
  <t>The client sends as much information upfront as possible, and does not wait for the authentication process to conclude before requesting the creation of a socket.</t>
  <t>The connection request also mimics the semantics of TCP Fast Open <xref target="RFC7413"/>. As part of the connection request, the client can supply the payload for the initial SYN that is sent out to the server.</t>
  <t>The protocol can be extended via options without breaking backward-compatibility.</t>
  <t>The protocol can leverage the aforementioned options to support 0-RTT authentication schemes.</t>
</list></t>
</section>

<section anchor="requirements-language" title="Requirements language">

<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 anchor="terminology" title="Terminology">

	<t> This memo makes use of the following terms, that have a specific meaning in the context of SOCKS 6:</t>
	<t><list style="symbols">
		<t>Client: TODO.</t>
		<t>Proxy: TODO.</t>
		<t>Server: TODO.</t>
	</list></t>
	
	
<t>TODO: client, proxy, server</t>

</section>-->


<section anchor="op" title="Mode of operation">

<figure title="The SOCKS version 6 protocol message exchange" anchor="SOCKS6-topview" ><artwork><![CDATA[
  
 CLIENT                                                        PROXY 

         +------------------------+ 
         | Authentication methods | Request
 --------> Command code           +------------------------------>
         | TFO                    |        
         | Address                |         
         | Port                   |         
         | Options                |         
         | Initial data           |
         +------------------------+

                                     +-----------------------+
                Authentication reply | Type                  |
  <----------------------------------+ Method                <-----
                                     | Options               |
                                     +-----------------------+    
     
  <-------------------(Authentication protocol)------------------>

                       +-----------------------+
     Operation reply   | Reply code            |
  <--------------------+ Bind address          <------------------
                       | Bind port             |
                       | Options               |
                       | Initial data offset   |
                       +-----------------------+
]]></artwork>
</figure>

<t>When a TCP-based client wishes to establish a connection to a server,
it must open a TCP connection to the appropriate SOCKS port on the
SOCKS proxy. The client then enters a negotiation phase, by
sending the request in figure <xref target="SOCKS6-topview"/>, that 
contains, in addition to fields present in SOCKS 5 <xref target="RFC1928"/>, fields 
that facilitate low RTT usage and faster authentication negotiation.</t>

<t>Next, the server sends an authentication reply. If the request did not contain the necessary 
authentication information, the proxy indicates an authentication method that must proceed. This 
may trigger a longer authentication sequence
that could include tokens for ulterior faster authentications. The part labeled 
"Authentication protocol" is specific to the authentication 
method employed and is not expected to be employed for every connection between a
client and its proxy server. The authentication protocol typically takes up 1 RTT or more.</t>

<t>If the authentication is successful, an operation reply is generated by the proxy.
It indicates whether the proxy was successful in creating the requested socket or not.</t>

<t>In the fast case, when authentication is properly set up, the proxy attempts to create the socket
immediately after the receipt of the request, thus achieving an operational conection 
in one RTT (provided TFO functionality is available at the client, proxy, and server). 
</t> 
   
</section>
<section anchor="req" title="Connection Requests">

<t>The client starts by sending a request to the proxy.</t>

<figure title="SOCKS 6 Request" anchor="fig-req"><artwork><![CDATA[
+---------------+-----------+----------+
|    Version    | Number of | Methods  |
| Major | Minor |  Methods  |          |
+-------+-------+-----------+----------+
|   1   |   1   |     1     | Variable |
+-------+-------+-----------+----------+
+---------+-----+---------+----------+------+
| Command | TFO | Address | Address  | Port |
|  Code   |     |  Type   |          |      |
+---------+-----+---------+----------+------+
|    1    |  1  |    1    | Variable |  2   |
+---------+-----+---------+----------+------+
+-----------+----------+--------------+--------------+
| Number of | Options  | Initial Data | Initial Data |
|  Options  |          |     Size     |              |
+-----------+----------+--------------+--------------+
|     1     | Variable |      2       |   Variable   |
+-----------+----------+--------------+--------------+
 
]]></artwork></figure>

<t><list style="symbols">
  <t>Version: The major byte MUST be set to 0x06, and the minor byte MUST be set to 0x00.</t>
  <t>Number of Methods: The number of supported authentication methods that the client wishes to advertise.</t>
  <t>Methods: One byte per advertised method. Method numbers are assigned by IANA.</t>
  <t>Command Code:
  <list style="symbols">
      <t>0x00 AUTH: authenticate the client and do nothing.</t>
      <t>0x01 CONNECT: requests the establishment of a TCP connection.</t>
      <t>0x02 BIND: requests the establishment of a TCP port binding.</t>
      <t>0x03 UDP ASSOCIATE: requests a UDP port association.</t>
    </list></t>
  <t>TFO:
  <list style="symbols">
      <t>0x00 indicates that the proxy MUST NOT attempt to use TFO in case of a CONNECT command, or accept TFO in case of a BIND command. In case of an AUTH or UDP ASSOCIATE command, this field MUST be set to 0x00.</t>
      <t>0x01 indicates that the proxy SHOULD attempt to use TFO in case of a CONNECT command, or accept TFO in case of a BIND command.</t>
    </list></t>
  <t>Address Type:
  <list style="symbols">
      <t>0x01: IPv4</t>
      <t>0x03: Domain Name</t>
      <t>0x04: IPv6</t>
    </list></t>
  <t>Address: this field’s format depends on the address type:
  <list style="symbols">
      <t>IPv4: a 4-byte IPv4 address</t>
      <t>Domain Name: one byte that contains the length of the FQDN, followed by the FQDN itself. The string is not NUL-terminated.</t>
      <t>IPv6: a 16-byte IPv6 address</t>
    </list></t>
  <t>Port: the port in network byte order.</t>
  <t>Number of Options: the number of SOCKS options that appear in the Options field.</t>
  <t>Options: see section <xref target="opts"/>.</t>
  <t>Initial Data Size: A two-byte number in network byte order. In case of AUTH, BIND or UDP ASSOCIATE, this field MUST be set to 0. In case of CONNECT, this is the number of bytes of initial data that are supplied in the following field.</t>
  <t>Initial Data: The first octets of the data stream.</t>
</list></t>

<t>Clients MUST support the “No authentication required” method. Clients MAY omit advertising the “No authentication required” option.</t>

<t>Clients SHOULD NOT issue AUTH commands unless they advertise authentication methods with support for 0-RTT authentication.</t>

<t>The server MAY truncate the initial data to an arbitrary size and disregard the rest.</t>

</section>
<section anchor="opts" title="SOCKS Options">

<t>SOCKS options have the following format:</t>

<figure title="SOCKS 6 Option" anchor="fig-opt"><artwork><![CDATA[
+---------------+-------------+
| Kind | Length | Option Data |
+------+--------+-------------+
|  1   |   1    |   Variable  |
+------+--------+-------------+
 
]]></artwork></figure>

<t><list style="symbols">
  <t>Kind: MUST be allocated by IANA. (See section <xref target="iana"/>.)</t>
  <t>Length: The length of the option data.</t>
  <t>Option Data: the contents are specific to each option kind.</t>
</list></t>

<section anchor="opts-auth" title="Authentication options">

<t>Authentication options have the following format:</t>

<figure title="Authentication Option" anchor="fig-opt-auth"><artwork><![CDATA[
+---------------+--------+---------------------+
| Kind | Length | Method | Authentication Data |
+------+--------+--------+---------------------+
|  1   |   1    |   1    |       Variable      |
+------+--------+--------+---------------------+
 
]]></artwork></figure>

<t><list style="symbols">
  <t>Kind: MUST be allocated by IANA. (See section <xref target="iana"/>.)</t>
  <t>Length: the length of the option data.</t>
  <t>Method: the number of the authentication method. These numbers are assigned by IANA.</t>
  <t>Authentication Data: the contents are specific to each method.</t>
</list></t>

<t>All proxy implementations MUST support authentication method options. Clients MAY omit advertising authentication methods for which they have included at least an authentication option.</t>

</section>
</section>
<section anchor="irep" title="Authentication Replies">

<t>Upon receipt of a request, the proxy sends an Authentication Reply:</t>

<figure title="SOCKS 6 Authentication Reply" anchor="fig-irep"><artwork><![CDATA[
+---------------+------+--------+-----------+----------+
|    Version    | Type | Method | Number of | Options  |
| Major | Minor |      |        |  Options  |          |
+-------+-------+------+--------+-----------+----------+
|   1   |   1   |  1   |   1    |     1     | Variable |
+-------+-------+------+--------+-----------+----------+
 
]]></artwork></figure>

<t><list style="symbols">
  <t>Version: The major byte MUST be set to 0x06, and the minor byte MUST be set to 0x00.</t>
  <t>Type:
  <list style="symbols">
      <t>0x00: authentication successful.</t>
      <t>0x01: further authentication needed.</t>
    </list></t>
  <t>Method: The chosen authentication method.</t>
  <t>Number of Options: the number of SOCKS options that appear in the Options field.</t>
  <t>Options: see section <xref target="opts"/>.</t>
</list></t>

<t>Multihomed clients SHOULD cache the chosen method on a per-interface basis and SHOULD NOT include authentication options related to any other methods in further requests originating from the same interface.</t>

<t>If the server signals that further authentication is needed and selects “No Acceptable Methods”, the client MUST close the connection.</t>

<t>The client and proxy begin a method-specific negotiation. During such negotiations, the proxy MAY supply information that allows the client to authenticate a future request using an authentication option. Descriptions of such negotiations are beyond the scope of this memo.</t>

<t>If the cliend issued an AUTH command, the client MUST close the connection after the negociation is complete.</t>

</section>
<section anchor="frep" title="Operation Replies">

<t>After the authentication negotiations are complete, the server sends an Operation Reply:</t>

<figure title="SOCKS 6 Operation Reply" anchor="fig-frep"><artwork><![CDATA[
+---------------+-------+---------+----------+------+
|    Version    | Reply | Address |   Bind   | Bind |
| Major | Minor | Code  |  Type   | Address  | Port |
+-------+-------+-------+---------+----------+------+
|   1   |   1   |   1   |    1    | Variable |  2   |
+-------+-------+-------+---------+----------+------+
+-----------+----------+--------------+
| Number of | Options  | Initial Data |
|  Options  |          |    Offset    |
+-----------+----------+--------------+
|     1     | Variable |      2       |
+-----------+----------+--------------+
 
]]></artwork></figure>

<t><list style="symbols">
  <t>Version: The major byte MUST be set to 0x06, and the minor byte MUST be set to 0x00.</t>
  <t>Reply Code:
  <list style="symbols">
      <t>0x00: Succes</t>
      <t>0x01: General SOCKS server failure</t>
      <t>0x02: Connection not allowed by ruleset</t>
      <t>0x03: Network unreachable</t>
      <t>0x04: Host unreachable</t>
      <t>0x05: Connection refused</t>
      <t>0x06: TTL expired</t>
      <t>0x07: Command not supported</t>
      <t>0x08: Address type not supported</t>
    </list></t>
  <t>Address Type:
  <list style="symbols">
      <t>0x01: IPv4</t>
      <t>0x03: Domain Name</t>
      <t>0x04: IPv6</t>
    </list></t>
  <t>Bind Address: the proxy bound address in the following format:
  <list style="symbols">
      <t>IPv4: a 4-byte IPv4 address</t>
      <t>Domain Name: one byte that contains the length of the FQDN, followed by the FQDN itself. The string is not NUL-terminated.</t>
      <t>IPv6: a 16-byte IPv6 address</t>
    </list></t>
  <t>Bind Port: the proxy bound port in network byte order.</t>
  <t>Number of Options: the number of SOCKS options that appear in the Options field.</t>
  <t>Options: see section <xref target="opts"/></t>
  <t>Initial Data Offset: A two-byte number in network byte order. In case of BIND or UDP ASSOCIATE, this field MUST be set to 0. In case of CONNECT, it represents the offset in the plain data stream from which the client is expected to continue sending data.</t>
</list></t>

<t>If the proxy returns a reply code other than "Success", the client MUST close the connection.</t>

<section anchor="handling-connect" title="Handling CONNECT">
	<t>In case the client has issued a CONNECT request, data can now pass. The client MUST resume the data stream at the offset indicated by the Initial Data Offset field.</t>
</section>

<section anchor="handling-bind" title="Handling BIND">
	<t>In case the client has issued a BIND request, it must wait for a second Operation reply from the proxy, which signifies that a host has connected to the bound port. The Bind Address and Bind Port fields contain the address and port of the connecting host. Afterwards, application data may pass.</t>
</section>

<section anchor="handling-udp-associate" title="Handling UDP ASSOCIATE">
	<t>The relay of UDP packets is handled exactly as in SOCKS 5 <xref target="RFC1928"/>.</t>
</section>

</section>

<section anchor="security-considerations" title="Security Considerations">

<t>Given the format of the request message, a malicious client could craft a request that is in excess of 100 KB and proxies could be prone to DDoS attacks.</t>

<t>To mitigate such attacks, proxy implementations SHOULD be able to incrementally parse the requests. Proxies MAY close the connection to the client if:</t>

<t><list style="symbols">
  <t>the request is not fully received after a certain timeout, or</t>
  <t>the number of options exceeds an imposed hard cap, or</t>
  <t>the total size of the options exceeds an imposed hard cap, or</t>
  <t>the size of the initial data excedes a hard cap.</t>
</list></t>

<t>Further, the server MAY choose not to buffer any initial data beyond what would fit in a TFO SYN’s payload.</t>

</section>
<section anchor="iana" title="IANA Considerations">

<t>This document requests that IANA allocate option codes for SOCKS 6 options. Further, this document requests an option code for authentication options.</t>

</section>
<section anchor="acknowledgements" title="Acknowledgements">

<t>The protocol described in this draft builds upon and is a direct continuation of SOCKS 5 <xref target="RFC1928"/>.</t>

</section>


</middle>

  <back>

    <references title='Normative References'>





<reference  anchor="RFC2119" target='http://www.rfc-editor.org/info/rfc2119'>
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials='S.' surname='Bradner' fullname='S. Bradner'><organization /></author>
<date year='1997' month='March' />
<abstract><t>In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized. This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t></abstract>
</front>
<seriesInfo name='BCP' value='14'/>
<seriesInfo name='RFC' value='2119'/>
<seriesInfo name='DOI' value='10.17487/RFC2119'/>
</reference>




    </references>

    <references title='Informative References'>





<reference  anchor="RFC1928" target='http://www.rfc-editor.org/info/rfc1928'>
<front>
<title>SOCKS Protocol Version 5</title>
<author initials='M.' surname='Leech' fullname='M. Leech'><organization /></author>
<author initials='M.' surname='Ganis' fullname='M. Ganis'><organization /></author>
<author initials='Y.' surname='Lee' fullname='Y. Lee'><organization /></author>
<author initials='R.' surname='Kuris' fullname='R. Kuris'><organization /></author>
<author initials='D.' surname='Koblas' fullname='D. Koblas'><organization /></author>
<author initials='L.' surname='Jones' fullname='L. Jones'><organization /></author>
<date year='1996' month='March' />
<abstract><t>This memo describes a protocol that is an evolution of the previous version of the protocol, version 4 [1]. This new protocol stems from active discussions and prototype implementations.  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='1928'/>
<seriesInfo name='DOI' value='10.17487/RFC1928'/>
</reference>



<reference  anchor="RFC7413" target='http://www.rfc-editor.org/info/rfc7413'>
<front>
<title>TCP Fast Open</title>
<author initials='Y.' surname='Cheng' fullname='Y. Cheng'><organization /></author>
<author initials='J.' surname='Chu' fullname='J. Chu'><organization /></author>
<author initials='S.' surname='Radhakrishnan' fullname='S. Radhakrishnan'><organization /></author>
<author initials='A.' surname='Jain' fullname='A. Jain'><organization /></author>
<date year='2014' month='December' />
<abstract><t>This document describes an experimental TCP mechanism called TCP Fast Open (TFO).  TFO allows data to be carried in the SYN and SYN-ACK packets and consumed by the receiving end during the initial connection handshake, and saves up to one full round-trip time (RTT) compared to the standard TCP, which requires a three-way handshake (3WHS) to complete before data can be exchanged.  However, TFO deviates from the standard TCP semantics, since the data in the SYN could be replayed to an application in some rare circumstances.  Applications should not use TFO unless they can tolerate this issue, as detailed in the Applicability section.</t></abstract>
</front>
<seriesInfo name='RFC' value='7413'/>
<seriesInfo name='DOI' value='10.17487/RFC7413'/>
</reference>



<reference  anchor="RFC6824" target='http://www.rfc-editor.org/info/rfc6824'>
<front>
<title>TCP Extensions for Multipath Operation with Multiple Addresses</title>
<author initials='A.' surname='Ford' fullname='A. Ford'><organization /></author>
<author initials='C.' surname='Raiciu' fullname='C. Raiciu'><organization /></author>
<author initials='M.' surname='Handley' fullname='M. Handley'><organization /></author>
<author initials='O.' surname='Bonaventure' fullname='O. Bonaventure'><organization /></author>
<date year='2013' month='January' />
<abstract><t>TCP/IP communication is currently restricted to a single path per connection, yet multiple paths often exist between peers.  The simultaneous use of these multiple paths for a TCP/IP session would improve resource usage within the network and, thus, improve user experience through higher throughput and improved resilience to network failure.</t><t>Multipath TCP provides the ability to simultaneously use multiple paths between peers.  This document presents a set of extensions to traditional TCP to support multipath operation.  The protocol offers the same type of service to applications as TCP (i.e., reliable bytestream), and it provides the components necessary to establish and use multiple TCP flows across potentially disjoint paths.  This  document defines an Experimental Protocol for the Internet community.</t></abstract>
</front>
<seriesInfo name='RFC' value='6824'/>
<seriesInfo name='DOI' value='10.17487/RFC6824'/>
</reference>



<reference anchor="I-D.ietf-tls-tls13">
<front>
<title>The Transport Layer Security (TLS) Protocol Version 1.3</title>

<author initials='E' surname='Rescorla' fullname='Eric Rescorla'>
    <organization />
</author>

<date month='April' day='28' year='2017' />

<abstract><t>This document specifies version 1.3 of the Transport Layer Security (TLS) protocol.  TLS allows client/server applications to communicate over the Internet in a way that is designed to prevent eavesdropping, tampering, and message forgery.</t></abstract>

</front>

<seriesInfo name='Internet-Draft' value='draft-ietf-tls-tls13-20' />
<format type='TXT'
        target='http://www.ietf.org/internet-drafts/draft-ietf-tls-tls13-20.txt' />
</reference>




    </references>



  </back>


</rfc>

