summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cms/cms_sd.c')
-rw-r--r--src/lib/libcrypto/cms/cms_sd.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/src/lib/libcrypto/cms/cms_sd.c b/src/lib/libcrypto/cms/cms_sd.c
index 9cdd4ce143..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.33 2024/04/20 10:11:55 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.
@@ -57,7 +57,6 @@
57 57
58#include <openssl/asn1.h> 58#include <openssl/asn1.h>
59#include <openssl/bio.h> 59#include <openssl/bio.h>
60#include <openssl/err.h>
61#include <openssl/evp.h> 60#include <openssl/evp.h>
62#include <openssl/cms.h> 61#include <openssl/cms.h>
63#include <openssl/objects.h> 62#include <openssl/objects.h>
@@ -66,6 +65,7 @@
66 65
67#include "asn1_local.h" 66#include "asn1_local.h"
68#include "cms_local.h" 67#include "cms_local.h"
68#include "err_local.h"
69#include "evp_local.h" 69#include "evp_local.h"
70#include "x509_local.h" 70#include "x509_local.h"
71 71
@@ -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)