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 the req object β€” or -1 if that attribute list is NULL. (not me getting a -1... 😭)
  • X509_REQ_get_attr_by_OBJ()</p> returns -1 if either the attribute list of the req object is empty OR obj is not found. otherwise it returns the location of obj in the attribute list. queen of boundaries πŸ’…
  • X509_REQ_get_attr_by_NID()</p> is similar to X509_REQ_get_attr_by_OBJ(), except it returns -2 if the nid is not known by OpenSSL. yes, -2. it's a whole different flavour of no.
  • X509_REQ_get_attr()</p> returns either an X509_ATTRIBUTE or NULL on error.
  • X509_REQ_delete_attr()</p> returns either the removed X509_ATTRIBUTE or NULL if there is a error.
  • X509_REQ_add1_attr()</p>, X509_REQ_add1_attr_by_OBJ()</p>, X509_REQ_add1_attr_by_NID()</p> and X509_REQ_add1_attr_by_txt()</p> return 1 on success or 0 on 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 πŸ‘‘


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