X509_ATTRIBUTE(3ossl)
π X509_ATTRIBUTE (3ossl) β X509 attribute functions π
okay bestie, welcome to the 3ossl manual page for X509_ATTRIBUTE and its whole friend group. grab a boba, because this is the X509 attribute functions page and it is lowkey a lot. π
β¨ NAME β¨
This page covers 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, and X509_ATTRIBUTE_get0_type β literally the 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 the main characters in a bunch of standards, including X509, X509_REQ, PKCS12, PKCS8, PKCS7, and CMS. π
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. β¨
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. π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 nonNULLor an error will occur. If*xisNULL, 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. no duplicates allowed, periodt π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 nonNULLor an error will occur. If*xisNULL, 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_OBJECT, then it is freed. An error occurs if eitherattrorobjareNULL, 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-1, then internallyASN1_STRING_type_new()is used with the passed inattrtype. Ifattrtypeis0, the 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*attrisNULL, 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. counting era π’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 toNULL. 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-1, then an error will occur if there are multiple objects in the listxthat matchobj. Iflastposis less than-2, then an error will occur if there is more than oneASN1_TYPEobject in the found attribute. π
π RETURN VALUES π
okay bestie this is the part where everybody's like "what do I actually get back" and honestly? valid question. let's go through it one by one, no cap π₯
X509at_get_attr_count()β returns the number of attributes in the list x, or-1if x isNULL. simple as that π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. yes,-1is doing double duty here, she's an icon πX509at_get_attr_by_NID()β basically the same vibe asX509at_get_attr_by_OBJ(), except it returns-2if the nid is not known by OpenSSL. so like,-2is the "girl I've never heard of her" code π«X509at_get_attr()β returns either anX509_ATTRIBUTEorNULLif there is an error.X509at_delete_attr()β returns either the removedX509_ATTRIBUTEorNULLif there is a error. (yes the original said "a error", iconic grammar moment, we keep it π)X509_ATTRIBUTE_count()β returns-1on error, otherwise it returns the number ofASN1_TYPEelements. count 'em up bestie β¨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. she's giving "here's the actual payload" πX509_ATTRIBUTE_set1_object()andX509_ATTRIBUTE_set1_data()β returns1on success, or0otherwise. classic ones-and-zeros energy fr fr βX509_ATTRIBUTE_create(),X509_ATTRIBUTE_create_by_OBJ(),X509_ATTRIBUTE_create_by_NID()andX509_ATTRIBUTE_create_by_txt()β return either aX509_ATTRIBUTEon success, orNULLif there is a error. the whole create squad, all matching π§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. note the flip:NULLmeans bad here, not "no match" πX509at_get0_data_by_OBJ()β returns the data retrieved from the found attributes firstASN1_TYPEobject, orNULLif an error occurs.
π¨ vibe check / PSA: watch those negatives carefully bestie.-1and-2show up as "not found" signals in some of these, whileNULLmeans error in others. they are not interchangeable, okay? don't be out here treating every failure like it's the same flavour π
π SEE ALSO π
go read these next, they're all part of the same family tree, iykyk π¦
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>.
and that's the whole page bestie, you ate that π
β¨ this little beauty is from OpenSSL 3.5.6, dated 2026-04-07 β go forth and handle your attributes responsibly, mwah π«Άππ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms