X509_REQ_GET_ATTR(3SSL)

🌸 NAME 🌸

okay bestie, gather round πŸ’– this is the OpenSSL 3SSL manual page β€” yes, the whole squad lives here:

  • X509_REQ_get_attr_count
  • X509_REQ_get_attr_by_NID
  • X509_REQ_get_attr_by_OBJ
  • X509_REQ_get_attr
  • X509_REQ_delete_attr
  • X509_REQ_add1_attr
  • X509_REQ_add1_attr_by_OBJ
  • X509_REQ_add1_attr_by_NID
  • X509_REQ_add1_attr_by_txt

and together they're the X509_ATTRIBUTE support for signed certificate requests. periodt. πŸ‘‘


✨ SYNOPSIS ✨

#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);

πŸ’… DESCRIPTION πŸ’…

X509_REQ_get_attr_by_OBJ() goes hunting for the location of the first matching object obj in the req attribute list. the search starts at the position after lastpos, okay? and here's the cute part β€” if the value it hands back is positive, you can totally feed it right back into the next call of X509_REQ_get_attr_by_OBJ() as the value of lastpos and just iterate through all the remaining attributes. slay. πŸ¦‹ and if you're starting fresh? set lastpos to any negative value on that first call and it'll search from the very start of the attribute list.

X509_REQ_get_attr_by_NID() is giving the same energy as X509_REQ_get_attr_by_OBJ(), except it passes the numerical identifier (NID) nid that's associated with the object. check <openssl/obj_mac.h> for the full list of NID_*. πŸ“‹

X509_REQ_get_attr() returns the X509_ATTRIBUTE object sitting at index loc in the req attribute list. quick vibe check: loc should be somewhere in the range from 0 to X509_REQ_get_attr_count() - 1. no off-by-one shenanigans pls 😭

X509_REQ_delete_attr() removes the X509_ATTRIBUTE object at index loc in the req object's list of attributes. an error occurs if req is NULL. gone, deleted, not me being dramatic πŸ’€

X509_REQ_add1_attr() pushes a copy of the passed-in X509_ATTRIBUTE attr to the req object's attribute list. an error will occur if either the attribute list is NULL or the attribute already exists. (yes, we do not do duplicates here bestie, rules are rules.)

X509_REQ_add1_attr_by_OBJ() creates a brand new X509_ATTRIBUTE 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 it to the req object's attribute list. req must be non NULL or an error will occur. and if obj already exists in the attribute list? an error occurs. πŸ™ˆ

X509_REQ_add1_attr_by_NID() is basically X509_REQ_add1_attr_by_OBJ() but it passes the numerical identifier (NID) nid associated with the object. check <openssl/obj_mac.h> for the list of NID_*. ⭐

X509_REQ_add1_attr_by_txt() is also basically X509_REQ_add1_attr_by_OBJ(), except it passes a name attrname associated with the object. look at <openssl/obj_mac.h> for the list of SN_* names. πŸŽ€

and for all the tea on attributes in general, refer to X509_ATTRIBUTE(3). πŸ‘‘


πŸ”₯ RETURN VALUES πŸ”₯

  • X509_REQ_get_attr_count() returns the number of attributes in the req object attribute list, or -1 if the attribute list is NULL. 😭
  • X509_REQ_get_attr_by_OBJ() returns -1 if either the req object's attribute list is empty OR obj is not found. otherwise it returns the location of the obj in the attribute list. πŸ’–
  • X509_REQ_get_attr_by_NID() is similar to X509_REQ_get_attr_by_OBJ(), except it returns -2 if the nid isn't known by OpenSSL. (a whole different number, iconic honestly.) πŸ’…
  • X509_REQ_get_attr() returns either an X509_ATTRIBUTE or NULL on error.
  • X509_REQ_delete_attr() returns either the removed X509_ATTRIBUTE or NULL if there is an error.
  • X509_REQ_add1_attr(), X509_REQ_add1_attr_by_OBJ(), X509_REQ_add1_attr_by_NID() and X509_REQ_add1_attr_by_txt() return 1 on success or 0 on error.

🌈 NOTES 🌈

any function that modifies the attributes β€” add or delete, both of them β€” internally sets a flag to indicate that the ASN.1 encoding has been modified. πŸ“ so like, yeah, the data knows it changed. main character behavior fr fr.


🫢 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 whole page bestie, no cap πŸ§šπŸ’œ this was X509_REQ_GET_ATTR(3SSL) from the OpenSSL fam β€” version 4.0.3, dated 2026-09-29. go forth and handle those attributes, you've got this πŸ“βœ¨

πŸ“¦ where this page comes from