---
name: "X509_LOOKUP_meth_new"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/X509_LOOKUP_meth_new"
---

# X509\_LOOKUP\_meth\_new(3ssl)

Routines to build up X509\_LOOKUP methods

## NAME

X509\_LOOKUP\_METHOD, X509\_LOOKUP\_meth\_new, X509\_LOOKUP\_meth\_free, X509\_LOOKUP\_meth\_set\_new\_item, X509\_LOOKUP\_meth\_get\_new\_item, X509\_LOOKUP\_meth\_set\_free, X509\_LOOKUP\_meth\_get\_free, X509\_LOOKUP\_meth\_set\_init, X509\_LOOKUP\_meth\_get\_init, X509\_LOOKUP\_meth\_set\_shutdown, X509\_LOOKUP\_meth\_get\_shutdown, X509\_LOOKUP\_ctrl\_fn, X509\_LOOKUP\_meth\_set\_ctrl, X509\_LOOKUP\_meth\_get\_ctrl, X509\_LOOKUP\_get\_by\_subject\_fn, X509\_LOOKUP\_meth\_set\_get\_by\_subject, X509\_LOOKUP\_meth\_get\_get\_by\_subject, X509\_LOOKUP\_get\_by\_issuer\_serial\_fn, X509\_LOOKUP\_meth\_set\_get\_by\_issuer\_serial, X509\_LOOKUP\_meth\_get\_get\_by\_issuer\_serial, X509\_LOOKUP\_get\_by\_fingerprint\_fn, X509\_LOOKUP\_meth\_set\_get\_by\_fingerprint, X509\_LOOKUP\_meth\_get\_get\_by\_fingerprint, X509\_LOOKUP\_get\_by\_alias\_fn, X509\_LOOKUP\_meth\_set\_get\_by\_alias, X509\_LOOKUP\_meth\_get\_get\_by\_alias, X509\_OBJECT\_set1\_X509, X509\_OBJECT\_set1\_X509\_CRL - 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

The **X509\_LOOKUP\_METHOD** type is a structure used for the implementation of new X509\_LOOKUP types. It provides a set of functions used by OpenSSL for the implementation of various X509 and X509\_CRL lookup capabilities. One instance of an X509\_LOOKUP\_METHOD can be associated to many instantiations of an **X509\_LOOKUP** structure.

**X509\_LOOKUP\_meth\_new()** creates a new **X509\_LOOKUP\_METHOD** structure. It should be given a human-readable string containing a brief description of the lookup method.

**X509\_LOOKUP\_meth\_free()** destroys a **X509\_LOOKUP\_METHOD** structure. If the argument is NULL, nothing is done.

**X509\_LOOKUP\_get\_new\_item()** and **X509\_LOOKUP\_set\_new\_item()** get and set the function that is called when an **X509\_LOOKUP** object is created with **X509\_LOOKUP\_new()**. If an X509\_LOOKUP\_METHOD requires any per-X509\_LOOKUP specific data, the supplied new\_item function should allocate this data and invoke **X509\_LOOKUP\_set\_method\_data**(3).

**X509\_LOOKUP\_get\_free()** and **X509\_LOOKUP\_set\_free()** get and set the function that is used to free any method data that was allocated and set from within new\_item function.

**X509\_LOOKUP\_meth\_get\_init()** and **X509\_LOOKUP\_meth\_set\_init()** get and set the function that is 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 that is used to shut down the method data whose state was previously initialized in the init function.

**X509\_LOOKUP\_meth\_get\_ctrl()** and **X509\_LOOKUP\_meth\_set\_ctrl()** get and set a function to be used to handle arbitrary control commands issued by **X509\_LOOKUP\_ctrl()**. The control function is given the X509\_LOOKUP **ctx**, along with the arguments passed by X509\_LOOKUP\_ctrl. **cmd** is an arbitrary integer that defines some operation. **argc** is a pointer to an array of characters. **argl** is an integer. **ret**, if set, points to a location where any return data should be written to. How **argc** and **argl** are used depends entirely on the control function.

**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 are given the X509\_LOOKUP context, the type of the X509\_OBJECT being requested, parameters related to the lookup, and an X509\_OBJECT that will receive the requested object.

Implementations must add objects they find to the **X509\_STORE** object using **X509\_STORE\_add\_cert()** or **X509\_STORE\_add\_crl()**.  This increments its reference count.  However, the **X509\_STORE\_CTX\_get\_by\_subject**(3) function also increases the reference count which leads to one too many references being held.  Therefore, applications should additionally call **X509\_free()** or **X509\_CRL\_free()** to decrement the reference count again.

Implementations should also use either **X509\_OBJECT\_set1\_X509()** or **X509\_OBJECT\_set1\_X509\_CRL()** to set the result.  Note that this also increments the result's reference count.

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). Successful lookups should return 1, and unsuccessful lookups should return 0.

**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 set by the corresponding setter.

## RETURN VALUES

The **X509\_LOOKUP\_meth\_set** functions return 1 on success or 0 on error.

The **X509\_LOOKUP\_meth\_get** functions return the corresponding function pointers.

## SEE ALSO

**X509\_STORE\_CTX\_get\_by\_subject**(3), **X509\_STORE\_new**(3), **SSL\_CTX\_set\_cert\_store**(3)

## HISTORY

The functions described here were added in OpenSSL 1.1.0i.

## 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\>.
