X509_NEW(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

πŸŽ€ X509_NEW(3) πŸŽ€ β€” the X.509 certificate object, but make it make sense

okay so this is X509_NEW(3), your Library Functions Manual entry for the X.509 certificate object, and we're gonna keep every fact intact while making it cute. no cap πŸ’…


🌸 NAME 🌸

X509_new, X509_dup, X509_REQ_to_X509, X509_free, X509_up_ref, X509_chain_up_ref β€” X.509 certificate object. that's the whole squad, bestie 🫢


✨ SYNOPSIS ✨

#include <openssl/x509.h>

X509 *
X509_new(void);

X509 *
X509_dup(X509 *a);

X509 *
X509_REQ_to_X509(X509_REQ *req, int days, EVP_PKEY *pkey);

void
X509_free(X509 *a);

int
X509_up_ref(X509 *a);

STACK_OF(X509) *
X509_chain_up_ref(STACK_OF(X509) *chain);

πŸ’– DESCRIPTION πŸ’–

  • X509_new() β€” allocates and initializes an empty X509 object with reference count 1. it represents an ASN.1 Certificate structure defined in RFC 5280 section 4.1. it can hold a public key together with information about the person, organization, device, or function the associated private key belongs to. iconic little container, honestly πŸ‘‘
  • X509_dup() β€” creates a deep copy of a using ASN1_item_dup(3), setting the reference count of the copy to 1. deep copy means deep copy, bestie πŸ¦‹
  • X509_REQ_to_X509() β€” allocates a new certificate object, copies the public key from req into it, copies the subject name of req to both the subject and issuer names of the new certificate, sets the notBefore field to the current time and the notAfter field to the given number of days in the future, and signs the new certificate with X509_sign(3) using pkey and the MD5 algorithm. if req contains at least one attribute, the version of the new certificate is set to 2. yes, MD5, that's literally what the page says 🫠
  • X509_free() β€” decrements the reference count of the X509 structure a and frees it up if the reference count reaches 0. if a is a NULL pointer, no action occurs. polite and tidy ✨
  • X509_up_ref() β€” increments the reference count of a by 1. this function is useful if a certificate structure is being used by several different operations each of which will free it up after use: this avoids the need to duplicate the entire certificate structure. sharing is caring, but with refcounts πŸ’…
  • X509_chain_up_ref() β€” performs a shallow copy of the given chain using sk_X509_dup() and increments the reference count of each contained certificate by 1. its purpose is similar to X509_up_ref(): the returned chain persists after the original is freed. shallow copy, strong boundaries 🧚

🌈 RETURN VALUES 🌈

  • X509_new(), X509_dup(), and X509_REQ_to_X509() β€” return a pointer to the newly allocated object or NULL if an error occurs; an error code can be obtained by ERR_get_error(3). bestie, check your errors 😭
  • X509_up_ref() β€” returns 1 for success or 0 for failure.
  • X509_chain_up_ref() β€” returns the copy of the chain or NULL if an error occurs.

πŸ¦‹ SEE ALSO πŸ¦‹


⭐ STANDARDS ⭐

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile. periodt πŸ’œ


πŸŽ€ HISTORY πŸŽ€

  • X509_new() and X509_free() appeared in SSLeay 0.4 or earlier.
  • X509_dup() appeared in SSLeay 0.4.4.
  • X509_REQ_to_X509() appeared in SSLeay 0.6.0.
  • These functions have been available since OpenBSD 2.4.
  • X509_up_ref() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.1.
  • X509_chain_up_ref() first appeared in OpenSSL 1.0.2 and has been available since OpenBSD 6.3.

ngl, that's a whole little timeline and it ate πŸ•°οΈβœ¨


πŸ’€ BUGS πŸ’€

The X.509 public key infrastructure and its data types contain too many design bugs to list them. for lots of examples, see the classic X.509 Style Guide: https://www.cs.auckland.ac.nz/~pgut001/pubs/x509guide.txt that Peter Gutmann published in 2000. not me exposing the lore, but there it is 😭


this X509_NEW(3) moment was brought to you by Debian, dated September 2, 2024 β€” now go forth and certify something, bestie πŸ’–

πŸ“¦ where this page comes from