Blame SOURCES/openssl-1.0.1e-cve-2013-6450.patch

2b5643
Fix DTLS retransmission from previous session.
2b5643
2b5643
For DTLS we might need to retransmit messages from the previous session
2b5643
so keep a copy of write context in DTLS retransmission buffers instead
2b5643
of replacing it after sending CCS. CVE-2013-6450.
2b5643
2b5643
diff --git a/ssl/d1_both.c b/ssl/d1_both.c
2b5643
index 65ec001..7a5596a 100644
2b5643
--- a/ssl/d1_both.c
2b5643
+++ b/ssl/d1_both.c
2b5643
@@ -214,6 +214,12 @@ dtls1_hm_fragment_new(unsigned long frag_len, int reassembly)
2b5643
 static void
2b5643
 dtls1_hm_fragment_free(hm_fragment *frag)
2b5643
 	{
2b5643
+
2b5643
+	if (frag->msg_header.is_ccs)
2b5643
+		{
2b5643
+		EVP_CIPHER_CTX_free(frag->msg_header.saved_retransmit_state.enc_write_ctx);
2b5643
+		EVP_MD_CTX_destroy(frag->msg_header.saved_retransmit_state.write_hash);
2b5643
+		}
2b5643
 	if (frag->fragment) OPENSSL_free(frag->fragment);
2b5643
 	if (frag->reassembly) OPENSSL_free(frag->reassembly);
2b5643
 	OPENSSL_free(frag);
2b5643
diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
2b5643
index 96ce9a7..e485907 100644
2b5643
--- a/ssl/ssl_locl.h
2b5643
+++ b/ssl/ssl_locl.h
2b5643
@@ -621,6 +621,8 @@ extern SSL3_ENC_METHOD TLSv1_enc_data;
2b5643
 extern SSL3_ENC_METHOD SSLv3_enc_data;
2b5643
 extern SSL3_ENC_METHOD DTLSv1_enc_data;
2b5643
 
2b5643
+#define SSL_IS_DTLS(s) (s->method->version == DTLS1_VERSION)
2b5643
+
2b5643
 #define IMPLEMENT_tls_meth_func(version, func_name, s_accept, s_connect, \
2b5643
 				s_get_meth) \
2b5643
 const SSL_METHOD *func_name(void)  \
2b5643
diff --git a/ssl/t1_enc.c b/ssl/t1_enc.c
2b5643
index 72015f5..56db834 100644
2b5643
--- a/ssl/t1_enc.c
2b5643
+++ b/ssl/t1_enc.c
2b5643
@@ -414,15 +414,20 @@ int tls1_change_cipher_state(SSL *s, int which)
2b5643
 			s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM;
2b5643
 			else
2b5643
 			s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM;
2b5643
-		if (s->enc_write_ctx != NULL)
2b5643
+		if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s))
2b5643
 			reuse_dd = 1;
2b5643
-		else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
2b5643
+		else if ((s->enc_write_ctx=EVP_CIPHER_CTX_new()) == NULL)
2b5643
 			goto err;
2b5643
-		else
2b5643
-			/* make sure it's intialized in case we exit later with an error */
2b5643
-			EVP_CIPHER_CTX_init(s->enc_write_ctx);
2b5643
 		dd= s->enc_write_ctx;
2b5643
-		mac_ctx = ssl_replace_hash(&s->write_hash,NULL);
2b5643
+		if (SSL_IS_DTLS(s))
2b5643
+			{
2b5643
+			mac_ctx = EVP_MD_CTX_create();
2b5643
+			if (!mac_ctx)
2b5643
+				goto err;
2b5643
+			s->write_hash = mac_ctx;
2b5643
+			}
2b5643
+		else
2b5643
+			mac_ctx = ssl_replace_hash(&s->write_hash,NULL);
2b5643
 #ifndef OPENSSL_NO_COMP
2b5643
 		if (s->compress != NULL)
2b5643
 			{
2b5643
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
2b5643
index 6fc469f..d14e8e4 100644
2b5643
--- a/crypto/evp/digest.c
2b5643
+++ b/crypto/evp/digest.c
2b5643
@@ -366,8 +366,11 @@ int EVP_Digest(const void *data, size_t count,
2b5643
 
2b5643
 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
2b5643
 	{
2b5643
-	EVP_MD_CTX_cleanup(ctx);
2b5643
-	OPENSSL_free(ctx);
2b5643
+	if (ctx)
2b5643
+		{
2b5643
+		EVP_MD_CTX_cleanup(ctx);
2b5643
+		OPENSSL_free(ctx);
2b5643
+		}
2b5643
 	}
2b5643
 
2b5643
 /* This call frees resources associated with the context */