Blame SOURCES/openssl-1.0.1e-cve-2015-0293.patch

96beb5
diff -up openssl-1.0.1e/ssl/s2_lib.c.ssl2-assert openssl-1.0.1e/ssl/s2_lib.c
96beb5
--- openssl-1.0.1e/ssl/s2_lib.c.ssl2-assert	2015-03-18 13:02:36.000000000 +0100
96beb5
+++ openssl-1.0.1e/ssl/s2_lib.c	2015-03-18 18:22:20.195322489 +0100
96beb5
@@ -488,7 +488,7 @@ int ssl2_generate_key_material(SSL *s)
96beb5
 
96beb5
 		OPENSSL_assert(s->session->master_key_length >= 0
96beb5
 		    && s->session->master_key_length
96beb5
-		    < (int)sizeof(s->session->master_key));
96beb5
+		    <= (int)sizeof(s->session->master_key));
96beb5
 		EVP_DigestUpdate(&ctx,s->session->master_key,s->session->master_key_length);
96beb5
 		EVP_DigestUpdate(&ctx,&c,1);
96beb5
 		c++;
96beb5
diff -up openssl-1.0.1e/ssl/s2_srvr.c.ssl2-assert openssl-1.0.1e/ssl/s2_srvr.c
96beb5
--- openssl-1.0.1e/ssl/s2_srvr.c.ssl2-assert	2013-02-11 16:26:04.000000000 +0100
96beb5
+++ openssl-1.0.1e/ssl/s2_srvr.c	2015-03-18 18:30:11.403974038 +0100
96beb5
@@ -446,9 +446,6 @@ static int get_client_master_key(SSL *s)
96beb5
 		SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_NO_PRIVATEKEY);
96beb5
 		return(-1);
96beb5
 		}
96beb5
-	i=ssl_rsa_private_decrypt(s->cert,s->s2->tmp.enc,
96beb5
-		&(p[s->s2->tmp.clear]),&(p[s->s2->tmp.clear]),
96beb5
-		(s->s2->ssl2_rollback)?RSA_SSLV23_PADDING:RSA_PKCS1_PADDING);
96beb5
 
96beb5
 	is_export=SSL_C_IS_EXPORT(s->session->cipher);
96beb5
 	
96beb5
@@ -467,21 +464,61 @@ static int get_client_master_key(SSL *s)
96beb5
 	else
96beb5
 		ek=5;
96beb5
 
96beb5
+	/*
96beb5
+	 * The format of the CLIENT-MASTER-KEY message is
96beb5
+	 * 1 byte message type
96beb5
+	 * 3 bytes cipher
96beb5
+	 * 2-byte clear key length (stored in s->s2->tmp.clear)
96beb5
+	 * 2-byte encrypted key length (stored in s->s2->tmp.enc)
96beb5
+	 * 2-byte key args length (IV etc)
96beb5
+	 * clear key
96beb5
+	 * encrypted key
96beb5
+	 * key args
96beb5
+	 *
96beb5
+	 * If the cipher is an export cipher, then the encrypted key bytes
96beb5
+	 * are a fixed portion of the total key (5 or 8 bytes). The size of
96beb5
+	 * this portion is in |ek|. If the cipher is not an export cipher,
96beb5
+	 * then the entire key material is encrypted (i.e., clear key length
96beb5
+	 * must be zero).
96beb5
+	 */
96beb5
+	 if ((!is_export && s->s2->tmp.clear != 0) ||
96beb5
+		(is_export && s->s2->tmp.clear + ek != EVP_CIPHER_key_length(c)))
96beb5
+		{
96beb5
+		ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
96beb5
+		SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_BAD_LENGTH);
96beb5
+		return -1;
96beb5
+		}
96beb5
+	/*
96beb5
+	 * The encrypted blob must decrypt to the encrypted portion of the key.
96beb5
+	 * Decryption can't be expanding, so if we don't have enough encrypted
96beb5
+	 * bytes to fit the key in the buffer, stop now.
96beb5
+	 */
96beb5
+	if ((is_export && s->s2->tmp.enc < ek) ||
96beb5
+		(!is_export && s->s2->tmp.enc < EVP_CIPHER_key_length(c)))
96beb5
+		{
96beb5
+		ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
96beb5
+		SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_LENGTH_TOO_SHORT);
96beb5
+		return -1;
96beb5
+		}
96beb5
+
96beb5
+	i = ssl_rsa_private_decrypt(s->cert, s->s2->tmp.enc,
96beb5
+		&(p[s->s2->tmp.clear]),
96beb5
+		&(p[s->s2->tmp.clear]),
96beb5
+		(s->s2->ssl2_rollback) ? RSA_SSLV23_PADDING : RSA_PKCS1_PADDING);
96beb5
+
96beb5
 	/* bad decrypt */
96beb5
 #if 1
96beb5
 	/* If a bad decrypt, continue with protocol but with a
96beb5
 	 * random master secret (Bleichenbacher attack) */
96beb5
-	if ((i < 0) ||
96beb5
-		((!is_export && (i != EVP_CIPHER_key_length(c)))
96beb5
-		|| (is_export && ((i != ek) || (s->s2->tmp.clear+(unsigned int)i !=
96beb5
-			(unsigned int)EVP_CIPHER_key_length(c))))))
96beb5
+	if ((i < 0) || ((!is_export && i != EVP_CIPHER_key_length(c))
96beb5
+		|| (is_export && i != ek)))
96beb5
 		{
96beb5
 		ERR_clear_error();
96beb5
 		if (is_export)
96beb5
 			i=ek;
96beb5
 		else
96beb5
 			i=EVP_CIPHER_key_length(c);
96beb5
-		if (RAND_pseudo_bytes(p,i) <= 0)
96beb5
+		if (RAND_pseudo_bytes(&p[s->s2->tmp.clear],i) <= 0)
96beb5
 			return 0;
96beb5
 		}
96beb5
 #else
96beb5
@@ -505,7 +542,8 @@ static int get_client_master_key(SSL *s)
96beb5
 		}
96beb5
 #endif
96beb5
 
96beb5
-	if (is_export) i+=s->s2->tmp.clear;
96beb5
+	if (is_export)
96beb5
+		i = EVP_CIPHER_key_length(c);
96beb5
 
96beb5
 	if (i > SSL_MAX_MASTER_KEY_LENGTH)
96beb5
 		{