2
0

ossl_provider_new.pod 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. =pod
  2. =head1 NAME
  3. ossl_provider_find, ossl_provider_new, ossl_provider_up_ref,
  4. ossl_provider_free,
  5. ossl_provider_set_module_path,
  6. ossl_provider_add_parameter, ossl_provider_set_child, ossl_provider_get_parent,
  7. ossl_provider_up_ref_parent, ossl_provider_free_parent,
  8. ossl_provider_default_props_update, ossl_provider_get0_dispatch,
  9. ossl_provider_init_as_child, ossl_provider_deinit_child,
  10. ossl_provider_activate, ossl_provider_deactivate, ossl_provider_add_to_store,
  11. ossl_provider_ctx,
  12. ossl_provider_doall_activated,
  13. ossl_provider_name, ossl_provider_dso,
  14. ossl_provider_module_name, ossl_provider_module_path,
  15. ossl_provider_libctx,
  16. ossl_provider_teardown, ossl_provider_gettable_params,
  17. ossl_provider_get_params,
  18. ossl_provider_query_operation, ossl_provider_unquery_operation,
  19. ossl_provider_set_operation_bit, ossl_provider_test_operation_bit,
  20. ossl_provider_get_capabilities
  21. - internal provider routines
  22. =head1 SYNOPSIS
  23. #include "internal/provider.h"
  24. OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
  25. int noconfig);
  26. OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
  27. ossl_provider_init_fn *init_function
  28. int noconfig);
  29. int ossl_provider_up_ref(OSSL_PROVIDER *prov);
  30. void ossl_provider_free(OSSL_PROVIDER *prov);
  31. /* Setters */
  32. int ossl_provider_set_module_path(OSSL_PROVIDER *prov, const char *path);
  33. int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
  34. const char *value);
  35. /* Child Providers */
  36. int ossl_provider_set_child(OSSL_PROVIDER *prov,
  37. const OSSL_CORE_HANDLE *handle);
  38. const OSSL_CORE_HANDLE *ossl_provider_get_parent(OSSL_PROVIDER *prov);
  39. int ossl_provider_up_ref_parent(OSSL_PROVIDER *prov, int activate);
  40. int ossl_provider_free_parent(OSSL_PROVIDER *prov, int deactivate);
  41. int ossl_provider_default_props_update(OSSL_LIB_CTX *libctx,
  42. const char *props);
  43. /*
  44. * Activate the Provider
  45. * If the Provider is a module, the module will be loaded
  46. */
  47. int ossl_provider_activate(OSSL_PROVIDER *prov, int upcalls, int aschild);
  48. int ossl_provider_deactivate(OSSL_PROVIDER *prov, int removechildren);
  49. int ossl_provider_add_to_store(OSSL_PROVIDER *prov, OSSL_PROVIDER **actualprov,
  50. int retain_fallbacks);
  51. /* Return pointer to the provider's context */
  52. void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
  53. const OSSL_DISPATCH *ossl_provider_get0_dispatch(const OSSL_PROVIDER *prov);
  54. /* Iterate over all loaded providers */
  55. int ossl_provider_doall_activated(OSSL_LIB_CTX *,
  56. int (*cb)(OSSL_PROVIDER *provider,
  57. void *cbdata),
  58. void *cbdata);
  59. /* Getters for other library functions */
  60. const char *ossl_provider_name(OSSL_PROVIDER *prov);
  61. const DSO *ossl_provider_dso(OSSL_PROVIDER *prov);
  62. const char *ossl_provider_module_name(OSSL_PROVIDER *prov);
  63. const char *ossl_provider_module_path(OSSL_PROVIDER *prov);
  64. OSSL_LIB_CTX *ossl_provider_libctx(const OSSL_PROVIDER *prov);
  65. /* Thin wrappers around calls to the provider */
  66. void ossl_provider_teardown(const OSSL_PROVIDER *prov);
  67. const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
  68. int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
  69. int ossl_provider_get_capabilities(const OSSL_PROVIDER *prov,
  70. const char *capability,
  71. OSSL_CALLBACK *cb,
  72. void *arg);
  73. const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
  74. int operation_id,
  75. int *no_cache);
  76. void ossl_provider_unquery_operation(const OSSL_PROVIDER *prov,
  77. int operation_id,
  78. const OSSL_ALGORITHM *algs);
  79. int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum);
  80. int ossl_provider_test_operation_bit(OSSL_PROVIDER *provider, size_t bitnum,
  81. int *result);
  82. int ossl_provider_init_as_child(OSSL_LIB_CTX *ctx,
  83. const OSSL_CORE_HANDLE *handle,
  84. const OSSL_DISPATCH *in);
  85. void ossl_provider_deinit_child(OSSL_LIB_CTX *ctx);
  86. =head1 DESCRIPTION
  87. I<OSSL_PROVIDER> is a type that holds all the necessary information
  88. to handle a provider, regardless of if it's built in to the
  89. application or the OpenSSL libraries, or if it's a loadable provider
  90. module.
  91. Instances of this type are commonly referred to as "provider objects".
  92. A provider object is always stored in a set of provider objects
  93. in the library context.
  94. Provider objects are reference counted.
  95. Provider objects are initially inactive, i.e. they are only recorded
  96. in the store, but are not used.
  97. They are activated with the first call to ossl_provider_activate(),
  98. and are deactivated with the last call to ossl_provider_deactivate().
  99. Activation affects a separate counter.
  100. =head2 Functions
  101. ossl_provider_find() finds an existing provider object in the provider
  102. object store by I<name>.
  103. The config file will be automatically loaded unless I<noconfig> is set.
  104. Typically I<noconfig> should be 0.
  105. We set I<noconfig> to 1 only when calling these functions while processing a
  106. config file in order to avoid recursively attempting to load the file.
  107. The provider object it finds has its reference count incremented.
  108. ossl_provider_new() creates a new provider object named I<name> and
  109. stores it in the provider object store, unless there already is one
  110. there with the same name.
  111. If there already is one with the same name, it's returned with its
  112. reference count incremented.
  113. The config file will be automatically loaded unless I<noconfig> is set.
  114. Typically I<noconfig> should be 0.
  115. We set I<noconfig> to 1 only when calling these functions while processing a
  116. config file in order to avoid recursively attempting to load the file.
  117. The reference count of a newly created provider object will always
  118. be 2; one for being added to the store, and one for the returned
  119. reference.
  120. If I<init_function> is NULL, the provider is assumed to be a
  121. dynamically loadable module, with the symbol B<OSSL_provider_init> as
  122. its initialisation function.
  123. If I<init_function> isn't NULL, the provider is assumed to be built
  124. in, with I<init_function> being the pointer to its initialisation
  125. function.
  126. For further description of the initialisation function, see the
  127. description of ossl_provider_activate() below.
  128. ossl_provider_up_ref() increments the provider object I<prov>'s
  129. reference count.
  130. ossl_provider_free() decrements the provider object I<prov>'s
  131. reference count; when it drops to zero, the provider object is assumed
  132. to have fallen out of use and will be deinitialized (its I<teardown>
  133. function is called), and the associated module will be unloaded if one
  134. was loaded, and I<prov> itself will be freed.
  135. ossl_provider_set_module_path() sets the module path to load the
  136. provider module given the provider object I<prov>.
  137. This will be used in preference to automatically trying to figure out
  138. the path from the provider name and the default module directory (more
  139. on this in L</NOTES>).
  140. ossl_provider_libctx() returns the library context the given
  141. provider I<prov> is registered in.
  142. ossl_provider_add_parameter() adds a global parameter for the provider
  143. to retrieve as it sees fit.
  144. The parameters are a combination of I<name> and I<value>, and the
  145. provider will use the name to find the value it wants.
  146. Only text parameters can be given, and it's up to the provider to
  147. interpret them.
  148. ossl_provider_set_child() marks this provider as a child of a provider in the
  149. parent library context. I<handle> is the B<OSSL_CORE_HANDLE> object passed to
  150. the provider's B<OSSL_provider_init> function.
  151. ossl_provider_get_parent() obtains the handle on the parent provider.
  152. ossl_provider_up_ref_parent() increases the reference count on the parent
  153. provider. If I<activate> is nonzero then the parent provider is also activated.
  154. ossl_provider_free_parent() decreases the reference count on the parent
  155. provider. If I<deactivate> is nonzero then the parent provider is also
  156. deactivated.
  157. ossl_provider_default_props_update() is responsible for informing any child
  158. providers of an update to the default properties. The new properties are
  159. supplied in the I<props> string.
  160. ossl_provider_activate() "activates" the provider for the given
  161. provider object I<prov> by incrementing its activation count, flagging
  162. it as activated, and initializing it if it isn't already initialized.
  163. Initializing means one of the following:
  164. =over 4
  165. =item *
  166. If an initialization function was given with ossl_provider_new(), that
  167. function will get called.
  168. =item *
  169. If no initialization function was given with ossl_provider_new(), a
  170. loadable module with the I<name> that was given to ossl_provider_new()
  171. will be located and loaded, then the symbol B<OSSL_provider_init> will
  172. be located in that module, and called.
  173. =back
  174. If I<upcalls> is nonzero then, if this is a child provider, upcalls to the
  175. parent libctx will be made to inform it of an up-ref. If I<aschild> is nonzero
  176. then the provider will only be activated if it is a child provider. Otherwise
  177. no action is taken and ossl_provider_activate() returns success.
  178. ossl_provider_deactivate() "deactivates" the provider for the given
  179. provider object I<prov> by decrementing its activation count. When
  180. that count reaches zero, the activation flag is cleared. If the
  181. I<removechildren> parameter is 0 then no attempt is made to remove any
  182. associated child providers.
  183. ossl_provider_add_to_store() adds the provider I<prov> to the provider store and
  184. makes it available to other threads. This will prevent future automatic loading
  185. of fallback providers, unless I<retain_fallbacks> is true. If a provider of the
  186. same name already exists in the store then it is not added but this function
  187. still returns success. On success the I<actualprov> value is populated with a
  188. pointer to the provider of the given name that is now in the store. The
  189. reference passed in the I<prov> argument is consumed by this function. A
  190. reference to the provider that should be used is passed back in the
  191. I<actualprov> argument.
  192. ossl_provider_ctx() returns a context created by the provider.
  193. Outside of the provider, it's completely opaque, but it needs to be
  194. passed back to some of the provider functions.
  195. ossl_provider_get0_dispatch() returns the dispatch table that the provider
  196. initially returned in the I<out> parameter of its B<OSSL_provider_init>
  197. function.
  198. ossl_provider_doall_activated() iterates over all the currently
  199. "activated" providers, and calls I<cb> for each of them.
  200. If no providers have been "activated" yet, it tries to activate all
  201. available fallback providers before iterating over them.
  202. ossl_provider_name() returns the name that was given with
  203. ossl_provider_new().
  204. ossl_provider_dso() returns a reference to the module, for providers
  205. that come in the form of loadable modules.
  206. ossl_provider_module_name() returns the filename of the module, for
  207. providers that come in the form of loadable modules.
  208. ossl_provider_module_path() returns the full path of the module file,
  209. for providers that come in the form of loadable modules.
  210. ossl_provider_teardown() calls the provider's I<teardown> function, if
  211. the provider has one.
  212. ossl_provider_gettable_params() calls the provider's I<gettable_params>
  213. function, if the provider has one.
  214. It should return an array of I<OSSL_PARAM> to describe all the
  215. parameters that the provider has for the provider object.
  216. ossl_provider_get_params() calls the provider's parameter request
  217. responder.
  218. It should treat the given I<OSSL_PARAM> array as described in
  219. L<OSSL_PARAM(3)>.
  220. ossl_provider_get_capabilities() calls the provider's I<get_capabilities> function,
  221. if the provider has one. It provides the name of the I<capability> and a
  222. callback I<cb> parameter to call for each capability that has a matching name in
  223. the provider. The callback gets passed OSSL_PARAM details about the capability as
  224. well as the caller supplied argument I<arg>.
  225. ossl_provider_query_operation() calls the provider's
  226. I<query_operation> function, if the provider has one.
  227. It should return an array of I<OSSL_ALGORITHM> for the given
  228. I<operation_id>.
  229. ossl_provider_unquery_operation() informs the provider that the result of
  230. ossl_provider_query_operation() is no longer going to be directly accessed and
  231. that all relevant information has been copied.
  232. ossl_provider_set_operation_bit() registers a 1 for operation I<bitnum>
  233. in a bitstring that's internal to I<provider>.
  234. ossl_provider_test_operation_bit() checks if the bit operation I<bitnum>
  235. is set (1) or not (0) in the internal I<provider> bitstring, and sets
  236. I<*result> to 1 or 0 accordingly.
  237. ossl_provider_init_as_child() stores in the library context I<ctx> references to
  238. the necessary upcalls for managing child providers. The I<handle> and I<in>
  239. parameters are the B<OSSL_CORE_HANDLE> and L<OSSL_DISPATCH(3)> pointers that were
  240. passed to the provider's B<OSSL_provider_init> function.
  241. ossl_provider_deinit_child() deregisters callbacks from the parent library
  242. context about provider creation or removal events for the child library context
  243. I<ctx>. Must only be called if I<ctx> is a child library context.
  244. =head1 NOTES
  245. Locating a provider module happens as follows:
  246. =over 4
  247. =item 1.
  248. If a path was given with ossl_provider_set_module_path(), use that as
  249. module path.
  250. Otherwise, use the provider object's name as module path, with
  251. platform specific standard extensions added.
  252. =item 2.
  253. If the environment variable B<OPENSSL_MODULES> is defined, assume its
  254. value is a directory specification and merge it with the module path.
  255. Otherwise, merge the value of the OpenSSL built in macro B<MODULESDIR>
  256. with the module path.
  257. =back
  258. When this process is done, the result is used when trying to load the
  259. provider module.
  260. The command C<openssl version -m> can be used to find out the value
  261. of the built in macro B<MODULESDIR>.
  262. =head1 RETURN VALUES
  263. ossl_provider_find() and ossl_provider_new() return a pointer to a
  264. provider object (I<OSSL_PROVIDER>) on success, or NULL on error.
  265. ossl_provider_up_ref() returns the value of the reference count after
  266. it has been incremented.
  267. ossl_provider_free() doesn't return any value.
  268. ossl_provider_doall_activated() returns 1 if the callback was called for all
  269. activated providers. A return value of 0 means that the callback was not
  270. called for any activated providers.
  271. ossl_provider_set_module_path(),
  272. ossl_provider_activate(), ossl_provider_activate_leave_fallbacks() and
  273. ossl_provider_deactivate(), ossl_provider_add_to_store(),
  274. ossl_provider_default_props_update() return 1 on success, or 0 on error.
  275. ossl_provider_name(), ossl_provider_dso(),
  276. ossl_provider_module_name(), and ossl_provider_module_path() return a
  277. pointer to their respective data if it's available, otherwise NULL
  278. is returned.
  279. ossl_provider_libctx() return a pointer to the library context.
  280. This may be NULL, and is perfectly valid, as it denotes the default
  281. global library context.
  282. ossl_provider_teardown() doesn't return any value.
  283. ossl_provider_gettable_params() returns a pointer to a constant
  284. I<OSSL_PARAM> array if this function is available in the provider,
  285. otherwise NULL.
  286. ossl_provider_get_params() returns 1 on success, or 0 on error.
  287. If this function isn't available in the provider, 0 is returned.
  288. ossl_provider_set_operation_bit() and ossl_provider_test_operation_bit()
  289. return 1 on success, or 0 on error.
  290. ossl_provider_get_capabilities() returns 1 on success, or 0 on error.
  291. If this function isn't available in the provider or the provider does not
  292. support the requested capability then 0 is returned.
  293. =head1 SEE ALSO
  294. L<OSSL_PROVIDER(3)>, L<provider(7)>, L<openssl(1)>
  295. =head1 HISTORY
  296. The functions described here were all added in OpenSSL 3.0.
  297. =head1 COPYRIGHT
  298. Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
  299. Licensed under the Apache License 2.0 (the "License"). You may not use
  300. this file except in compliance with the License. You can obtain a copy
  301. in the file LICENSE in the source distribution or at
  302. L<https://www.openssl.org/source/license.html>.
  303. =cut