2019-02-07 00:42:50 +08:00
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2021-04-28 22:23:16 +08:00
|
|
|
OSSL_LIB_CTX, OSSL_LIB_CTX_new, OSSL_LIB_CTX_new_from_dispatch,
|
2021-05-05 21:43:19 +08:00
|
|
|
OSSL_LIB_CTX_new_child, OSSL_LIB_CTX_free, OSSL_LIB_CTX_load_config,
|
|
|
|
OSSL_LIB_CTX_get0_global_default, OSSL_LIB_CTX_set0_default
|
2020-03-20 18:25:39 +08:00
|
|
|
- OpenSSL library context
|
2019-02-07 00:42:50 +08:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
typedef struct ossl_lib_ctx_st OSSL_LIB_CTX;
|
2019-02-07 00:42:50 +08:00
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *OSSL_LIB_CTX_new(void);
|
2021-04-21 23:51:41 +08:00
|
|
|
OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle,
|
|
|
|
const OSSL_DISPATCH *in);
|
2021-05-05 21:43:19 +08:00
|
|
|
OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle,
|
|
|
|
const OSSL_DISPATCH *in);
|
2020-10-15 17:55:50 +08:00
|
|
|
int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file);
|
|
|
|
void OSSL_LIB_CTX_free(OSSL_LIB_CTX *ctx);
|
2021-04-16 18:13:30 +08:00
|
|
|
OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void);
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *ctx);
|
2019-02-07 00:42:50 +08:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
B<OSSL_LIB_CTX> is an internal OpenSSL library context type.
|
2020-06-22 19:12:53 +08:00
|
|
|
Applications may allocate their own, but may also use NULL to use
|
2020-10-15 17:55:50 +08:00
|
|
|
a default context with functions that take an B<OSSL_LIB_CTX>
|
2019-02-07 00:42:50 +08:00
|
|
|
argument.
|
|
|
|
|
2019-05-29 23:04:17 +08:00
|
|
|
When a non default library context is in use care should be taken with
|
|
|
|
multi-threaded applications to properly clean up thread local resources before
|
2020-10-15 17:55:50 +08:00
|
|
|
the OSSL_LIB_CTX is freed.
|
2019-05-29 23:04:17 +08:00
|
|
|
See L<OPENSSL_thread_stop_ex(3)> for more information.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_new() creates a new OpenSSL library context.
|
2020-06-22 19:12:53 +08:00
|
|
|
|
2021-04-28 22:23:16 +08:00
|
|
|
OSSL_LIB_CTX_new_from_dispatch() creates a new OpenSSL library context
|
|
|
|
initialised to use callbacks from the OSSL_DISPATCH structure. This is primarily
|
2021-04-21 23:51:41 +08:00
|
|
|
useful for provider authors. The I<handle> and dispatch structure arguments
|
|
|
|
passed should be the same ones as passed to a provider's
|
|
|
|
OSSL_provider_init function. Some OpenSSL functions, such as
|
|
|
|
L<BIO_new_from_core_bio(3)>, require the library context to be created in this
|
|
|
|
way in order to work.
|
2021-04-28 22:23:16 +08:00
|
|
|
|
2021-05-05 21:43:19 +08:00
|
|
|
OSSL_LIB_CTX_new_child() is only useful to provider authors and does the same
|
|
|
|
thing as OSSL_LIB_CTX_new_from_dispatch() except that it additionally links the
|
|
|
|
new library context to the application library context. The new library context
|
|
|
|
is a full library context in its own right, but will have all the same providers
|
|
|
|
available to it that are available in the application library context (without
|
|
|
|
having to reload them). If the application loads or unloads providers from the
|
|
|
|
application library context then this will be automatically mirrored in the
|
|
|
|
child library context.
|
|
|
|
|
|
|
|
In addition providers that are not loaded in the parent library context can be
|
|
|
|
explicitly loaded into the child library context independently from the parent
|
|
|
|
library context. Providers loaded independently in this way will not be mirrored
|
|
|
|
in the parent library context and will not be affected if the parent library
|
|
|
|
context subsequently loads the same provider.
|
|
|
|
|
|
|
|
A provider may call the function L<OSSL_PROVIDER_load(3)> with the child library
|
|
|
|
context as required. If the provider already exists due to it being mirrored
|
|
|
|
from the parent library context then it will remain available and its reference
|
|
|
|
count will be increased. If L<OSSL_PROVIDER_load(3)> is called in this way then
|
|
|
|
L<OSSL_PROVIDER_unload(3)> should be subsequently called to decrement the
|
|
|
|
reference count. L<OSSL_PROVIDER_unload(3)> must not be called for a provider in
|
|
|
|
the child library context that did not have an earlier L<OSSL_PROVIDER_load(3)>
|
|
|
|
call for that provider in that child library context.
|
|
|
|
|
2021-05-11 23:49:45 +08:00
|
|
|
In addition to providers, a child library context will also mirror the default
|
|
|
|
properties (set via L<EVP_set_default_properties(3)>) from the parent library
|
|
|
|
context. If L<EVP_set_default_properties(3)> is called directly on a child
|
|
|
|
library context then the new properties will override anything from the parent
|
|
|
|
library context and mirroring of the properties will stop.
|
|
|
|
|
2021-05-05 21:43:19 +08:00
|
|
|
OSSL_LIB_CTX_new_child() must only be called from within the scope of a
|
|
|
|
provider's B<OSSL_provider_init> function (see L<provider-base(7)>). Calling it
|
|
|
|
outside of that function may succeed but may not correctly mirror all providers
|
|
|
|
and is considered undefined behaviour. When called from within the scope of a
|
|
|
|
provider's B<OSSL_provider_init> function the currently initialising provider is
|
|
|
|
not yet available in the application's library context and therefore will
|
|
|
|
similarly not yet be available in the newly constructed child library context.
|
|
|
|
As soon as the B<OSSL_provider_init> function returns then the new provider is
|
|
|
|
available in the application's library context and will be similarly mirrored in
|
|
|
|
the child library context. Since the current provider is still initialising
|
|
|
|
the provider should not attempt to perform fetches, or call any function that
|
|
|
|
performs a fetch using the child library context until after the initialisation
|
|
|
|
function has completed.
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_load_config() loads a configuration file using the given C<ctx>.
|
2020-06-22 19:12:53 +08:00
|
|
|
This can be used to associate a library context with providers that are loaded
|
|
|
|
from a configuration.
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_free() frees the given I<ctx>, unless it happens to be the
|
2020-06-22 19:12:53 +08:00
|
|
|
default OpenSSL library context.
|
2020-03-20 18:25:39 +08:00
|
|
|
|
2021-04-16 18:13:30 +08:00
|
|
|
OSSL_LIB_CTX_get0_global_default() returns a concrete (non NULL) reference to
|
|
|
|
the global default library context.
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_set0_default() sets the default OpenSSL library context to be
|
2020-06-22 19:12:53 +08:00
|
|
|
I<ctx> in the current thread. The previous default library context is
|
|
|
|
returned. Care should be taken by the caller to restore the previous
|
2021-04-15 23:46:35 +08:00
|
|
|
default library context with a subsequent call of this function. If I<ctx> is
|
|
|
|
NULL then no change is made to the default library context, but a pointer to
|
2021-04-16 18:13:30 +08:00
|
|
|
the current library context is still returned. On a successful call of this
|
|
|
|
function the returned value will always be a concrete (non NULL) library
|
|
|
|
context.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
2020-06-26 18:00:25 +08:00
|
|
|
Care should be taken when changing the default library context and starting
|
|
|
|
async jobs (see L<ASYNC_start_job(3)>), as the default library context when
|
|
|
|
the job is started will be used throughout the lifetime of an async job, no
|
|
|
|
matter how the calling thread makes further default library context changes
|
|
|
|
in the mean time. This means that the calling thread must not free the
|
|
|
|
library context that was the default at the start of the async job before
|
|
|
|
that job has finished.
|
|
|
|
|
2019-02-07 00:42:50 +08:00
|
|
|
=head1 RETURN VALUES
|
|
|
|
|
2021-04-16 18:13:30 +08:00
|
|
|
OSSL_LIB_CTX_new(), OSSL_LIB_CTX_get0_global_default() and
|
|
|
|
OSSL_LIB_CTX_set0_default() return a library context pointer on success, or NULL
|
|
|
|
on error.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX_free() doesn't return any value.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
|
|
|
=head1 HISTORY
|
|
|
|
|
2021-04-28 22:23:16 +08:00
|
|
|
All of the functions described on this page were added in OpenSSL 3.0.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
|
2021-04-22 21:38:44 +08:00
|
|
|
Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2019-02-07 00:42:50 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
this file except in compliance with the License. You can obtain a copy
|
|
|
|
in the file LICENSE in the source distribution or at
|
|
|
|
L<https://www.openssl.org/source/license.html>.
|
|
|
|
|
|
|
|
=cut
|