I2D_RE_X509_TBS(3SSL)
π I2D_RE_X509_TBS β the OpenSSL one, bestie
okay so this is from the OpenSSL manual, section 3SSL, and it's all about the encode/decode glow-up for X509 certs. sit down, hydrate, we're doing certificates π
β¨ NAME β¨
d2i_X509_AUX, i2d_X509_AUX, i2d_re_X509_tbs, i2d_re_X509_CRL_tbs, i2d_re_X509_REQ_tbs β X509 encode and decode functions. that's the whole squad π«Ά
β¨ 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);
β¨ DESCRIPTION β¨
so the X509 encode + decode routines do their thing on an X509 structure, which is, like, the whole personality of an X509 certificate. iconic. π
d2i_X509_AUX() is basically d2i_X509(3)'s cousin, except the input is expected to be an X509 certificate followed by auxiliary trust information. the PEM routines use this to read "TRUSTED CERTIFICATE" objects.
π¨ bestie. This function should not be called on untrusted input. do not pass random bytes to it, i am begging.
i2d_X509_AUX() is the i2d_X509(3)-ish one, but the encoded output contains BOTH the certificate AND any auxiliary trust information. the PEM routines use it to write "TRUSTED CERTIFICATE" objects. heads up tho: this is a non-standard, OpenSSL-specific data format. it's giving β¨customβ¨, not giving RFC.
i2d_re_X509_tbs() is like 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 ones for a CRL and a certificate request respectively. the "re" in i2d_re_X509_tbs stands for "re-encode", and it makes sure a fresh encoding gets generated in case the object was modified after creation (peep the BUGS section for why that matters π).
the encoding of the TBSCertificate portion of a certificate is cached inside the X509 structure, internally β lowkey for encoding performance, highkey so certificate signatures get verified correctly in some certs that have broken (non-DER) encodings. slay for correctness π
and if, after modification, the X509 object gets 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 validX509structure, orNULLif an error occurred. πi2d_X509_AUX()returns the length of the encoded data, or-1on error.i2d_re_X509_tbs(),i2d_re_X509_CRL_tbs()andi2d_re_X509_REQ_tbs()return the length of the encoded data, or<=0on error.
β¨ SEE ALSO β¨
go read these too, i'm obsessed:
ERR_get_error(3)X509_CRL_get0_by_serial(3)X509_get0_signature(3)X509_get_ext_d2i(3)X509_get_extension_flags(3)X509_get_pubkey(3)X509_get_subject_name(3)X509_get_version(3)X509_NAME_add_entry_by_txt(3)X509_NAME_ENTRY_get_object(3)X509_NAME_get_index_by_NID(3)X509_NAME_print_ex(3)X509_new(3)X509_sign(3)X509V3_get_d2i(3)X509_verify_cert(3)
β¨ COPYRIGHT β¨
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, no skips no cuts π¦ and for the sign-off: this one's from OpenSSL 4.0.3, dated 2026-09-29 β so if you're reading this, hi from the future, go re-encode your TBS, mwah ππβ¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms