---
name: "CMS_signed_get_attr"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/CMS_signed_get_attr"
---

# CMS\_signed\_get\_attr(3ssl)

CMS signed and unsigned attribute functions

## NAME

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 - CMS signed and unsigned attribute functions

## 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

CMS\_signerInfo contains separate attribute lists for signed and unsigned attributes. Each **CMS\_signed\_XXX()** function is used for signed attributes, and each **CMS\_unsigned\_XXX()** function is used for unsigned attributes. Since the **CMS\_unsigned\_XXX()** functions work in the same way as the **CMS\_signed\_XXX()** equivalents, only the **CMS\_signed\_XXX()** functions are described below.

**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 then it can be used on the next call to **CMS\_signed\_get\_attr\_by\_OBJ()** as the value of *lastpos* in order to iterate through the remaining attributes. *lastpos* can be set to any negative value on the first call, in order to start searching from the start of the signed attribute list.

**CMS\_signed\_get\_attr\_by\_NID()** is similar to **CMS\_signed\_get\_attr\_by\_OBJ()** except that it passes the numerical identifier (NID) *nid* associated with the object. See \<openssl/obj\_mac.h\> for a 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* and then pushes it to the *key* object's attribute list.

**CMS\_signed\_add1\_attr\_by\_NID()** is similar to **CMS\_signed\_add1\_attr\_by\_OBJ()** except that it passes the numerical identifier (NID) *nid* associated with the object. See \<openssl/obj\_mac.h\> for a list of NID\_\*.

**CMS\_signed\_add1\_attr\_by\_txt()** is similar to **CMS\_signed\_add1\_attr\_by\_OBJ()** except that it passes a name *attrname* associated with the object. See \<openssl/obj\_mac.h\> for a list of SN\_\* names.

**CMS\_signed\_get0\_data\_by\_OBJ()** finds the first attribute in a *si* signed attributes list that matches the *obj* starting at index *lastpos* and returns the data retrieved from the found attributes first **ASN1\_TYPE** object. An error will occur if the attribute type *type* does not match the type of the **ASN1\_TYPE** object OR if *type* is either **V\_ASN1\_BOOLEAN** or **V\_ASN1\_NULL** OR the attribute is not found. If *lastpos* is less than -1 then an error will occur if there are multiple objects in the signed attribute list that match *obj*. If *lastpos* is less than -2 then an error will occur if there is more than one **ASN1\_TYPE** object in the found signed attribute.

Refer to **X509\_ATTRIBUTE**(3) for information related to attributes.

## RETURN VALUES

The **CMS\_unsigned\_XXX()** functions return values are similar to those of the equivalent **CMS\_signed\_XXX()** functions.

**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* is not found, otherwise it returns the location of the *obj* in the SignerInfo's *si* signed attribute list.

**CMS\_signed\_get\_attr\_by\_NID()** is similar to **CMS\_signed\_get\_attr\_by\_OBJ()** except that it returns -2 if the *nid* is not 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 is a 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 attributes first **ASN1\_TYPE** object, or NULL if an error occurs.

## NOTES

Some attributes are added automatically during the signing process.

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.

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 information.

OpenSSL applies special rules for the following attribute NIDs:

- 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

**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, and are 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()** or **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

**X509\_ATTRIBUTE**(3)

## 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\>.
