X509_ATTRIBUTE(3ossl)
π
X509_ATTRIBUTE (3ossl) β X509 attribute functions π
okay bestie, this is the OpenSSL page for the X509 attribute girlies, and there are a lot of function names on the guest list. No cap, we're going through all of them.
πΈ NAME πΈ
X509_ATTRIBUTE, X509at_get_attr, X509at_get_attr_count, X509at_get_attr_by_NID, X509at_get_attr_by_OBJ, X509at_delete_attr, X509at_add1_attr, X509at_add1_attr_by_OBJ, X509at_add1_attr_by_NID, X509at_add1_attr_by_txt, X509at_get0_data_by_OBJ, X509_ATTRIBUTE_create, X509_ATTRIBUTE_create_by_NID, X509_ATTRIBUTE_create_by_OBJ, X509_ATTRIBUTE_create_by_txt, X509_ATTRIBUTE_set1_object, X509_ATTRIBUTE_set1_data, X509_ATTRIBUTE_count, X509_ATTRIBUTE_get0_data, X509_ATTRIBUTE_get0_object, X509_ATTRIBUTE_get0_type β X509 attribute functions β¨
β¨ SYNOPSIS β¨
#include <openssl/x509.h>
typedef struct x509_attributes_st X509_ATTRIBUTE;
int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
int lastpos);
int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk,
const ASN1_OBJECT *obj, int lastpos);
X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
X509_ATTRIBUTE *attr);
STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE)
**x, const ASN1_OBJECT *obj,
int type,
const unsigned char *bytes,
int len);
STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE)
**x, int nid, int type,
const unsigned char *bytes,
int len);
STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE)
**x, const char *attrname,
int type,
const unsigned char *bytes,
int len);
void *X509at_get0_data_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *x,
const ASN1_OBJECT *obj, int lastpos, int type);
X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
int atrtype, const void *data,
int len);
X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
const ASN1_OBJECT *obj,
int atrtype, const void *data,
int len);
X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
const char *atrname, int type,
const unsigned char *bytes,
int len);
int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
const void *data, int len);
void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype,
void *data);
int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr);
ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
π DESCRIPTION π
X509_ATTRIBUTE objects are used by many standards, including X509, X509_REQ, PKCS12, PKCS8, PKCS7 and CMS. iconic cross-standard behavior, honestly.
The X509_ATTRIBUTE object is used to represent the ASN.1 Attribute as defined in RFC 5280, i.e.
Attribute ::= SEQUENCE {
type AttributeType,
values SET OF AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY -- DEFINED BY AttributeType
For example, CMS defines the signing-time attribute as:
id-signingTime OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 5 }
SigningTime ::= Time
Time ::= CHOICE {
utcTime UTCTime,
generalizedTime GeneralizedTime }
In OpenSSL, AttributeType maps to an ASN1_OBJECT object, and AttributeValue maps to a list of ASN1_TYPE objects. slay.
The following functions are used for X509_ATTRIBUTE objects.
X509at_get_attr_by_OBJ()β finds the location of the first matching objectobjin a list of attributessk. The search starts at the position afterlastpos. If the returned value is positive, then it can be used on the next call toX509at_get_attr_by_OBJ()as the value oflastposin order to iterate through the remaining attributes.lastposcan be set to any negative value on the first call, in order to start searching from the start of the list. go off, iterator queen.X509at_get_attr_by_NID()β similar toX509at_get_attr_by_OBJ()except that it passes the numerical identifier (NID)nidassociated with the object. See<openssl/obj_mac.h>for a list ofNID_*.X509at_get_attr()β returns theX509_ATTRIBUTEobject at indexlocin the list of attributesx.locshould be in the range from0toX509at_get_attr_count() - 1.X509at_delete_attr()β removes theX509_ATTRIBUTEobject at indexlocin the list of attributesx. bye bestie πX509at_add1_attr()β pushes a copy of the passed inX509_ATTRIBUTEobject to the listx. Bothxandattrmust be non NULL or an error will occur. If*xis NULL then a new list is created, otherwise it uses the passed in list. An error will occur if an existing attribute (with the same attribute type) already exists in the attribute list.X509at_add1_attr_by_OBJ()β creates a newX509_ATTRIBUTEusingX509_ATTRIBUTE_set1_object()andX509_ATTRIBUTE_set1_data()to assign a newobjwith typetypeand databytesof lengthlen, and then pushes it to the attribute listx. Bothxandattrmust be non NULL or an error will occur. If*xis NULL then a new attribute list is created. Ifobjalready exists in the attribute list then an error occurs.X509at_add1_attr_by_NID()β similar toX509at_add1_attr_by_OBJ()except that it passes the numerical identifier (NID)nidassociated with the object. See<openssl/obj_mac.h>for a list ofNID_*.X509at_add1_attr_by_txt()β similar toX509at_add1_attr_by_OBJ()except that it passes a nameattrnameassociated with the object. See<openssl/obj_mac.h>for a list ofSN_*names.X509_ATTRIBUTE_set1_object()β assigns anASN1_OBJECTobjto the attributeattr. Ifattrcontained an existingASN1_OBJECTthen it is freed. An error occurs if eitherattrorobjare NULL, or if the passed inobjcannot be duplicated.X509_ATTRIBUTE_set1_data()β pushes a newASN1_TYPEobject onto theattrattributes list. The new object is assigned a copy of the data indataof sizelen. Ifattrtypehas flagMBSTRING_FLAGset then a table lookup using theattrattributes NID is used to set anASN1_STRINGusingASN1_STRING_set_by_NID(), and the passed indatamust be in the format required for that object type or an error will occur. Iflenis not-1then internallyASN1_STRING_type_new()is used with the passed inattrtype. Ifattrtypeis0the call does nothing except return1.X509_ATTRIBUTE_create()β creates a newX509_ATTRIBUTEusing thenidto set theASN1_OBJECTOID and theatrtypeandvalueto set theASN1_TYPE.X509_ATTRIBUTE_create_by_OBJ()β usesX509_ATTRIBUTE_set1_object()andX509_ATTRIBUTE_set1_data()to assign a newobjwith typeatrtypeand datadataof lengthlen. If the passed in attributeattrOR*attris NULL then a newX509_ATTRIBUTEwill be returned, otherwise the passed inX509_ATTRIBUTEis used. Note that theASN1_OBJECTobjis pushed onto the attributes existing list of objects, which could be an issue if the attributes<ASN1_OBJECT>was different.X509_ATTRIBUTE_create_by_NID()β similar toX509_ATTRIBUTE_create_by_OBJ()except that it passes the numerical identifier (NID)nidassociated with the object. See<openssl/obj_mac.h>for a list ofNID_*.X509_ATTRIBUTE_create_by_txt()β similar toX509_ATTRIBUTE_create_by_OBJ()except that it passes a nameatrnameassociated with the object. See<openssl/obj_mac.h>for a list ofSN_*names.X509_ATTRIBUTE_count()β returns the number ofASN1_TYPEobjects in an attributeattr.X509_ATTRIBUTE_get0_type()β returns theASN1_TYPEobject at indexidxin the attribute listattr.idxshould be in the range of0toX509_ATTRIBUTE_count() - 1or an error will occur.X509_ATTRIBUTE_get0_data()β returns the data of anASN1_TYPEobject at indexidxin the attributeattr.datais unused and can be set to NULL. An error will occur if the attribute typeatrtypedoes not match the type of theASN1_TYPEobject at indexidxOR ifatrtypeis eitherV_ASN1_BOOLEANorV_ASN1_NULLOR if theidxis not in the range0toX509_ATTRIBUTE_count() - 1.X509at_get0_data_by_OBJ()β finds the first attribute in an attribute listxthat matches theobjstarting at indexlastposand returns the data retrieved from the found attributes firstASN1_TYPEobject. An error will occur if the attribute typetypedoes not match the type of theASN1_TYPEobject OR iftypeis eitherV_ASN1_BOOLEANorV_ASN1_NULLOR the attribute is not found. Iflastposis less than-1then an error will occur if there are multiple objects in the listxthat matchobj. Iflastposis less than-2then an error will occur if there is more than oneASN1_TYPEobject in the found attribute.
π RETURN VALUES π
okay bestie, hereβs the vibe check on what each function hands back β no cap, every return value matters:
X509at_get_attr_count()β gives you the number of attributes in the listx, or-1ifxisNULL.X509at_get_attr_by_OBJ()β returns-1if either the list is empty OR the object is not found; otherwise it returns the location of the object in the list.X509at_get_attr_by_NID()β same energy asX509at_get_attr_by_OBJ(), except it returns-2if thenidis not known by OpenSSL.X509at_get_attr()β returns either anX509_ATTRIBUTEorNULLif there is an error.X509at_delete_attr()β returns either the removedX509_ATTRIBUTEorNULLif there is an error.X509_ATTRIBUTE_count()β returns-1on error; otherwise it returns the number ofASN1_TYPEelements.X509_ATTRIBUTE_get0_type()β returnsNULLon error; otherwise it returns anASN1_TYPEobject.X509_ATTRIBUTE_get0_data()β returnsNULLif an error occurs; otherwise it returns the data associated with anASN1_TYPEobject.X509_ATTRIBUTE_set1_object()andX509_ATTRIBUTE_set1_data()β both return1on success, or0otherwise.X509_ATTRIBUTE_create(),X509_ATTRIBUTE_create_by_OBJ(),X509_ATTRIBUTE_create_by_NID()andX509_ATTRIBUTE_create_by_txt()β return either anX509_ATTRIBUTEon success, orNULLif there is an error.X509at_add1_attr(),X509at_add1_attr_by_OBJ(),X509at_add1_attr_by_NID()andX509at_add1_attr_by_txt()β returnNULLon error; otherwise they return a list ofX509_ATTRIBUTE.X509at_get0_data_by_OBJ()β returns the data retrieved from the firstASN1_TYPEobject of the found attributes, orNULLif an error occurs.
π SEE ALSO π
go peek at these besties, theyβre all part of the lore:
ASN1_TYPE_get(3)ASN1_INTEGER_get(3)ASN1_ENUMERATED_get(3)ASN1_STRING_get0_data(3)ASN1_STRING_length(3)ASN1_STRING_type(3)X509_REQ_get_attr(3)EVP_PKEY_get_attr(3)CMS_signed_get_attr(3)PKCS8_pkey_get0_attrs(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>.
mwah π source/version 3.5.0, dated 2026-09-25 β X509_ATTRIBUTE(3ossl) signing off π«Άβ¨
π¦ 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