CMS_SIGNED_GET_ATTR(3ossl)
π NAME π
okay so bestie, this whole page is the CMS signed + unsigned attribute functions from 3ossl β a whole friend group of them, actually. Here's the full roster, no cap:
CMS_signed_get_attr_countCMS_signed_get_attr_by_NIDCMS_signed_get_attr_by_OBJCMS_signed_get_attrCMS_signed_delete_attrCMS_signed_add1_attrCMS_signed_add1_attr_by_OBJCMS_signed_add1_attr_by_NIDCMS_signed_add1_attr_by_txtCMS_signed_get0_data_by_OBJCMS_unsigned_get_attr_countCMS_unsigned_get_attr_by_NIDCMS_unsigned_get_attr_by_OBJCMS_unsigned_get_attrCMS_unsigned_delete_attrCMS_unsigned_add1_attrCMS_unsigned_add1_attr_by_OBJCMS_unsigned_add1_attr_by_NIDCMS_unsigned_add1_attr_by_txtCMS_unsigned_get0_data_by_OBJ
β¨ SYNOPSIS β¨
#include <openssl/cms.h>
int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
int lastpos);
int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
int lastpos);
X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
const ASN1_OBJECT *obj, int type,
const void *bytes, int len);
int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
int nid, int type,
const void *bytes, int len);
int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
const char *attrname, int type,
const void *bytes, int len);
void *CMS_signed_get0_data_by_OBJ(const CMS_SignerInfo *si,
const ASN1_OBJECT *oid,
int lastpos, int type);
int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
int lastpos);
int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
const ASN1_OBJECT *obj, int lastpos);
X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
const ASN1_OBJECT *obj, int type,
const void *bytes, int len);
int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
int nid, int type,
const void *bytes, int len);
int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
const char *attrname, int type,
const void *bytes, int len);
void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
int lastpos, int type);
π¦ DESCRIPTION π¦
So a CMS_signerInfo is literally carrying two separate attribute lists β one for signed attributes, one for unsigned attributes. The CMS_signed_XXX() squad handles the signed ones, and the CMS_unsigned_XXX() squad handles the unsigned ones. And because the CMS_unsigned_XXX() girlies work in exactly the same way as their CMS_signed_XXX() equivalents, we're only describing the CMS_signed_XXX() ones down below. iykyk π
CMS_signed_get_attr_by_OBJ()β finds the location of the first matching objectobjin the SignerInfo'ssisigned attribute list. The search starts at the position afterlastpos. If the returned value is positive, you can pass it as the value oflastposon the next call toCMS_signed_get_attr_by_OBJ()to iterate through the rest of the attributes. First call? Setlastposto any negative value so it starts searching from the very beginning of the signed attribute list. πCMS_signed_get_attr_by_NID()β same vibe asCMS_signed_get_attr_by_OBJ(), except it passes the numerical identifier (NID)nidassociated with the object. Peep<openssl/obj_mac.h>for a whole list ofNID_*. β¨CMS_signed_get_attr()β returns theX509_ATTRIBUTEobject at indexlocin thesisigned attribute list.locshould be in the range from0toCMS_signed_get_attr_count() - 1. π«ΆCMS_signed_delete_attr()β removes theX509_ATTRIBUTEobject at indexlocin thesisigned attribute list. An error occurs if thesiattribute list isNULL. πCMS_signed_add1_attr()β pushes a copy of the passed-inX509_ATTRIBUTEobject to thesisigned attribute list. A new signed attribute list is created if required. An error occurs ifattrisNULL. πCMS_signed_add1_attr_by_OBJ()β creates a new signedX509_ATTRIBUTEusingX509_ATTRIBUTE_set1_object()andX509_ATTRIBUTE_set1_data()to assign a newobjwith typetypeand databytesof lengthlen, then pushes it to the key object's attribute list. iconic β¨CMS_signed_add1_attr_by_NID()β same asCMS_signed_add1_attr_by_OBJ(), except it passes the numerical identifier (NID)nidassociated with the object. Check<openssl/obj_mac.h>for theNID_*list. πΈCMS_signed_add1_attr_by_txt()β same asCMS_signed_add1_attr_by_OBJ(), except it passes a nameattrnameassociated with the object. See<openssl/obj_mac.h>for theSN_*names. πCMS_signed_get0_data_by_OBJ()β finds the first attribute in asisigned attributes list that matchesobj, starting at indexlastpos, and returns the data retrieved from the found attribute's firstASN1_TYPEobject. An error will occur if the attribute typetypedoesn't match the type of theASN1_TYPEobject, OR iftypeis eitherV_ASN1_BOOLEANorV_ASN1_NULL, OR the attribute isn't found. Iflastposis less than-1, an error occurs when there are multiple objects in the signed attribute list matchingobj. Iflastposis less than-2, an error occurs if there's more than oneASN1_TYPEobject in the found signed attribute. π so many rules, but we respect them.
ngl, go read X509_ATTRIBUTE(3) if you want the full tea on attributes themselves.
π RETURN VALUES π
The CMS_unsigned_XXX() functions return values similar to those of the equivalent CMS_signed_XXX() functions. fr fr.
CMS_signed_get_attr_count()β returns the number of signed attributes in the SignerInfosi, or-1if the signed attribute list isNULL.CMS_signed_get_attr_by_OBJ()β returns-1if either the signed attribute list ofsiis empty OR ifobjisn't found; otherwise it returns the location of theobjin the SignerInfo'ssisigned attribute list.CMS_signed_get_attr_by_NID()β same asCMS_signed_get_attr_by_OBJ(), except it returns-2if thenidisn't known by OpenSSL.CMS_signed_get_attr()β returns either a signedX509_ATTRIBUTEorNULLon error.CMS_signed_delete_attr()β returns either the removed signedX509_ATTRIBUTEorNULLif there's an error.CMS_signed_add1_attr(),CMS_signed_add1_attr_by_OBJ(),CMS_signed_add1_attr_by_NID(),CMS_signed_add1_attr_by_txt()β return1on success or0on error.CMS_signed_get0_data_by_OBJ()β returns the data retrieved from the found signed attribute's firstASN1_TYPEobject, orNULLif an error occurs.
π NOTES π
Some attributes get added automatically during the signing process β not you doing it, the library doing it. main character energy tbh.
- Calling
CMS_SignerInfo_sign()adds theNID_pkcs9_signingTimesigned attribute. β° - Calling
CMS_final(),CMS_final_digest()orCMS_dataFinal()adds theNID_pkcs9_messageDigestsigned attribute. π© - The
NID_pkcs9_contentTypesigned attribute is always added if theNID_pkcs9_signingTimeattribute is added. periodt. - Calling
CMS_sign_ex(),CMS_sign_receipt()orCMS_add1_signer()may add attributes depending on theflagsparameter. SeeCMS_add1_signer(3)for more info. π§
π Special-cased attribute NIDs
OpenSSL applies special rules for the following attribute NIDs β like, these ones get the VIP treatment:
CMS Signed Attributes
NID_pkcs9_contentTypeNID_pkcs9_messageDigestNID_pkcs9_signingTime
ESS Signed Attributes
NID_id_smime_aa_signingCertificateNID_id_smime_aa_signingCertificateV2NID_id_smime_aa_receiptRequest
CMS Unsigned Attributes
NID_pkcs9_countersignature
π Duplicates? yeah, they're allowed
CMS_signed_add1_attr(), CMS_signed_add1_attr_by_OBJ(), CMS_signed_add1_attr_by_NID(), CMS_signed_add1_attr_by_txt() and the equivalent CMS_unsigned_add1_attrXXX() functions allow duplicate attributes to be added. The attribute rules are not checked during these function calls β they're deferred until the sign or verify process, i.e. during calls to any of:
CMS_sign_ex()CMS_sign()CMS_sign_receipt()CMS_add1_signer()CMS_Final()CMS_dataFinal()CMS_final_digest()CMS_verify()CMS_verify_receipt()CMS_SignedData_verify()
For CMS attribute rules see RFC 5652 Section 11. For ESS attribute rules see RFC 2634 Section 1.3.4 and RFC 5035 Section 5.4. π
π₯ SEE ALSO π₯
π COPYRIGHT π
Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π«Ά mwah π β this was CMS_SIGNED_GET_ATTR(3ossl), version 3.5.0, dated 2026-09-25. slay, go add some attributes β¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms