X509_GET_SERIALNUMBER(3ossl)
π X509_GET_SERIALNUMBER π
okay bestie, so this is the 3ossl page for the OpenSSL serial number girlies. it's all about getting and setting the serial number on a certificate. yes, THE serial number. the one that makes your cert β¨uniqueβ¨. let's get into it π
β¨ NAME β¨
X509_get_serialNumber, X509_get0_serialNumber, X509_set_serialNumber, X509_ACERT_get0_serialNumber, X509_ACERT_set1_serialNumber β get or set certificate serial number. that's the whole vibe, we're fetching numbers and we're setting numbers π¦
β¨ SYNOPSIS β¨
first up, the regular cert ones:
#include <openssl/x509.h>
ASN1_INTEGER *X509_get_serialNumber(X509 *x);
const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x);
int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
and then the attribute certificate ones, different header, same energy:
#include <openssl/x509_acert.h>
ASN1_INTEGER *X509_ACERT_get0_serialNumber(X509_ACERT *x);
int X509_ACERT_set1_serialNumber(X509_ACERT *x, ASN1_INTEGER *serial);
β¨ DESCRIPTION β¨
X509_get_serialNumber() hands you back the serial number of certificate x, and it comes as an ASN1_INTEGER structure. you can examine it, you can initialise it, do your thing. but β and this is the part where you gotta pay attention, no cap β the value it returns is an internal pointer, and it MUST NOT be freed up after the call. like, do not free it. put the free() down. it's not yours π
X509_get0_serialNumber() is literally the same as X509_get_serialNumber() except it takes a const parameter and gives you back a const result. const girlie behaviour, we respect it π
X509_set_serialNumber() sets the serial number of certificate x to serial. here's the tea: a copy of the serial number is used internally, so you should free up serial after use. yes bestie, that one IS yours to free. different rules, keep up π«Ά
X509_ACERT_get0_serialNumber() does the exact same operation as X509_get_serialNumber(), but for attribute certificates.
X509_ACERT_set1_serialNumber() does the exact same operation as X509_set_serialNumber(), but for attribute certificates. matching set, slay π
β¨ RETURN VALUES β¨
X509_get_serialNumber(), X509_get0_serialNumber() and X509_ACERT_get0_serialNumber() all return a pointer to an ASN1_INTEGER structure. pointer city π«
X509_set_serialNumber() and X509_ACERT_set1_serialNumber() return 1 for success and 0 for failure. classic binary, love that for them β¨
β¨ 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)
the whole friend group fr fr π
β¨ HISTORY β¨
X509_get_serialNumber() and X509_set_serialNumber() have been around since all versions of OpenSSL. og behaviour, iconic, periodt π
X509_get0_serialNumber() showed up in OpenSSL 1.1.0. the const queen arrives π
X509_ACERT_get0_serialNumber() and X509_ACERT_set1_serialNumber() are the babies β added in OpenSSL 3.4 π
β¨ COPYRIGHT β¨
Copyright 2016-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 π go forth and serial-number responsibly. remember: internal pointer = do NOT free. copied serial = DO free. iykyk π§
okay love u, bye!! this was OpenSSL 3.5.9, dated 2026-09-29, and yeah it's the X509_GET_SERIALNUMBER(3ossl) page in case you forgot where you were πΈπ
π¦ 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