DOC: Add documentation related to X509_LOOKUPs
[openssl.git] / doc / man3 / X509_LOOKUP.pod
1 =pod
2
3 =head1 NAME
4
5 X509_LOOKUP, X509_LOOKUP_TYPE,
6 X509_LOOKUP_new, X509_LOOKUP_free, X509_LOOKUP_init,
7 X509_LOOKUP_shutdown,
8 X509_LOOKUP_set_method_data, X509_LOOKUP_get_method_data,
9 X509_LOOKUP_ctrl,
10 X509_LOOKUP_load_file, X509_LOOKUP_add_dir,
11 X509_LOOKUP_get_store, X509_LOOKUP_by_subject,
12 X509_LOOKUP_by_issuer_serial, X509_LOOKUP_by_fingerprint,
13 X509_LOOKUP_by_alias
14 - OpenSSL certificate lookup mechanisms
15
16 =head1 SYNOPSIS
17
18  #include <openssl/x509_vfy.h>
19
20  typedef x509_lookup_st X509_LOOKUP;
21
22  typedef enum X509_LOOKUP_TYPE;
23
24  X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
25  int X509_LOOKUP_init(X509_LOOKUP *ctx);
26  int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
27  void X509_LOOKUP_free(X509_LOOKUP *ctx);
28
29  int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data);
30  void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx);
31
32  int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
33                       long argl, char **ret);
34  int X509_LOOKUP_load_file(X509_LOOKUP *ctx, char *name, long type);
35  int X509_LOOKUP_add_dir(X509_LOOKUP *ctx, char *name, long type);
36
37  X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx);
38
39  int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
40                             X509_NAME *name, X509_OBJECT *ret);
41  int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
42                                   X509_NAME *name, ASN1_INTEGER *serial,
43                                   X509_OBJECT *ret);
44  int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
45                                 const unsigned char *bytes, int len,
46                                 X509_OBJECT *ret);
47  int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
48                           const char *str, int len, X509_OBJECT *ret);
49
50 =head1 DESCRIPTION
51
52 The B<X509_LOOKUP> structure holds the information needed to look up
53 certificates and CRLs according to an associated L<X509_LOOKUP_METHOD(3)>.
54 Multiple B<X509_LOOKUP> instances can be added to an L<X509_STORE(3)>
55 to enable lookup in that store.
56
57 X509_LOOKUP_new() creates a new B<X509_LOOKUP> using the given lookup
58 I<method>.
59 It can also be created by calling L<X509_STORE_add_lookup(3)>, which
60 will associate a B<X509_STORE> with the lookup mechanism.
61
62 X509_LOOKUP_init() initializes the internal state and resources as
63 needed by the given B<X509_LOOKUP> to do its work.
64
65 X509_LOOKUP_shutdown() tears down the internal state and resources of
66 the given B<X509_LOOKUP>.
67
68 X509_LOOKUP_free() destructs the given B<X509_LOOKUP>.
69
70 X509_LOOKUP_set_method_data() and X509_LOOKUP_get_method_data()
71 associates and retrieves a pointer to application data to and from the
72 given B<X509_LOOKUP>, respectively.
73
74 X509_LOOKUP_ctrl() is used to set or get additional data to or from a
75 B<X509_LOOKUP> structure or its associated L<X509_LOOKUP_METHOD(3)>.
76 The arguments of the control command are passed via I<argc> and I<argl>,
77 its return value via I<*ret>.
78 The meaning of the arguments depends on the I<cmd> number of the
79 control command. In general, this function is not called directly, but
80 wrapped by a macro call, see below.
81 The control I<cmd>s known to OpenSSL are discussed in more depth
82 in L</Control Commands>.
83
84 X509_LOOKUP_load_file() passes a filename to be loaded immediately
85 into the associated B<X509_STORE>.
86 I<type> indicates what type of object is expected.
87 This can only be used with a lookup using the implementation
88 L<X509_LOOKUP_file(3)>.
89
90 X509_LOOKUP_add_dir() passes a directory specification from which
91 certificates and CRLs are loaded on demand into the associated
92 B<X509_STORE>.
93 I<type> indicates what type of object is expected.
94 This can only be used with a lookup using the implementation
95 L<X509_LOOKUP_hash_dir(3)>.
96
97 X509_LOOKUP_load_file(), X509_LOOKUP_add_dir(),
98 X509_LOOKUP_add_store(), and X509_LOOKUP_load_store() are implemented
99 as macros that use X509_LOOKUP_ctrl().
100
101 X509_LOOKUP_by_subject(), X509_LOOKUP_by_issuer_serial(),
102 X509_LOOKUP_by_fingerprint(), and X509_LOOKUP_by_alias() look up
103 certificates and CRLs in the L<X509_STORE(3)> associated with the
104 B<X509_LOOKUP> using different criteria, where the looked up object is
105 stored in I<ret>.
106 Some of the underlying B<X509_LOOKUP_METHOD>s will also cache objects
107 matching the criteria in the associated B<X509_STORE>, which makes it
108 possible to handle cases where the criteria have more than one hit.
109
110 =head2 Control Commands
111
112 The B<X509_LOOKUP_METHOD>s built into OpenSSL recognise the following
113 X509_LOOKUP_ctrl() I<cmd>s:
114
115 =over 4
116
117 =item B<X509_L_FILE_LOAD>
118
119 This is the command that X509_LOOKUP_load_file() uses.
120 The filename is passed in I<argc>, and the type in I<argl>.
121
122 =item B<X509_L_ADD_DIR>
123
124 This is the command that X509_LOOKUP_add_dir() uses.
125 The directory specification is passed in I<argc>, and the type in
126 I<argl>.
127
128 =item B<X509_L_ADD_STORE>
129
130 This is the command that X509_LOOKUP_add_store() uses.
131 The URI is passed in I<argc>.
132
133 =item B<X509_L_LOAD_STORE>
134
135 This is the command that X509_LOOKUP_load_store() uses.
136 The URI is passed in I<argc>.
137
138 =back
139
140 =head1 RETURN VALUES
141
142 X509_LOOKUP_new() returns a B<X509_LOOKUP> pointer when successful,
143 or NULL on error.
144
145 X509_LOOKUP_init() and X509_LOOKUP_shutdown() return 1 on success, or
146 0 on error.
147
148 X509_LOOKUP_ctrl() returns -1 if the B<X509_LOOKUP> doesn't have an
149 associated B<X509_LOOKUP_METHOD>, or 1 if the X<509_LOOKUP_METHOD>
150 doesn't have a control function.
151 Otherwise, it returns what the control function in the
152 B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 in
153 error.
154
155 X509_LOOKUP_get_store() returns a B<X509_STORE> pointer if there is
156 one, otherwise NULL.
157
158 X509_LOOKUP_by_subject(), X509_LOOKUP_by_issuer_serial(),
159 X509_LOOKUP_by_fingerprint(), and X509_LOOKUP_by_alias() all return 0
160 if there is no B<X509_LOOKUP_METHOD> or that method doesn't implement
161 the corresponding function.
162 Otherwise, it returns what the corresponding function in the
163 B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 in
164 error.
165
166 =head1 SEE ALSO
167
168 L<X509_LOOKUP_METHOD(3)>, L<X509_STORE(3)>
169
170 =head1 COPYRIGHT
171
172 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
173
174 Licensed under the Apache License 2.0 (the "License").  You may not use
175 this file except in compliance with the License.  You can obtain a copy
176 in the file LICENSE in the source distribution or at
177 L<https://www.openssl.org/source/license.html>.
178
179 =cut