mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-04-29 19:24:37 +00:00
Add the function openssl_ctx_get_concrete()
This adds the ability to take an OPENSSL_CTX parameter and either return it as is (unchanged), or if it is NULL return a pointer to the default ctx. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9040)
This commit is contained in:
parent
30478c9783
commit
d4c051cef3
@ -129,6 +129,18 @@ void OPENSSL_CTX_free(OPENSSL_CTX *ctx)
|
|||||||
OPENSSL_free(ctx);
|
OPENSSL_free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)
|
||||||
|
{
|
||||||
|
#ifndef FIPS_MODE
|
||||||
|
if (ctx == NULL) {
|
||||||
|
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||||
|
return 0;
|
||||||
|
return default_context;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,
|
static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,
|
||||||
CRYPTO_EX_DATA *ad, int index,
|
CRYPTO_EX_DATA *ad, int index,
|
||||||
long argl_ign, void *argp)
|
long argl_ign, void *argp)
|
||||||
@ -154,13 +166,7 @@ static int openssl_ctx_init_index(OPENSSL_CTX *ctx, int static_index,
|
|||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
#ifndef FIPS_MODE
|
ctx = openssl_ctx_get_concrete(ctx);
|
||||||
if (ctx == NULL) {
|
|
||||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
|
||||||
return 0;
|
|
||||||
ctx = default_context;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -180,13 +186,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
|
|||||||
{
|
{
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
|
|
||||||
#ifndef FIPS_MODE
|
ctx = openssl_ctx_get_concrete(ctx);
|
||||||
if (ctx == NULL) {
|
|
||||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
|
||||||
return NULL;
|
|
||||||
ctx = default_context;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -210,18 +210,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
|
|||||||
|
|
||||||
OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)
|
OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)
|
||||||
{
|
{
|
||||||
/*
|
ctx = openssl_ctx_get_concrete(ctx);
|
||||||
* The default context code is not needed in FIPS_MODE and ctx should never
|
|
||||||
* be NULL in the FIPS provider. However we compile this code out to ensure
|
|
||||||
* we fail immediately if ctx == NULL in FIPS_MODE
|
|
||||||
*/
|
|
||||||
#ifndef FIPS_MODE
|
|
||||||
if (ctx == NULL) {
|
|
||||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
|
||||||
return NULL;
|
|
||||||
ctx = default_context;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return &ctx->global;
|
return &ctx->global;
|
||||||
@ -232,13 +221,7 @@ int openssl_ctx_run_once(OPENSSL_CTX *ctx, unsigned int idx,
|
|||||||
{
|
{
|
||||||
int done = 0, ret = 0;
|
int done = 0, ret = 0;
|
||||||
|
|
||||||
#ifndef FIPS_MODE
|
ctx = openssl_ctx_get_concrete(ctx);
|
||||||
if (ctx == NULL) {
|
|
||||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
|
||||||
return 0;
|
|
||||||
ctx = default_context;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -156,6 +156,8 @@ typedef struct openssl_ctx_method {
|
|||||||
void (*free_func)(void *);
|
void (*free_func)(void *);
|
||||||
} OPENSSL_CTX_METHOD;
|
} OPENSSL_CTX_METHOD;
|
||||||
|
|
||||||
|
OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx);
|
||||||
|
|
||||||
/* Functions to retrieve pointers to data by index */
|
/* Functions to retrieve pointers to data by index */
|
||||||
void *openssl_ctx_get_data(OPENSSL_CTX *, int /* index */,
|
void *openssl_ctx_get_data(OPENSSL_CTX *, int /* index */,
|
||||||
const OPENSSL_CTX_METHOD * ctx);
|
const OPENSSL_CTX_METHOD * ctx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user