1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
.\" $OpenBSD: X509_LOOKUP_hash_dir.3,v 1.8 2018/03/27 17:35:50 schwarze Exp $
.\" full merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
.\"
.\" This file was written by Victor B. Wagner <vitus@cryptocom.ru>
.\" and Claus Assmann.
.\" Copyright (c) 2015, 2016, 2017 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 27 2018 $
.Dt X509_LOOKUP_HASH_DIR 3
.Os
.Sh NAME
.Nm X509_LOOKUP_hash_dir ,
.Nm X509_LOOKUP_file ,
.Nm X509_load_cert_file ,
.Nm X509_load_crl_file ,
.Nm X509_load_cert_crl_file
.Nd default OpenSSL certificate lookup methods
.Sh SYNOPSIS
.In openssl/x509_vfy.h
.Ft X509_LOOKUP_METHOD *
.Fn X509_LOOKUP_hash_dir void
.Ft X509_LOOKUP_METHOD *
.Fn X509_LOOKUP_file void
.Ft int
.Fo X509_load_cert_file
.Fa "X509_LOOKUP *ctx"
.Fa "const char *file"
.Fa "int type"
.Fc
.Ft int
.Fo X509_load_crl_file
.Fa "X509_LOOKUP *ctx"
.Fa "const char *file"
.Fa "int type"
.Fc
.Ft int
.Fo X509_load_cert_crl_file
.Fa "X509_LOOKUP *ctx"
.Fa "const char *file"
.Fa "int type"
.Fc
.Sh DESCRIPTION
.Fn X509_LOOKUP_hash_dir
and
.Fn X509_LOOKUP_file
are two certificate lookup methods to use with
.Vt X509_STORE ,
provided by the OpenSSL library.
.Pp
Users of the library typically do not need to create instances of these
methods manually.
They are created automatically by the
.Xr X509_STORE_load_locations 3
or
.Xr SSL_CTX_load_verify_locations 3
functions.
.Pp
Internally, loading of certificates and CRLs is implemented via the functions
.Fn X509_load_cert_crl_file ,
.Fn X509_load_cert_file
and
.Fn X509_load_crl_file .
These functions support a parameter
.Fa type ,
which can be one of the constants
.Dv FILETYPE_PEM ,
.Dv FILETYPE_ASN1 ,
and
.Dv FILETYPE_DEFAULT .
They load certificates and/or CRLs from the specified file into a
memory cache of
.Vt X509_STORE
objects which the given
.Fa ctx
parameter is associated with.
.Pp
The functions
.Fn X509_load_cert_file
and
.Fn X509_load_crl_file
can load both PEM and DER formats depending on the
.Fa type
value.
Because DER format cannot contain more than one certificate or CRL
object (while PEM can contain several concatenated PEM objects),
.Fn X509_load_cert_crl_file
with
.Dv FILETYPE_ASN1
is equivalent to
.Fn X509_load_cert_file .
.Pp
The constant
.Dv FILETYPE_DEFAULT
with
.Dv NULL
filename causes these functions to load the default certificate
store file (see
.Xr X509_STORE_set_default_paths 3 ) .
.Pp
Both methods support adding several certificate locations into one
.Sy X509_STORE .
.Pp
This page documents certificate store formats used by these methods and
caching policy.
.Ss File Method
The
.Fn X509_LOOKUP_file
method loads all the certificates or CRLs present in a file into memory
at the time the file is added as a lookup source.
.Pp
The file format is ASCII text which contains concatenated PEM
certificates and CRLs.
.Pp
This method should be used by applications which work with a small set
of CAs.
.Ss Hashed Directory Method
.Fa X509_LOOKUP_hash_dir
is a more advanced method which loads certificates and CRLs on demand,
and caches them in memory once they are loaded.
As of OpenSSL 1.0.0, it also checks for newer CRLs upon each lookup, so
that newer CRLs are used as soon as they appear in the directory.
.Pp
The directory should contain one certificate or CRL per file in PEM
format, with a file name of the form
.Ar hash . Ns Ar N
for a certificate, or
.Ar hash . Ns Sy r Ns Ar N
for a CRL.
The
.Ar hash
is the value returned by the
.Xr X509_NAME_hash 3
function applied to the subject name for certificates or issuer
name for CRLs.
The hash can also be obtained via the
.Fl hash
option of the
.Xr openssl 1
.Cm x509
or
.Cm crl
commands.
.Pp
The
.Ar N
suffix is a sequence number that starts at zero and is incremented
consecutively for each certificate or CRL with the same
.Ar hash
value.
Gaps in the sequence numbers are not supported.
It is assumed that there are no more objects with the same hash
beyond the first missing number in the sequence.
.Pp
Sequence numbers make it possible for the directory to contain multiple
certificates with the same subject name hash value.
For example, it is possible to have in the store several certificates
with the same subject or several CRLs with the same issuer (and, for
example, a different validity period).
.Pp
When checking for new CRLs, once one CRL for a given hash value is
loaded, hash_dir lookup method checks only for certificates with
sequence number greater than that of the already cached CRL.
.Pp
Note that the hash algorithm used for subject name hashing changed in
OpenSSL 1.0.0, and all certificate stores have to be rehashed when
moving from OpenSSL 0.9.8 to 1.0.0.
.Sh RETURN VALUES
.Fn X509_LOOKUP_hash_dir
and
.Fn X509_LOOKUP_file
always return a pointer to a static
.Vt X509_LOOKUP_METHOD
structure.
.Pp
.Fn X509_load_cert_file ,
.Fn X509_load_crl_file ,
and
.Fn X509_load_cert_crl_file
return the number of objects loaded from the
.Fa file
or 0 on error.
.Sh SEE ALSO
.Xr d2i_X509_bio 3 ,
.Xr PEM_read_PrivateKey 3 ,
.Xr SSL_CTX_load_verify_locations 3 ,
.Xr X509_STORE_load_locations 3
.Sh HISTORY
.Fn X509_LOOKUP_hash_dir ,
.Fn X509_LOOKUP_file ,
and
.Fn X509_load_cert_file
first appeared in SSLeay 0.8.0.
.Fn X509_load_crl_file
first appeared in SSLeay 0.9.0.
These functions have been available since
.Ox 2.4 .
.Pp
.Fn X509_load_cert_crl_file
first appeared in OpenSSL 0.9.5 and has been available since
.Ox 2.7 .
|