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