X509_LOOKUP.pod 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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, OSSL_LIB_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. OSSL_LIB_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. OSSL_LIB_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, OSSL_LIB_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, OSSL_LIB_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. OSSL_LIB_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 using any control function in the
  76. associated L<X509_LOOKUP_METHOD(3)>.
  77. The arguments of the control command are passed via I<argc> and I<argl>,
  78. its return value via I<*ret>. The library context I<libctx> and property
  79. query I<propq> are used when fetching algorithms from providers.
  80. The meaning of the arguments depends on the I<cmd> number of the
  81. control command. In general, this function is not called directly, but
  82. wrapped by a macro call, see below.
  83. The control I<cmd>s known to OpenSSL are discussed in more depth
  84. in L</Control Commands>.
  85. X509_LOOKUP_ctrl() is similar to X509_LOOKUP_ctrl_ex() but
  86. uses NULL for the library context I<libctx> and property query I<propq>.
  87. X509_LOOKUP_load_file_ex() passes a filename to be loaded immediately
  88. into the associated B<X509_STORE>. The library context I<libctx> and property
  89. query I<propq> are used when fetching algorithms from providers.
  90. I<type> indicates what type of object is expected.
  91. This can only be used with a lookup using the implementation
  92. L<X509_LOOKUP_file(3)>.
  93. X509_LOOKUP_load_file() is similar to X509_LOOKUP_load_file_ex() but
  94. uses NULL for the library context I<libctx> and property query I<propq>.
  95. X509_LOOKUP_add_dir() passes a directory specification from which
  96. certificates and CRLs are loaded on demand into the associated
  97. B<X509_STORE>.
  98. I<type> indicates what type of object is expected.
  99. This can only be used with a lookup using the implementation
  100. L<X509_LOOKUP_hash_dir(3)>.
  101. X509_LOOKUP_add_store_ex() passes a URI for a directory-like structure
  102. from which containers with certificates and CRLs are loaded on demand
  103. into the associated B<X509_STORE>. The library context I<libctx> and property
  104. query I<propq> are used when fetching algorithms from providers.
  105. X509_LOOKUP_add_store() is similar to X509_LOOKUP_add_store_ex() but
  106. uses NULL for the library context I<libctx> and property query I<propq>.
  107. X509_LOOKUP_load_store_ex() passes a URI for a single container from
  108. which certificates and CRLs are immediately loaded into the associated
  109. B<X509_STORE>. The library context I<libctx> and property query I<propq> are used
  110. when fetching algorithms from providers.
  111. These functions can only be used with a lookup using the
  112. implementation L<X509_LOOKUP_store(3)>.
  113. X509_LOOKUP_load_store() is similar to X509_LOOKUP_load_store_ex() but
  114. uses NULL for the library context I<libctx> and property query I<propq>.
  115. X509_LOOKUP_load_file_ex(), X509_LOOKUP_load_file(),
  116. X509_LOOKUP_add_dir(),
  117. X509_LOOKUP_add_store_ex() X509_LOOKUP_add_store(),
  118. X509_LOOKUP_load_store_ex() and X509_LOOKUP_load_store() are
  119. implemented as macros that use X509_LOOKUP_ctrl().
  120. X509_LOOKUP_by_subject_ex(), X509_LOOKUP_by_subject(),
  121. X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and
  122. X509_LOOKUP_by_alias() look up certificates and CRLs in the L<X509_STORE(3)>
  123. associated with the B<X509_LOOKUP> using different criteria, where the looked up
  124. object is stored in I<ret>.
  125. Some of the underlying B<X509_LOOKUP_METHOD>s will also cache objects
  126. matching the criteria in the associated B<X509_STORE>, which makes it
  127. possible to handle cases where the criteria have more than one hit.
  128. =head2 Control Commands
  129. The B<X509_LOOKUP_METHOD>s built into OpenSSL recognize the following
  130. X509_LOOKUP_ctrl() I<cmd>s:
  131. =over 4
  132. =item B<X509_L_FILE_LOAD>
  133. This is the command that X509_LOOKUP_load_file_ex() and
  134. X509_LOOKUP_load_file() use.
  135. The filename is passed in I<argc>, and the type in I<argl>.
  136. =item B<X509_L_ADD_DIR>
  137. This is the command that X509_LOOKUP_add_dir() uses.
  138. The directory specification is passed in I<argc>, and the type in
  139. I<argl>.
  140. =item B<X509_L_ADD_STORE>
  141. This is the command that X509_LOOKUP_add_store_ex() and
  142. X509_LOOKUP_add_store() use.
  143. The URI is passed in I<argc>.
  144. =item B<X509_L_LOAD_STORE>
  145. This is the command that X509_LOOKUP_load_store_ex() and
  146. X509_LOOKUP_load_store() use.
  147. The URI is passed in I<argc>.
  148. =back
  149. =head1 RETURN VALUES
  150. X509_LOOKUP_new() returns a B<X509_LOOKUP> pointer when successful,
  151. or NULL on error.
  152. X509_LOOKUP_init() and X509_LOOKUP_shutdown() return 1 on success, or
  153. 0 on error.
  154. X509_LOOKUP_ctrl_ex() and X509_LOOKUP_ctrl()
  155. return -1 if the B<X509_LOOKUP> doesn't have an
  156. associated B<X509_LOOKUP_METHOD>, or 1 if the X<509_LOOKUP_METHOD>
  157. doesn't have a control function.
  158. Otherwise, it returns what the control function in the
  159. B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 on error
  160. but could also be -1 on failure.
  161. X509_LOOKUP_get_store() returns a B<X509_STORE> pointer if there is
  162. one, otherwise NULL.
  163. X509_LOOKUP_by_subject_ex() returns 0 if there is no B<X509_LOOKUP_METHOD>
  164. that implements any of the get_by_subject_ex() or get_by_subject() functions.
  165. It calls get_by_subject_ex() if present, otherwise get_by_subject(), and returns
  166. the result of the function, which is usually 1 on success and 0 on error.
  167. X509_LOOKUP_by_subject() is similar to X509_LOOKUP_by_subject_ex()
  168. but passes NULL for both the libctx and propq.
  169. X509_LOOKUP_by_issuer_serial(), X509_LOOKUP_by_fingerprint(), and
  170. X509_LOOKUP_by_alias() all return 0 if there is no B<X509_LOOKUP_METHOD> or that
  171. method doesn't implement the corresponding function.
  172. Otherwise, they return what the corresponding function in the
  173. B<X509_LOOKUP_METHOD> returns, which is usually 1 on success and 0 in
  174. error.
  175. =head1 SEE ALSO
  176. L<X509_LOOKUP_METHOD(3)>, L<X509_STORE(3)>
  177. =head1 HISTORY
  178. The functions X509_LOOKUP_by_subject_ex() and
  179. X509_LOOKUP_ctrl_ex() were added in OpenSSL 3.0.
  180. The macros X509_LOOKUP_load_file_ex(),
  181. X509_LOOKUP_load_store_ex() and 509_LOOKUP_add_store_ex() were
  182. added in OpenSSL 3.0.
  183. =head1 COPYRIGHT
  184. Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  185. Licensed under the Apache License 2.0 (the "License"). You may not use
  186. this file except in compliance with the License. You can obtain a copy
  187. in the file LICENSE in the source distribution or at
  188. L<https://www.openssl.org/source/license.html>.
  189. =cut