summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cms')
-rw-r--r--src/lib/libcrypto/cms/cms_pwri.c12
-rw-r--r--src/lib/libcrypto/cms/cms_sd.c42
-rw-r--r--src/lib/libcrypto/cms/cms_smime.c33
3 files changed, 37 insertions, 50 deletions
diff --git a/src/lib/libcrypto/cms/cms_pwri.c b/src/lib/libcrypto/cms/cms_pwri.c
index 1f64fc71f7..f64f4ab68c 100644
--- a/src/lib/libcrypto/cms/cms_pwri.c
+++ b/src/lib/libcrypto/cms/cms_pwri.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_pwri.c,v 1.32 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: cms_pwri.c,v 1.35 2025/09/30 12:51:16 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.
@@ -267,7 +267,7 @@ kek_unwrap_key(unsigned char *out, size_t *outlen, const unsigned char *in,
267 /* Check byte failure */ 267 /* Check byte failure */
268 goto err; 268 goto err;
269 } 269 }
270 if (inlen < (size_t)(tmp[0] - 4)) { 270 if (inlen < 4 + (size_t)tmp[0]) {
271 /* Invalid length value */ 271 /* Invalid length value */
272 goto err; 272 goto err;
273 } 273 }
@@ -368,13 +368,13 @@ cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
368 kekcipher = EVP_get_cipherbyobj(kekalg->algorithm); 368 kekcipher = EVP_get_cipherbyobj(kekalg->algorithm);
369 if (!kekcipher) { 369 if (!kekcipher) {
370 CMSerror(CMS_R_UNKNOWN_CIPHER); 370 CMSerror(CMS_R_UNKNOWN_CIPHER);
371 return 0; 371 goto err;
372 } 372 }
373 373
374 kekctx = EVP_CIPHER_CTX_new(); 374 kekctx = EVP_CIPHER_CTX_new();
375 if (kekctx == NULL) { 375 if (kekctx == NULL) {
376 CMSerror(ERR_R_MALLOC_FAILURE); 376 CMSerror(ERR_R_MALLOC_FAILURE);
377 return 0; 377 goto err;
378 } 378 }
379 /* Fixup cipher based on AlgorithmIdentifier to set IV etc */ 379 /* Fixup cipher based on AlgorithmIdentifier to set IV etc */
380 if (!EVP_CipherInit_ex(kekctx, kekcipher, NULL, NULL, NULL, en_de)) 380 if (!EVP_CipherInit_ex(kekctx, kekcipher, NULL, NULL, NULL, en_de))
@@ -389,8 +389,8 @@ cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
389 389
390 /* Finish password based key derivation to setup key in "ctx" */ 390 /* Finish password based key derivation to setup key in "ctx" */
391 391
392 if (EVP_PBE_CipherInit(algtmp->algorithm, (char *)pwri->pass, 392 if (!EVP_PBE_CipherInit(algtmp->algorithm, (char *)pwri->pass,
393 pwri->passlen, algtmp->parameter, kekctx, en_de) < 0) { 393 pwri->passlen, algtmp->parameter, kekctx, en_de)) {
394 CMSerror(ERR_R_EVP_LIB); 394 CMSerror(ERR_R_EVP_LIB);
395 goto err; 395 goto err;
396 } 396 }
diff --git a/src/lib/libcrypto/cms/cms_sd.c b/src/lib/libcrypto/cms/cms_sd.c
index f79d740482..abcac83e47 100644
--- a/src/lib/libcrypto/cms/cms_sd.c
+++ b/src/lib/libcrypto/cms/cms_sd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_sd.c,v 1.34 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: cms_sd.c,v 1.36 2025/07/31 02:24:21 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.
@@ -484,35 +484,6 @@ CMS_add1_signer(CMS_ContentInfo *cms, X509 *signer, EVP_PKEY *pk,
484} 484}
485LCRYPTO_ALIAS(CMS_add1_signer); 485LCRYPTO_ALIAS(CMS_add1_signer);
486 486
487static int
488cms_add1_signingTime(CMS_SignerInfo *si, ASN1_TIME *t)
489{
490 ASN1_TIME *tt;
491 int r = 0;
492
493 if (t)
494 tt = t;
495 else
496 tt = X509_gmtime_adj(NULL, 0);
497
498 if (!tt)
499 goto merr;
500
501 if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime,
502 tt->type, tt, -1) <= 0)
503 goto merr;
504
505 r = 1;
506
507 merr:
508 if (!t)
509 ASN1_TIME_free(tt);
510 if (!r)
511 CMSerror(ERR_R_MALLOC_FAILURE);
512
513 return r;
514}
515
516EVP_PKEY_CTX * 487EVP_PKEY_CTX *
517CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si) 488CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si)
518{ 489{
@@ -778,6 +749,7 @@ cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain)
778int 749int
779CMS_SignerInfo_sign(CMS_SignerInfo *si) 750CMS_SignerInfo_sign(CMS_SignerInfo *si)
780{ 751{
752 ASN1_TIME *at = NULL;
781 const EVP_MD *md; 753 const EVP_MD *md;
782 unsigned char *buf = NULL, *sig = NULL; 754 unsigned char *buf = NULL, *sig = NULL;
783 int buf_len = 0; 755 int buf_len = 0;
@@ -788,7 +760,12 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si)
788 goto err; 760 goto err;
789 761
790 if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) { 762 if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) {
791 if (!cms_add1_signingTime(si, NULL)) 763 if ((at = X509_gmtime_adj(NULL, 0)) == NULL) {
764 CMSerror(ERR_R_MALLOC_FAILURE);
765 goto err;
766 }
767 if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime,
768 at->type, at, -1))
792 goto err; 769 goto err;
793 } 770 }
794 771
@@ -828,6 +805,7 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si)
828 ret = 1; 805 ret = 1;
829 806
830 err: 807 err:
808 ASN1_TIME_free(at);
831 (void)EVP_MD_CTX_reset(si->mctx); 809 (void)EVP_MD_CTX_reset(si->mctx);
832 freezero(buf, buf_len); 810 freezero(buf, buf_len);
833 freezero(sig, sig_len); 811 freezero(sig, sig_len);
@@ -1012,6 +990,8 @@ LCRYPTO_ALIAS(CMS_add_smimecap);
1012 * Add AlgorithmIdentifier OID of type |nid| to the SMIMECapability attribute 990 * Add AlgorithmIdentifier OID of type |nid| to the SMIMECapability attribute
1013 * set |*out_algs| (see RFC 3851, section 2.5.2). If keysize > 0, the OID has 991 * set |*out_algs| (see RFC 3851, section 2.5.2). If keysize > 0, the OID has
1014 * an integer parameter of value |keysize|, otherwise parameters are omitted. 992 * an integer parameter of value |keysize|, otherwise parameters are omitted.
993 *
994 * See also PKCS7_simple_smimecap().
1015 */ 995 */
1016int 996int
1017CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **out_algs, int nid, int keysize) 997CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **out_algs, int nid, int keysize)
diff --git a/src/lib/libcrypto/cms/cms_smime.c b/src/lib/libcrypto/cms/cms_smime.c
index 85a0e6f6e5..a4918643d2 100644
--- a/src/lib/libcrypto/cms/cms_smime.c
+++ b/src/lib/libcrypto/cms/cms_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_smime.c,v 1.29 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: cms_smime.c,v 1.31 2025/11/28 06:07:09 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.
@@ -277,25 +277,32 @@ CMS_ContentInfo *
277CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, 277CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
278 const unsigned char *key, size_t keylen, unsigned int flags) 278 const unsigned char *key, size_t keylen, unsigned int flags)
279{ 279{
280 CMS_ContentInfo *cms; 280 CMS_ContentInfo *cms = NULL;
281 281
282 if (!cipher) { 282 if (cipher == NULL) {
283 CMSerror(CMS_R_NO_CIPHER); 283 CMSerror(CMS_R_NO_CIPHER);
284 return NULL; 284 goto err;
285 } 285 }
286 cms = CMS_ContentInfo_new(); 286
287 if (cms == NULL) 287 if ((cms = CMS_ContentInfo_new()) == NULL)
288 return NULL; 288 goto err;
289
289 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) 290 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
290 return NULL; 291 goto err;
291 292
292 if (!(flags & CMS_DETACHED)) 293 if ((flags & CMS_DETACHED) == 0) {
293 CMS_set_detached(cms, 0); 294 if (!CMS_set_detached(cms, 0))
295 goto err;
296 }
294 297
295 if ((flags & (CMS_STREAM | CMS_PARTIAL)) || 298 if ((flags & (CMS_STREAM | CMS_PARTIAL)) == 0) {
296 CMS_final(cms, in, NULL, flags)) 299 if (!CMS_final(cms, in, NULL, flags))
297 return cms; 300 goto err;
301 }
298 302
303 return cms;
304
305 err:
299 CMS_ContentInfo_free(cms); 306 CMS_ContentInfo_free(cms);
300 307
301 return NULL; 308 return NULL;