2
0

OSSL_LIB_CTX.pod 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. =pod
  2. =head1 NAME
  3. OSSL_LIB_CTX, OSSL_LIB_CTX_new, OSSL_LIB_CTX_new_from_dispatch,
  4. OSSL_LIB_CTX_new_child, OSSL_LIB_CTX_free, OSSL_LIB_CTX_load_config,
  5. OSSL_LIB_CTX_get0_global_default, OSSL_LIB_CTX_set0_default
  6. - OpenSSL library context
  7. =head1 SYNOPSIS
  8. #include <openssl/crypto.h>
  9. typedef struct ossl_lib_ctx_st OSSL_LIB_CTX;
  10. OSSL_LIB_CTX *OSSL_LIB_CTX_new(void);
  11. OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle,
  12. const OSSL_DISPATCH *in);
  13. OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle,
  14. const OSSL_DISPATCH *in);
  15. int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file);
  16. void OSSL_LIB_CTX_free(OSSL_LIB_CTX *ctx);
  17. OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void);
  18. OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *ctx);
  19. =head1 DESCRIPTION
  20. B<OSSL_LIB_CTX> is an internal OpenSSL library context type.
  21. Applications may allocate their own, but may also use NULL to use
  22. a default context with functions that take an B<OSSL_LIB_CTX>
  23. argument.
  24. When a non default library context is in use care should be taken with
  25. multi-threaded applications to properly clean up thread local resources before
  26. the OSSL_LIB_CTX is freed.
  27. See L<OPENSSL_thread_stop_ex(3)> for more information.
  28. OSSL_LIB_CTX_new() creates a new OpenSSL library context.
  29. OSSL_LIB_CTX_new_from_dispatch() creates a new OpenSSL library context
  30. initialised to use callbacks from the OSSL_DISPATCH structure. This is primarily
  31. useful for provider authors. The I<handle> and dispatch structure arguments
  32. passed should be the same ones as passed to a provider's
  33. OSSL_provider_init function. Some OpenSSL functions, such as
  34. L<BIO_new_from_core_bio(3)>, require the library context to be created in this
  35. way in order to work.
  36. OSSL_LIB_CTX_new_child() is only useful to provider authors and does the same
  37. thing as OSSL_LIB_CTX_new_from_dispatch() except that it additionally links the
  38. new library context to the application library context. The new library context
  39. is a full library context in its own right, but will have all the same providers
  40. available to it that are available in the application library context (without
  41. having to reload them). If the application loads or unloads providers from the
  42. application library context then this will be automatically mirrored in the
  43. child library context.
  44. In addition providers that are not loaded in the parent library context can be
  45. explicitly loaded into the child library context independently from the parent
  46. library context. Providers loaded independently in this way will not be mirrored
  47. in the parent library context and will not be affected if the parent library
  48. context subsequently loads the same provider.
  49. A provider may call the function L<OSSL_PROVIDER_load(3)> with the child library
  50. context as required. If the provider already exists due to it being mirrored
  51. from the parent library context then it will remain available and its reference
  52. count will be increased. If L<OSSL_PROVIDER_load(3)> is called in this way then
  53. L<OSSL_PROVIDER_unload(3)> should be subsequently called to decrement the
  54. reference count. L<OSSL_PROVIDER_unload(3)> must not be called for a provider in
  55. the child library context that did not have an earlier L<OSSL_PROVIDER_load(3)>
  56. call for that provider in that child library context.
  57. In addition to providers, a child library context will also mirror the default
  58. properties (set via L<EVP_set_default_properties(3)>) from the parent library
  59. context. If L<EVP_set_default_properties(3)> is called directly on a child
  60. library context then the new properties will override anything from the parent
  61. library context and mirroring of the properties will stop.
  62. When OSSL_LIB_CTX_new_child() is called from within the scope of a provider's
  63. B<OSSL_provider_init> function the currently initialising provider is not yet
  64. available in the application's library context and therefore will similarly not
  65. yet be available in the newly constructed child library context. As soon as the
  66. B<OSSL_provider_init> function returns then the new provider is available in the
  67. application's library context and will be similarly mirrored in the child
  68. library context.
  69. OSSL_LIB_CTX_load_config() loads a configuration file using the given I<ctx>.
  70. This can be used to associate a library context with providers that are loaded
  71. from a configuration.
  72. OSSL_LIB_CTX_free() frees the given I<ctx>, unless it happens to be the
  73. default OpenSSL library context.
  74. OSSL_LIB_CTX_get0_global_default() returns a concrete (non NULL) reference to
  75. the global default library context.
  76. OSSL_LIB_CTX_set0_default() sets the default OpenSSL library context to be
  77. I<ctx> in the current thread. The previous default library context is
  78. returned. Care should be taken by the caller to restore the previous
  79. default library context with a subsequent call of this function. If I<ctx> is
  80. NULL then no change is made to the default library context, but a pointer to
  81. the current library context is still returned. On a successful call of this
  82. function the returned value will always be a concrete (non NULL) library
  83. context.
  84. Care should be taken when changing the default library context and starting
  85. async jobs (see L<ASYNC_start_job(3)>), as the default library context when
  86. the job is started will be used throughout the lifetime of an async job, no
  87. matter how the calling thread makes further default library context changes
  88. in the mean time. This means that the calling thread must not free the
  89. library context that was the default at the start of the async job before
  90. that job has finished.
  91. =head1 RETURN VALUES
  92. OSSL_LIB_CTX_new(), OSSL_LIB_CTX_get0_global_default() and
  93. OSSL_LIB_CTX_set0_default() return a library context pointer on success, or NULL
  94. on error.
  95. OSSL_LIB_CTX_free() doesn't return any value.
  96. OSSL_LIB_CTX_load_config() returns 1 on success, 0 on error.
  97. =head1 HISTORY
  98. All of the functions described on this page were added in OpenSSL 3.0.
  99. =head1 COPYRIGHT
  100. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  101. Licensed under the Apache License 2.0 (the "License"). You may not use
  102. this file except in compliance with the License. You can obtain a copy
  103. in the file LICENSE in the source distribution or at
  104. L<https://www.openssl.org/source/license.html>.
  105. =cut