CMS_SIGNED_GET_ATTR(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… 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_count
  • CMS_signed_get_attr_by_NID
  • CMS_signed_get_attr_by_OBJ
  • CMS_signed_get_attr
  • CMS_signed_delete_attr
  • CMS_signed_add1_attr
  • CMS_signed_add1_attr_by_OBJ
  • CMS_signed_add1_attr_by_NID
  • CMS_signed_add1_attr_by_txt
  • CMS_signed_get0_data_by_OBJ
  • CMS_unsigned_get_attr_count
  • CMS_unsigned_get_attr_by_NID
  • CMS_unsigned_get_attr_by_OBJ
  • CMS_unsigned_get_attr
  • CMS_unsigned_delete_attr
  • CMS_unsigned_add1_attr
  • CMS_unsigned_add1_attr_by_OBJ
  • CMS_unsigned_add1_attr_by_NID
  • CMS_unsigned_add1_attr_by_txt
  • CMS_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 object obj in the SignerInfo's si signed attribute list. The search starts at the position after lastpos. If the returned value is positive, you can pass it as the value of lastpos on the next call to CMS_signed_get_attr_by_OBJ() to iterate through the rest of the attributes. First call? Set lastpos to any negative value so it starts searching from the very beginning of the signed attribute list. πŸŽ€
  • CMS_signed_get_attr_by_NID() β€” same vibe as CMS_signed_get_attr_by_OBJ(), except it passes the numerical identifier (NID) nid associated with the object. Peep <openssl/obj_mac.h> for a whole list of NID_*. ✨
  • CMS_signed_get_attr() β€” returns the X509_ATTRIBUTE object at index loc in the si signed attribute list. loc should be in the range from 0 to CMS_signed_get_attr_count() - 1. 🫢
  • CMS_signed_delete_attr() β€” removes the X509_ATTRIBUTE object at index loc in the si signed attribute list. An error occurs if the si attribute list is NULL. πŸ’€
  • CMS_signed_add1_attr() β€” pushes a copy of the passed-in X509_ATTRIBUTE object to the si signed attribute list. A new signed attribute list is created if required. An error occurs if attr is NULL. πŸ“
  • CMS_signed_add1_attr_by_OBJ() β€” creates a new signed X509_ATTRIBUTE using X509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new obj with type type and data bytes of length len, then pushes it to the key object's attribute list. iconic ✨
  • CMS_signed_add1_attr_by_NID() β€” same as CMS_signed_add1_attr_by_OBJ(), except it passes the numerical identifier (NID) nid associated with the object. Check <openssl/obj_mac.h> for the NID_* list. 🌸
  • CMS_signed_add1_attr_by_txt() β€” same as CMS_signed_add1_attr_by_OBJ(), except it passes a name attrname associated with the object. See <openssl/obj_mac.h> for the SN_* names. 🌈
  • CMS_signed_get0_data_by_OBJ() β€” finds the first attribute in a si signed attributes list that matches obj, starting at index lastpos, and returns the data retrieved from the found attribute's first ASN1_TYPE object. An error will occur if the attribute type type doesn't match the type of the ASN1_TYPE object, OR if type is either V_ASN1_BOOLEAN or V_ASN1_NULL, OR the attribute isn't found. If lastpos is less than -1, an error occurs when there are multiple objects in the signed attribute list matching obj. If lastpos is less than -2, an error occurs if there's more than one ASN1_TYPE object 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 SignerInfo si, or -1 if the signed attribute list is NULL.
  • CMS_signed_get_attr_by_OBJ() β€” returns -1 if either the signed attribute list of si is empty OR if obj isn't found; otherwise it returns the location of the obj in the SignerInfo's si signed attribute list.
  • CMS_signed_get_attr_by_NID() β€” same as CMS_signed_get_attr_by_OBJ(), except it returns -2 if the nid isn't known by OpenSSL.
  • CMS_signed_get_attr() β€” returns either a signed X509_ATTRIBUTE or NULL on error.
  • CMS_signed_delete_attr() β€” returns either the removed signed X509_ATTRIBUTE or NULL if 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() β€” return 1 on success or 0 on error.
  • CMS_signed_get0_data_by_OBJ() β€” returns the data retrieved from the found signed attribute's first ASN1_TYPE object, or NULL if 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 the NID_pkcs9_signingTime signed attribute. ⏰
  • Calling CMS_final(), CMS_final_digest() or CMS_dataFinal() adds the NID_pkcs9_messageDigest signed attribute. πŸ“©
  • The NID_pkcs9_contentType signed attribute is always added if the NID_pkcs9_signingTime attribute is added. periodt.
  • Calling CMS_sign_ex(), CMS_sign_receipt() or CMS_add1_signer() may add attributes depending on the flags parameter. See CMS_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_contentType
  • NID_pkcs9_messageDigest
  • NID_pkcs9_signingTime

ESS Signed Attributes

  • NID_id_smime_aa_signingCertificate
  • NID_id_smime_aa_signingCertificateV2
  • NID_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 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