From f59562ebd74d9b3a3f4b55a022f14f2aa4246ddd Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Fri, 13 Dec 2013 14:41:32 +0000 Subject: =?UTF-8?q?Backport=20TLS=20padding=20extension=20from=20master.=0A(?= =?UTF-8?q?cherry=20picked=20from=20commit=208c6d8c2a498146992123ef5407d7ba0?= =?UTF-8?q?1a1e7224d)?= Conflicts: CHANGES ssl/t1_lib.c (cherry picked from commit 4a55631e4dc76fb8d668218bf461c45a9abc5b94) Conflicts: CHANGES modified: ssl/t1_lib.c --- ssl/t1_lib.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c index e22ebbf..29ccd83 100644 --- a/ssl/t1_lib.c +++ b/ssl/t1_lib.c @@ -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; -- 1.7.9.5