summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2025-07-27 07:11:36 +0000
committertb <>2025-07-27 07:11:36 +0000
commitb2cb32920a6667af40d758ec04123fa98612d608 (patch)
treef47be480d7bdd6de671c9ccdb1b8da57ba430859 /src
parentd943e504ca5f07a9282522f6183ff0b704ec8c78 (diff)
downloadopenbsd-b2cb32920a6667af40d758ec04123fa98612d608.tar.gz
openbsd-b2cb32920a6667af40d758ec04123fa98612d608.tar.bz2
openbsd-b2cb32920a6667af40d758ec04123fa98612d608.zip
Fix PKCS7_add0_attrib_signing_time()
If the caller passes in NULL, helpfully a new ASN1_TIME is allocated with X509_gmtime_adj() and leaked if PKCS7_add0_attrib_signing_time() fails afterward. Fix this. Also don't blindly set the signing time to a UTCTime. Validate the usual RFC 5280 format before setting it, as that's what RFC 5652, section 11.3 mandates. ok kenjiro
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
index c43b0ae2f1..c35b153b84 100644
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_attr.c,v 1.16 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: pk7_attr.c,v 1.17 2025/07/27 07:11:36 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -63,6 +63,7 @@
63#include <openssl/pkcs7.h> 63#include <openssl/pkcs7.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66#include "asn1_local.h"
66#include "err_local.h" 67#include "err_local.h"
67 68
68int 69int
@@ -148,12 +149,30 @@ LCRYPTO_ALIAS(PKCS7_add_attrib_content_type);
148int 149int
149PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) 150PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t)
150{ 151{
151 if (!t && !(t = X509_gmtime_adj(NULL, 0))) { 152 ASN1_TIME *tm;
153 int ret = 0;
154
155 if ((tm = t) == NULL)
156 tm = X509_gmtime_adj(NULL, 0);
157 if (tm == NULL) {
152 PKCS7error(ERR_R_MALLOC_FAILURE); 158 PKCS7error(ERR_R_MALLOC_FAILURE);
153 return 0; 159 goto err;
154 } 160 }
155 return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, 161
156 V_ASN1_UTCTIME, t); 162 /* RFC 5652, section 11.3 - UTCTime for times between 1950 and 2050. */
163 if (ASN1_time_parse(tm->data, tm->length, NULL, tm->type) == -1)
164 goto err;
165 if (!PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, tm->type, tm))
166 goto err;
167 tm = NULL;
168
169 ret = 1;
170
171 err:
172 if (tm != t)
173 ASN1_TIME_free(tm);
174
175 return ret;
157} 176}
158LCRYPTO_ALIAS(PKCS7_add0_attrib_signing_time); 177LCRYPTO_ALIAS(PKCS7_add0_attrib_signing_time);
159 178