<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!-- One method to get references from the online citation libraries.
     There has to be one entity for each item to be referenced. 
     An alternate method (rfc include) is described in the references. -->

<!ENTITY RFC1122 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1122.xml">
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2817 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2817.xml">
<!ENTITY RFC3948 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3948.xml">
<!ENTITY RFC4303 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4303.xml">
<!ENTITY RFC4555 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4555.xml">
<!ENTITY RFC5246 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml">
<!ENTITY RFC6520 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6520.xml">
<!ENTITY RFC7296 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7296.xml">
<!ENTITY I-D.tschofenig-hourglass SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.draft-tschofenig-hourglass-00.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs), 
     please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use.
     (Here they are set differently than their defaults in xml2rfc v1.32) -->
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC -->
<?rfc tocdepth="4"?>
<!-- the number of levels of subsections in ToC. default: 3 -->
<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space 
     (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<rfc ipr="trust200902"
    updates=""
    obsoletes=""
    category="std"
    docName="draft-pauly-ipsecme-tcp-encaps-00">

  <!-- category values: std, bcp, info, exp, and historic -->

  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the 
         full title is longer than 39 characters -->

    <title>TCP Encapsulation of IKEv2 and IPSec Packets</title>

    <!-- add 'role="editor"' below for the editors if appropriate -->

    <author fullname="Tommy Pauly" initials="T." surname="Pauly">
      <organization>Apple Inc.</organization>

      <address>
        <postal>
          <street>1 Infinite Loop</street>
          <city>Cupertino</city>
          <region>California</region>
          <code>95014</code>
          <country>US</country>
        </postal>

        <phone></phone>
        <email>tpauly@apple.com</email>
      </address>
    </author>

<author fullname="Samy Touati" initials="S." surname="Touati">
	<organization>Ericsson</organization>

	<address>
		<postal>
			<street>300 Holger Way</street>
			<city>San Jose</city>
			<region>California</region>
			<code>95134</code>
			<country>US</country>
		</postal>

		<phone></phone>
		<email>samy.touati@ericsson.com</email>
	</address>
</author>

    <date/>

    <!-- If the month and year are both specified and are the current ones, xml2rfc will fill
         in the current day for you. If only the current year is specified, xml2rfc will fill 
     in the current day and month for you. If the year is not the current one, it is 
     necessary to specify at least a month (xml2rfc assumes day="1" if not specified for the 
     purpose of calculating the expiry date).  With drafts it is normally sufficient to 
     specify just the year. -->

    <!-- Meta-data Declarations -->

    <area>General</area>

    <workgroup>Network</workgroup>

    <!-- WG name at the upperleft corner of the doc,
         IETF is fine for individual submissions.  
     If this element is not present, the default is "Network Working Group",
         which is used by the RFC Editor as a nod to the history of the IETF. -->

    <keyword>IKEv2</keyword>
	<keyword>IPSec</keyword>
    <keyword>TCP</keyword>

    <!-- Keywords will be incorporated into HTML output
         files in a meta tag but they have no effect on text or nroff
         output. If you submit your draft to the RFC Editor, the
         keywords will be used for the search engine. -->

    <abstract>
      <t>This document describes a method to transport IKEv2 and IPSec packets over a TCP connection for traversing network middleboxes that may block IKEv2 negotiation over UDP. This method, referred to as TCP encapsulation, involves sending all packets for tunnel establishment as well as tunneled packets over a TCP connection.</t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>IKEv2 <xref target="RFC7296"/> is a protocol for establishing IPSec tunnels, using IKE messages over UDP for control traffic, and using ESP messages (or ESP over UDP) for its data traffic. Many network middleboxes that filter traffic on public hotspots block all UDP traffic, including IKEv2 and IPSec, but allow TCP connections through since they appear to be web traffic. Devices on these networks that need to use IPSec (to access private enterprise networks, to route voice-over-IP calls to carrier networks, or because of security policies) are unable to establish IPSec tunnels. This document defines a method for encapsulating both the IKEv2 control messages as well as the IPSec data messages within a TCP connection.</t>
      <t>Using TCP as a transport for IPSec packets adds a third option to the list of traditional IPSec transports:
      <list style="hanging" hangIndent="6">
          <t hangText="1.">Direct. Currently, IKEv2 negotiations begin over UDP port 500. If no NAT is detected between the initiator and the receiver, then subsequent IKEv2 packets are sent over UDP port 500 and IPSec data packets are sent using ESP <xref target="RFC4303"/>.</t>
          <t hangText="2.">UDP Encapsulation <xref target="RFC3948"/>. If a NAT is detected between the initiator and the receiver, then subsequent IKEv2 packets are sent over UDP port 4500 with four bytes of zero at the start of the UDP payload and ESP packets are sent out over UDP port 4500.</t>
          <t hangText="3.">TCP Encapsulation. If both of the other two methods are not available or appropriate, both IKEv2 negotiation packets as well as ESP packets can be sent over a single TCP connection to the peer. This connection can itself use TLS <xref target="RFC5246"/> or other methods if needed. If the connection uses TLS, it will also be capable of traversing a web proxy <xref target="RFC2817"/>.</t>
      </list>
      </t>

      <section 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">RFC 2119</xref>.</t>
      </section>
    </section>

    <section title="Configuration">
		<t>One of the main reasons to use TCP encapsulation is that UDP traffic may be entirely blocked on a network. Because of this, support for TCP encapsulation is not specifically negotiated in the IKEv2 exchange. Instead, support for TCP encapsulation must be pre-configured on both the initiator and the responder.</t>
		<t>The configuration defined on each peer should include the following parameters:</t>
		<t><list style="symbols">
			<t>One or more TCP ports on which the responder will listen for incoming connections. Note that the initiator may initiate TCP connections to the responder from any local port.</t>
			<t>Whether or not to use TLS for connections to a given TCP port. The responder may expect to read encapsulated IKEv2 and ESP packets directly from the TCP connection, or it may expect to read them from a stream of TLS data packets. The initiator should be pre-configured to use TLS or not when communicating with a given port on the responder.</t>
		</list></t>
        <t>Since TCP encapsulation of IKEv2 and IPSec packets adds overhead and has potential performance trade-offs compared to direct or UDP-encapsulated tunnels (as described in Performance Considerations, <xref target="mobike"/>), implementations SHOULD prefer IKEv2 negotiation over UDP.</t>
    </section>

    <section title="TCP-Encapsulated Header Formats">

    <section title="TCP-Encapsulated IKEv2 Header Format">
        <figure align="center" anchor="ikev2_tcp_header">
            <artwork align="left"><![CDATA[
                    1                   2                   3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             Length                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Non-ESP Marker                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     IKEv2 header [RFC7296]                    |
~                                                               ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            ]]></artwork>

        </figure>

        <t>The IKE header is preceded by a 32-bit length field in network byte order that specifies the length of the IKE packet within the TCP stream. As with IKEv2 over UDP port 4500, a zeroed 32-bit Non-ESP Marker is inserted before the start of the IKEv2 header in order to differentiate the traffic from ESP traffic between the same addresses and ports.</t>

        <t><list style="symbols">
            <t>Length (4 octets, unsigned integer) - Length of the IKE packet including the Length Field and Non-ESP Marker.</t>
        </list></t>
      </section>

      <section title="TCP-Encapsulated ESP Header Format">

<figure align="center" anchor="esp_tcp_header">
    <artwork align="left"><![CDATA[
                    1                   2                   3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             Length                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     ESP header [RFC4303]                      |
~                                                               ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    ]]></artwork>
</figure>

    <t>The ESP header is preceded by a 32-bit length field in network byte order that specifies the length of the ESP packet within the TCP stream.</t>

    <t><list style="symbols">
        <t>Length (4 octets, unsigned integer) - Length of the ESP packet including the Length Field.</t>
    </list></t>

      </section>
      </section>
	<section title="Applicability">
		<t>TCP encapsulation is applicable only when it has been configured to be used with specific IKEv2 peers. If a responder is configured to use TCP encapsulation, it MUST listen on the configured port(s) in case any peers will initiate new IKEv2 sessions. Initiators MAY use TCP encapsulation for any IKEv2 session to a peer that is configured to support TCP encapsulation, although it is recommended that initiators should only use TCP encapsulation when traffic over UDP is blocked.</t>
		<t>Any specific IKE SA, along with its Child SAs, is either TCP encapsulated or not. A mix of TCP and UDP encapsulation for a single SA is not allowed. The exception to this rule is SAs that are migrated between addresses using MOBIKE (<xref target="mobike"/>).</t>
	</section>

    <section title="Connection Establishment and Teardown">
    <t>When the initiator decides to use TCP encapsulation for IKEv2 negotiation, the initiator will initiate a TCP connection with the responder using the configured TCP port. If TLS is being used, it may be negotiated at this point, although the policy for the TLS negotiation is out of scope of this document. If a web proxy is applied to the ports for the TCP connection, and TLS is being used, the initiator can send an HTTP CONNECT message to establish a tunnel through the proxy <xref target="RFC2817"/></t>
    <t>Before either initiator or responder closes the TCP connection by sending a FIN or a RST, session teardown SHOULD be gracefully negotiated with DELETE payloads. Once all SAs have been deleted, the initiator of the original connection MUST close the TCP connection.</t>
	<t>An unexpected FIN or a RST on the TCP connection may indicate either a loss of connectivity, an attack, or some other error. If a DELETE payload has not been sent, both sides SHOULD maintain the state for their SAs for the standard lifetime or time-out period. The original initiator (that is, the endpoint that initiated the TCP connection and sent the first IKE_SA_INIT message) is responsible for re-establishing the TCP connection if it is torn down for any unexpected reason. Since new TCP connections may use different ports due to NAT mappings or local port allocations changing, the responder MUST allow packets for existing SAs to be received from new source ports.</t>
	<t>The streams of data sent over any TCP connection used for this protocol MUST begin with a complete IKEv2 or ESP message, complying to the format specified in <xref target="ikev2_tcp_header"/> and <xref target="esp_tcp_header"/>. If either initiator or responder receives a stream that cannot be parsed correctly, it MUST close the TCP connection.</t>
	<t>Multiple TCP connections between the initiator and the responder are allowed, but not recommended. IKE and IPSec messages MUST be processed according to the standard source identification (using the SPI) and ordering rules. It is also possible to negotiate multiple IKE SAs over the same TCP connection, in which case messages are de-multiplexed using the SPI of the message.</t>
    </section>

	<section title="Interaction with NAT Detection Payloads">
	<t>When negotiating over UDP port 500, IKE_SA_INIT packets include NAT_DETECTION_SOURCE_IP and NAT_DETECTION_DESTINATION_IP payloads to determine if UDP encapsulation of IPSec packets should be used. These payloads contain SHA-1 digests of the SPIs, IP addresses, and ports. IKE_SA_INIT packets sent on a TCP connection SHOULD include these payloads, and SHOULD use the applicable TCP ports when creating and checking the SHA-1 digests.</t>
	<t>If a NAT is detected due to the SHA-1 digests not matching the expected values, no change should be made for encapsulation of subsequent IKEv2 or ESP packets, since TCP encapsulation inherently supports NAT traversal. Implementations MAY use the information that a NAT is present to influence keep-alive timer values.</t>
	</section>

    <section title="Considerations for Keep-alives and DPD">

    <t>Encapsulating IKE and IPSec inside of a TCP connection can impact the strategy that implementations use to detect peer liveness and to maintain middlebox mappings. In addition to mechanisms in IKE and IPSec, TCP keepalives are available. The following mechanisms may be employed:</t>

    <t><list style="symbols">
        <t>IKEv2 Informational packets <xref target="RFC7296"/></t>
        <t>IPSec ESP NAT keep-alives <xref target="RFC3948"/></t>
        <t>TCP NAT keep-alives <xref target="RFC1122"/></t>
		<t>TLS keep-alives <xref target="RFC6520"/></t>
    </list></t>

	<t>It is up to the implementation to decide which keepalives are appropriate for TCP-encapsulated connections. NAT timeouts are generally longer for TCP ports, but implementations should still use some form of keep-alive when a NAT is detected. If TCP NAT keep-alives are used, IPSec ESP NAT keep-alives may be considered redundant and can safely be disabled.</t>

    </section>

    <section title="Using MOBIKE with TCP encapsulation" anchor="mobike">

<t>When an IKEv2 session is transitioned between networks using MOBIKE <xref target="RFC4555"/>, the initiator of the transition may switch between using TCP encapsulation, UDP encapsulation, or no encapsulation. Implementations that implement both MOBIKE and TCP encapsulation MUST support dynamically enabling and disabling TCP encapsulation as interfaces change.</t>

<t>The encapsulation method of ESP packets MUST always match the encapsulation method of the IKEv2 negotiation, which may be different when an IKEv2 endpoint changes networks. When an MOBIKE-enabled initiator changes networks, the UPDATE_SA_ADDRESSES notification SHOULD be sent out first over UDP before attempting over TCP. If there is a response to the UPDATE_SA_ADDRESSES notification sent over UDP, then the ESP packets should be sent directly over IP or over UDP port 4500 (depending on if a NAT was detected), regardless of if a connection on a previous network was using TCP encapsulation. Similarly, if the responder only responds to the UPDATE_SA_ADDRESSES notification over TCP, then the ESP packets should be sent over the TCP connection, regardless of if a connection on a previous network did not use TCP encapsulation.</t>

    </section>

<section title="Performance Considerations" anchor="performance">
    <t>Several aspects of TCP encapsulation for IKEv2 and IPSec packets may negatively impact the performance of connections within the tunnel. Implementations should be aware of these and take these into consideration when determining when to use TCP encapsulation.</t>

<section title="TCP-in-TCP">
    <t>If the outer connection between IKEv2 peers is over TCP, inner TCP connections may suffer effects from using TCP within TCP. In particular, the inner TCP's round-trip-time estimation will be affected by the burstiness of the outer TCP. This will make loss-recovery of the inner TCP traffic less reactive and more prone to spurious retransmission timeouts.</t>
</section>

<section title="Added Reliability for Unreliable Protocols">
	<t>Since ESP is an unreliable protocol, transmitting ESP packets over a TCP connection will change the fundamental behavior of the packets. Some application-level protocols that prefer packet loss to delay (such as Voice over IP or other real-time protocols) may be negatively impacted if their packets are retransmitted by the TCP connection due to packet loss.</t>
</section>

<section title="Encryption Overhead">
    <t>If TLS or another encryption method is used on the TCP connection, there may be increased processing overhead for encrypting and decrypting. This overhead may be experienced as a decrease in throughput on CPU-limited devices, or an increase in CPU usage or battery consumption on other devices, therefore the initiator and responder MUST allow the selection of NULL cipher when using TLS. Additionally, the TLS record introduces another layer of overhead, requiring more bytes to transmit a given IKEv2 and IPSec packet.</t>
</section>
</section>

<section anchor="Security" title="Security Considerations">
    <t>IKEv2 responders that support TCP encapsulation may become vulnerable to new Denial-of-Service (DoS) attacks that are specific to TCP, such as SYN-flooding attacks. Responders should be aware of this additional attack-surface.</t>
	<t>Attackers may be able to disrupt the TCP connection by sending spurious RST packets. Due to this, implementations SHOULD make sure that IKE session state persists even if the underlying TCP connection is torn down.</t>
    <t>If TLS is used on the encapsulating TCP connection, it should not be considered as a security measure. The security of the IKEv2 session is entirely derived from the IKEv2 negotiation and key establishment.</t>
</section>

    <section anchor="IANA" title="IANA Considerations">
      <t>This memo includes no request to IANA.</t>
	  <t>TCP port 4500 is already allocated to IPSec. This port MAY be used for the protocol described in this document, but implementations MAY prefer to use other ports based on local policy. We foresee some implementations using TCP port 443 to more easily pass through some middleboxes <xref target="I-D.tschofenig-hourglass"/>.</t>
    </section>

<section anchor="acknowledgments" title="Acknowledgments">
	<t>The authors would like to acknowledge the input and advice of Stuart Cheshire, Delziel Fernandes, Yoav Nir, Christoph Paasch, Yaron Sheffer, David Schinazi, March Wu and Kingwel Xie. Special thanks to Eric Kinnear for his implementation work.</t>
</section>


  </middle>

  <!--  *****BACK MATTER ***** -->

  <back>
    <!-- References split into informative and normative -->

    <!-- There are 2 ways to insert reference entries from the citation libraries:
     1. define an ENTITY at the top, and use "ampersand character"RFC2629; here (as shown)
     2. simply use a PI "less than character"?rfc include="reference.RFC.2119.xml"?> here
        (for I-Ds: include="reference.I-D.narten-iana-considerations-rfc2434bis.xml")

     Both are cited textually in the same manner: by using xref elements.
     If you use the PI option, xml2rfc will, by default, try to find included files in the same
     directory as the including file. You can also define the XML_LIBRARY environment variable
     with a value containing a set of directories to search.  These can be either in the local
     filing system or remote ones accessed by http (http://domain/dir/... ).-->

    <references title="Normative References">
      <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?-->
      &RFC2119;
	  &RFC7296;

    </references>

    <references title="Informative References">
      <!-- Here we use entities that we defined at the beginning. -->

        &RFC1122;
		&RFC2817;
        &RFC3948;
        &RFC4303;
        &RFC4555;
        &RFC5246;
		&RFC6520;
		&I-D.tschofenig-hourglass;

    </references>
  </back>
</rfc>
