Backport TLS padding extension from master.
authorDr. Stephen Henson <steve@openssl.org>
Fri, 13 Dec 2013 14:41:32 +0000 (14:41 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 5 Feb 2014 15:42:04 +0000 (15:42 +0000)
(cherry picked from commit 8c6d8c2a498146992123ef5407d7ba01a1e7224d)

Conflicts:

CHANGES
ssl/t1_lib.c

CHANGES
ssl/t1_lib.c

diff --git a/CHANGES b/CHANGES
index f6fabf9380f42df03d1928877c8134a5084721cf..58ac884d80907e14a918380d5b4d4211dce11c7e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,24 @@
 
  Changes between 1.0.1f and 1.0.1g [xx XXX xxxx]
 
-  *)
+  *) TLS pad extension: draft-agl-tls-padding-02
+
+     Workaround for the "TLS hang bug" (see FAQ and PR#2771): if the
+     TLS client Hello record length value would otherwise be > 255 and
+     less that 512 pad with a dummy extension containing zeroes so it
+     is at least 512 bytes long.
+
+     To enable it use an unused extension number (for example chrome uses
+     35655) using:
+
+     e.g. -DTLSEXT_TYPE_padding=35655
+
+     Since the extension is ignored the actual number doesn't matter as long
+     as it doesn't clash with any existing extension.
+
+     This will be updated when the extension gets an official number.
+
+     [Adam Langley, Steve Henson]
 
  Changes between 1.0.1e and 1.0.1f [6 Jan 2014]
 
index e22ebbff855ab8911c975374621abfbc0bf4bfa7..29ccd833ec06eb36c64163209c99885694de6ff2 100644 (file)
@@ -662,6 +662,36 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
                 }
 #endif
 
+#ifdef TLSEXT_TYPE_padding
+       /* Add padding to workaround bugs in F5 terminators.
+        * See https://tools.ietf.org/html/draft-agl-tls-padding-02
+        *
+        * NB: because this code works out the length of all existing
+        * extensions it MUST always appear last.
+        */
+       {
+       int hlen = ret - (unsigned char *)s->init_buf->data;
+       /* The code in s23_clnt.c to build ClientHello messages includes the
+        * 5-byte record header in the buffer, while the code in s3_clnt.c does
+        * not. */
+       if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
+               hlen -= 5;
+       if (hlen > 0xff && hlen < 0x200)
+               {
+               hlen = 0x200 - hlen;
+               if (hlen >= 4)
+                       hlen -= 4;
+               else
+                       hlen = 0;
+
+               s2n(TLSEXT_TYPE_padding, ret);
+               s2n(hlen, ret);
+               memset(ret, 0, hlen);
+               ret += hlen;
+               }
+       }
+#endif
+
        if ((extdatalen = ret-p-2)== 0) 
                return p;