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