PKCS7_ADD_ATTRIBUTE(3)
π NAME π
okay bestie, welcome to PKCS7_ADD_ATTRIBUTE(3) β literally the manual page for the attribute-handling squad of SignerInfo objects. The whole crew is: PKCS7_add_attribute, PKCS7_set_attributes, PKCS7_get_attribute, PKCS7_add_signed_attribute, PKCS7_set_signed_attributes, PKCS7_get_signed_attribute, PKCS7_add_attrib_content_type, PKCS7_add1_attrib_digest, PKCS7_add0_attrib_signing_time, and PKCS7_add_attrib_smimecap β attributes of SignerInfo objects. π«Ά
β¨ SYNOPSIS β¨
#include <openssl/pkcs7.h>
int
PKCS7_add_attribute(PKCS7_SIGNER_INFO *si, int nid, int attrtype,
void *value);
int
PKCS7_set_attributes(PKCS7_SIGNER_INFO *si,
STACK_OF(X509_ATTRIBUTE) *sk);
ASN1_TYPE *
PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
int
PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *si, int nid, int attrtype,
void *value);
int
PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *si,
STACK_OF(X509_ATTRIBUTE) *sk);
ASN1_TYPE *
PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
int
PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid);
int
PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, const unsigned char *md,
int mdlen);
int
PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t);
int
PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
STACK_OF(X509_ALGOR) *cap);
π DESCRIPTION π
okay so these functions are all about poking at the attribute lists hanging off a PKCS7_SIGNER_INFO (si). The two lists that matter are unauthenticatedAttributes and authenticatedAttributes. The vibe check is: add stuff, set whole stacks, get stuff back, and know which list youβre touching. π
PKCS7_add_attribute()β appends a new attribute of typenidto theunauthenticatedAttributeslist ofsi, and it adds a newASN.1 ANYobject of typeattrtypewith the givenvalueto that new attribute. Ownership ofvalueis transferred into the new attribute object, so the calling code must notfree(3)thevalue. If the list already contains an unauthenticated attribute of typenidbefore the call, the new attribute replaces the old one instead of being appended to the end of the list. no duplicates, bestie. πPKCS7_set_attributes()β frees theunauthenticatedAttributeslist ofsiand all the attributes contained in it, then replaces it with a deep copy ofsk. itβs giving βout with the old, in with the clone.β π¦PKCS7_get_attribute()β retrieves the firstASN.1 ANYmember of the attribute of typenidfrom theunauthenticatedAttributeslist ofsi.PKCS7_add_signed_attribute(),PKCS7_set_signed_attributes(), andPKCS7_get_signed_attribute()β behaviour is identical except that they operate on the list ofauthenticatedAttributes. same energy, different list. β¨
The normal way to use PKCS7_add_signed_attribute() is to first create a SignedInfo object with PKCS7_sign(3) using the PKCS7_PARTIAL or PKCS7_STREAM flag, retrieve the PKCS7_SIGNER_INFO object with PKCS7_get_signer_info(3) or add an additional one with PKCS7_sign_add_signer(3), call PKCS7_add_signed_attribute() for each desired additional attribute, then do the signing with PKCS7_final(3) or with another finalizing function. thatβs the whole routine, and it slays. π₯
The four remaining functions are wrappers around PKCS7_add_signed_attribute():
PKCS7_add_attrib_content_type()β sets theNID_pkcs9_contentTypeattribute tocoid, which specifies the content type of theContentInfovalue to be signed. This attribute is mandatory and automatically added byPKCS7_sign(3)andPKCS7_sign_add_signer(3)unless thePKCS7_NOATTRflag is present. Objects suitable ascoidarguments can for example be obtained withOBJ_nid2obj(3). IfcoidisNULL, the content type defaults toNID_pkcs7_data. πPKCS7_add1_attrib_digest()β sets or replaces theNID_pkcs9_messageDigestattribute, which is the message digest of the contents octets of the DER-encoding of the content field of theContentInfovalue being signed, to a copy ofmd, which is assumed to bemdlenbytes long. Ifmdlenis-1, thenstrlen(md)is used instead ofmdlen. This attribute is mandatory and automatically added byPKCS7_dataFinal(3)andPKCS7_final(3). πPKCS7_add0_attrib_signing_time()β sets or replaces the optionalNID_pkcs9_signingTimeattribute tot, specifying the time at which the signer performed the signing process. Ownership oftis transferred into the new attribute object, so the calling code must notfree(3)t. IftisNULL, a newASN1_TIMEstructure is allocated. This attribute is automatically added byPKCS7_dataFinal(3)andPKCS7_final(3). β°PKCS7_add_attrib_smimecap()β sets or replaces the optionalNID_SMIMECapabilitiesattribute, indicating algorithms the sender is prepared to handle. Thecappointer is not stored in the new attribute object and can be passed tosk_X509_ALGOR_pop_free()after the call. This attribute is automatically added byPKCS7_sign(3)andPKCS7_sign_add_signer(3)unless thePKCS7_NOATTRorPKCS7_NOSMIMECAPflag is present. π
π RETURN VALUES π
PKCS7_add_attribute(), PKCS7_set_attributes(), PKCS7_add_signed_attribute(), PKCS7_set_signed_attributes(), PKCS7_add_attrib_content_type(), PKCS7_add1_attrib_digest(), PKCS7_add0_attrib_signing_time(), and PKCS7_add_attrib_smimecap() return 1 on success or 0 on failure. The most common reason for failure is lack of memory. PKCS7_add_attribute() and PKCS7_add_signed_attribute() also fail if nid is invalid, and PKCS7_add_attrib_content_type() if si already contains an authenticated attribute of type NID_pkcs9_contentType. π
PKCS7_get_attribute() and PKCS7_get_signed_attribute() return an internal pointer to an ASN.1 ANY object or NULL on failure. They fail if nid is invalid, if the respective list in si contains no attribute of the requested type, or if an invalid element is found in the list before finding the attribute of the requested type. vibe check failed, return NULL. π
π¦ SEE ALSO π¦
ASN1_TIME_new(3), ASN1_TYPE_new(3), OBJ_nid2obj(3), PKCS7_final(3), PKCS7_get_signer_info(3), PKCS7_new(3), PKCS7_sign(3), PKCS7_sign_add_signer(3), STACK_OF(3), X509_ALGOR_new(3), X509_ATTRIBUTE_new(3)
πΈ STANDARDS πΈ
RFC 2315: PKCS #7: Cryptographic Message Syntax Version 1.5, section 9.2: SignerInfo typeRFC 2985: PKCS #9: Selected Object Classes and Attribute Types Version 2.0, section 5.3: Attribute types for use in PKCS #7 data and section 5.6: Attributes defined in S/MIMERFC 8551: Secure/Multipurpose Internet Mail Extensions (S/MIME) Version 4.0 Message Specification, section 2.5.2: SMIMECapabilities Attribute
π§ HISTORY π§
PKCS7_add_attribute(),PKCS7_set_attributes(),PKCS7_get_attribute(),PKCS7_add_signed_attribute(),PKCS7_set_signed_attributes(), andPKCS7_get_signed_attribute()first appeared inOpenSSL 0.9.1and have been available sinceOpenBSD 2.6. the OGs fr fr.PKCS7_add_attrib_smimecap()first appeared inOpenSSL 0.9.5and has been available sinceOpenBSD 2.7.PKCS7_add_attrib_content_type(),PKCS7_add1_attrib_digest(), andPKCS7_add0_attrib_signing_time()first appeared inOpenSSL 1.0.0and have been available sinceOpenBSD 4.9.
π¨ CAVEATS π¨
PKCS7_set_signed_attributes()does not validate thatskcontains the PKCS #9 content type and message digest attributes required byRFC 2315. It succeeds even whenskis empty, leavingsiin a state that violates the standard. not the flex you think it is. π
PKCS7_add0_attrib_signing_time()does not validatetin any way. In particular, it may set the signing time to the future or to the remote past. time travel? in my signing attribute? itβs more likely than you think. β³
π BUGS π
A function to remove individual attributes from these lists does not appear to exist. A program desiring to do that might have to manually iterate the fields auth_attr and unauth_attr of si, which are both of type STACK_OF(X509_ATTRIBUTE), using the facilities described in STACK_OF(3) and OPENSSL_sk_new(3). manual looping era, lowkey tragic. π
mwah π β this page is from the Debian edition, dated June 10, 2020, for PKCS7_ADD_ATTRIBUTE(3). periodt. π
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms