Skip to content

Commit 410a49a

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 82ba68c commit 410a49a

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

ssl/s3_clnt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ int ssl3_connect(SSL *s)
491491
case SSL3_ST_CR_FINISHED_A:
492492
case SSL3_ST_CR_FINISHED_B:
493493

494+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
494495
ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
495496
SSL3_ST_CR_FINISHED_B);
496497
if (ret <= 0) goto end;
@@ -777,6 +778,7 @@ int ssl3_get_server_hello(SSL *s)
777778
SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
778779
goto f_err;
779780
}
781+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
780782
s->hit=1;
781783
}
782784
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
@@ -1166,6 +1166,15 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
11661166
goto f_err;
11671167
}
11681168

1169+
if (!(s->s3->flags & SSL3_FLAGS_CCS_OK))
1170+
{
1171+
al=SSL_AD_UNEXPECTED_MESSAGE;
1172+
SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_CCS_RECEIVED_EARLY);
1173+
goto f_err;
1174+
}
1175+
1176+
s->s3->flags &= ~SSL3_FLAGS_CCS_OK;
1177+
11691178
rr->length=0;
11701179

11711180
if (s->msg_callback)

ssl/s3_srvr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ int ssl3_accept(SSL *s)
523523
case SSL3_ST_SR_CERT_VRFY_A:
524524
case SSL3_ST_SR_CERT_VRFY_B:
525525

526+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
526527
/* we should decide if we expected this one */
527528
ret=ssl3_get_cert_verify(s);
528529
if (ret <= 0) goto end;
@@ -533,6 +534,7 @@ int ssl3_accept(SSL *s)
533534

534535
case SSL3_ST_SR_FINISHED_A:
535536
case SSL3_ST_SR_FINISHED_B:
537+
s->s3->flags |= SSL3_FLAGS_CCS_OK;
536538
ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
537539
SSL3_ST_SR_FINISHED_B);
538540
if (ret <= 0) goto end;

ssl/ssl3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ typedef struct ssl3_buffer_st
333333
#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
334334
#define SSL3_FLAGS_POP_BUFFER 0x0004
335335
#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
336+
#define SSL3_FLAGS_CCS_OK 0x0080
336337

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

0 commit comments

Comments
 (0)