diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_env.c')
-rw-r--r-- | src/lib/libcrypto/cms/cms_env.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lib/libcrypto/cms/cms_env.c b/src/lib/libcrypto/cms/cms_env.c index 8640f459fb..74d957eee0 100644 --- a/src/lib/libcrypto/cms/cms_env.c +++ b/src/lib/libcrypto/cms/cms_env.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cms_env.c,v 1.22 2019/08/11 11:07:40 jsing Exp $ */ | 1 | /* $OpenBSD: cms_env.c,v 1.23 2019/10/04 18:03:56 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
4 | * project. | 4 | * project. |
@@ -426,6 +426,7 @@ cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri) | |||
426 | EVP_PKEY *pkey = ktri->pkey; | 426 | EVP_PKEY *pkey = ktri->pkey; |
427 | unsigned char *ek = NULL; | 427 | unsigned char *ek = NULL; |
428 | size_t eklen; | 428 | size_t eklen; |
429 | size_t fixlen = 0; | ||
429 | int ret = 0; | 430 | int ret = 0; |
430 | CMS_EncryptedContentInfo *ec; | 431 | CMS_EncryptedContentInfo *ec; |
431 | 432 | ||
@@ -436,6 +437,19 @@ cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri) | |||
436 | return 0; | 437 | return 0; |
437 | } | 438 | } |
438 | 439 | ||
440 | if (cms->d.envelopedData->encryptedContentInfo->havenocert && | ||
441 | !cms->d.envelopedData->encryptedContentInfo->debug) { | ||
442 | X509_ALGOR *calg = ec->contentEncryptionAlgorithm; | ||
443 | const EVP_CIPHER *ciph; | ||
444 | |||
445 | if ((ciph = EVP_get_cipherbyobj(calg->algorithm)) == NULL) { | ||
446 | CMSerror(CMS_R_UNKNOWN_CIPHER); | ||
447 | return 0; | ||
448 | } | ||
449 | |||
450 | fixlen = EVP_CIPHER_key_length(ciph); | ||
451 | } | ||
452 | |||
439 | ktri->pctx = EVP_PKEY_CTX_new(pkey, NULL); | 453 | ktri->pctx = EVP_PKEY_CTX_new(pkey, NULL); |
440 | if (ktri->pctx == NULL) | 454 | if (ktri->pctx == NULL) |
441 | return 0; | 455 | return 0; |
@@ -453,8 +467,11 @@ cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri) | |||
453 | } | 467 | } |
454 | 468 | ||
455 | if (EVP_PKEY_decrypt(ktri->pctx, NULL, &eklen, ktri->encryptedKey->data, | 469 | if (EVP_PKEY_decrypt(ktri->pctx, NULL, &eklen, ktri->encryptedKey->data, |
456 | ktri->encryptedKey->length) <= 0) | 470 | ktri->encryptedKey->length) <= 0 || eklen == 0 || |
471 | (fixlen != 0 && eklen != fixlen)) { | ||
472 | CMSerror(CMS_R_CMS_LIB); | ||
457 | goto err; | 473 | goto err; |
474 | } | ||
458 | 475 | ||
459 | ek = malloc(eklen); | 476 | ek = malloc(eklen); |
460 | 477 | ||