X509_LOOKUP_hash_dir.pod 5.6 KB

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