X509_LOOKUP.pod 6.9 KB

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