Return an error if no recipient type matches.

If the key type does not match any CMS recipient type return
an error instead of using a random key (MMA mitigation). This
does not leak any useful information to an attacker.

PR#3348
This commit is contained in:
Dr. Stephen Henson 2014-05-08 13:17:11 +01:00
parent 9e456a8537
commit d61be85581

View File

@ -611,7 +611,7 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
STACK_OF(CMS_RecipientInfo) *ris; STACK_OF(CMS_RecipientInfo) *ris;
CMS_RecipientInfo *ri; CMS_RecipientInfo *ri;
int i, r; int i, r;
int debug = 0; int debug = 0, ri_match = 0;
ris = CMS_get0_RecipientInfos(cms); ris = CMS_get0_RecipientInfos(cms);
if (ris) if (ris)
debug = cms->d.envelopedData->encryptedContentInfo->debug; debug = cms->d.envelopedData->encryptedContentInfo->debug;
@ -620,6 +620,7 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
ri = sk_CMS_RecipientInfo_value(ris, i); ri = sk_CMS_RecipientInfo_value(ris, i);
if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_TRANS) if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_TRANS)
continue; continue;
ri_match = 1;
/* If we have a cert try matching RecipientInfo /* If we have a cert try matching RecipientInfo
* otherwise try them all. * otherwise try them all.
*/ */
@ -655,7 +656,7 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
} }
} }
/* If no cert and not debugging always return success */ /* If no cert and not debugging always return success */
if (!cert && !debug) if (ri_match && !cert && !debug)
{ {
ERR_clear_error(); ERR_clear_error();
return 1; return 1;