<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd"[
 <!ENTITY RFC2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
 <!ENTITY RFC2616 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2616.xml'>
 <!ENTITY RFC5077 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5077.xml'>
 <!ENTITY RFC5246 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml'>
]>

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

<rfc ipr="trust200902" docName="draft-agl-tls-nextprotoneg-03">
  <front>
    <title abbrev="TLS Next Protocol Negotiation">Transport Layer Security (TLS) Next Protocol Negotiation Extension</title>
    <author initials="A." surname="Langley" fullname="Adam Langley">
      <organization>Google Inc</organization>
      <address>
        <email>agl@google.com</email>
      </address>
    </author>

    <date month="April" year="2012" />
    <area>Security</area>
    <abstract>
      <t>
        This document describes a Transport Layer Security (TLS) extension for application layer protocol negotiation. This allows the application layer to negotiate which protocol should be performed over the secure connection.
      </t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction" anchor="intro">
      <t>
        The Next Protocol Negotiation extension (NPN) is currently used to negotiate the use of <xref target="spdy">SPDY</xref> as an application level protocol on port 443, and to perform SPDY version negotiation. However, it is not SPDY specific in any way.
      </t>

      <t>
        Designers of new application level protocols are faced with a problem: there are no good options for establishing a clean transport for a new protocol and negotiating its use. Negotiations on port 80 will run afoul of intercepting proxies. Ports other than 80 and 443 are likely to be firewalled without any fast method of detection, and are also unlikely to traverse HTTP proxies with CONNECT. Negotiating on port 443 is possible, but may run afoul of MITM proxies and also uses a round trip for negotiation on top of the round trips for establishing the TLS connection. Negotiation at that level is also dependent on the application level protocol, i.e. the real world tolerance of servers to HTTP Upgrade requests.
      </t>

      <t>
        Next Protocol Negotiation allows application level protocols to be negotiated without additional round trips and with clean fallback in the case of an unsupportive MITM proxy.
      </t>
    </section>

    <section title="Requirements Notation">
      <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">RFC 2119</xref>.
      </t>
    </section>

    <section title="Next Protocol Negotiation Extension">
      <t>
        A new extension type (<spanx style="verb">next_protocol_negotiation(13172)</spanx>) is defined and MAY be included by the client in its <spanx style="verb">ClientHello</spanx> message. If, and only if, the server sees this extension in the <spanx style="verb">ClientHello</spanx>, it MAY choose to echo the extension in its <spanx style="verb">ServerHello</spanx>.
      </t>

      <figure>
        <artwork>
enum {
  next_protocol_negotiation(13172), (65535)
} ExtensionType;
        </artwork>
      </figure>

      <t>
        The <spanx style="verb">extension_data</spanx> field of a <spanx style="verb">next_protocol_negotiation</spanx> extension in a <spanx style="verb">ClientHello</spanx> MUST be empty.
      </t>

      <t>
        The <spanx style="verb">extension_data</spanx> field of a <spanx style="verb">next_protocol_negotiation</spanx> extension in a <spanx style="verb">ServerHello</spanx> contains an optional list of protocols advertised by the server. Protocols are named by opaque, non-empty byte strings and the list of protocols is serialized as a concatenation of 8-bit, length prefixed byte strings. Implementations MUST ensure that the empty string is not included and that no byte strings are truncated.
      </t>

      <t>
        A new handshake message type (<spanx style="verb">next_protocol(67)</spanx>) is defined. If, and only if, the server included a <spanx style="verb">next_protocol_negotiation</spanx> extension in its <spanx style="verb">ServerHello</spanx> message, the client MUST send a <spanx style="verb">NextProtocol</spanx> message after its <spanx style="verb">ChangeCipherSpec</spanx> and before its <spanx style="verb">Finished</spanx> message.
      </t>

      <figure>
        <artwork>
enum {
  next_protocol(67), (65535)
} HandshakeType;
        </artwork>
      </figure>

      <t>Therefore a full handshake with <spanx style="verb">NextProtocol</spanx> has the following flow (contrast with section 7.3 of <xref target="RFC5246">RFC 5246</xref>):</t>

      <figure>
        <artwork>
Client                                               Server

ClientHello (NPN extension)   --------&gt;
                                                ServerHello
                                                  (NPN extension &amp;
                                                   list of protocols)
                                               Certificate*
                                         ServerKeyExchange*
                                        CertificateRequest*
                             &lt;--------      ServerHelloDone
Certificate*
ClientKeyExchange
CertificateVerify*
[ChangeCipherSpec]
NextProtocol
Finished                     --------&gt;
                                         [ChangeCipherSpec]
                             &lt;--------             Finished
Application Data             &lt;-------&gt;     Application Data
        </artwork>
      </figure>

      <t>An abbreviated handshake with <spanx style="verb">NextProtocol</spanx> has the following flow:</t>

      <figure>
        <artwork>
Client                                                Server

