X509_REQ_GET_ATTR(3ossl)
π X509_REQ_GET_ATTR π
okay bestie, sit down, hydrate, and let's talk π«Ά this one is X509_REQ_GET_ATTR(3ossl), aka the OpenSSL manual page for X509_ATTRIBUTE support for signed certificate requests. it's giving "certificate request but make it β¨decoratedβ¨" and honestly? iconic. no cap, every function on this page is here to help you poke at the attribute list inside an X509_REQ, and you're gonna slay it.
β¨ NAME β¨
X509_REQ_get_attr_count</p>, X509_REQ_get_attr_by_NID</p>, X509_REQ_get_attr_by_OBJ</p>, X509_REQ_get_attr</p>, X509_REQ_delete_attr</p>, X509_REQ_add1_attr</p>, X509_REQ_add1_attr_by_OBJ</p>, X509_REQ_add1_attr_by_NID</p>, X509_REQ_add1_attr_by_txt</p> β that's the whole squad π
and the vibe is X509_ATTRIBUTE support for signed certificate requests.
π SYNOPSIS π
okay so first things first, you gotta invite the header:
#include <openssl/x509.h>
int X509_REQ_get_attr_count(const X509_REQ *req);
int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, int lastpos);
int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj,
int lastpos);
X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
const ASN1_OBJECT *obj, int type,
const unsigned char *bytes, int len);
int X509_REQ_add1_attr_by_NID(X509_REQ *req,
int nid, int type,
const unsigned char *bytes, int len);
int X509_REQ_add1_attr_by_txt(X509_REQ *req,
const char *attrname, int type,
const unsigned char *bytes, int len);
copy it exactly bestie, don't get creative with the signatures π
πΈ DESCRIPTION πΈ
X509_REQ_get_attr_by_OBJ()</p> hunts down the location of the first matching object obj in the attribute list of req. the search does NOT start at zero β it starts at the position after lastpos. so if the value it hands back is positive, congrats, you can feed it straight into the next X509_REQ_get_attr_by_OBJ() call as the new lastpos and keep iterating through the rest of the attributes like a little for-loop main character π¦. and on that very first call? you can set lastpos to any negative value and it'll start searching from the beginning of the attribute list. periodt.
X509_REQ_get_attr_by_NID()</p> is the same energy as X509_REQ_get_attr_by_OBJ(), except instead of the object itself you pass the numerical identifier (NID) nid that's associated with that object. wanna know your options? go look at <openssl/obj_mac.h> for the list of NID_* β
X509_REQ_get_attr()</p> returns the X509_ATTRIBUTE object sitting at index loc in the attribute list of req. and loc has to be in the range from 0 to X509_REQ_get_attr_count() - 1, so please stay in your lane π«Ά
X509_REQ_delete_attr()</p> removes the X509_ATTRIBUTE object at index loc in the list of attributes of the req object. and heads up β an error occurs if req is NULL π
X509_REQ_add1_attr()</p> pushes a copy of the X509_ATTRIBUTE you handed it (attr>) onto the req object's attribute list. but bestie, an error will occur if either the attribute list is NULL or the attribute already exists. we do not do duplicates here, we do not do chaos.
X509_REQ_add1_attr_by_OBJ()</p> builds a brand new X509_ATTRIBUTE for you, 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 that fresh little thing onto the req object's attribute list. req must be non NULL or an error will occur, fr fr. and if obj already exists in the attribute list? error. again. no duplicates, no exceptions.
X509_REQ_add1_attr_by_NID()</p> is similar to X509_REQ_add1_attr_by_OBJ(), except it passes the numerical identifier (NID) nid associated with the object. once again, <openssl/obj_mac.h> has your list of NID_* π
X509_REQ_add1_attr_by_txt()</p> is similar to X509_REQ_add1_attr_by_OBJ(), except it passes a name attrname associated with the object. and this time you want <openssl/obj_mac.h> for the list of SN_* names β¨
and if you want the deep lore on attributes themselves, refer to X509_ATTRIBUTE(3). it's the prequel, babe π¬
π«Ά RETURN VALUES π«Ά
X509_REQ_get_attr_count()</p> returns the number of attributes in the attribute list of thereqobject β or-1if that attribute list isNULL. (not me getting a-1... π)X509_REQ_get_attr_by_OBJ()</p> returns-1if either the attribute list of thereqobject is empty ORobjis not found. otherwise it returns the location ofobjin the attribute list. queen of boundaries πX509_REQ_get_attr_by_NID()</p> is similar toX509_REQ_get_attr_by_OBJ(), except it returns-2if thenidis not known by OpenSSL. yes,-2. it's a whole different flavour of no.X509_REQ_get_attr()</p> returns either anX509_ATTRIBUTEorNULLon error.X509_REQ_delete_attr()</p> returns either the removedX509_ATTRIBUTEorNULLif there is a error.X509_REQ_add1_attr()</p>,X509_REQ_add1_attr_by_OBJ()</p>,X509_REQ_add1_attr_by_NID()</p> andX509_REQ_add1_attr_by_txt()</p> return1on success or0on error. classic 1-or-0 behaviour, we love consistency β
π¦ NOTES π¦
any functions that modify the attributes (add or delete) internally set a flag to indicate the ASN.1 encoding has been modified. so like, yeah, they're marking their territory. the encoding knows. you know. everybody knows. π₯
π SEE ALSO π
X509_ATTRIBUTE(3)β go read it, it's the source material π
π 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 page bestie!! π this whole thing is from OpenSSL 3.5.9, dated 2026-09-29, and it's filed under X509_REQ_GET_ATTR(3ossl) β go forth, manage those attributes, and remember: no duplicates, no NULL, no drama. mwah πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms