X509_GET_VERSION(3ossl)

πŸ’– X509_GET_VERSION πŸ’–

okay bestie, welcome to the X509_GET_VERSION(3ossl) page β€” yes it's an OpenSSL joint, section 3ossl, and it's literally the whole get-or-set-the-version-field situation for certificates, cert requests, CRLs and the new attribute certs. buckle up, it's giving very specific but very slay. πŸŽ€


✨ NAME ✨

So the whole squad here is: X509_get_version, X509_set_version, X509_REQ_get_version, X509_REQ_set_version, X509_ACERT_get_version, X509_ACERT_set_version, X509_CRL_get_version, and X509_CRL_set_version.

And what do they do? They get or set the version of a certificate, a certificate request, or a CRL. that's the whole job. no cap. πŸ’…


🌈 SYNOPSIS 🌈

first you gotta pull in the header, and for the ACERT girlies you need a different one, so pay attention:

#include <openssl/x509.h>

long X509_get_version(const X509 *x);
int X509_set_version(X509 *x, long version);

long X509_REQ_get_version(const X509_REQ *req);
int X509_REQ_set_version(X509_REQ *x, long version);

long X509_CRL_get_version(const X509_CRL *crl);
int X509_CRL_set_version(X509_CRL *x, long version);

#include <openssl/x509_acert.h>

int X509_ACERT_set_version(X509_ACERT *x, long version);
long X509_ACERT_get_version(const X509_ACERT *x);

πŸ¦‹ DESCRIPTION πŸ¦‹

X509_get_version() hands you back the numerical value of the version field of certificate x. and those numbers line up with the constants X509_VERSION_1, X509_VERSION_2, and X509_VERSION_3.

🚨 okay this is the plot twist, so listen: the values of these constants are defined by standards (X.509 et al) to be one less than the certificate version. so X509_VERSION_3 has value 2, and X509_VERSION_1 has value 0. it's not a typo, it's the standards being iconic in the worst way. πŸ’€

X509_set_version() sets the numerical value of the version field of certificate x to version. boom. done.

Similarly β€” and yes, similarly is doing a lot of heavy lifting here β€” X509_REQ_get_version(), X509_REQ_set_version(), X509_ACERT_get_version(), X509_ACERT_set_version(), X509_CRL_get_version() and X509_CRL_set_version() get and set the version number of certificate requests and CRLs. They use the constants X509_REQ_VERSION_1, X509_ACERT_VERSION_2, X509_CRL_VERSION_1, and X509_CRL_VERSION_2. periodt. 🫢


🌸 NOTES 🌸

The version field of certificates, certificate requests and CRLs has a DEFAULT value of v1(0) β€” meaning the field should just be omitted for version 1. and the best part? this is handled transparently by these functions, so you don't gotta do anything. she does it herself, main character energy fr fr. ✨


πŸ’œ RETURN VALUES πŸ’œ

  • X509_get_version(), X509_REQ_get_version() and X509_CRL_get_version() return the numerical value of the version field. πŸ’–
  • X509_set_version(), X509_REQ_set_version() and X509_CRL_set_version() return 1 for success and 0 for failure. so like, check it, bestie, don't just vibe past it.

πŸ‘‘ SEE ALSO πŸ‘‘

the whole extended universe, go read these:


🧚 HISTORY 🧚

  • X509_get_version(), X509_REQ_get_version() and X509_CRL_get_version() are functions in OpenSSL 1.1.0 β€” in previous versions they were macros. glow-up fr. πŸ”₯
  • X509_ACERT_get_version(), X509_ACERT_set_version() were added in OpenSSL 3.4. the new girls on the block. πŸŽ€

Copyright 2015-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, you ate. go set some versions, but responsibly. πŸ’…πŸ¦‹

signing off from the 3.5.9 era, dated 2026-09-29 β€” stay iconic, xoxo πŸ’–

πŸ“¦ where this page comes from