X509_ATTRIBUTE_NEW(3)
π X509_ATTRIBUTE_NEW(3) π
hii bestie π so this is a page from the Library Functions Manual, and it's all about the generic X.501 Attribute β like, the ASN.1 version, not the vibe you're thinking of. it's giving "very foundational, very abstract, slightly unhinged" and honestly? we're gonna get through it together. buckle up π¦
β¨ NAME β¨
X509_ATTRIBUTE_new, X509_ATTRIBUTE_create, X509_ATTRIBUTE_dup, X509_ATTRIBUTE_free β generic X.501 Attribute π
okay so, four functions, one data type, let's GO π
πΈ SYNOPSIS πΈ
library βlibcryptoβ
#include <openssl/x509.h>
X509_ATTRIBUTE *
X509_ATTRIBUTE_new(void);
X509_ATTRIBUTE *
X509_ATTRIBUTE_create(int nid, int type, void *value);
X509_ATTRIBUTE *
X509_ATTRIBUTE_dup(X509_ATTRIBUTE *attr);
void
X509_ATTRIBUTE_free(X509_ATTRIBUTE *attr);
no cap, that's the whole cast of characters right there π
π¦ DESCRIPTION π¦
so in the X.501 standard, an Attribute is the fundamental ASN.1 data type used to represent, like, any kind of property of any kind of directory entry. yes ma'am, it's the "one size fits all" of ASN.1 and it is absolutely main character energy β¨
now here's the tea π β in OpenSSL, very few objects actually use it directly. the big three that do:
- the
X509_REQ_INFOobject used for PKCS#10 certification requests, described inX509_REQ_new(3) - the
PKCS8_PRIV_KEY_INFOobject used for PKCS#8 private key information, described inPKCS8_PRIV_KEY_INFO_new(3) - the
PKCS12_SAFEBAGcontainer object described inPKCS12_SAFEBAG_new(3)
like, ikykyk, it's a whole little squad π«Ά
the four functions, one by one
X509_ATTRIBUTE_new()β allocates and initializes an emptyX509_ATTRIBUTEobject. that's it, that's the whole thing. a fresh blank slate, a clean girlie with nothing in her set of values yet πX509_ATTRIBUTE_create()β allocates a shiny new multi-valuedX509_ATTRIBUTEobject of type nid, and initializes its set of values to contain one new ASN.1 ANY object with the given value and type. β¨ the type usually is one of theV_ASN1_*constants defined in<openssl/asn1.h>; it is stored without validating it (yes, really, no vibe check at all π). if the function succeeds, ownership of the value is transferred to the newX509_ATTRIBUTEobject β so don't go freeing it yourself afterwards, that's a whole mess πͺ¦
β οΈ bestie pls be careful to not confuse the type of the attribute and the type of the value. they are two different things and mixing them up is a classic own-goal π
X509_ATTRIBUTE_dup()β creates a deep copy of attr. deep. copy. not a little hand-holdy shallow one, a real one πX509_ATTRIBUTE_free()β frees attr. bye bestie π
π RETURN VALUES π
X509_ATTRIBUTE_new(),X509_ATTRIBUTE_create(), andX509_ATTRIBUTE_dup()return the newX509_ATTRIBUTEobject, orNULLif an error occurs.
in particular, these functions fail if memory allocation fails (rude of the allocator honestly π). X509_ATTRIBUTE_create() also fails if OBJ_nid2obj(3) fails on nid.
π₯ SEE ALSO π₯
the whole extended friend group, no gatekeeping π«Ά
d2i_X509_ATTRIBUTE(3)OBJ_nid2obj(3)PKCS12_SAFEBAG_new(3)PKCS7_add_attribute(3)PKCS8_pkey_get0_attrs(3)PKCS8_PRIV_KEY_INFO_new(3)X509_ATTRIBUTE_get0_object(3)X509_ATTRIBUTE_set1_object(3)X509_EXTENSION_new(3)X509_new(3)X509_REQ_add1_attr(3)X509_REQ_new(3)
π STANDARDS π
the receipts, as promised π§Ύ
for the general definition of the Attribute data type:
ITU-T Recommendation X.501, also known as ISO/IEC 9594-2: Information Technology β Open Systems Interconnection β The Directory: Models, section 8.2: Overall structure
for the specific definition in the context of certification requests:
RFC 2986: PKCS #10: Certification Request Syntax Specification, section 4.1: CertificationRequestInfo
for the specific use in the context of private key information:
RFC 5208: Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification
for the specific definition in the context of PFX:
RFC 7292: PKCS #12: Personal Information Exchange Syntax, section 4.2: The SafeBag Type
slay, citations complete β
πΊ HISTORY πΊ
a lil throwback moment π°οΈ
X509_ATTRIBUTE_new()andX509_ATTRIBUTE_free()first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.X509_ATTRIBUTE_create()andX509_ATTRIBUTE_dup()first appeared in SSLeay 0.9.1 and have been available since OpenBSD 2.6.
elder emojis only for these two, they've been here a WHILE π§
π BUGS π
okay this section is fully just the manpage author having a moment and honestly? valid. π
- A data type designed to hold arbitrary data is an oxymoron.
- While it may occasionally be useful for abstract syntax specification or for generic container objects, using it for the representation of specific data in a specific data structure feels like dubious design.
- Having two distinct data types to hold arbitrary data β in this case,
X509_ATTRIBUTEon the X.501 language level andX509_EXTENSIONas described inX509_EXTENSION_new(3)on the X.509 language level β feels even more questionable, in particular considering that Attributes in certification requests can be used to ask for Extensions in certificates. - At the very least, the direct use of the low-level generic
X509_ATTRIBUTEtype in specific data types like certification requests or private key information looks like a layering violation and appears to put type safety into jeopardy.
ngl the last two paragraphs are a read π and the author ate, no crumbs.
and that's the page bestie!! π this one's from the Debian build, dated June 8, 2025, and it lives under the name X509_ATTRIBUTE_NEW(3) in your manpages π go forth and don't confuse your attribute type with your value type, mwah π«Άβ¨
π¦ 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) 2016, 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