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. soX509_VERSION_3has value 2, andX509_VERSION_1has 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()andX509_CRL_get_version()return the numerical value of the version field. πX509_set_version(),X509_REQ_set_version()andX509_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:
d2i_X509(3)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_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)
π§ HISTORY π§
X509_get_version(),X509_REQ_get_version()andX509_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 β
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
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms