X509_LOOKUP.pod 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. =pod
  2. =head1 NAME
  3. X509_LOOKUP, X509_LOOKUP_TYPE,
  4. X509_LOOKUP_new, X509_LOOKUP_free, X509_LOOKUP_init,
  5. X509_LOOKUP_shutdown,
  6. X509_LOOKUP_set_method_data, X509_LOOKUP_get_method_data,
  7. X509_LOOKUP_ctrl_ex, X509_LOOKUP_ctrl,
  8. X509_LOOKUP_load_file_ex, X509_LOOKUP_load_file,
  9. X509_LOOKUP_add_dir,
  10. X509_LOOKUP_add_store_ex, X509_LOOKUP_add_store,
  11. X509_LOOKUP_load_store_ex, X509_LOOKUP_load_store,
  12. X509_LOOKUP_get_store,
  13. X509_LOOKUP_by_subject_ex, X509_LOOKUP_by_subject,
  14. X509_LOOKUP_by_issuer_serial, X509_LOOKUP_by_fingerprint,
  15. X509_LOOKUP_by_alias
  16. - OpenSSL certificate lookup mechanisms
  17. =head1 SYNOPSIS
  18. #include <openssl/x509_vfy.h>
  19. typedef x509_lookup_st X509_LOOKUP;
  20. typedef enum X509_LOOKUP_TYPE;
  21. X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
  22. int X509_LOOKUP_init(X509_LOOKUP *ctx);
  23. int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
  24. void X509_LOOKUP_free(X509_LOOKUP *ctx);
  25. int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data);
  26. void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx);
  27. int X509_LOOKUP_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
  28. char **ret, OPENSSL_CTX *libctx, const char *propq);
  29. int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
  30. long argl, char **ret);
  31. int X509_LOOKUP_load_file_ex(X509_LOOKUP *ctx, char *name, long type,
  32. OPENSSL_CTX *libctx, const char *propq);
  33. int X509_LOOKUP_load_file(X509_LOOKUP *ctx, char *name, long type);
  34. int X509_LOOKUP_load_file_ex(X509_LOOKUP *ctx, char *name, long type,
  35. OPENSSL_CTX *libctx, const char *propq);
  36. int X509_LOOKUP_add_dir(X509_LOOKUP *ctx, char *name, long type);
  37. int X509_LOOKUP_add_store_ex(X509_LOOKUP *ctx, char *uri, OPENSSL_CTX *libctx,
  38. const char *propq);
  39. int X509_LOOKUP_add_store(X509_LOOKUP *ctx, char *uri);
  40. int X509_LOOKUP_load_store_ex(X509_LOOKUP *ctx, char *uri, OPENSSL_CTX *libctx,
  41. const char *propq);
  42. int X509_LOOKUP_load_store(X509_LOOKUP *ctx, char *uri);
  43. X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx);
  44. int X509_LOOKUP_by_subject_ex(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  45. const X509_NAME *name, X509_OBJECT *ret,
  46. OPENSSL_CTX *libctx, const char *propq);
  47. int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  48. const X509_NAME *name, X509_OBJECT *ret);
  49. int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  50. const X509_NAME *name,
  51. const ASN1_INTEGER *serial, X509_OBJECT *ret);
  52. int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  53. const unsigned char *bytes, int len,
  54. X509_OBJECT *ret);
  55. int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  56. const char *str, int len, X509_OBJECT *ret);
  57. =head1 DESCRIPTION
  58. The B<X509_LOOKUP> structure holds the information needed to look up
  59. certificates and CRLs according to an associated L<X509_LOOKUP_METHOD(3)>.
  60. Multiple B<X509_LOOKUP> instances can be added to an L<X509_STORE(3)>
  61. to enable lookup in that store.
  62. X509_LOOKUP_new() creates a new B<X509_LOOKUP> using the given lookup
  63. I<method>.
  64. It can also be created by calling L<X509_STORE_add_lookup(3)>, which
  65. will associate a B<X509_STORE> with the lookup mechanism.
  66. X509_LOOKUP_init() initializes the internal state and resources as
  67. needed by the given B<X509_LOOKUP> to do its work.
  68. X509_LOOKUP_shutdown() tears down the internal state and resources of
  69. the given B<X509_LOOKUP>.
  70. X509_LOOKUP_free() destructs the given B<X509_LOOKUP>.
  71. X509_LOOKUP_set_method_data() and X509_LOOKUP_get_method_data()
  72. associates and retrieves a pointer to application data to and from the
  73. given B<X509_LOOKUP>, respectively.
  74. X509_LOOKUP_ctrl_ex() is used to set or get additional data to or from
  75. a B<X509_LOOKUP> structure or its associated L<X509_LOOKUP_METHOD(3)>.
  76. The arguments of the control command are passed via I<argc> and I<argl>,
  77. its return value via I<*ret>. The library context I<libctx> and property
  78. query <propq> are used when fetching algorithms from providers.
  79. The meaning of the arguments depends on the I<cmd> number of the
  80. control command. In general, this function is not called directly, but
  81. wrapped by a macro call, see below.
  82. The control I<cmd>s known to OpenSSL are discussed in more depth
  83. in L</Control Commands>.
  84. X509_LOOKUP_ctrl() is similar to X509_LOOKUP_ctrl_ex() but
  85. uses NULL for the library context I<libctx> and property query <propq>.
  86. X509_LOOKUP_load_file_ex() passes a filename to be loaded immediately
  87. into the associated B<X509_STORE>. The library context I<libctx> and property
  88. query <propq> are used when fetching algorithms from providers.
  89. I<type> indicates what type of object is expected.
  90. This can only be used with a lookup using the implementation
  91. L<X509_LOOKUP_file(3)>.
  92. X509_LOOKUP_load_file() is similar to X509_LOOKUP_load_file_ex() but
  93. uses NULL for the library context I<libctx> and property query <propq>.
  94. X509_LOOKUP_add_dir() passes a directory specification from which
  95. certificates and CRLs are loaded on demand into the associated
  96. B<X509_STORE>.
  97. I<type> indicates what type of object is expected.
  98. This can only be used with a lookup using the implementation
  99. L<X509_LOOKUP_hash_dir(3)>.
  100. X509_LOOKUP_add_store_ex() passes a URI for a directory-like structure
  101. from which containers with certificates and CRLs are loaded on demand
  102. into the associated B<X509_STORE>. The library context I<libctx> and property
  103. query <propq> are used when fetching algorithms from providers.
  104. X509_LOOKUP_add_store() is similar to X509_LOOKUP_add_store_ex() but
  105. uses NULL for the library context I<libctx> and property query <propq>.
  106. X509_LOOKUP_load_store_ex() passes a URI for a single container from
  107. which certificates and CRLs are immediately loaded into the associated
  108. B<X509_STORE>. The library context I<libctx> and property query <propq> are used
  109. when fetching algorithms from providers.
  110. These functions can only be used with a lookup using the
  111. implementation L<X509_LOOKUP_store(3)>.
  112. X509_LOOKUP_load_store() is similar to X509_LOOKUP_load_store_ex() but
  113. uses NULL for the library context I<libctx> and property query <propq>.
  114. X509_LOOKUP_load_file_ex(), X509_LOOKUP_load_file(),
  115. X509_LOOKUP_add_dir(),
  116. X509_LOOKUP_add_store_ex() X509_LOOKUP_add_store(),
  117. X509_LOOKUP_load_store_ex() and X509_LOOKUP_load_store() are
  118. implemented as macros that use X509_LOOKUP_ctrl().
  119. X509_LOOKUP_by_subject_ex(), X509_LOOKUP_by_subject(),
  120. X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and
  121. X509_LOOKUP_by_alias() look up certificates and CRLs in the L<X509_STORE(3)>
  122. associated with the B<X509_LOOKUP> using different criteria, where the looked up
  123. object is stored in I<ret>.
  124. Some of the underlying B<X509_LOOKUP_METHOD>s will also cache objects
  125. matching the criteria in the associated B<X509_STORE>, which makes it
  126. possible to handle cases where the criteria have more than one hit.
  127. =head2 Control Commands
  128. The B<X509_LOOKUP_METHOD>s built into OpenSSL recognize the following
  129. X509_LOOKUP_ctrl() I<cmd>s:
  130. =over 4
  131. =item B<X509_L_FILE_LOAD>
  132. This is the command that X509_LOOKUP_load_file_ex() and
  133. X509_LOOKUP_load_file() use.
  134. The filename is passed in I<argc>, and the type in I<argl>.
  135. =item B<X509_L_ADD_DIR>
  136. This is the command that X509_LOOKUP_add_dir() uses.
  137. The directory specification is passed in I<argc>, and the type in
  138. I<argl>.
  139. =item B<X509_L_ADD_STORE>
  140. This is the command that X509_LOOKUP_add_store_ex() and
  141. X509_LOOKUP_add_store() use.
  142. The URI is passed in I<argc>.
  143. =item B<X509_L_LOAD_STORE>
  144. This is the command that X509_LOOKUP_load_store_ex() and
  145. X509_LOOKUP_load_store() use.
  146. The URI is passed in I<argc>.
  147. =back
  148. =head1 RETURN VALUES
  149. X509_LOOKUP_new() returns a B<X509_LOOKUP> pointer when successful,
  150. or NULL on error.
  151. X509_LOOKUP_init() and X509_LOOKUP_shutdown() return 1 on success, or
  152. 0 on error.
  153. X509_LOOKUP_ctrl() returns -1 if the B<X509_LOOKUP> doesn't have an
  154. associated B<X509_LOOKUP_METHOD>, or 1 if the X<509_LOOKUP_METHOD>
  155. doesn't have a control function.
  156. Otherwise, it returns what the control function in the
  157. B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 in
  158. error.
  159. X509_LOOKUP_get_store() returns a B<X509_STORE> pointer if there is
  160. one, otherwise NULL.
  161. X509_LOOKUP_by_subject_ex(), X509_LOOKUP_by_subject(),
  162. X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and
  163. X509_LOOKUP_by_alias() all return 0 if there is no B<X509_LOOKUP_METHOD> or that
  164. method doesn't implement the corresponding function.
  165. Otherwise, it returns what the corresponding function in the
  166. B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 in
  167. error.
  168. =head1 SEE ALSO
  169. L<X509_LOOKUP_METHOD(3)>, L<X509_STORE(3)>
  170. =head1 HISTORY
  171. The functions X509_LOOKUP_by_subject_ex() and
  172. X509_LOOKUP_ctrl_ex() were added in OpenSSL 3.0.
  173. The macros X509_LOOKUP_load_file_ex(),
  174. X509_LOOKUP_load_store_ex() and 509_LOOKUP_add_store_ex() were
  175. added in OpenSSL 3.0.
  176. =head1 COPYRIGHT
  177. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  178. Licensed under the Apache License 2.0 (the "License"). You may not use
  179. this file except in compliance with the License. You can obtain a copy
  180. in the file LICENSE in the source distribution or at
  181. L<https://www.openssl.org/source/license.html>.
  182. =cut