From 0647719d809abdfe6b871949f4f75ce82da6616a Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 22 Jul 2016 14:58:19 +0100 Subject: [PATCH] Make the checks for an SSLv2 style record stricter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit SSLv2 is no longer supported in 1.1.0, however we *do* still accept an SSLv2 style ClientHello, as long as we then subsequently negotiate a protocol version >= SSLv3. The record format for SSLv2 style ClientHellos is quite different to SSLv3+. We only accept this format in the first record of an initial ClientHello. Previously we checked this by confirming s->first_packet is set and s->server is true. However, this really only tells us that we are dealing with an initial ClientHello, not that it is the first record (s->first_packet is badly named...it really means this is the first message). To check this is the first record of the initial ClientHello we should also check that we've not received any data yet (s->init_num == 0), and that we've not had any empty records. GitHub Issue #1298 Reviewed-by: Emilia Käsper --- ssl/record/ssl3_record.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c index b4d89811fe..ad240bc52d 100644 --- a/ssl/record/ssl3_record.c +++ b/ssl/record/ssl3_record.c @@ -160,12 +160,18 @@ int ssl3_get_record(SSL *s) /* * Check whether this is a regular record or an SSLv2 style record. - * The latter is only used in an initial ClientHello for old - * clients. We check s->read_hash and s->enc_read_ctx to ensure this - * does not apply during renegotiation + * The latter can only be used in the first record of an initial + * ClientHello for old clients. Initial ClientHello means + * s->first_packet is set and s->server is true. The first record + * means we've not received any data so far (s->init_num == 0) and + * have had no empty records. We check s->read_hash and + * s->enc_read_ctx to ensure this does not apply during + * renegotiation. */ - if (s->first_packet && s->server && !s->read_hash - && !s->enc_read_ctx + if (s->first_packet && s->server + && s->init_num == 0 + && RECORD_LAYER_get_empty_record_count(&s->rlayer) == 0 + && s->read_hash == NULL && s->enc_read_ctx == NULL && (p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) { /* * SSLv2 style record -- 2.25.1