X509_ADD_CERT(3ossl)
π X509_add_cert, X509_add_certs β X509 certificate list addition functions π
okay bestie, welcome to X509_ADD_CERT(3ossl) β yes that's the manual page name, we're in the OpenSSL docs, section 3ossl, and today we're talking about adding certs to lists. riveting? no. essential? absolutely. let's go π¦
β¨ SYNOPSIS β¨
#include <openssl/x509.h>
int X509_add_cert(STACK_OF(X509) *sk, X509 *cert, int flags);
int X509_add_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs, int flags);
πΈ DESCRIPTION πΈ
so X509_add_cert() takes a certificate cert and adds it to the given list sk. and listen β if you pass NULL as the cert argument, that's an error, no cap. don't do it. π
then we have X509_add_certs(), which is the group-chat version: it adds a whole list of certificates certs to the given list sk. the certs argument is allowed to be NULL, and if it is, nothing happens at all β it's giving "no effect", truly nothing. also important: it does not modify the list certs itself. but β and this is the plot twist β if the X509_ADD_FLAG_UP_REF flag (we'll get to it, hold on) is set, then the reference counters of those of its members that actually got added to sk get increased. so like, the members are being touched, just not the list itself. π
both of these functions have a flags parameter, and that's the lil control panel for all the details of the operation. let's break it down:
X509_ADD_FLAG_DEFAULTβ this one equals0, and it means... no special semantics. literally just vibes. the default-est default to ever default. β¨X509_ADD_FLAG_UP_REFβ set this and the reference counts of those certificates that were added successfully get increased. (successfully is doing a lot of work in that sentence, keep it in mind, we come back to it in NOTES π)X509_ADD_FLAG_PREPENDβ set this and the certificates get prepended tosk. by default they're appended tosk. and in both cases the original order of the added certificates is preserved. so nobody's getting shuffled, we respect the queue. πX509_ADD_FLAG_NO_DUPβ set this and any certificates already contained inskget ignored. how do we know they're already there? that's determined usingX509_cmp(3). no dupes on this list, we're not doing that. π«X509_ADD_FLAG_NO_SSβ set this and certificates that are marked self-signed get ignored. and how do we know they're self-signed? that's determined usingX509_self_signed(3). bye self-signed girlies, not today. π
π₯ RETURN VALUES π₯
both functions return 1 for success and 0 for failure. that's it, that's the whole system. binary. slay. π
π«Ά NOTES π«Ά
okay real talk, this part matters:
if you useX509_add_certs()with the flagsX509_ADD_FLAG_NO_DUPorX509_ADD_FLAG_NO_SS, it is advisable to also useX509_ADD_FLAG_UP_REF, because otherwise, likely not for all members of thecertslist is the ownership transferred to the list of certificatessk. (that's the manpage talking, and it's saying: some of them won't get their ownership handed over, and you'd be leaving refcounts in a weird spot. messy. don't.) π
also, care should be taken in case the certs argument equals sk. like, same list? adding a list to itself? take care. be careful. that's the warning. π§
π SEE ALSO π
β HISTORY β
the functions X509_add_cert() and X509_add_certs() were added in OpenSSL 3.0. glow-up era. π
π COPYRIGHT π
Copyright 2019-2025 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 π«Ά this was version 3.5.9, dated 2026-09-29, and honestly? iconic of it. go forth and add your certs responsibly. periodt. πβ¨π
π¦ 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