X509_LOOKUP_METH_NEW(3ossl)
π NAME π
okay bestie, gather round, because this is the X509_LOOKUP_METHOD page β aka the whole toolkit for building your own X509 lookup methods. The manpage name is X509_LOOKUP_METH_NEW(3ossl) and it ships with OpenSSL, and honestly it's giving "backstage pass to the certificate-finding machine" energy.
Here's the full cast, no cap, nobody left out:
- the type itself:
X509_LOOKUP_METHOD - construction + destruction:
X509_LOOKUP_meth_new,X509_LOOKUP_meth_free - new-item hooks:
X509_LOOKUP_meth_set_new_item,X509_LOOKUP_meth_get_new_item - free hooks:
X509_LOOKUP_meth_set_free,X509_LOOKUP_meth_get_free - init hooks:
X509_LOOKUP_meth_set_init,X509_LOOKUP_meth_get_init - shutdown hooks:
X509_LOOKUP_meth_set_shutdown,X509_LOOKUP_meth_get_shutdown - control-command vibes:
X509_LOOKUP_ctrl_fn,X509_LOOKUP_meth_set_ctrl,X509_LOOKUP_meth_get_ctrl - lookup by subject:
X509_LOOKUP_get_by_subject_fn,X509_LOOKUP_meth_set_get_by_subject,X509_LOOKUP_meth_get_get_by_subject - lookup by issuer + serial:
X509_LOOKUP_get_by_issuer_serial_fn,X509_LOOKUP_meth_set_get_by_issuer_serial,X509_LOOKUP_meth_get_get_by_issuer_serial - lookup by fingerprint:
X509_LOOKUP_get_by_fingerprint_fn,X509_LOOKUP_meth_set_get_by_fingerprint,X509_LOOKUP_meth_get_get_by_fingerprint - lookup by alias:
X509_LOOKUP_get_by_alias_fn,X509_LOOKUP_meth_set_get_by_alias,X509_LOOKUP_meth_get_get_by_alias - result-setting besties:
X509_OBJECT_set1_X509,X509_OBJECT_set1_X509_CRL
tl;dr the whole page is routines to build up X509_LOOKUP methods π«Ά
β¨ SYNOPSIS β¨
#include <openssl/x509_vfy.h>
typedef x509_lookup_method_st X509_LOOKUP_METHOD;
X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name);
void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method);
int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
int (*new_item) (X509_LOOKUP *ctx));
int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
(X509_LOOKUP *ctx);
int X509_LOOKUP_meth_set_free(X509_LOOKUP_METHOD *method,
void (*free) (X509_LOOKUP *ctx));
void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
(X509_LOOKUP *ctx);
int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
int (*init) (X509_LOOKUP *ctx));
int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
(X509_LOOKUP *ctx);
int X509_LOOKUP_meth_set_shutdown(X509_LOOKUP_METHOD *method,
int (*shutdown) (X509_LOOKUP *ctx));
int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
(X509_LOOKUP *ctx);
typedef int (*X509_LOOKUP_ctrl_fn)(X509_LOOKUP *ctx, int cmd, const char *argc,
long argl, char **ret);
int X509_LOOKUP_meth_set_ctrl(X509_LOOKUP_METHOD *method,
X509_LOOKUP_ctrl_fn ctrl_fn);
X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method);
typedef int (*X509_LOOKUP_get_by_subject_fn)(X509_LOOKUP *ctx,
X509_LOOKUP_TYPE type,
const X509_NAME *name,
X509_OBJECT *ret);
int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
X509_LOOKUP_get_by_subject_fn fn);
X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
const X509_LOOKUP_METHOD *method);
typedef int (*X509_LOOKUP_get_by_issuer_serial_fn)(X509_LOOKUP *ctx,
X509_LOOKUP_TYPE type,
const X509_NAME *name,
const ASN1_INTEGER *serial,
X509_OBJECT *ret);
int X509_LOOKUP_meth_set_get_by_issuer_serial(
X509_LOOKUP_METHOD *method, X509_LOOKUP_get_by_issuer_serial_fn fn);
X509_LOOKUP_get_by_issuer_serial_fn X509_LOOKUP_meth_get_get_by_issuer_serial(
const X509_LOOKUP_METHOD *method);
typedef int (*X509_LOOKUP_get_by_fingerprint_fn)(X509_LOOKUP *ctx,
X509_LOOKUP_TYPE type,
const unsigned char* bytes,
int len,
X509_OBJECT *ret);
int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
X509_LOOKUP_get_by_fingerprint_fn fn);
X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
const X509_LOOKUP_METHOD *method);
typedef int (*X509_LOOKUP_get_by_alias_fn)(X509_LOOKUP *ctx,
X509_LOOKUP_TYPE type,
const char *str,
int len,
X509_OBJECT *ret);
int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
X509_LOOKUP_get_by_alias_fn fn);
X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
const X509_LOOKUP_METHOD *method);
int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj);
int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj);
π¦ DESCRIPTION π¦
So the X509_LOOKUP_METHOD type is a struct you use to implement brand-new X509_LOOKUP types. It's basically a little bundle of function pointers that OpenSSL leans on to make all sorts of X509 and X509_CRL lookup capabilities happen. And here's the slay part: one single instance of an X509_LOOKUP_METHOD can be associated with many instantiations of an X509_LOOKUP structure. one method, many lookups, main character energy β¨
X509_LOOKUP_meth_new() creates a fresh new X509_LOOKUP_METHOD structure. Feed it a human-readable string with a short lil description of what the lookup method does β that's the name argument, and yes it's purely for the humans.
X509_LOOKUP_meth_free() destroys an X509_LOOKUP_METHOD structure. And if the argument is NULL? nothing happens. nothing. is. done. π
X509_LOOKUP_get_new_item() and X509_LOOKUP_set_new_item() get and set the function that gets called when an X509_LOOKUP object is created with X509_LOOKUP_new(). And listen β if an X509_LOOKUP_METHOD needs any per-X509_LOOKUP specific data, that supplied new_item function should allocate the data and invoke X509_LOOKUP_set_method_data(3). like, that's the assignment, bestie.
X509_LOOKUP_get_free() and X509_LOOKUP_set_free() get and set the function used to free any method data that was allocated and set from inside the new_item function. cleanup crew 4ever π§Ή
X509_LOOKUP_meth_get_init() and X509_LOOKUP_meth_set_init() get and set the function used to initialize the method data that was set with X509_LOOKUP_set_method_data(3) as part of the new_item routine.
X509_LOOKUP_meth_get_shutdown() and X509_LOOKUP_meth_set_shutdown() get and set the function used to shut down the method data whose state was previously initialized in the init function. closing time, iconically π
X509_LOOKUP_meth_get_ctrl() and X509_LOOKUP_meth_set_ctrl() get and set a function used to handle arbitrary control commands issued by X509_LOOKUP_ctrl(). That control function receives the X509_LOOKUP ctx, plus all the arguments that X509_LOOKUP_ctrl passed along. Let's break down the crew:
cmdβ an arbitrary integer that defines some operation. you decide what it means, iykyk.argcβ a pointer to an array of characters.arglβ an integer.retβ if set, points to a location where any return data should be written to.
And how argc and argl actually get used? depends entirely on the control function. fully your call, no rules, we love that for you π
X509_LOOKUP_set_get_by_subject(), X509_LOOKUP_set_get_by_issuer_serial(), X509_LOOKUP_set_get_by_fingerprint(), X509_LOOKUP_set_get_by_alias() set the functions used to retrieve an X509 or X509_CRL object by the object's subject, issuer, fingerprint, and alias respectively. These functions get handed the X509_LOOKUP context, the type of the X509_OBJECT being requested, the parameters related to the lookup, and an X509_OBJECT that will receive the requested object. very "here's the mission, here's the output slot" of them π―
β οΈ ok important part, read this twice: implementations must add objects they find to theX509_STOREobject usingX509_STORE_add_cert()orX509_STORE_add_crl(). This increments its reference count. However, theX509_STORE_CTX_get_by_subject(3)function also increases the reference count, which leads to one too many references being held. So applications should additionally callX509_free()orX509_CRL_free()to decrement the reference count again. one extra ref, one extra free. balance restored π§
Implementations should also use either X509_OBJECT_set1_X509() or X509_OBJECT_set1_X509_CRL() to set the result. Heads up though: this also increments the result's reference count. yeah. noted. π
Any method data that was created as a result of the new_item function set by X509_LOOKUP_meth_set_new_item() can be accessed with X509_LOOKUP_get_method_data(3). The X509_STORE object that owns the X509_LOOKUP may be accessed with X509_LOOKUP_get_store(3). And the return values? successful lookups should return 1, and unsuccessful lookups should return 0. simple as that, periodt.
X509_LOOKUP_get_get_by_subject(), X509_LOOKUP_get_get_by_issuer_serial(), X509_LOOKUP_get_get_by_fingerprint(), X509_LOOKUP_get_get_by_alias() retrieve the function that was set by the corresponding setter. getters getting getters, it's giving symmetry πΈ
π RETURN VALUES π
The X509_LOOKUP_meth_set functions return 1 on success or 0 on error. binary queen π
The X509_LOOKUP_meth_get functions return the corresponding function pointers.
π SEE ALSO π
go read those next, bestie, they're literally right there π«Ά
π HISTORY π
The functions described here were added in OpenSSL 1.1.0i. vintage but make it cute.
π COPYRIGHT π
Copyright 2018-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>.
and that's the whole page!! mwah π this was OpenSSL 3.5.6, dated 2026-04-07, page X509_LOOKUP_METH_NEW(3ossl) β go build something iconic with it, ily, bye π¦β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms