]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/X509_LOOKUP_hash_dir.pod
Remove an unnecessary call to BN_CTX_free.
[thirdparty/openssl.git] / doc / man3 / X509_LOOKUP_hash_dir.pod
CommitLineData
c03726ca
RS
1=pod
2
3=head1 NAME
4
849d91a6 5X509_LOOKUP_hash_dir, X509_LOOKUP_file, X509_LOOKUP_store,
c03726ca
RS
6X509_load_cert_file,
7X509_load_crl_file,
8X509_load_cert_crl_file - Default OpenSSL certificate
9lookup methods
10
11=head1 SYNOPSIS
12
e9b77246 13 #include <openssl/x509_vfy.h>
c03726ca 14
e9b77246
BB
15 X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
16 X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
849d91a6 17 X509_LOOKUP_METHOD *X509_LOOKUP_store(void);
c03726ca 18
e9b77246
BB
19 int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
20 int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
21 int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
c03726ca
RS
22
23=head1 DESCRIPTION
24
25B<X509_LOOKUP_hash_dir> and B<X509_LOOKUP_file> are two certificate
26lookup methods to use with B<X509_STORE>, provided by OpenSSL library.
27
8f243018 28Users of the library typically do not need to create instances of these
c03726ca
RS
29methods manually, they would be created automatically by
30L<X509_STORE_load_locations(3)> or
31L<SSL_CTX_load_verify_locations(3)>
32functions.
33
34Internally loading of certificates and CRLs is implemented via functions
35B<X509_load_cert_crl_file>, B<X509_load_cert_file> and
36B<X509_load_crl_file>. These functions support parameter I<type>, which
37can be one of constants B<FILETYPE_PEM>, B<FILETYPE_ASN1> and
38B<FILETYPE_DEFAULT>. They load certificates and/or CRLs from specified
39file into memory cache of B<X509_STORE> objects which given B<ctx>
40parameter is associated with.
41
42Functions B<X509_load_cert_file> and
43B<X509_load_crl_file> can load both PEM and DER formats depending of
44type value. Because DER format cannot contain more than one certificate
45or CRL object (while PEM can contain several concatenated PEM objects)
46B<X509_load_cert_crl_file> with B<FILETYPE_ASN1> is equivalent to
47B<X509_load_cert_file>.
48
49Constant B<FILETYPE_DEFAULT> with NULL filename causes these functions
50to load default certificate store file (see
c1e35057 51L<X509_STORE_set_default_paths(3)>.
c03726ca
RS
52
53
54Functions return number of objects loaded from file or 0 in case of
1bc74519 55error.
c03726ca
RS
56
57Both methods support adding several certificate locations into one
58B<X509_STORE>.
59
60This page documents certificate store formats used by these methods and
61caching policy.
62
05ea606a 63=head2 File Method
c03726ca 64
8f243018
VD
65The B<X509_LOOKUP_file> method loads all the certificates or CRLs
66present in a file into memory at the time the file is added as a
67lookup source.
c03726ca
RS
68
69File format is ASCII text which contains concatenated PEM certificates
70and CRLs.
71
8f243018
VD
72This method should be used by applications which work with a small
73set of CAs.
c03726ca 74
05ea606a 75=head2 Hashed Directory Method
c03726ca 76
8f243018
VD
77B<X509_LOOKUP_hash_dir> is a more advanced method, which loads
78certificates and CRLs on demand, and caches them in memory once
79they are loaded. As of OpenSSL 1.0.0, it also checks for newer CRLs
80upon each lookup, so that newer CRLs are as soon as they appear in
81the directory.
82
83The directory should contain one certificate or CRL per file in PEM format,
9c0586d5 84with a filename of the form I<hash>.I<N> for a certificate, or
8f243018
VD
85I<hash>.B<r>I<N> for a CRL.
86The I<hash> is the value returned by the L<X509_NAME_hash(3)> function applied
87to the subject name for certificates or issuer name for CRLs.
1903a9b7
RS
88The hash can also be obtained via the B<-hash> option of the
89L<openssl-x509(1)> or L<openssl-crl(1)> commands.
8f243018
VD
90
91The .I<N> or .B<r>I<N> suffix is a sequence number that starts at zero, and is
92incremented consecutively for each certificate or CRL with the same I<hash>
93value.
94Gaps in the sequence numbers are not supported, it is assumed that there are no
95more objects with the same hash beyond the first missing number in the
96sequence.
97
98Sequence numbers make it possible for the directory to contain multiple
99certificates with same subject name hash value.
100For example, it is possible to have in the store several certificates with same
101subject or several CRLs with same issuer (and, for example, different validity
102period).
103
104When checking for new CRLs once one CRL for given hash value is
105loaded, hash_dir lookup method checks only for certificates with
106sequence number greater than that of the already cached CRL.
107
108Note that the hash algorithm used for subject name hashing changed in OpenSSL
1091.0.0, and all certificate stores have to be rehashed when moving from OpenSSL
c03726ca
RS
1100.9.8 to 1.0.0.
111
1903a9b7
RS
112OpenSSL includes a L<openssl-rehash(1)> utility which creates symlinks with
113hashed names for all files with F<.pem> suffix in a given directory.
c03726ca 114
849d91a6
RL
115=head2 OSSL_STORE Method
116
117B<X509_LOOKUP_store> is a method that allows access to any store of
118certificates and CRLs through any loader supported by
fadb57e5 119L<ossl_store(7)>.
849d91a6
RL
120It works with the help of URIs, which can be direct references to
121certificates or CRLs, but can also be references to catalogues of such
122objects (that behave like directories).
123
124This method overlaps the L</File Method> and L</Hashed Directory Method>
125because of the 'file:' scheme loader.
fadb57e5 126It does no caching of its own, but can use a caching L<ossl_store(7)>
849d91a6
RL
127loader, and therefore depends on the loader's capability.
128
1f13ad31
PY
129=head1 RETURN VALUES
130
849d91a6
RL
131X509_LOOKUP_hash_dir(), X509_LOOKUP_file() and X509_LOOKUP_store()
132always return a valid B<X509_LOOKUP_METHOD> structure.
1f13ad31
PY
133
134X509_load_cert_file(), X509_load_crl_file() and X509_load_cert_crl_file() return
135the number of loaded objects or 0 on error.
136
c03726ca
RS
137=head1 SEE ALSO
138
8162f6f5 139L<PEM_read_PrivateKey(3)>,
c03726ca 140L<X509_STORE_load_locations(3)>,
9e183d22 141L<X509_store_add_lookup(3)>,
c03726ca 142L<SSL_CTX_load_verify_locations(3)>,
0124f32a 143L<X509_LOOKUP_meth_new(3)>,
fadb57e5 144L<ossl_store(7)>
849d91a6
RL
145
146=head1 HISTORY
147
148B<X509_LOOKUP_store> was added in OpenSSL 3.0.
c03726ca 149
e2f92610
RS
150=head1 COPYRIGHT
151
849d91a6 152Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 153
4746f25a 154Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
155this file except in compliance with the License. You can obtain a copy
156in the file LICENSE in the source distribution or at
157L<https://www.openssl.org/source/license.html>.
158
159=cut