ClientHello (NPN extension)    --------&gt;
                                                ServerHello
                                                  (NPN extension &amp;
                                                   list of protocols)
                                         [ChangeCipherSpec]
                              &lt;--------            Finished
[ChangeCipherSpec]
NextProtocol
Finished                      --------&gt;
Application Data              &lt;-------&gt;    Application Data
        </artwork>
      </figure>

      <t>The <spanx style="verb">NextProtocol</spanx> message has the following format:</t>

      <figure>
        <artwork>
struct {
  opaque selected_protocol&lt;0..255&gt;;
  opaque padding&lt;0..255&gt;;
} NextProtocol;
        </artwork>
      </figure>

      <t>
        The contents of <spanx style="verb">selected_protocol</spanx> are an opaque protocol string, but need not have been advertised by the server. The length of <spanx style="verb">padding</spanx> SHOULD be 32 - ((len(selected_protocol) + 2) % 32). Note that len(selected_protocol) does not include its length prefix.
      </t>

      <t>
        Unlike many other TLS extensions, this extension does not establish properties of the session, only of the connection. When session resumption or <xref target="RFC5077">session tickets</xref> are used, the previous contents of this extension are irrelevant and only the values in the new handshake messages are considered.
      </t>

      <t>
	For the same reasons, after a handshake has been performed for a given connection, renegotiations on the same connection MUST NOT include the <spanx style="verb">next_protocol_negotiation</spanx> extension.
      </t>
    </section>

    <section title="Protocol selection">

      <t>
        It's expected that a client will have a list of protocols that it supports, in preference order, and will only select a protocol if the server supports it. In that case, the client SHOULD select the first protocol advertised by the server that it also supports. In the event that the client doesn't support any of server's protocols, or the server doesn't advertise any, it SHOULD select the first protocol that it supports.
      </t>

      <t>
        There may be cases where the client knows, via other means, that a server supports an unadvertised protocol. In these cases the client can simply select that protocol.
      </t>
    </section>

    <section title="Design discussion">

      <t>
        NPN is an outlier from TLS in several respects: firstly that it introduces a handshake message between the <spanx style="verb">ChangeCipherSpec</spanx> and <spanx style="verb">Finished</spanx> message, that the handshake message is padded, and that the negotiation isn't done purely with the hello messages. All these aspects of the protocol are intended to prevent middle-ware discrimination based on the negotiated protocol and follow the general principle that anything that can be encrypted, should be encrypted. The server's list of advertised protocols is in the clear as a compromise between performance and robustness.
      </t>
    </section>

    <section title="Security considerations">
      <t>
        The server's list of supported protocols is still advertised in the clear with this extension.  This may be undesirable for certain protocols (such as <xref target="tor">Tor</xref>) where one could imagine that hostile networks would terminate any TLS connection with a server that advertised such a capability. In this case, clients may wish to opportunistically select a protocol that wasn't advertised by the server. However, the workings of such a scheme are outside the scope of this document.
      </t>
    </section>

    <section title="IANA Considerations">
      <t>
        This document requires IANA to update its registry of TLS extensions to assign entry 13172 as <spanx style="verb">next_protocol_negotiation</spanx>.
      </t>

      <t>
        This document also requires IANA to update its registry of TLS handshake types to assign entry 67 as <spanx style="verb">next_protocol</spanx>.
      </t>

      <t>
        This document also requires IANA to create a registry of TLS Next Protocol Negotiation protocol strings on a first come, first served basis, initially containing the following entries:
        <list style="symbols">
          <t><spanx style="verb">http/1.1</spanx>: <xref target="RFC2616">HTTP/1.1</xref></t>
          <t><spanx style="verb">spdy/1</spanx>: (obsolete) SPDY version 1</t>
          <t><spanx style="verb">spdy/2</spanx>: SPDY version 2</t>
          <t><spanx style="verb">spdy/3</spanx>: SPDY version 3</t>
        </list>
      </t>
    </section>

    <section title="Acknowledgments">
      <t>
        This document benefited specifically from discussions with Wan-Teh Chang and Nagendra Modadugu.
      </t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      &RFC2119;
      &RFC5246;
    </references>

    <references title="Informative References">
      &RFC2616;
      &RFC5077;

      <reference anchor="tor">
        <front>
          <title>Tor: The Second-Generation Onion Router</title>
          <author initials="R." surname="Dingledine"> <organization/> </author>
          <author initials="N." surname="Matthewson"> <organization/> </author>
          <author initials="P." surname="Syverson"> <organization/> </author>
          <date month="August" year="2004"/>
        </front>
      </reference>

      <reference anchor="spdy">
        <front>
          <title>SPDY Protocol (Internet Draft)</title>
          <author initials="M." surname="Belshe"> <organization/> </author>
          <author initials="R." surname="Peon"> <organization/> </author>
          <date month="Feb" year="2012"/>
        </front>
      </reference>
    </references>
  </back>
</rfc>
