xref: /freebsd/crypto/openssl/doc/man3/X509_LOOKUP_meth_new.pod (revision f6a3b357e9be4c6423c85eff9a847163a0d307c8)
1=pod
2
3=head1 NAME
4
5X509_LOOKUP_meth_new, X509_LOOKUP_meth_free, X509_LOOKUP_meth_set_new_item,
6X509_LOOKUP_meth_get_new_item, X509_LOOKUP_meth_set_free,
7X509_LOOKUP_meth_get_free, X509_LOOKUP_meth_set_init,
8X509_LOOKUP_meth_get_init, X509_LOOKUP_meth_set_shutdown,
9X509_LOOKUP_meth_get_shutdown,
10X509_LOOKUP_ctrl_fn, X509_LOOKUP_meth_set_ctrl, X509_LOOKUP_meth_get_ctrl,
11X509_LOOKUP_get_by_subject_fn, X509_LOOKUP_meth_set_get_by_subject,
12X509_LOOKUP_meth_get_get_by_subject,
13X509_LOOKUP_get_by_issuer_serial_fn, X509_LOOKUP_meth_set_get_by_issuer_serial,
14X509_LOOKUP_meth_get_get_by_issuer_serial,
15X509_LOOKUP_get_by_fingerprint_fn, X509_LOOKUP_meth_set_get_by_fingerprint,
16X509_LOOKUP_meth_get_get_by_fingerprint,
17X509_LOOKUP_get_by_alias_fn, X509_LOOKUP_meth_set_get_by_alias,
18X509_LOOKUP_meth_get_get_by_alias,
19X509_LOOKUP_set_method_data, X509_LOOKUP_get_method_data,
20X509_LOOKUP_get_store, X509_OBJECT_set1_X509, X509_OBJECT_set1_X509_CRL
21- Routines to build up X509_LOOKUP methods
22
23=head1 SYNOPSIS
24
25 #include <openssl/x509_vfy.h>
26
27 X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name);
28 void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method);
29
30 int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
31                                   int (*new_item) (X509_LOOKUP *ctx));
32 int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
33     (X509_LOOKUP *ctx);
34
35 int X509_LOOKUP_meth_set_free(X509_LOOKUP_METHOD *method,
36                               void (*free) (X509_LOOKUP *ctx));
37 void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
38     (X509_LOOKUP *ctx);
39
40 int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
41                               int (*init) (X509_LOOKUP *ctx));
42 int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
43     (X509_LOOKUP *ctx);
44
45 int X509_LOOKUP_meth_set_shutdown(X509_LOOKUP_METHOD *method,
46                                   int (*shutdown) (X509_LOOKUP *ctx));
47 int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
48     (X509_LOOKUP *ctx);
49
50 typedef int (*X509_LOOKUP_ctrl_fn)(X509_LOOKUP *ctx, int cmd, const char *argc,
51                                    long argl, char **ret);
52 int X509_LOOKUP_meth_set_ctrl(X509_LOOKUP_METHOD *method,
53     X509_LOOKUP_ctrl_fn ctrl_fn);
54 X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method);
55
56 typedef int (*X509_LOOKUP_get_by_subject_fn)(X509_LOOKUP *ctx,
57                                              X509_LOOKUP_TYPE type,
58                                              X509_NAME *name,
59                                              X509_OBJECT *ret);
60 int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
61     X509_LOOKUP_get_by_subject_fn fn);
62 X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
63     const X509_LOOKUP_METHOD *method);
64
65 typedef int (*X509_LOOKUP_get_by_issuer_serial_fn)(X509_LOOKUP *ctx,
66                                                    X509_LOOKUP_TYPE type,
67                                                    X509_NAME *name,
68                                                    ASN1_INTEGER *serial,
69                                                    X509_OBJECT *ret);
70 int X509_LOOKUP_meth_set_get_by_issuer_serial(
71     X509_LOOKUP_METHOD *method, X509_LOOKUP_get_by_issuer_serial_fn fn);
72 X509_LOOKUP_get_by_issuer_serial_fn X509_LOOKUP_meth_get_get_by_issuer_serial(
73     const X509_LOOKUP_METHOD *method);
74
75 typedef int (*X509_LOOKUP_get_by_fingerprint_fn)(X509_LOOKUP *ctx,
76                                                  X509_LOOKUP_TYPE type,
77                                                  const unsigned char* bytes,
78                                                  int len,
79                                                  X509_OBJECT *ret);
80 int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
81     X509_LOOKUP_get_by_fingerprint_fn fn);
82 X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
83     const X509_LOOKUP_METHOD *method);
84
85 typedef int (*X509_LOOKUP_get_by_alias_fn)(X509_LOOKUP *ctx,
86                                            X509_LOOKUP_TYPE type,
87                                            const char *str,
88                                            int len,
89                                            X509_OBJECT *ret);
90 int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
91     X509_LOOKUP_get_by_alias_fn fn);
92 X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
93     const X509_LOOKUP_METHOD *method);
94
95 int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data);
96 void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx);
97
98 X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx);
99
100 int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj);
101 int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj);
102
103=head1 DESCRIPTION
104
105The B<X509_LOOKUP_METHOD> type is a structure used for the implementation of new
106X509_LOOKUP types. It provides a set of functions used by OpenSSL for the
107implementation of various X509 and X509_CRL lookup capabilities. One instance
108of an X509_LOOKUP_METHOD can be associated to many instantiations of an
109B<X509_LOOKUP> structure.
110
111X509_LOOKUP_meth_new() creates a new B<X509_LOOKUP_METHOD> structure. It should
112be given a human-readable string containing a brief description of the lookup
113method.
114
115X509_LOOKUP_meth_free() destroys a B<X509_LOOKUP_METHOD> structure.
116
117X509_LOOKUP_get_new_item() and X509_LOOKUP_set_new_item() get and set the
118function that is called when an B<X509_LOOKUP> object is created with
119X509_LOOKUP_new(). If an X509_LOOKUP_METHOD requires any per-X509_LOOKUP
120specific data, the supplied new_item function should allocate this data and
121invoke X509_LOOKUP_set_method_data().
122
123X509_LOOKUP_get_free() and X509_LOOKUP_set_free() get and set the function
124that is used to free any method data that was allocated and set from within
125new_item function.
126
127X509_LOOKUP_meth_get_init() and X509_LOOKUP_meth_set_init() get and set the
128function that is used to initialize the method data that was set with
129X509_LOOKUP_set_method_data() as part of the new_item routine.
130
131X509_LOOKUP_meth_get_shutdown() and X509_LOOKUP_meth_set_shutdown() get and set
132the function that is used to shut down the method data whose state was
133previously initialized in the init function.
134
135X509_LOOKUP_meth_get_ctrl() and X509_LOOKUP_meth_set_ctrl() get and set a
136function to be used to handle arbitrary control commands issued by
137X509_LOOKUP_ctrl(). The control function is given the X509_LOOKUP
138B<ctx>, along with the arguments passed by X509_LOOKUP_ctrl. B<cmd> is
139an arbitrary integer that defines some operation. B<argc> is a pointer
140to an array of characters. B<argl> is an integer. B<ret>, if set,
141points to a location where any return data should be written to. How
142B<argc> and B<argl> are used depends entirely on the control function.
143
144
145X509_LOOKUP_set_get_by_subject(), X509_LOOKUP_set_get_by_issuer_serial(),
146X509_LOOKUP_set_get_by_fingerprint(), X509_LOOKUP_set_get_by_alias() set
147the functions used to retrieve an X509 or X509_CRL object by the object's
148subject, issuer, fingerprint, and alias respectively. These functions are given
149the X509_LOOKUP context, the type of the X509_OBJECT being requested, parameters
150related to the lookup, and an X509_OBJECT that will receive the requested
151object.
152
153Implementations must add objects they find to the B<X509_STORE> object
154using X509_STORE_add_cert() or X509_STORE_add_crl().  This increments
155its reference count.  However, the X509_STORE_CTX_get_by_subject()
156function also increases the reference count which leads to one too
157many references being held.  Therefore applications should
158additionally call X509_free() or X509_CRL_free() to decrement the
159reference count again.
160
161Implementations should also use either X509_OBJECT_set1_X509() or
162X509_OBJECT_set1_X509_CRL() to set the result.  Note that this also
163increments the result's reference count.
164
165Any method data that was created as a result of the new_item function
166set by X509_LOOKUP_meth_set_new_item() can be accessed with
167X509_LOOKUP_get_method_data(). The B<X509_STORE> object that owns the
168X509_LOOKUP may be accessed with X509_LOOKUP_get_store(). Successful lookups
169should return 1, and unsuccessful lookups should return 0.
170
171X509_LOOKUP_get_get_by_subject(), X509_LOOKUP_get_get_by_issuer_serial(),
172X509_LOOKUP_get_get_by_fingerprint(), X509_LOOKUP_get_get_by_alias() retrieve
173the function set by the corresponding setter.
174
175=head1 RETURN VALUES
176
177The B<X509_LOOKUP_meth_set> functions return 1 on success or 0 on error.
178
179The B<X509_LOOKUP_meth_get> functions return the corresponding function
180pointers.
181
182=head1 SEE ALSO
183
184L<X509_STORE_new(3)>, L<SSL_CTX_set_cert_store(3)>
185
186=head1 HISTORY
187
188The functions described here were added in OpenSSL 1.1.0i.
189
190=head1 COPYRIGHT
191
192Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
193
194Licensed under the OpenSSL license (the "License").  You may not use
195this file except in compliance with the License.  You can obtain a copy
196in the file LICENSE in the source distribution or at
197L<https://www.openssl.org/source/license.html>.
198
199=cut
200