X509_LOOKUP(3ossl)
π X509_LOOKUP β the whole OpenSSL cert-lookup situation, explained π
okay bestie, so this is the X509_LOOKUP page from the OpenSSL manual, section 3ossl. It covers X509_LOOKUP, X509_LOOKUP_TYPE, and honestly a whole friend group of functions β grab a snack, we're going through all of them, no skips, no cap. π
β¨ NAME β¨
X509_LOOKUP, X509_LOOKUP_TYPE, X509_LOOKUP_new, X509_LOOKUP_free, X509_LOOKUP_init, X509_LOOKUP_shutdown, X509_LOOKUP_set_method_data, X509_LOOKUP_get_method_data, X509_LOOKUP_ctrl_ex, X509_LOOKUP_ctrl, X509_LOOKUP_load_file_ex, X509_LOOKUP_load_file, X509_LOOKUP_add_dir, X509_LOOKUP_add_store_ex, X509_LOOKUP_add_store, X509_LOOKUP_load_store_ex, X509_LOOKUP_load_store, X509_LOOKUP_get_store, X509_LOOKUP_by_subject_ex, X509_LOOKUP_by_subject, X509_LOOKUP_by_issuer_serial, X509_LOOKUP_by_fingerprint, X509_LOOKUP_by_alias β aka OpenSSL certificate lookup mechanisms π
Like, that's the whole cast. It's giving ensemble show energy. π
π SYNOPSIS π
#include <openssl/x509_vfy.h>
typedef x509_lookup_st X509_LOOKUP;
typedef enum X509_LOOKUP_TYPE;
X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
int X509_LOOKUP_init(X509_LOOKUP *ctx);
int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
void X509_LOOKUP_free(X509_LOOKUP *ctx);
int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data);
void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx);
int X509_LOOKUP_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
char **ret, OSSL_LIB_CTX *libctx, const char *propq);
int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
long argl, char **ret);
int X509_LOOKUP_load_file_ex(X509_LOOKUP *ctx, char *name, long type,
OSSL_LIB_CTX *libctx, const char *propq);
int X509_LOOKUP_load_file(X509_LOOKUP *ctx, char *name, long type);
int X509_LOOKUP_load_file_ex(X509_LOOKUP *ctx, char *name, long type,
OSSL_LIB_CTX *libctx, const char *propq);
int X509_LOOKUP_add_dir(X509_LOOKUP *ctx, char *name, long type);
int X509_LOOKUP_add_store_ex(X509_LOOKUP *ctx, char *uri, OSSL_LIB_CTX *libctx,
const char *propq);
int X509_LOOKUP_add_store(X509_LOOKUP *ctx, char *uri);
int X509_LOOKUP_load_store_ex(X509_LOOKUP *ctx, char *uri, OSSL_LIB_CTX *libctx,
const char *propq);
int X509_LOOKUP_load_store(X509_LOOKUP *ctx, char *uri);
X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx);
int X509_LOOKUP_by_subject_ex(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
const X509_NAME *name, X509_OBJECT *ret,
OSSL_LIB_CTX *libctx, const char *propq);
int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
const X509_NAME *name, X509_OBJECT *ret);
int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
const X509_NAME *name,
const ASN1_INTEGER *serial, X509_OBJECT *ret);
int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
const unsigned char *bytes, int len,
X509_OBJECT *ret);
int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
const char *str, int len, X509_OBJECT *ret);
π yes, X509_LOOKUP_load_file_ex() shows up twice in the synopsis up there. I'm not fixing it, I'm not merging it, I'm not gaslighting you β it's literally written twice in the original, so it stays twice. we love a double feature. β¨
π DESCRIPTION π
The X509_LOOKUP structure is the little container that holds everything needed to look up certificates and CRLs according to an associated X509_LOOKUP_METHOD(3). And the way that multiple X509_LOOKUP instances can just be added to an X509_STORE(3) to enable lookup in that store? iconic behaviour, honestly. π
X509_LOOKUP_new() creates a brand new X509_LOOKUP using the lookup method you hand it. You can also get one by calling X509_STORE_add_lookup(3), which β plot twist β associates an X509_STORE with the lookup mechanism for you. π¦
X509_LOOKUP_init() initializes the internal state and resources, as needed by the given X509_LOOKUP, so it can actually do its work. glow-up complete. β¨
X509_LOOKUP_shutdown() tears down the internal state and resources of the given X509_LOOKUP. we love a clean exit. π
X509_LOOKUP_free() destructs the given X509_LOOKUP. And if the argument is NULL? Nothing happens. Nothing. It simply does not engage. π
X509_LOOKUP_set_method_data() and X509_LOOKUP_get_method_data() associate and retrieve (respectively) a pointer to application data, to and from the given X509_LOOKUP.
X509_LOOKUP_ctrl_ex() is how you set or get additional data to or from an X509_LOOKUP structure, using any control function in the associated X509_LOOKUP_METHOD(3). The arguments of the control command get passed via argc and argl, and its return value comes back via *ret. The library context libctx and property query propq are used when fetching algorithms from providers. What the arguments even mean depends on the cmd number of the control command. Generally speaking this function isn't called directly β it's wrapped by a macro call, see below. The control cmds that OpenSSL knows about are discussed in more depth down in "Control Commands". π
X509_LOOKUP_ctrl() is similar to X509_LOOKUP_ctrl_ex() but uses NULL for the library context libctx and property query propq.
X509_LOOKUP_load_file_ex() passes a filename that gets loaded immediately into the associated X509_STORE. The library context libctx and property query propq are used when fetching algorithms from providers. type indicates what type of object is expected. Heads up bestie: this can only be used with a lookup using the implementation X509_LOOKUP_file(3).
X509_LOOKUP_load_file() is similar to X509_LOOKUP_load_file_ex() but uses NULL for the library context libctx and property query propq.
X509_LOOKUP_add_dir() passes a directory specification from which certificates and CRLs are loaded on demand into the associated X509_STORE. type indicates what type of object is expected. And this one can only be used with a lookup using the implementation X509_LOOKUP_hash_dir(3).
X509_LOOKUP_add_store_ex() passes a URI for a directory-like structure, from which containers with certificates and CRLs are loaded on demand into the associated X509_STORE. The library context libctx and property query propq are used when fetching algorithms from providers.
X509_LOOKUP_add_store() is similar to X509_LOOKUP_add_store_ex() but uses NULL for the library context libctx and property query propq.
X509_LOOKUP_load_store_ex() passes a URI for a single container, from which certificates and CRLs are immediately loaded into the associated X509_STORE. The library context libctx and property query propq are used when fetching algorithms from providers. And yeah β these functions can only be used with a lookup using the implementation X509_LOOKUP_store(3).
X509_LOOKUP_load_store() is similar to X509_LOOKUP_load_store_ex() but uses NULL for the library context libctx and property query propq.
so, plot twist: X509_LOOKUP_load_file_ex(), X509_LOOKUP_load_file(), X509_LOOKUP_add_dir(), X509_LOOKUP_add_store_ex(), X509_LOOKUP_add_store(), X509_LOOKUP_load_store_ex() and X509_LOOKUP_load_store() are actually implemented as macros that use X509_LOOKUP_ctrl(). they're not even real functions like that, they're just macros in a trench coat. π§
X509_LOOKUP_by_subject_ex(), X509_LOOKUP_by_subject(), X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and X509_LOOKUP_by_alias() look up certificates and CRLs in the X509_STORE(3) associated with the X509_LOOKUP, using different criteria β and the looked-up object gets stored in ret. Some of the underlying X509_LOOKUP_METHODs will also cache objects matching the criteria in the associated X509_STORE, which makes it possible to handle cases where the criteria have more than one hit. multitasking queen. π
π₯ Control Commands π₯
The X509_LOOKUP_METHODs built into OpenSSL recognize the following X509_LOOKUP_ctrl() cmds:
X509_L_FILE_LOADβ this is the command thatX509_LOOKUP_load_file_ex()andX509_LOOKUP_load_file()use. The filename is passed inargc, and the type inargl.X509_L_ADD_DIRβ this is the command thatX509_LOOKUP_add_dir()uses. The directory specification is passed inargc, and the type inargl.X509_L_ADD_STOREβ this is the command thatX509_LOOKUP_add_store_ex()andX509_LOOKUP_add_store()use. The URI is passed inargc.X509_L_LOAD_STOREβ this is the command thatX509_LOOKUP_load_store_ex()andX509_LOOKUP_load_store()use. The URI is passed inargc.
πΈ RETURN VALUES πΈ
X509_LOOKUP_new() returns an X509_LOOKUP pointer when it's successful, or NULL on error. π
X509_LOOKUP_init() and X509_LOOKUP_shutdown() return 1 on success, or 0 on error.
X509_LOOKUP_ctrl_ex() and X509_LOOKUP_ctrl() return -1 if the X509_LOOKUP doesn't have an associated X509_LOOKUP_METHOD, or 1 if the doesn't have a control function. Otherwise, it returns what the control function in the X509_LOOKUP_METHOD returns β which is usually 1 on success and 0 on error, but could also be -1 on failure. π«
X509_LOOKUP_get_store() returns an X509_STORE pointer if there is one, otherwise NULL.
X509_LOOKUP_by_subject_ex() returns 0 if there's no X509_LOOKUP_METHOD that implements any of the get_by_subject_ex() or get_by_subject() functions. It calls get_by_subject_ex() if present, otherwise get_by_subject(), and returns the result of the function β which is usually 1 on success and 0 on error.
X509_LOOKUP_by_subject() is similar to X509_LOOKUP_by_subject_ex() but passes NULL for both the libctx and propq.
X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and X509_LOOKUP_by_alias() all return 0 if there's no X509_LOOKUP_METHOD, or that method doesn't implement the corresponding function. Otherwise, they return what the corresponding function in the X509_LOOKUP_METHOD returns β which is usually 1 on success and 0 in error.
π¦ SEE ALSO π¦
X509_LOOKUP_METHOD(3), X509_STORE(3)
β HISTORY β
- The functions
X509_LOOKUP_by_subject_ex()andX509_LOOKUP_ctrl_ex()were added in OpenSSL 3.0. - The macros
X509_LOOKUP_load_file_ex(),X509_LOOKUP_load_store_ex()and509_LOOKUP_add_store_ex()were added in OpenSSL 3.0.
π«Ά and yes, that last macro name really is509_LOOKUP_add_store_ex()up there, missing its leadingXβ that's how it's written in the original, so that's how it stays. we do not edit history in this house. periodt. π
π COPYRIGHT π
Copyright 2020-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>.
okay that's the whole page, bestie, you ate that. π and for the cute sign-off: this was OpenSSL 3.5.9, dated 2026-09-29, and it's the X509_LOOKUP(3ossl) page β go forth and look things up. mwah. πβ¨π¦
π¦ 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