mturk / rpms / openssl

Forked from rpms/openssl 3 years ago
Clone
ba40f6b
*) Avoid PKCS #1 v1.5 signature attack discovered by Daniel Bleichenbacher
ba40f6b
(CVE-2006-4339)  [Ben Laurie; Google Security Team]
ba40f6b
openssl/crypto/rsa/rsa.h     1.55.2.4 -> 1.55.2.5
ba40f6b
ba40f6b
--- openssl/crypto/rsa/rsa.h 2006/01/09 16:05:18 1.55.2.4
ba40f6b
+++ openssl/crypto/rsa/rsa.h 2006/09/05 08:25:42 1.55.2.5
ba40f6b
@@ -412,6 +412,7 @@
ba40f6b
 #define RSA_R_N_DOES_NOT_EQUAL_P_Q			 127
ba40f6b
 #define RSA_R_OAEP_DECODING_ERROR			 121
ba40f6b
 #define RSA_R_PADDING_CHECK_FAILED			 114
ba40f6b
+#define RSA_R_PKCS1_PADDING_TOO_SHORT			 105
ba40f6b
 #define RSA_R_P_NOT_PRIME				 128
ba40f6b
 #define RSA_R_Q_NOT_PRIME				 129
ba40f6b
 #define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED		 130
ba40f6b
ba40f6b
openssl/crypto/rsa/rsa_eay.c     1.46.2.4 -> 1.46.2.5
ba40f6b
ba40f6b
--- openssl/crypto/rsa/rsa_eay.c 2006/06/14 08:51:40 1.46.2.4
ba40f6b
+++ openssl/crypto/rsa/rsa_eay.c 2006/09/05 08:25:42 1.46.2.5
ba40f6b
@@ -640,6 +640,15 @@
ba40f6b
 		{
ba40f6b
 	case RSA_PKCS1_PADDING:
ba40f6b
 		r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
ba40f6b
+		/* Generally signatures should be at least 2/3 padding, though
ba40f6b
+		   this isn't possible for really short keys and some standard
ba40f6b
+		   signature schemes, so don't check if the unpadded data is
ba40f6b
+		   small. */
ba40f6b
+		if(r > 42 && 3*8*r >= BN_num_bits(rsa->n))
ba40f6b
+			{
ba40f6b
+			RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_PKCS1_PADDING_TOO_SHORT);
ba40f6b
+			goto err;
ba40f6b
+			}
ba40f6b
 		break;
ba40f6b
 	case RSA_X931_PADDING:
ba40f6b
 		r=RSA_padding_check_X931(to,num,buf,i,num);
ba40f6b
ba40f6b
openssl/crypto/rsa/rsa_err.c     1.17.2.3 -> 1.17.2.4
ba40f6b
ba40f6b
--- openssl/crypto/rsa/rsa_err.c 2006/01/09 16:05:18 1.17.2.3
ba40f6b
+++ openssl/crypto/rsa/rsa_err.c 2006/09/05 08:25:42 1.17.2.4
ba40f6b
@@ -142,6 +142,7 @@
ba40f6b
 {ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q)  ,"n does not equal p q"},
ba40f6b
 {ERR_REASON(RSA_R_OAEP_DECODING_ERROR)   ,"oaep decoding error"},
ba40f6b
 {ERR_REASON(RSA_R_PADDING_CHECK_FAILED)  ,"padding check failed"},
ba40f6b
+{ERR_REASON(RSA_R_PKCS1_PADDING_TOO_SHORT),"pkcs1 padding too short"},
ba40f6b
 {ERR_REASON(RSA_R_P_NOT_PRIME)           ,"p not prime"},
ba40f6b
 {ERR_REASON(RSA_R_Q_NOT_PRIME)           ,"q not prime"},
ba40f6b
 {ERR_REASON(RSA_R_RSA_OPERATIONS_NOT_SUPPORTED),"rsa operations not supported"},
ba40f6b
ba40f6b
openssl/crypto/rsa/rsa_sign.c     1.21 -> 1.21.2.1
ba40f6b
ba40f6b
--- openssl/crypto/rsa/rsa_sign.c 2005/04/26 22:07:17 1.21
ba40f6b
+++ openssl/crypto/rsa/rsa_sign.c 2006/09/05 08:25:42 1.21.2.1
ba40f6b
@@ -185,6 +185,23 @@
ba40f6b
 		sig=d2i_X509_SIG(NULL,&p,(long)i);
ba40f6b
 
ba40f6b
 		if (sig == NULL) goto err;
ba40f6b
+
ba40f6b
+		/* Excess data can be used to create forgeries */
ba40f6b
+		if(p != s+i)
ba40f6b
+			{
ba40f6b
+			RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
ba40f6b
+			goto err;
ba40f6b
+			}
ba40f6b
+
ba40f6b
+		/* Parameters to the signature algorithm can also be used to
ba40f6b
+		   create forgeries */
ba40f6b
+		if(sig->algor->parameter
ba40f6b
+		   && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL)
ba40f6b
+			{
ba40f6b
+			RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
ba40f6b
+			goto err;
ba40f6b
+			}
ba40f6b
+
ba40f6b
 		sigtype=OBJ_obj2nid(sig->algor->algorithm);
ba40f6b
 
ba40f6b