---
name: "X509_get_version"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/X509_get_version"
---

# X509\_get\_version(3ssl)

get or set certificate, certificate request or CRL version

## NAME

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, X509\_CRL\_set\_version - get or set certificate, certificate request or CRL version

## SYNOPSIS

```
 #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()** returns the numerical value of the version field of certificate *x*. These correspond to the constants **X509\_VERSION\_1**, **X509\_VERSION\_2**, and **X509\_VERSION\_3**. Note: 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.

**X509\_set\_version()** sets the numerical value of the version field of certificate *x* to *version*.

Similarly **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 constants **X509\_REQ\_VERSION\_1**, **X509\_ACERT\_VERSION\_2**, **X509\_CRL\_VERSION\_1**, and **X509\_CRL\_VERSION\_2**.

## NOTES

The version field of certificates, certificate requests and CRLs has a DEFAULT value of **v1(0)** meaning the field should be omitted for version 1. This is handled transparently by these functions.

## 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.

## SEE ALSO

**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()** and **X509\_CRL\_get\_version()** are functions in OpenSSL 1.1.0, in previous versions they were macros.

**X509\_ACERT\_get\_version()**, **X509\_ACERT\_set\_version()** were added in OpenSSL 3.4.

## 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\>.
