ossl_provider_new.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. =pod
  2. =head1 NAME
  3. ossl_provider_find, ossl_provider_new, ossl_provider_up_ref,
  4. ossl_provider_free,
  5. ossl_provider_set_fallback, ossl_provider_set_module_path,
  6. ossl_provider_add_parameter,
  7. ossl_provider_activate, ossl_provider_available,
  8. ossl_provider_ctx,
  9. ossl_provider_forall_loaded,
  10. ossl_provider_name, ossl_provider_dso,
  11. ossl_provider_module_name, ossl_provider_module_path,
  12. ossl_provider_library_context,
  13. ossl_provider_teardown, ossl_provider_gettable_params,
  14. ossl_provider_get_params, ossl_provider_query_operation,
  15. ossl_provider_set_operation_bit, ossl_provider_test_operation_bit,
  16. ossl_provider_get_capabilities
  17. - internal provider routines
  18. =head1 SYNOPSIS
  19. #include "internal/provider.h"
  20. OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name,
  21. int noconfig);
  22. OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
  23. ossl_provider_init_fn *init_function
  24. int noconfig);
  25. int ossl_provider_up_ref(OSSL_PROVIDER *prov);
  26. void ossl_provider_free(OSSL_PROVIDER *prov);
  27. /* Setters */
  28. int ossl_provider_set_fallback(OSSL_PROVIDER *prov);
  29. int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
  30. int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
  31. const char *value);
  32. /* Load and initialize the Provider */
  33. int ossl_provider_activate(OSSL_PROVIDER *prov);
  34. /* Check if provider is available */
  35. int ossl_provider_available(OSSL_PROVIDER *prov);
  36. /* Return pointer to the provider's context */
  37. void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
  38. /* Iterate over all loaded providers */
  39. int ossl_provider_forall_loaded(OPENSSL_CTX *,
  40. int (*cb)(OSSL_PROVIDER *provider,
  41. void *cbdata),
  42. void *cbdata);
  43. /* Getters for other library functions */
  44. const char *ossl_provider_name(OSSL_PROVIDER *prov);
  45. const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
  46. const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
  47. const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
  48. OPENSSL_CTX *ossl_provider_library_context(const OSSL_PROVIDER *prov);
  49. /* Thin wrappers around calls to the provider */
  50. void ossl_provider_teardown(const OSSL_PROVIDER *prov);
  51. const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
  52. int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
  53. int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
  54. const char *capability,
  55. OSSL_CALLBACK *cb,
  56. void *arg);
  57. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  58. int operation_id,
  59. int *no_cache);
  60. int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum);
  61. int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
  62. int *result);
  63. =head1 DESCRIPTION
  64. I<OSSL_PROVIDER> is a type that holds all the necessary information
  65. to handle a provider, regardless of if it's built in to the
  66. application or the OpenSSL libraries, or if it's a loadable provider
  67. module.
  68. Instances of this type are commonly referred to as "provider objects".
  69. A provider object is always stored in a set of provider objects
  70. in the library context.
  71. Provider objects are reference counted.
  72. Provider objects are initially inactive, i.e. they are only recorded
  73. in the store, but are not used.
  74. They are activated with the first call to ossl_provider_activate(),
  75. and are inactivated when ossl_provider_free() has been called as many
  76. times as ossl_provider_activate() has.
  77. =head2 Functions
  78. ossl_provider_find() finds an existing provider object in the provider
  79. object store by I<name>.
  80. The config file will be automatically loaded unless I<noconfig> is set.
  81. Typically I<noconfig> should be 0.
  82. We set I<noconfig> to 1 only when calling these functions while processing a
  83. config file in order to avoid recursively attempting to load the file.
  84. The provider object it finds has its reference count incremented.
  85. ossl_provider_new() creates a new provider object named I<name> and
  86. stores it in the provider object store, unless there already is one
  87. there with the same name.
  88. If there already is one with the same name, it's returned with its
  89. reference count incremented.
  90. The config file will be automatically loaded unless I<noconfig> is set.
  91. Typically I<noconfig> should be 0.
  92. We set I<noconfig> to 1 only when calling these functions while processing a
  93. config file in order to avoid recursively attempting to load the file.
  94. The reference count of a newly created provider object will always
  95. be 2; one for being added to the store, and one for the returned
  96. reference.
  97. If I<init_function> is NULL, the provider is assumed to be a
  98. dynamically loadable module, with the symbol B<OSSL_provider_init> as
  99. its initialisation function.
  100. If I<init_function> isn't NULL, the provider is assumed to be built
  101. in, with I<init_function> being the pointer to its initialisation
  102. function.
  103. For further description of the initialisation function, see the
  104. description of ossl_provider_activate() below.
  105. ossl_provider_up_ref() increments the provider object I<prov>'s
  106. reference count.
  107. ossl_provider_free() decrements the provider object I<prov>'s
  108. reference count; if it drops below 2, the provider object is assumed
  109. to have fallen out of use and will be deactivated (its I<teardown>
  110. function is called); if it drops down to zero, I<prov> is assumed to
  111. have been taken out of the store, and the associated module will be
  112. unloaded if one was loaded, and I<prov> itself will be freed.
  113. ossl_provider_set_fallback() marks an available provider I<prov> as
  114. fallback.
  115. Note that after this call, the provider object pointer that was
  116. used can simply be dropped, but not freed.
  117. ossl_provider_set_module_path() sets the module path to load the
  118. provider module given the provider object I<prov>.
  119. This will be used in preference to automatically trying to figure out
  120. the path from the provider name and the default module directory (more
  121. on this in L</NOTES>).
  122. ossl_provider_library_context() returns the library context the given
  123. provider I<prov> is registered in.
  124. ossl_provider_add_parameter() adds a global parameter for the provider
  125. to retrieve as it sees fit.
  126. The parameters are a combination of I<name> and I<value>, and the
  127. provider will use the name to find the value it wants.
  128. Only text parameters can be given, and it's up to the provider to
  129. interpret them.
  130. ossl_provider_activate() "activates" the provider for the given
  131. provider object I<prov>.
  132. What "activates" means depends on what type of provider object it
  133. is:
  134. =over 4
  135. =item *
  136. If an initialization function was given with ossl_provider_new(), that
  137. function will get called.
  138. =item *
  139. If no initialization function was given with ossl_provider_new(), a
  140. loadable module with the I<name> that was given to ossl_provider_new()
  141. will be located and loaded, then the symbol B<OSSL_provider_init> will
  142. be located in that module, and called.
  143. =back
  144. ossl_provider_available() activates all fallbacks if no provider is
  145. activated yet, then checks if given provider object I<prov> is
  146. activated.
  147. ossl_provider_ctx() returns a context created by the provider.
  148. Outside of the provider, it's completely opaque, but it needs to be
  149. passed back to some of the provider functions.
  150. ossl_provider_forall_loaded() iterates over all the currently
  151. "activated" providers, and calls I<cb> for each of them.
  152. If no providers have been "activated" yet, it tries to activate all
  153. available fallback providers and tries another iteration.
  154. ossl_provider_name() returns the name that was given with
  155. ossl_provider_new().
  156. ossl_provider_dso() returns a reference to the module, for providers
  157. that come in the form of loadable modules.
  158. ossl_provider_module_name() returns the filename of the module, for
  159. providers that come in the form of loadable modules.
  160. ossl_provider_module_path() returns the full path of the module file,
  161. for providers that come in the form of loadable modules.
  162. ossl_provider_teardown() calls the provider's I<teardown> function, if
  163. the provider has one.
  164. ossl_provider_gettable_params() calls the provider's I<gettable_params>
  165. function, if the provider has one.
  166. It should return an array of I<OSSL_PARAM> to describe all the
  167. parameters that the provider has for the provider object.
  168. ossl_provider_get_params() calls the provider's parameter request
  169. responder.
  170. It should treat the given I<OSSL_PARAM> array as described in
  171. L<OSSL_PARAM(3)>.
  172. ossl_provider_get_capabilities() calls the provider's I<get_capabilities> function,
  173. if the provider has one. It provides the name of the I<capability> and a
  174. callback I<cb> parameter to call for each capability that has a matching name in
  175. the provider. The callback gets passed OSSL_PARAM details about the capability as
  176. well as the caller supplied argument I<arg>.
  177. ossl_provider_query_operation() calls the provider's
  178. I<query_operation> function, if the provider has one.
  179. It should return an array of I<OSSL_ALGORITHM> for the given
  180. I<operation_id>.
  181. ossl_provider_set_operation_bit() registers a 1 for operation I<bitnum>
  182. in a bitstring that's internal to I<provider>.
  183. ossl_provider_tests_operation_bit() checks if the bit operation I<bitnum>
  184. is set (1) or not (0) in the internal I<provider> bitstring, and sets
  185. I<*result> to 1 or 0 accorddingly.
  186. =head1 NOTES
  187. Locating a provider module happens as follows:
  188. =over 4
  189. =item 1.
  190. If a path was given with ossl_provider_set_module_path(), use that as
  191. module path.
  192. Otherwise, use the provider object's name as module path, with
  193. platform specific standard extensions added.
  194. =item 2.
  195. If the environment variable B<OPENSSL_MODULES> is defined, assume its
  196. value is a directory specification and merge it with the module path.
  197. Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
  198. with the module path.
  199. =back
  200. When this process is done, the result is used when trying to load the
  201. provider module.
  202. The command C<openssl version -m> can be used to find out the value
  203. of the built in macro B<MODULESDIR>.
  204. =head1 RETURN VALUES
  205. ossl_provider_find() and ossl_provider_new() return a pointer to a
  206. provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
  207. ossl_provider_up_ref() returns the value of the reference count after
  208. it has been incremented.
  209. ossl_provider_free() doesn't return any value.
  210. ossl_provider_set_module_path(), ossl_provider_set_fallback() and
  211. ossl_provider_activate() return 1 on success, or 0 on error.
  212. ossl_provider_available() return 1 if the provider is available,
  213. otherwise 0.
  214. ossl_provider_name(), ossl_provider_dso(),
  215. ossl_provider_module_name(), and ossl_provider_module_path() return a
  216. pointer to their respective data if it's available, otherwise NULL
  217. is returned.
  218. ossl_provider_library_context() return a pointer to the library context.
  219. This may be NULL, and is perfectly valid, as it denotes the default
  220. global library context.
  221. ossl_provider_teardown() doesn't return any value.
  222. ossl_provider_gettable_params() returns a pointer to a constant
  223. I<OSSL_PARAM> array if this function is available in the provider,
  224. otherwise NULL.
  225. ossl_provider_get_params() returns 1 on success, or 0 on error.
  226. If this function isn't available in the provider, 0 is returned.
  227. ossl_provider_set_operation_bit() and ossl_provider_test_operation_bit()
  228. return 1 on success, or 0 on error.
  229. ossl_provider_get_capabilities() returns 1 on success, or 0 on error.
  230. If this function isn't available in the provider or the provider does not
  231. support the requested capability then 0 is returned.
  232. =head1 SEE ALSO
  233. L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
  234. =head1 HISTORY
  235. The functions described here were all added in OpenSSL 3.0.
  236. =head1 COPYRIGHT
  237. Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
  238. Licensed under the Apache License 2.0 (the "License"). You may not use
  239. this file except in compliance with the License. You can obtain a copy
  240. in the file LICENSE in the source distribution or at
  241. L<https://www.openssl.org/source/license.html>.
  242. =cut