diff options
author | davidben@chromium.org <davidben@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c> | 2014-05-01 23:35:34 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c> | 2014-05-01 23:35:34 +0000 |
commit | 152164bc423807c6945662c94d724554a027eeca (patch) | |
tree | 229a1fcedb338566b8baf68a5e5f4cc1e88e7515 | |
parent | 176b84dd04aaadd8b6ec29d285ef7234c9fb1e85 (diff) | |
download | openssl-152164bc423807c6945662c94d724554a027eeca.tar.gz |
Tidy up OpenSSL padding extension code.
Add (redundant because of SSL3_RT_MAX_PLAIN_LENGTH) length check,
don't pad DTLS, and move the SSL23 special case closer to the SSL23
code.
BUG=none
Review URL: https://codereview.chromium.org/242453005
git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/openssl@267663 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
-rw-r--r-- | README.chromium | 4 | ||||
-rw-r--r-- | openssl/ssl/d1_clnt.c | 2 | ||||
-rw-r--r-- | openssl/ssl/s23_clnt.c | 11 | ||||
-rw-r--r-- | openssl/ssl/s3_clnt.c | 4 | ||||
-rw-r--r-- | openssl/ssl/ssl_locl.h | 2 | ||||
-rw-r--r-- | openssl/ssl/t1_lib.c | 39 | ||||
-rw-r--r-- | patches.chromium/0012-paddingext2.patch | 137 |
7 files changed, 172 insertions, 27 deletions
diff --git a/README.chromium b/README.chromium index dcc03de..30df8b5 100644 --- a/README.chromium +++ b/README.chromium @@ -192,6 +192,10 @@ located in patches.chromium/. Currently this consists of: chacha.patch Add support for ChaCha20+Poly1305 cipher suites. + paddingext.patch + paddingext2.patch + Add ClientHello padding to workaround bug in F5 terminators. + stricter_cutthrough.patch Requires NPN and a PFS cipher suite to enable cut-through (false start) on the client. diff --git a/openssl/ssl/d1_clnt.c b/openssl/ssl/d1_clnt.c index 7e8077e..735e544 100644 --- a/openssl/ssl/d1_clnt.c +++ b/openssl/ssl/d1_clnt.c @@ -874,7 +874,7 @@ int dtls1_client_hello(SSL *s) *(p++)=0; /* Add the NULL method */ #ifndef OPENSSL_NO_TLSEXT - if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) + if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, 0)) == NULL) { SSLerr(SSL_F_DTLS1_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); goto err; diff --git a/openssl/ssl/s23_clnt.c b/openssl/ssl/s23_clnt.c index 08ee86d..750d208 100644 --- a/openssl/ssl/s23_clnt.c +++ b/openssl/ssl/s23_clnt.c @@ -467,9 +467,9 @@ static int ssl23_client_hello(SSL *s) /* create Client Hello in SSL 3.0/TLS 1.0 format */ /* do the record header (5 bytes) and handshake message - * header (4 bytes) last. Note: the code to add the - * padding extension in t1_lib.c depends on the size of - * this prefix. */ + * header (4 bytes) last. Note: the final argument to + * ssl_add_clienthello_tlsext below depends on the size + * of this prefix. */ d = p = &(buf[9]); *(p++) = version_major; @@ -526,7 +526,10 @@ static int ssl23_client_hello(SSL *s) SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT); return -1; } - if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) + /* The buffer includes the 5 byte record header, so + * subtract it to compute hlen for + * ssl_add_clienthello_tlsext. */ + if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, p-buf-5)) == NULL) { SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); return -1; diff --git a/openssl/ssl/s3_clnt.c b/openssl/ssl/s3_clnt.c index d1b3224..640df80 100644 --- a/openssl/ssl/s3_clnt.c +++ b/openssl/ssl/s3_clnt.c @@ -759,7 +759,7 @@ int ssl3_client_hello(SSL *s) goto err; /* Do the message type and length last. - * Note: the code to add the padding extension in t1_lib.c + * Note: the final argument to ssl_add_clienthello_tlsext below * depends on the size of this prefix. */ d=p= &(buf[4]); @@ -867,7 +867,7 @@ int ssl3_client_hello(SSL *s) SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT); goto err; } - if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) + if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, p-buf)) == NULL) { SSLerr(SSL_F_SSL3_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); goto err; diff --git a/openssl/ssl/ssl_locl.h b/openssl/ssl/ssl_locl.h index 4e27d9e..531a291 100644 --- a/openssl/ssl/ssl_locl.h +++ b/openssl/ssl/ssl_locl.h @@ -1127,7 +1127,7 @@ int tls1_ec_nid2curve_id(int nid); #endif /* OPENSSL_NO_EC */ #ifndef OPENSSL_NO_TLSEXT -unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit); +unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, size_t header_len); unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit); int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); diff --git a/openssl/ssl/t1_lib.c b/openssl/ssl/t1_lib.c index a53d56b..3fe6612 100644 --- a/openssl/ssl/t1_lib.c +++ b/openssl/ssl/t1_lib.c @@ -341,7 +341,10 @@ int tls12_get_req_sig_algs(SSL *s, unsigned char *p) return (int)slen; } -unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit) +/* header_len is the length of the ClientHello header written so far, used to + * compute padding. It does not include the record header. Pass 0 if no padding + * is to be done. */ +unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, size_t header_len) { int extdatalen=0; unsigned char *orig = buf; @@ -664,27 +667,25 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned c /* Add padding to workaround bugs in F5 terminators. * See https://tools.ietf.org/html/draft-agl-tls-padding-02 */ - { - 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) + if (header_len > 0) { - hlen = 0x200 - hlen; - if (hlen >= 4) - hlen -= 4; - else - hlen = 0; + header_len += ret - orig; + if (header_len > 0xff && header_len < 0x200) + { + size_t padding_len = 0x200 - header_len; + if (padding_len >= 4) + padding_len -= 4; + else + padding_len = 0; + if (limit - ret - 4 - (long)padding_len < 0) + return NULL; - s2n(TLSEXT_TYPE_padding, ret); - s2n(hlen, ret); - memset(ret, 0, hlen); - ret += hlen; + s2n(TLSEXT_TYPE_padding, ret); + s2n(padding_len, ret); + memset(ret, 0, padding_len); + ret += padding_len; + } } - } if ((extdatalen = ret-orig-2)== 0) diff --git a/patches.chromium/0012-paddingext2.patch b/patches.chromium/0012-paddingext2.patch new file mode 100644 index 0000000..cb7652a --- /dev/null +++ b/patches.chromium/0012-paddingext2.patch @@ -0,0 +1,137 @@ +diff --git android-openssl.orig/ssl/d1_clnt.c android-openssl/ssl/d1_clnt.c +index 7e8077e..735e544 100644 +--- android-openssl.orig/ssl/d1_clnt.c ++++ android-openssl/ssl/d1_clnt.c +@@ -874,7 +874,7 @@ int dtls1_client_hello(SSL *s) + *(p++)=0; /* Add the NULL method */ + + #ifndef OPENSSL_NO_TLSEXT +- if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) ++ if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, 0)) == NULL) + { + SSLerr(SSL_F_DTLS1_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); + goto err; +diff --git android-openssl.orig/ssl/s23_clnt.c android-openssl/ssl/s23_clnt.c +index 08ee86d..750d208 100644 +--- android-openssl.orig/ssl/s23_clnt.c ++++ android-openssl/ssl/s23_clnt.c +@@ -467,9 +467,9 @@ static int ssl23_client_hello(SSL *s) + /* create Client Hello in SSL 3.0/TLS 1.0 format */ + + /* do the record header (5 bytes) and handshake message +- * header (4 bytes) last. Note: the code to add the +- * padding extension in t1_lib.c depends on the size of +- * this prefix. */ ++ * header (4 bytes) last. Note: the final argument to ++ * ssl_add_clienthello_tlsext below depends on the size ++ * of this prefix. */ + d = p = &(buf[9]); + + *(p++) = version_major; +@@ -526,7 +526,10 @@ static int ssl23_client_hello(SSL *s) + SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT); + return -1; + } +- if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) ++ /* The buffer includes the 5 byte record header, so ++ * subtract it to compute hlen for ++ * ssl_add_clienthello_tlsext. */ ++ if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, p-buf-5)) == NULL) + { + SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); + return -1; +diff --git android-openssl.orig/ssl/s3_clnt.c android-openssl/ssl/s3_clnt.c +index d1b3224..640df80 100644 +--- android-openssl.orig/ssl/s3_clnt.c ++++ android-openssl/ssl/s3_clnt.c +@@ -759,7 +759,7 @@ int ssl3_client_hello(SSL *s) + goto err; + + /* Do the message type and length last. +- * Note: the code to add the padding extension in t1_lib.c ++ * Note: the final argument to ssl_add_clienthello_tlsext below + * depends on the size of this prefix. */ + d=p= &(buf[4]); + +@@ -867,7 +867,7 @@ int ssl3_client_hello(SSL *s) + SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_CLIENTHELLO_TLSEXT); + goto err; + } +- if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH)) == NULL) ++ if ((p = ssl_add_clienthello_tlsext(s, p, buf+SSL3_RT_MAX_PLAIN_LENGTH, p-buf)) == NULL) + { + SSLerr(SSL_F_SSL3_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); + goto err; +diff --git android-openssl.orig/ssl/ssl_locl.h android-openssl/ssl/ssl_locl.h +index 4e27d9e..531a291 100644 +--- android-openssl.orig/ssl/ssl_locl.h ++++ android-openssl/ssl/ssl_locl.h +@@ -1127,7 +1127,7 @@ int tls1_ec_nid2curve_id(int nid); + #endif /* OPENSSL_NO_EC */ + + #ifndef OPENSSL_NO_TLSEXT +-unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit); ++unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, size_t header_len); + unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit); + int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); + int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al); +diff --git android-openssl.orig/ssl/t1_lib.c android-openssl/ssl/t1_lib.c +index a53d56b..3fe6612 100644 +--- android-openssl.orig/ssl/t1_lib.c ++++ android-openssl/ssl/t1_lib.c +@@ -341,7 +341,10 @@ int tls12_get_req_sig_algs(SSL *s, unsigned char *p) + return (int)slen; + } + +-unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit) ++/* header_len is the length of the ClientHello header written so far, used to ++ * compute padding. It does not include the record header. Pass 0 if no padding ++ * is to be done. */ ++unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, size_t header_len) + { + int extdatalen=0; + unsigned char *orig = buf; +@@ -664,27 +667,25 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned c + + /* Add padding to workaround bugs in F5 terminators. + * See https://tools.ietf.org/html/draft-agl-tls-padding-02 */ +- { +- 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) ++ if (header_len > 0) + { +- hlen = 0x200 - hlen; +- if (hlen >= 4) +- hlen -= 4; +- else +- hlen = 0; ++ header_len += ret - orig; ++ if (header_len > 0xff && header_len < 0x200) ++ { ++ size_t padding_len = 0x200 - header_len; ++ if (padding_len >= 4) ++ padding_len -= 4; ++ else ++ padding_len = 0; ++ if (limit - ret - 4 - (long)padding_len < 0) ++ return NULL; + +- s2n(TLSEXT_TYPE_padding, ret); +- s2n(hlen, ret); +- memset(ret, 0, hlen); +- ret += hlen; ++ s2n(TLSEXT_TYPE_padding, ret); ++ s2n(padding_len, ret); ++ memset(ret, 0, padding_len); ++ ret += padding_len; ++ } + } +- } + + + if ((extdatalen = ret-orig-2)== 0) |