Blame SOURCES/openssl-1.0.1e-cve-2014-0224.patch

ff4ef5
diff -up openssl-1.0.1e/ssl/ssl3.h.keying-mitm openssl-1.0.1e/ssl/ssl3.h
ff4ef5
--- openssl-1.0.1e/ssl/ssl3.h.keying-mitm	2014-06-02 19:48:04.518100562 +0200
ff4ef5
+++ openssl-1.0.1e/ssl/ssl3.h	2014-06-02 19:48:04.642103429 +0200
ff4ef5
@@ -388,6 +388,7 @@ typedef struct ssl3_buffer_st
ff4ef5
 #define TLS1_FLAGS_TLS_PADDING_BUG		0x0008
ff4ef5
 #define TLS1_FLAGS_SKIP_CERT_VERIFY		0x0010
ff4ef5
 #define TLS1_FLAGS_KEEP_HANDSHAKE		0x0020
ff4ef5
+#define SSL3_FLAGS_CCS_OK			0x0080
ff4ef5
  
ff4ef5
 /* SSL3_FLAGS_SGC_RESTART_DONE is set when we
ff4ef5
  * restart a handshake because of MS SGC and so prevents us
ff4ef5
diff -up openssl-1.0.1e/ssl/s3_clnt.c.keying-mitm openssl-1.0.1e/ssl/s3_clnt.c
ff4ef5
--- openssl-1.0.1e/ssl/s3_clnt.c.keying-mitm	2013-02-11 16:26:04.000000000 +0100
ff4ef5
+++ openssl-1.0.1e/ssl/s3_clnt.c	2014-06-02 19:49:57.042701985 +0200
83c29f
@@ -510,6 +510,7 @@ int ssl3_connect(SSL *s)
83c29f
 				s->method->ssl3_enc->client_finished_label,
83c29f
 				s->method->ssl3_enc->client_finished_label_len);
83c29f
 			if (ret <= 0) goto end;
83c29f
+			s->s3->flags |= SSL3_FLAGS_CCS_OK;
83c29f
 			s->state=SSL3_ST_CW_FLUSH;
83c29f
 
83c29f
 			/* clear flags */
83c29f
@@ -559,6 +560,7 @@ int ssl3_connect(SSL *s)
ff4ef5
 		case SSL3_ST_CR_FINISHED_A:
ff4ef5
 		case SSL3_ST_CR_FINISHED_B:
ff4ef5
 
ff4ef5
+			s->s3->flags |= SSL3_FLAGS_CCS_OK;
ff4ef5
 			ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
ff4ef5
 				SSL3_ST_CR_FINISHED_B);
ff4ef5
 			if (ret <= 0) goto end;
83c29f
@@ -901,6 +903,7 @@ int ssl3_get_server_hello(SSL *s)
83c29f
 			{
83c29f
 			s->session->cipher = pref_cipher ?
83c29f
 				pref_cipher : ssl_get_cipher_by_char(s, p+j);
83c29f
+			s->s3->flags |= SSL3_FLAGS_CCS_OK;
83c29f
 			}
83c29f
 		}
83c29f
 #endif /* OPENSSL_NO_TLSEXT */
83c29f
@@ -916,6 +918,7 @@ int ssl3_get_server_hello(SSL *s)
ff4ef5
 		SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
ff4ef5
 		goto f_err;
ff4ef5
 		}
ff4ef5
+	    s->s3->flags |= SSL3_FLAGS_CCS_OK;
ff4ef5
 	    s->hit=1;
ff4ef5
 	    }
ff4ef5
 	else	/* a miss or crap from the other end */
ff4ef5
diff -up openssl-1.0.1e/ssl/s3_pkt.c.keying-mitm openssl-1.0.1e/ssl/s3_pkt.c
ff4ef5
--- openssl-1.0.1e/ssl/s3_pkt.c.keying-mitm	2014-06-02 19:48:04.640103383 +0200
ff4ef5
+++ openssl-1.0.1e/ssl/s3_pkt.c	2014-06-02 19:48:04.643103452 +0200
ff4ef5
@@ -1298,6 +1298,15 @@ start:
ff4ef5
 			goto f_err;
ff4ef5
 			}
ff4ef5
 
ff4ef5
+		if (!(s->s3->flags & SSL3_FLAGS_CCS_OK))
ff4ef5
+			{
ff4ef5
+			al=SSL_AD_UNEXPECTED_MESSAGE;
ff4ef5
+			SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_CCS_RECEIVED_EARLY);
ff4ef5
+			goto f_err;
ff4ef5
+			}
ff4ef5
+
ff4ef5
+		s->s3->flags &= ~SSL3_FLAGS_CCS_OK;
ff4ef5
+
ff4ef5
 		rr->length=0;
ff4ef5
 
ff4ef5
 		if (s->msg_callback)
ff4ef5
@@ -1432,7 +1441,7 @@ int ssl3_do_change_cipher_spec(SSL *s)
ff4ef5
 
ff4ef5
 	if (s->s3->tmp.key_block == NULL)
ff4ef5
 		{
ff4ef5
-		if (s->session == NULL) 
ff4ef5
+		if (s->session == NULL || s->session->master_key_length == 0)
ff4ef5
 			{
ff4ef5
 			/* might happen if dtls1_read_bytes() calls this */
ff4ef5
 			SSLerr(SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC,SSL_R_CCS_RECEIVED_EARLY);
ff4ef5
diff -up openssl-1.0.1e/ssl/s3_srvr.c.keying-mitm openssl-1.0.1e/ssl/s3_srvr.c
ff4ef5
--- openssl-1.0.1e/ssl/s3_srvr.c.keying-mitm	2014-06-02 19:48:04.630103151 +0200
ff4ef5
+++ openssl-1.0.1e/ssl/s3_srvr.c	2014-06-02 19:48:04.643103452 +0200
ff4ef5
@@ -673,6 +673,7 @@ int ssl3_accept(SSL *s)
ff4ef5
 		case SSL3_ST_SR_CERT_VRFY_A:
ff4ef5
 		case SSL3_ST_SR_CERT_VRFY_B:
ff4ef5
 
ff4ef5
+			s->s3->flags |= SSL3_FLAGS_CCS_OK;
ff4ef5
 			/* we should decide if we expected this one */
ff4ef5
 			ret=ssl3_get_cert_verify(s);
ff4ef5
 			if (ret <= 0) goto end;
ff4ef5
@@ -700,6 +701,7 @@ int ssl3_accept(SSL *s)
ff4ef5
 
ff4ef5
 		case SSL3_ST_SR_FINISHED_A:
ff4ef5
 		case SSL3_ST_SR_FINISHED_B:
ff4ef5
+			s->s3->flags |= SSL3_FLAGS_CCS_OK;
ff4ef5
 			ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
ff4ef5
 				SSL3_ST_SR_FINISHED_B);
ff4ef5
 			if (ret <= 0) goto end;
ff4ef5
@@ -770,7 +772,10 @@ int ssl3_accept(SSL *s)
ff4ef5
 				s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
ff4ef5
 #else
ff4ef5
 				if (s->s3->next_proto_neg_seen)
ff4ef5
+					{
ff4ef5
+					s->s3->flags |= SSL3_FLAGS_CCS_OK;
ff4ef5
 					s->s3->tmp.next_state=SSL3_ST_SR_NEXT_PROTO_A;
ff4ef5
+					}
ff4ef5
 				else
ff4ef5
 					s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
ff4ef5
 #endif