1 diff -pu a/nss/lib/ssl/ssl3con.c b/nss/lib/ssl/ssl3con.c
2 --- a/nss/lib/ssl/ssl3con.c 2014-01-03 19:03:25.346656907 -0800
3 +++ b/nss/lib/ssl/ssl3con.c 2014-01-03 19:03:36.916845935 -0800
4 @@ -4987,6 +4987,7 @@ ssl3_SendClientHello(sslSocket *ss, PRBo
6 PRBool isTLS = PR_FALSE;
7 PRInt32 total_exten_len = 0;
8 + unsigned paddingExtensionLen;
9 unsigned numCompressionMethods;
12 @@ -5264,6 +5265,20 @@ ssl3_SendClientHello(sslSocket *ss, PRBo
13 length += 1 + ss->ssl3.hs.cookieLen;
16 + /* A padding extension may be included to ensure that the record containing
17 + * the ClientHello doesn't have a length between 256 and 511 bytes
18 + * (inclusive). Initial, ClientHello records with such lengths trigger bugs
21 + * This is not done for DTLS nor for renegotiation. */
22 + if (!IS_DTLS(ss) && isTLS && !ss->firstHsDone) {
23 + paddingExtensionLen = ssl3_CalculatePaddingExtensionLength(length);
24 + total_exten_len += paddingExtensionLen;
25 + length += paddingExtensionLen;
27 + paddingExtensionLen = 0;
30 rv = ssl3_AppendHandshakeHeader(ss, client_hello, length);
31 if (rv != SECSuccess) {
32 if (sid->u.ssl3.lock) { PR_RWLock_Unlock(sid->u.ssl3.lock); }
33 @@ -5398,6 +5413,13 @@ ssl3_SendClientHello(sslSocket *ss, PRBo
38 + extLen = ssl3_AppendPaddingExtension(ss, paddingExtensionLen, maxBytes);
44 PORT_Assert(!maxBytes);
47 diff -pu a/nss/lib/ssl/ssl3ext.c b/nss/lib/ssl/ssl3ext.c
48 --- a/nss/lib/ssl/ssl3ext.c 2014-01-03 18:58:03.661401846 -0800
49 +++ b/nss/lib/ssl/ssl3ext.c 2014-01-03 19:03:36.916845935 -0800
50 @@ -2315,3 +2315,56 @@ ssl3_ClientSendSigAlgsXtn(sslSocket * ss
56 +ssl3_CalculatePaddingExtensionLength(unsigned int clientHelloLength)
58 + unsigned int recordLength = 1 /* handshake message type */ +
59 + 3 /* handshake message length */ +
61 + unsigned int extensionLength;
63 + if (recordLength < 256 || recordLength >= 512) {
67 + extensionLength = 512 - recordLength;
68 + /* Extensions take at least four bytes to encode. */
69 + if (extensionLength < 4) {
70 + extensionLength = 4;
73 + return extensionLength;
76 +/* ssl3_AppendPaddingExtension possibly adds an extension which ensures that a
77 + * ClientHello record is either < 256 bytes or is >= 512 bytes. This ensures
78 + * that we don't trigger bugs in F5 products. */
80 +ssl3_AppendPaddingExtension(sslSocket *ss, unsigned int extensionLen,
83 + unsigned int paddingLen = extensionLen - 4;
84 + unsigned char padding[256];
86 + if (extensionLen == 0) {
90 + if (extensionLen < 4 ||
91 + extensionLen > maxBytes ||
92 + paddingLen > sizeof(padding)) {
97 + if (SECSuccess != ssl3_AppendHandshakeNumber(ss, ssl_padding_xtn, 2))
99 + if (SECSuccess != ssl3_AppendHandshakeNumber(ss, paddingLen, 2))
101 + memset(padding, 0, paddingLen);
102 + if (SECSuccess != ssl3_AppendHandshake(ss, padding, paddingLen))
105 + return extensionLen;
107 diff -pu a/nss/lib/ssl/sslimpl.h b/nss/lib/ssl/sslimpl.h
108 --- a/nss/lib/ssl/sslimpl.h 2014-01-03 19:03:25.346656907 -0800
109 +++ b/nss/lib/ssl/sslimpl.h 2014-01-03 19:03:36.916845935 -0800
110 @@ -237,6 +237,13 @@ extern PRInt32
111 ssl3_CallHelloExtensionSenders(sslSocket *ss, PRBool append, PRUint32 maxBytes,
112 const ssl3HelloExtensionSender *sender);
115 +ssl3_CalculatePaddingExtensionLength(unsigned int clientHelloLength);
118 +ssl3_AppendPaddingExtension(sslSocket *ss, unsigned int extensionLen,
119 + PRUint32 maxBytes);
122 struct sslSocketOpsStr {
123 int (*connect) (sslSocket *, const PRNetAddr *);
124 diff -pu a/nss/lib/ssl/sslt.h b/nss/lib/ssl/sslt.h
125 --- a/nss/lib/ssl/sslt.h 2014-01-03 19:02:30.135754914 -0800
126 +++ b/nss/lib/ssl/sslt.h 2014-01-03 19:03:36.916845935 -0800
127 @@ -205,9 +205,10 @@ typedef enum {
128 ssl_session_ticket_xtn = 35,
129 ssl_next_proto_nego_xtn = 13172,
130 ssl_channel_id_xtn = 30032,
131 + ssl_padding_xtn = 35655,
132 ssl_renegotiation_info_xtn = 0xff01 /* experimental number */
135 -#define SSL_MAX_EXTENSIONS 11
136 +#define SSL_MAX_EXTENSIONS 11 /* doesn't include ssl_padding_xtn. */
138 #endif /* __sslt_h_ */