SSL_CTX_LOAD...IFY_LOCATIONS(3ossl)

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

πŸ’… SSL_CTX_LOAD...IFY_LOCATIONS (3ossl) β€” like, the whole "where do I trust CA certs from" situation

okay bestie, so this is an OpenSSL manual page, manual section 3ossl, and it's literally all about telling your SSL_CTX where to find the trusted CA certificates it should be vibing with during verification. it's giving "trust fund but for certificates" πŸŽ€


✨ NAME ✨

SSL_CTX_load_verify_dir, SSL_CTX_load_verify_file, SSL_CTX_load_verify_store, SSL_CTX_set_default_verify_paths, SSL_CTX_set_default_verify_dir, SSL_CTX_set_default_verify_file, SSL_CTX_set_default_verify_store, SSL_CTX_load_verify_locations β€” set default locations for trusted CA certificates πŸ’–


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);

int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);

int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);

int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
                                  const char *CApath);

πŸ¦‹ DESCRIPTION πŸ¦‹

SSL_CTX_load_verify_locations(), SSL_CTX_load_verify_dir(), SSL_CTX_load_verify_file() and SSL_CTX_load_verify_store() all tell ctx where the CA certificates for verification purposes live. anything you hand over via CAfile, CApath and CAstore is trusted β€” like, officially 🫢 and ctx MUST NOT be NULL, periodt.

the deets of the certificate verification + chain checking process are described in "Certification Path Validation" in openssl-verification-options(1) β€” go read that if you're nosy (ily) πŸ’œ

SSL_CTX_set_default_verify_paths() says "bestie just use the default locations for loading CA certs". there is one default directory, one default file and one default store. the default CA certificates directory is called certs in the default OpenSSL directory, and this is also the default store. alternatively the SSL_CERT_DIR environment variable can be defined to override this location. the default CA certificates file is called cert.pem in the default OpenSSL directory. alternatively the SSL_CERT_FILE environment variable can be defined to override this location. also ctx MUST NOT be NULL ⭐

SSL_CTX_set_default_verify_dir() is literally SSL_CTX_set_default_verify_paths() except that just the default directory is used.

SSL_CTX_set_default_verify_file() is the same story but just the default file is used.

SSL_CTX_set_default_verify_store() β€” you guessed it, just the default store is used. iconic, consistent, we love her πŸ’…


🧚 NOTES 🧚

if CAfile is not NULL, it points to a file of CA certificates in PEM format. the file can contain several CA certificates identified by

-----BEGIN CERTIFICATE-----
... (CA certificate in base64 encoding) ...
-----END CERTIFICATE-----

sequences. before, between, and after the certificates, text is allowed β€” which can be used e.g. for descriptions of the certificates ✍️ cute.

the CAfile is processed on execution of the SSL_CTX_load_verify_locations() function.

if CApath is not NULL, it points to a directory containing CA certificates in PEM format. the files each contain one CA certificate. the files are looked up by the CA subject name hash value, which must hence be available. if more than one CA certificate with the same name hash value exists, the extension must be different (e.g. 9d66eef0.0, 9d66eef0.1 etc). the search is performed in the ordering of the extension number, regardless of other properties of the certificates. use the c_rehash utility to create the necessary links πŸ”—

the certificates in CApath are only looked up when required β€” e.g. when building the certificate chain or when actually performing the verification of a peer certificate. she's lowkey lazy but in a smart way πŸ’€

when looking up CA certificates for chain building, the OpenSSL library will search for suitable certificates first in CAfile, then in CApath. details of the chain building process are described in "Certification Path Building" in openssl-verification-options(1).

if CAstore is not NULL, it's a URI for to a store, which may represent a single container or a whole catalogue of containers. apart from the CAstore not necessarily being a local file or directory, it's generally treated the same way as a CApath. (yes, the original says "a URI for to a store" β€” we keep the facts, not the grammar, but the meaning is exactly that 🫑)

in server mode, when requesting a client certificate, the server must send the list of CAs of which it will accept client certificates. this list is not influenced by the contents of CAfile or CApath and must explicitly be set using the SSL_CTX_set_client_CA_list(3) family of functions πŸ‘‘

when building its own certificate chain, an OpenSSL client/server will try to fill in missing certificates from CAfile/CApath, if the certificate chain was not explicitly specified (see SSL_CTX_add_extra_chain_cert(3), SSL_CTX_use_certificate(3)).


πŸ’€ WARNINGS πŸ’€

if several CA certificates matching the name, key identifier, and serial number condition are available, only the first one will be examined. this is a whole trap, bestie β€” it may lead to unexpected results if the same CA certificate is available with different expiration dates. if a "certificate expired" verification error occurs, no other certificate will be searched. make sure to not have expired certificates mixed with valid ones. like, do the vibe check on your cert folder, fr fr πŸ™ˆ


πŸ”₯ RETURN VALUES πŸ”₯

for SSL_CTX_load_verify_locations the following return values can occur:

  • 0 β€” the operation failed because CAfile and CApath are NULL or the processing at one of the locations specified failed. check the error stack to find out the reason 😭
  • 1 β€” the operation succeeded ✨ slay.

SSL_CTX_set_default_verify_paths(), SSL_CTX_set_default_verify_dir() and SSL_CTX_set_default_verify_file() all return 1 on success or 0 on failure. a missing default location is still treated as a success β€” yes, really, she's chill like that 🌈


πŸ“ EXAMPLES πŸ“

generate a CA certificate file with descriptive text from the CA certificates ca1.pem ca2.pem ca3.pem:

#!/bin/sh
rm CAfile.pem
for i in ca1.pem ca2.pem ca3.pem ; do
    openssl x509 -in $i -text >> CAfile.pem
done

prepare the directory /some/where/certs containing several CA certificates for use as CApath:

cd /some/where/certs
c_rehash .

πŸ‘‘ SEE ALSO πŸ‘‘

ssl(7), SSL_CTX_set_client_CA_list(3), SSL_get_client_CA_list(3), SSL_CTX_use_certificate(3), SSL_CTX_add_extra_chain_cert(3), SSL_CTX_set_cert_store(3), SSL_CTX_set_client_CA_list(3)

(and yes, SSL_CTX_set_client_CA_list(3) is listed twice in the original β€” we don't gatekeep, we keep every single reference exactly as written πŸ’–)


copyright 2000-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, no cap. go forth and verify those chains, main character πŸ¦‹βœ¨

version 3.5.6, dated 2026-04-0 β€” mwah, that's the sign-off, love u, bye bestie πŸ’…πŸŽ€

πŸ“¦ where this page comes from