X509_LOOKUP_HASH_DIR(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… X509_LOOKUP_HASH_DIR β€” okay bestie, let's talk cert lookups

So this is the 3ossl page for OpenSSL's default certificate lookup methods β€” yes including X509_LOOKUP_hash_dir, X509_LOOKUP_file, X509_LOOKUP_store, X509_load_cert_file_ex, X509_load_cert_file, X509_load_crl_file, X509_load_cert_crl_file_ex and X509_load_cert_crl_file. It's giving "everything you need to know about how OpenSSL finds your certs" and honestly? Iconic. πŸŽ€


✨ SYNOPSIS ✨

#include <openssl/x509_vfy.h>

X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
X509_LOOKUP_METHOD *X509_LOOKUP_store(void);

int X509_load_cert_file_ex(X509_LOOKUP *ctx, const char *file, int type,
                           OSSL_LIB_CTX *libctx, const char *propq);
int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
int X509_load_cert_crl_file_ex(X509_LOOKUP *ctx, const char *file, int type,
                               OSSL_LIB_CTX *libctx, const char *propq);
int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);

🌸 DESCRIPTION 🌸

X509_LOOKUP_hash_dir and X509_LOOKUP_file are two certificate lookup methods you use with X509_STORE, and they're provided by the OpenSSL library. Two vibes, one job. πŸ¦‹

Okay so real talk: if you're just using the library normally, you do not need to create instances of these methods yourself β€” they get created automatically by X509_STORE_load_locations(3) or SSL_CTX_load_verify_locations(3). So like... don't overthink it, bestie. ✨

Internally, loading of certificates and CRLs is implemented via the functions X509_load_cert_crl_file, X509_load_cert_file and X509_load_crl_file. These functions support the type parameter, which can be one of the constants FILETYPE_PEM, FILETYPE_ASN1 and FILETYPE_DEFAULT. They load certificates and/or CRLs from the specified file into the memory cache of the X509_STORE objects that the given ctx parameter is associated with. Caching era fr fr. πŸ’Ύ

X509_load_cert_file and X509_load_crl_file can load both PEM and DER formats, depending on the type value. And here's the tea: because DER format cannot contain more than one certificate or CRL object (whereas PEM can contain several concatenated PEM objects), X509_load_cert_crl_file with FILETYPE_ASN1 is equivalent to X509_load_cert_file. One object only, no cap. πŸ’€

The constant FILETYPE_DEFAULT with a NULL filename causes these functions to load the default certificate store file (see X509_STORE_set_default_paths(3)).

These functions return the number of objects loaded from the file, or 0 in case of error.

Both methods support adding several certificate locations into one X509_STORE. Collect them all, lowkey. πŸ‘‘

This page documents the certificate store formats used by these methods, plus the caching policy.


πŸ—‚οΈ File Method

The X509_LOOKUP_file method loads all the certificates or CRLs present in a file into memory at the time the file is added as a lookup source. All in, immediately, no waiting.

The file format is ASCII text containing concatenated PEM certificates and CRLs.

This method should be used by applications that work with a small set of CAs. Small CAs, small file, big slay. πŸ“


🧚 Hashed Directory Method

X509_LOOKUP_hash_dir is the more advanced method: it loads certificates and CRLs on demand, and caches them in memory once they're loaded. As of OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so newer CRLs land as soon as they appear in the directory. Main character energy, honestly. ✨

The directory should contain one certificate or CRL per file in PEM format, with a filename of the form hash.N for a certificate, or hash.rN for a CRL. The hash is the value returned by the X509_NAME_hash_ex(3) function applied to the subject name for certificates, or the issuer name for CRLs. You can also get the hash via the -hash option of the openssl-x509(1) or openssl-crl(1) commands. iykyk. πŸ”₯

The .N or .rN suffix is a sequence number that starts at zero, and is incremented consecutively for each certificate or CRL with the same hash value. Gaps in the sequence numbers are not supported β€” it is assumed that there are no more objects with the same hash beyond the first missing number in the sequence. So like... no skipping numbers, bestie, it will not vibe check well. πŸ™ˆ

Sequence numbers make it possible for the directory to contain multiple certificates with the same subject name hash value. For example, you can have several certificates with the same subject in the store, or several CRLs with the same issuer (and, for example, different validity period). Variety! πŸ’…

When checking for new CRLs once one CRL for a given hash value is loaded, the hash_dir lookup method checks only for certificates with a sequence number greater than that of the already cached CRL.

⚠️ Note that the hash algorithm used for subject name hashing changed in OpenSSL 1.0.0, and all certificate stores have to be rehashed when moving from OpenSSL 0.9.8 to 1.0.0. Do not skip this step, I'm begging. 😭

OpenSSL includes an openssl-rehash(1) utility which creates symlinks with hashed names for all files with a .pem suffix in a given directory. It literally does the naming for you. 🫢


🌈 OSSL_STORE Method

X509_LOOKUP_store is a method that allows access to any store of certificates and CRLs through any loader supported by ossl_store(7). It works with the help of URIs, which can be direct references to certificates or CRLs, but can also be references to catalogues of such objects (that behave like directories). Very "choose your own adventure". πŸ¦‹

This method overlaps the "File Method" and the "Hashed Directory Method" because of the 'file:' scheme loader. It does no caching of its own, but it can use a caching ossl_store(7) loader, and therefore depends on the loader's capability. Borrowed cache, borrowed clout. ⭐


πŸ’– RETURN VALUES πŸ’–

X509_LOOKUP_hash_dir(), X509_LOOKUP_file() and X509_LOOKUP_store() always return a valid X509_LOOKUP_METHOD structure. Always. Guaranteed. Slay. πŸ‘‘

X509_load_cert_file(), X509_load_crl_file() and X509_load_cert_crl_file() return the number of loaded objects, or 0 on error.


πŸ‘€ SEE ALSO πŸ‘€

PEM_read_PrivateKey(3), X509_STORE_load_locations(3), SSL_CTX_load_verify_locations(3), X509_LOOKUP_meth_new(3), ossl_store(7)


πŸŽ€ HISTORY πŸŽ€

The functions X509_load_cert_file_ex(), X509_load_cert_crl_file_ex() and X509_LOOKUP_store() were added in OpenSSL 3.0. Baby functions, but they've grown. 🌱


Copyright 2015-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>.


Okay that's the whole page bestie, go rehash your cert stores and hydrate πŸ’œ

This was X509_LOOKUP_HASH_DIR(3ossl) from OpenSSL 3.5.0, dated 2026-09-25 β€” mwah, catch you in the next manpage, love u, bye! πŸ’…βœ¨

πŸ“¦ where this page comes from