ossl_provider_new.pod 11 KB

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