I2D_RE_X509_TBS(3ossl)

πŸ’– I2D_RE_X509_TBS πŸ’–

okay bestie, so this is a page from the OpenSSL manual, and it's all about the X509 encode/decode girlies. specifically d2i_X509_AUX, i2d_X509_AUX, i2d_re_X509_tbs, i2d_re_X509_CRL_tbs and i2d_re_X509_REQ_tbs. we're gonna get into it. no cap.


✨ NAME ✨

d2i_X509_AUX, i2d_X509_AUX, i2d_re_X509_tbs, i2d_re_X509_CRL_tbs, i2d_re_X509_REQ_tbs β€” the X509 encode and decode functions. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/x509.h>

X509 *d2i_X509_AUX(X509 **px, const unsigned char **in, long len);
int i2d_X509_AUX(const X509 *x, unsigned char **out);
int i2d_re_X509_tbs(X509 *x, unsigned char **out);
int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp);
int i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp);

look at her. five functions. iconic. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the X509 encode and decode routines encode and parse an X509 structure, which β€” plot twist β€” represents an X509 certificate. slay.


d2i_X509_AUX() is giving similar-to-d2i_X509(3) energy, except the input is expected to consist of an X509 certificate followed by auxiliary trust information. this is what the PEM routines use to read "TRUSTED CERTIFICATE" objects. πŸ’–

🚨 bestie listen to me: this function should not be called on untrusted input. fr fr. don't do it.

i2d_X509_AUX() is the i2d_X509(3) cousin, but the encoded output contains both the certificate and any auxiliary trust information. the PEM routines use this one to write "TRUSTED CERTIFICATE" objects. 😌

ngl, this is a non-standard OpenSSL-specific data format. iykyk. it's not like, universal.

i2d_re_X509_tbs() is similar to i2d_X509(3) except it encodes only the TBSCertificate portion of the certificate. and i2d_re_X509_CRL_tbs() and i2d_re_X509_REQ_tbs() are the analogous girlies for CRL and certificate request, respectively. 🌈

the "re" in i2d_re_X509_tbs stands for "re-encode", and it ensures a fresh encoding is generated in case the object has been modified after creation (peep the BUGS section πŸ‘€).


okay so the encoding of the TBSCertificate portion of a certificate is cached in the X509 structure internally β€” to improve encoding performance, and also to make sure certificate signatures are verified correctly in some certificates with broken (non-DER) encodings. she's doing two jobs. main character energy. πŸ‘‘


and here's the tea πŸ“: if, after modification, the X509 object is re-signed with X509_sign(), the encoding is automatically renewed. otherwise? you can manually renew the encoding of the TBSCertificate portion of the X509 by calling i2d_re_X509_tbs(). your girl, your call. πŸ’…


⭐ RETURN VALUES ⭐

  • d2i_X509_AUX() β€” returns a valid X509 structure, or NULL if an error occurred. 😭
  • i2d_X509_AUX() β€” returns the length of encoded data, or -1 on error.
  • i2d_re_X509_tbs(), i2d_re_X509_CRL_tbs() and i2d_re_X509_REQ_tbs() β€” return the length of encoded data, or <=0 on error.

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, periodt:


Copyright 2002-2018 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>.


okay that's the whole page, bestie!! you ate. go re-encode something responsibly πŸ’œβœ¨

this was OpenSSL 3.5.9, dated 2026-09-29 β€” I2D_RE_X509_TBS(3ossl), signing off πŸ¦‹πŸ’–

πŸ“¦ where this page comes from