<?xml version="1.0"?>
<!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 TLS SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml">
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2434 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2434.xml">
<!ENTITY DTLS SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6347.xml">
]>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<rfc ipr="trust200902" updates="5246,6347" category="std" docName="draft-mavrogiannopoulos-new-tls-padding-00">
  <front>
    <title abbrev="A new TLS record padding mechanism">A new TLS record padding mechanism</title>

    <author initials="N." surname="Mavrogiannopoulos" fullname="Nikos Mavrogiannopoulos">
      <organization abbrev="Red Hat">Red Hat</organization>
      <address>
        <postal>
          <street/>
          <street>Purkyňova 99/75a</street>
          <city>Brno</city>
          <region/>
          <code>612 00</code>
          <country>Czech Republic</country>
        </postal>
        <email>nmav@redhat.com</email>
      </address>
    </author>
    <author initials="A." surname="Pironti" fullname="Alfredo Pironti">
      <organization>INRIA Paris-Rocquencourt</organization>
      <address>
        <postal>
          <street>23, Avenue d'Italie</street>
          <city>Paris</city>
          <region/>
          <code>75214 CEDEX 13</code>
          <country>France</country>
        </postal>
        <email>alfredo.pironti@inria.fr</email>
      </address>
    </author>
    <date month="November" year="2013"/>
    <area>Security</area>
    <!--      <workgroup>TLS Working Group</workgroup> -->
    <keyword>I-D</keyword>
    <keyword>Internet-Draft</keyword>
    <keyword>Length Hiding</keyword>
    <keyword>TLS</keyword>
    <keyword>Transport Layer Security</keyword>
    <abstract>
      <t>
This memo proposes a new padding mechanism the TLS and DTLS record protocols.
It defines a TLS extension to allow arbitrary amount of padding in any 
ciphersuite. The new padding mechanism eliminates any known padding oracle
attacks on the CBC ciphersuites and allows novel length hiding techniques.
         </t>
    </abstract>
  </front>
  <middle>
    <section anchor="intro" title="Introduction">
      <t>
When using CBC block ciphers, the TLS protocol <xref target="RFC5246"/><xref target="RFC6347"/> provides means to
frustrate attacks based on analysis of the length of exchanged messages, by adding extra
padding to TLS records. However this extra padding has the following issues:
	<list style="numbers">
	<t>No other than the CBC ciphersuites can take advantage of padding to
	hide the length of the records.</t>
	<t>It is limited to 255 bytes.</t>
    <t>The plaintext is padded after it is authenticated, allowing for
	padding oracle attacks <xref target="CBCTIME"/><xref target="DTLS-ATTACK"/>.
    </t>
    </list>
      </t>
<t>
To overcome these limitations, the TLS
extension proposed in this document enables a new padding mechanism for
for both block and stream ciphers.
The proposed extension eliminates padding oracles (both in errors and timing)
that have been plaguing standard TLS block ciphers, without modifying
critical aspects of the protocol such as the order of encryption and
authentication.
         </t>
    </section>
    <section anchor="terms" title="Terminology">
      <t>
           This document uses the same notation and terminology used in the TLS
           and DTLS protocol specifications
           <xref target="RFC5246"/><xref target="RFC6347"/>.
	 </t>
      <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="paddingext" title="TLS Extension: Extended Record Padding">
