X509_STORE_ADD_CERT(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… X509_STORE_ADD_CERT(3ossl) β€” the OpenSSL manual, but make it make sense

okay so bestie, grab a strawberry matcha πŸ“ because we're about to talk about X509_STORE manipulation, and honestly? It's the glow-up era of your X.509 life. This is from the OpenSSL manual, page X509_STORE_ADD_CERT(3ossl). Let's get into it ✨


🌸 NAME 🌸

X509_STORE, X509_STORE_add_cert, X509_STORE_add_crl, X509_STORE_set_depth, X509_STORE_set_flags, X509_STORE_set_purpose, X509_STORE_set_trust, X509_STORE_add_lookup, X509_STORE_load_file_ex, X509_STORE_load_file, X509_STORE_load_path, X509_STORE_load_store_ex, X509_STORE_load_store, X509_STORE_set_default_paths_ex, X509_STORE_set_default_paths, X509_STORE_load_locations_ex, X509_STORE_load_locations β€” all of them, together, doing X509_STORE manipulation πŸ’–


✨ SYNOPSIS ✨

#include <openssl/x509_vfy.h>

typedef x509_store_st X509_STORE;

int X509_STORE_add_cert(X509_STORE *xs, X509 *x);
int X509_STORE_add_crl(X509_STORE *xs, X509_CRL *x);
int X509_STORE_set_depth(X509_STORE *store, int depth);
int X509_STORE_set_flags(X509_STORE *xs, unsigned long flags);
int X509_STORE_set_purpose(X509_STORE *xs, int purpose);
int X509_STORE_set_trust(X509_STORE *xs, int trust);

X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *store,
                                   X509_LOOKUP_METHOD *meth);

int X509_STORE_set_default_paths_ex(X509_STORE *xs, OSSL_LIB_CTX *libctx,
                                    const char *propq);
int X509_STORE_set_default_paths(X509_STORE *xs);
int X509_STORE_load_file_ex(X509_STORE *xs, const char *file,
                            OSSL_LIB_CTX *libctx, const char *propq);
int X509_STORE_load_file(X509_STORE *xs, const char *file);
int X509_STORE_load_path(X509_STORE *xs, const char *dir);
int X509_STORE_load_store_ex(X509_STORE *xs, const char *uri,
                             OSSL_LIB_CTX *libctx, const char *propq);
int X509_STORE_load_store(X509_STORE *xs, const char *uri);
int X509_STORE_load_locations_ex(X509_STORE *xs, const char *file,
                                 const char *dir, OSSL_LIB_CTX *libctx,
                                 const char *propq);
int X509_STORE_load_locations(X509_STORE *xs,
                              const char *file, const char *dir);

like, look at that list. she's thorough πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

The X509_STORE structure is literally the main character of certificate storage: it's designed to be a consolidated mechanism for holding info about X.509 certificates and CRLs, and for constructing and validating chains of certificates that terminate in trusted roots. It admits multiple lookup mechanisms, scales efficiently with large numbers of certificates, and gives you a lot of flexibility in how validation and policy checks get performed. it's giving organized queen πŸŽ€

The deets on chain building and checking live in "Certification Path Building" in openssl-verification-options(1) and "Certification Path Validation" in openssl-verification-options(1). go read those if you want the full lore πŸ“–

X509_STORE_new(3) creates an empty X509_STORE structure β€” and ngl, it's kind of useless at that point: it contains no information about trusted certificates or where such certificates are located on disk, and is generally not usable. Normally you add trusted certificates to the X509_STORE to prepare it for use, via mechanisms such as X509_STORE_add_lookup() and X509_LOOKUP_file(), or PEM_read_bio_X509_AUX() and X509_STORE_add_cert(). CRLs can also be added, and lots of behaviors configured however you want πŸ’…

Once the X509_STORE is suitably configured, X509_STORE_CTX_new() is used to instantiate a single-use X509_STORE_CTX for each chain-building and verification operation. That process includes providing the end-entity certificate to be verified and an additional set of untrusted certificates that may be used in chain-building. So yeah β€” the certificates included in the X509_STORE are expected to be the ones representing trusted entities like root certificate authorities (CAs). OpenSSL represents these trusted certificates internally as X509 objects with an associated X509_CERT_AUX, exactly as produced by PEM_read_bio_X509_AUX() and similar routines that refer to X509_AUX. The public interfaces that operate on such trusted certificates still operate on pointers to X509 objects, though. iykyk 🧚

