X509_LOOKUP_hash_dir.pod 4.9 KB

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