<t>
The TLS extended record padding is a variant of the TLS record protocol where every record can be padded up to 2^14 bytes,
regardless of the cipher being used.
</t>

      <section anchor="extnegotiation" title="Extension Negotiation">
         <t>
   In order to indicate the support of the new record padding, clients MUST include an
           extension of type "extended_record_padding" to the extended client hello
           message.  The "extended_record_padding" TLS extension is assigned the value of TDB-BY-IANA from the TLS
           ExtensionType registry.  This value is used as the extension number 
           for the extensions in both the client hello message and the server hello message. 
           The hello extension mechanism is described in <xref target="RFC5246"/>.
        </t>

        <t>
   This extension carries no payload and indicates support for the extended record padding. 
   The "extension_data" field of this extension are of zero length in both the client and the server.
    </t>
    <t>
    The negotiated record padding applies for the duration of the session, including session resumption.
    A client wishing to resume a session where the extended record padding was negotiated SHOULD
    include the "extended_record_padding" extension in the client hello.
    </t>
        </section>

      <section anchor="recpayload" title="Record Payload">

	<t>
      The translation of the TLSCompressed structure into TLSCiphertext remains
      the same as in <xref target="RFC5246"/>.
      When the cipher is BulkCipherAlgorithm.null, the 'fragment' structure of
      TLSCiphertext also remains unchanged. That is, for the
      TLS_NULL_WITH_NULL_NULL ciphersuite and
      for MAC-only ciphersuites this extension has no effect.
      For all other ciphersuites, the 'fragment' structure of TLSCiphertext
      is modified as follows.

              <figure><artwork><![CDATA[
      stream-ciphered struct {
          opaque pad<0..2^14>;
          opaque content[TLSCompressed.length];
          opaque MAC[SecurityParameters.mac_length];
      } GenericStreamCipher;

      struct {
          opaque IV[SecurityParameters.record_iv_length];
          block-ciphered ciphered struct {
              opaque pad<0..2^14>;
              opaque content[TLSCompressed.length];
              opaque MAC[CipherSpec.hash_size];
          };
      } GenericBlockCipher;

      struct {
          opaque nonce_explicit[SecurityParameters.record_iv_length];
          aead-ciphered struct {
              opaque pad<0..2^14>;
              opaque content[TLSCompressed.length];
          };
      } GenericAEADCipher;
	       ]]></artwork></figure>
       </t>
       <t>
        The padding can be filled with arbitrary data, and it is authenticated as part
        of the MAC.
    	For block ciphers, the length of the pad MUST be such that the total length
    	(i.e., the pad, the content and the MAC) are a multiple of the block size.
       </t>
       <t>
       Note: In typical applications that take no steps to hide the length of the
       record and are not using block ciphers, the size of the pad will be
       zero.
       </t>
       <t>
   For the various ciphers the data are authenticated as follows.

       <list style="hanging">
       <t>Standard Stream Ciphers:
        <figure><artwork><![CDATA[
              MAC(MAC_write_key, seq_num +
                  TLSCompressed.type +
                  TLSCompressed.version +
                  length +
                  TLSCiphertext.fragment.GenericStreamCipher.pad +
                  TLSCompressed.fragment);
        ]]></artwork></figure>
       </t>

       <t>Block Ciphers:
        <figure><artwork><![CDATA[
              MAC(MAC_write_key, seq_num +
                  TLSCompressed.type +
                  TLSCompressed.version +
                  length +
                  TLSCiphertext.fragment.GenericBlockCipher.pad +
                  TLSCompressed.fragment);
        ]]></artwork></figure>
       </t>

       <t>AEAD Ciphers:
        <figure><artwork><![CDATA[
              additional_data = seq_num + TLSCompressed.type +
                                TLSCompressed.version + length;
              
              AEADEncrypted = AEAD-Encrypt(write_key, nonce,
                                           pad + plaintext,
                                           additional_data);
        ]]></artwork></figure>
       </t>
       </list>
       <list style="hanging" hangIndent="6">
       <t hangText="length">
         <vspace />
         For all the above cases, a uint16 containing the sum of the padding
         length and the content length.
       </t>
       </list>
       </t>

       <t>
       Implementation note: With block and stream ciphers, in order to avoid
       padding oracles, decryption, MAC verification and payload decoding
       MUST be executed in the following order.
       <list style="numbers">
       <t>Decrypt TLSCiphertext.fragment.</t>
<!--       <t>Split TLSCiphertext.fragment.MAC from the remaining
       TLSCiphertext.fragment</t>-->
       <t>Verify the MAC.</t>
       <t>Split plaintext from pad.</t>
       </list>
       </t>

        </section>
    </section>
    
    <section anchor="security" title="Security Considerations">
<t>
Since the padding is always included in the MAC computation, attacks that utilize the
CBC-padding timing channel (e.g., <xref target="DTLS-ATTACK"/>) are not applicable.
</t>
<t>
In a way, the extended record padding can be seen as a special way of encoding application data before encryption (where application data given by the user are prefixed by some padding).
Hence, previous security results on standard TLS block and stream ciphers still apply to the extended record padding.
</t>
</section>
    <section anchor="IANA" title="IANA Considerations">
      <t>
              This document defines a new TLS extension, "extended_record_padding", assigned
              a value of TBD-BY-IANA (the value 48015 is suggested) from the TLS
              ExtensionType registry defined in <xref target="RFC5246"/>.
              This value is used as the extension number for the extensions in both the client 
              hello message and the server hello message. 
          </t>
    </section>
  </middle>
  <back>
    <references title="Normative References"><!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml"?-->
	&TLS;

    <!--?rfc
    include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6347.xml"?-->
	&DTLS;

	<!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?-->
	&RFC2119;
	
	<reference anchor='DTLS-ATTACK'>
	<front>
	    <title>Plaintext-recovery attacks against datagram TLS.</title>
	    <author initials='N. J.' surname='Nadhem'
		    fullname='Nadhem J. AlFardan'>
	    </author>
	    <author initials='K. G.' surname='Paterson'
		    fullname='Kenneth G. Paterson'>
	    </author>

	    <date year='2012' />
	</front>
	<seriesInfo name="Network and Distributed System Security Symposium" value=""/>
	</reference>

	<reference anchor='CBCTIME'>
	<front>
	    <title>Password Interception in a SSL/TLS Channel</title>
	    <author initials='B.' surname='Canvel'
		    fullname='Brice Canvel'>
	    </author>
	    <author initials='A.' surname='Hiltgen'
		    fullname='Alain Hiltgen'>
	    </author>
	    <author initials='S.' surname='Vaudenay'
		    fullname='Serge Vaudenay'>
	    </author>
	    <author initials='M.' surname='Vuagnoux'
		    fullname='Martin Vuagnoux'>
	    </author>

	    <date year='2003' />
	</front>
	<seriesInfo name="Advances in Cryptology -- CRYPTO" value=""/>
	</reference>
	
   	  </references>
    <!--
   	  <references title="Informative References">
         
   	  </references>
   -->
      <section title="Acknowledgements">
      <t>
	 The authors wish to thank Kenny Paterson for his suggestions on improving this document.
      </t>
      </section>
  </back>
</rfc>