X509_STORE_add_cert() and X509_STORE_add_crl() add the respective object to the X509_STORE's local storage. Untrusted objects should not be added this way β€” no cap, don't do it πŸ™ˆ The added object's reference count is incremented by one, hence the caller retains ownership of the object and needs to free it when it's no longer needed. you still own it, bestie, don't forget to clean up 🫢

X509_STORE_set_depth(), X509_STORE_set_flags(), X509_STORE_set_purpose(), X509_STORE_set_trust(), and X509_STORE_set1_param() set the default values for the corresponding values used in certificate chain validation. Their behavior is documented in the corresponding X509_VERIFY_PARAM manual pages, e.g., X509_VERIFY_PARAM_set_depth(3). The X509_STORE MUST NOT be NULL. like literally do not, it's not the vibe πŸ’€

X509_STORE_add_lookup() finds or creates a X509_LOOKUP(3) with the X509_LOOKUP_METHOD(3) meth and adds it to the X509_STORE store. This also associates the X509_STORE with the lookup, so X509_LOOKUP functions can look up objects in that store. match made in heaven πŸ”₯

X509_STORE_load_file_ex() loads trusted certificate(s) into an X509_STORE from a given file. The library context libctx and property query propq are used when fetching algorithms from providers. algorithms from providers, slay ✨

X509_STORE_load_file() is similar to X509_STORE_load_file_ex() but uses NULL for the library context libctx and property query propq. the lazy-but-fine version πŸŽ€

X509_STORE_load_path() loads trusted certificate(s) into an X509_STORE from a given directory path dir. The certificates in the directory must be in hashed form, as documented in X509_LOOKUP_hash_dir(3). hashed form only, bestie β€” don't just dump random files in there 😭

X509_STORE_load_store_ex() loads trusted certificate(s) into an X509_STORE from a store at a given URI uri. The library context libctx and property query propq are used when fetching algorithms from providers. URI-based, very modern of you 🌈

X509_STORE_load_store() is similar to X509_STORE_load_store_ex() but uses NULL for the library context libctx and property query propq.

X509_STORE_load_locations_ex() combines X509_STORE_load_file_ex() and X509_STORE_load_path() for a given file and/or directory path dir. It is permitted to specify just a file, just a directory, or both paths. choose your own adventure πŸ’–

X509_STORE_load_locations() is similar to X509_STORE_load_locations_ex() but uses NULL for the library context libctx and property query propq.

X509_STORE_set_default_paths_ex() is somewhat misnamed, in that it does not set what default paths should be used for loading certificates. Instead, it loads certificates into the X509_STORE from the hardcoded default paths. The library context libctx and property query propq are used when fetching algorithms from providers. the name is a whole lie but she's still iconic πŸ’…

X509_STORE_set_default_paths() is similar to X509_STORE_set_default_paths_ex() but uses NULL for the library context libctx and property query propq.


⭐ RETURN VALUES ⭐

X509_STORE_add_cert(), X509_STORE_add_crl(), X509_STORE_set_depth(), X509_STORE_set_flags(), X509_STORE_set_purpose(), X509_STORE_set_trust(), X509_STORE_load_file_ex(), X509_STORE_load_file(), X509_STORE_load_path(), X509_STORE_load_store_ex(), X509_STORE_load_store(), X509_STORE_load_locations_ex(), X509_STORE_load_locations(), X509_STORE_set_default_paths_ex() and X509_STORE_set_default_paths() return 1 on success or 0 on failure. one for the win, zero for the flop πŸ“

X509_STORE_add_lookup() returns the found or created X509_LOOKUP(3), or NULL on error. periodt.


πŸ‘‘ SEE ALSO πŸ‘‘

X509_LOOKUP_hash_dir(3). X509_VERIFY_PARAM_set_depth(3). X509_STORE_new(3), X509_STORE_get0_param(3) β€” go read your sisters' pages, bestie 🫢


πŸŽ€ HISTORY πŸŽ€

The functions X509_STORE_set_default_paths_ex(), X509_STORE_load_file_ex(), X509_STORE_load_store_ex() and X509_STORE_load_locations_ex() were added in OpenSSL 3.0. the _ex girlies are new-new ✨


Copyright 2017-2021 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 OpenSSL 3.5.6, dated 2026-04-07 β€” X509_STORE_ADD_CERT(3ossl), signing off πŸ¦‹βœ¨ mwah πŸ’–

πŸ“¦ where this page comes from