LIBRESSL-X509_ATTRIBUTE_SET1_OBJECT(3)
π X509_ATTRIBUTE_SET1_OBJECT(3) β the glow-up
okay bestie, so this is the X509_ATTRIBUTE_SET1_OBJECT(3) page from the libcrypto library, and it's literally all about messing with an X.501 Attribute. it's giving "small API, big feelings" energy π
β¨ NAME β¨
X509_ATTRIBUTE_set1_object, X509_ATTRIBUTE_set1_data, X509_ATTRIBUTE_create_by_OBJ, X509_ATTRIBUTE_create_by_NID, X509_ATTRIBUTE_create_by_txt β modify an X.501 Attribute π
πΈ SYNOPSIS πΈ
library βlibcryptoβ #include <openssl/x509.h>
int
X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr,
const ASN1_OBJECT *obj);
int
X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int type,
const void *data, int len);
X509_ATTRIBUTE *
X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **pattr,
const ASN1_OBJECT *obj, int type, const void *data, int len);
X509_ATTRIBUTE *
X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **pattr, int nid, int type,
const void *data, int len);
X509_ATTRIBUTE *
X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **pattr, const char *name,
int type, const unsigned char *data, int len);
π DESCRIPTION π
π¦ X509_ATTRIBUTE_set1_object()
so this one sets the type of attr to obj. if obj is dynamically allocated, a deep copy is created (iconic, no sharing, we don't do that here π«Ά).
if the type of attr was already set, the old type is freed as far as it was dynamically allocated. periodt.
β οΈ heads up bestie β after calling this function, attr may be in an inconsistent state because its values may not agree with the new attribute type. it's giving "changed my whole personality but my old receipts are still in my bag" π
π X509_ATTRIBUTE_set1_data()
this one sets attr to be multi-valued and initializes its set of values to contain a single new ASN.1 ANY object representing the data. slay π
β the four cases (yes there are four, buckle up)
the interpretation of the data depends on the values of the type and len arguments; there are four different cases:
MBSTRING_FLAGis set. if thetypeargument has the bitMBSTRING_FLAGset,datais expected to point to a multibyte character string that islenbytes long and uses the encoding specified by thetypeargument, and it is expected that an attribute type was already assigned toattr, for example by callingX509_ATTRIBUTE_set1_object()before callingX509_ATTRIBUTE_set1_data(). in this case, an appropriate ASN.1 multibyte string type is chosen and a new object of that type is allocated and populated to represent the data by callingASN1_STRING_set_by_NID(3). the type of that new ASN.1 string object is subsequently used instead of thetypeargument. iykyk π₯- no
MBSTRING_FLAG, andlenis not-1. if thetypeargument does not have the bitMBSTRING_FLAGset and thelenargument is not-1, thetypeargument is expected to be one of the types documented inASN1_STRING_new(3)anddatais expected to point to a buffer oflenbytes. in this case, a new object is allocated withASN1_STRING_type_new(3)and populated withASN1_STRING_set(3). cute, simple, we love π - no
MBSTRING_FLAG, andlenis-1. if thetypeargument does not have the bitMBSTRING_FLAGset and thelenargument is-1,datais expected to point to an object of the given type rather than to a buffer. in this case, a deep copy of the existing object into the new ASN.1 ANY object is performed withASN1_TYPE_set1(3). deep copy queen π typeis0. if thetypeargument is0, thedataandlenarguments are ignored and the set of values is left empty instead of adding a single ASN.1 ANY object to it.
π warning, and this is real: case 4 violates section 8.2 of the X.501 standard, which requires every attribute to contain at least one value. but some attribute types used by the library use empty sets of values anyway. so like. we know. we do it anyway. not me being a rulebreaker π
π the create-by-* trio
X509_ATTRIBUTE_create_by_OBJ()β sets the type of**attrtoobjusingX509_ATTRIBUTE_set1_object()and copies the data into it usingX509_ATTRIBUTE_set1_data(). ifattror*attrisNULL, a newX509_ATTRIBUTEobject is allocated, populated, and returned. main character energy, it does everything for you β¨X509_ATTRIBUTE_create_by_NID()β a wrapper aroundX509_ATTRIBUTE_create_by_OBJ()that obtains the requiredobjargument by callingOBJ_nid2obj(3)on thenidargument.X509_ATTRIBUTE_create_by_txt()β a similar wrapper that obtainsobjby callingOBJ_txt2obj(3)with the argumentsnameand0, which means that long names, short names, and numerical OID strings are all acceptable. flexible icon π
π RETURN VALUES π
X509_ATTRIBUTE_set1_object()returns1if successful or0ifattrorobjisNULLor if memory allocation fails.X509_ATTRIBUTE_set1_data()returns1if successful or0ifattrisNULLor ifASN1_STRING_set_by_NID(3),ASN1_STRING_set(3),ASN1_TYPE_set1(3), or memory allocation fails.X509_ATTRIBUTE_create_by_OBJ(),X509_ATTRIBUTE_create_by_NID(), andX509_ATTRIBUTE_create_by_txt()return a pointer to the changed or new object orNULLif obtainingobj, allocating memory, or copying fails.
π§ SEE ALSO π§
ASN1_OBJECT_new(3), ASN1_STRING_new(3), ASN1_STRING_set(3), ASN1_STRING_set_by_NID(3), ASN1_TYPE_new(3), OBJ_nid2obj(3), X509_ATTRIBUTE_get0_object(3), X509_ATTRIBUTE_new(3)
like, read those too bestie, they're literally the supporting cast π«Ά
πΈ HISTORY πΈ
these functions first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7. vintage but still serving β¨
π BUGS π
if attr already contains one or more values, X509_ATTRIBUTE_set1_data(), X509_ATTRIBUTE_create_by_OBJ(), X509_ATTRIBUTE_create_by_NID(), and X509_ATTRIBUTE_create_by_txt() silently overwrite the pointers to the old values and leak the memory used for them. π no cap, that's a memory leak, keep it in mind!
mwah π that's the whole page β brought to you by Debian, dated June 8, 2025, and yes we're still out here reading X509_ATTRIBUTE_SET1_OBJECT(3) for fun. bye bestie! π¦π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms