Skip to content

Commit bc8923b

Browse files
committed
Fix for CVE-2014-0224
Only accept change cipher spec when it is expected instead of at any time. This prevents premature setting of session keys before the master secret is determined which an attacker could use as a MITM attack. Thanks to KIKUCHI Masashi (Lepidum Co. Ltd.) for reporting this issue and providing the initial fix this patch is based on.
1 parent 1632ef7 commit bc8923b

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

ssl/s3_clnt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ int ssl3_connect(SSL *s)
559559
case SSL3_ST_CR_FINISHED_A:
560560
case SSL3_ST_CR_FINISHED_B:
561561

562+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
562563
ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
563564
SSL3_ST_CR_FINISHED_B);
564565
if (ret <= 0) goto end;
@@ -915,6 +916,7 @@ int ssl3_get_server_hello(SSL *s)
915916
SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
916917
goto f_err;
917918
}
919+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
918920
s->hit=1;
919921
}
920922
else /* a miss or crap from the other end */

ssl/s3_pkt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,15 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
13161316
goto f_err;
13171317
}
13181318

1319+
if (!(s->s3->flags & SSL3_FLAGS_CCS_OK))
1320+
{
1321+
al=SSL_AD_UNEXPECTED_MESSAGE;
1322+
SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_CCS_RECEIVED_EARLY);
1323+
goto f_err;
1324+
}
1325+
1326+
s->s3->flags &= ~SSL3_FLAGS_CCS_OK;
1327+
13191328
rr->length=0;
13201329

13211330
if (s->msg_callback)

ssl/s3_srvr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ int ssl3_accept(SSL *s)
673673
case SSL3_ST_SR_CERT_VRFY_A:
674674
case SSL3_ST_SR_CERT_VRFY_B:
675675

676+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
676677
/* we should decide if we expected this one */
677678
ret=ssl3_get_cert_verify(s);
678679
if (ret <= 0) goto end;
@@ -700,6 +701,7 @@ int ssl3_accept(SSL *s)
700701

701702
case SSL3_ST_SR_FINISHED_A:
702703
case SSL3_ST_SR_FINISHED_B:
704+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
703705
ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
704706
SSL3_ST_SR_FINISHED_B);
705707
if (ret <= 0) goto end;
@@ -770,7 +772,10 @@ int ssl3_accept(SSL *s)
770772
s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
771773
#else
772774
if (s->s3->next_proto_neg_seen)
775+
{
776+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
773777
s->s3->tmp.next_state=SSL3_ST_SR_NEXT_PROTO_A;
778+
}
774779
else
775780
s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
776781
#endif

ssl/ssl3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ typedef struct ssl3_buffer_st
388388
#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
389389
#define TLS1_FLAGS_SKIP_CERT_VERIFY 0x0010
390390
#define TLS1_FLAGS_KEEP_HANDSHAKE 0x0020
391+
#define SSL3_FLAGS_CCS_OK 0x0080
391392

392393
/* SSL3_FLAGS_SGC_RESTART_DONE is set when we
393394
* restart a handshake because of MS SGC and so prevents us

0 commit comments

Comments
 (0)