Lines Matching +full:no +full:- +full:dynamic +full:- +full:engine
2 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
10 /* We need to use some engine deprecated APIs */
18 * Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE
19 * loader should implement the hook-up functions with the following
23 /* Our ENGINE handlers */
24 static int dynamic_init(ENGINE *e);
25 static int dynamic_finish(ENGINE *e);
26 static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p,
31 static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
41 /* The constants used when creating the ENGINE */
42 static const char *engine_dynamic_id = "dynamic";
43 static const char *engine_dynamic_name = "Dynamic engine loading support";
47 "Specifies the path to the new ENGINE shared library",
55 "Specifies an ENGINE id name for loading",
59 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
63 "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)",
71 "Load up the ENGINE specified by other settings",
77 * Loading code stores state inside the ENGINE structure via the "ex_data"
82 /* The DSO object we load that supplies the ENGINE code */
89 * The function pointer to the engine-binding shared library function
96 /* If non-NULL, stipulates the 'id' of the ENGINE to be loaded */
99 * If non-zero, a successfully loaded ENGINE should be added to the
100 * internal ENGINE list. If 2, the add must succeed or the entire load
106 /* The symbol name for the "initialise ENGINE structure" function */
121 static int dynamic_ex_data_idx = -1;
130 * whether a "first-use" occurs before the ENGINE is freed, we have a memory
132 * we don't want a dynamic_data_ctx in *all* ENGINE structures of all types
134 * a "free" handler and that will get called if an ENGINE is being destroyed
143 DSO_free(ctx->dynamic_dso); in dynamic_data_ctx_free_func()
144 OPENSSL_free(ctx->DYNAMIC_LIBNAME); in dynamic_data_ctx_free_func()
145 OPENSSL_free(ctx->engine_id); in dynamic_data_ctx_free_func()
146 sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); in dynamic_data_ctx_free_func()
152 * Construct the per-ENGINE context. We create it blindly and then use a lock
153 * to check for a race - if so, all but one of the threads "racing" will have
157 static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) in dynamic_set_data_ctx()
166 c->dirs = sk_OPENSSL_STRING_new_null(); in dynamic_set_data_ctx()
167 if (c->dirs == NULL) { in dynamic_set_data_ctx()
171 c->DYNAMIC_F1 = "v_check"; in dynamic_set_data_ctx()
172 c->DYNAMIC_F2 = "bind_engine"; in dynamic_set_data_ctx()
173 c->dir_load = 1; in dynamic_set_data_ctx()
189 * If we lost the race to set the context, c is non-NULL and *ctx is the in dynamic_set_data_ctx()
194 sk_OPENSSL_STRING_free(c->dirs); in dynamic_set_data_ctx()
200 * This function retrieves the context structure from an ENGINE's "ex_data",
203 static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e) in dynamic_get_data_ctx()
208 * Create and register the ENGINE ex_data, and associate our "free" in dynamic_get_data_ctx()
210 * an ENGINE goes underground. in dynamic_get_data_ctx()
214 if (new_idx == -1) { in dynamic_get_data_ctx()
224 new_idx = -1; in dynamic_get_data_ctx()
228 * In theory we could "give back" the index here if (new_idx>-1), but in dynamic_get_data_ctx()
240 static ENGINE *engine_dynamic(void) in engine_dynamic()
242 ENGINE *ret = ENGINE_new(); in engine_dynamic()
260 ENGINE *toadd = engine_dynamic(); in engine_load_dynamic_int()
268 * release our just-created reference. in engine_load_dynamic_int()
279 static int dynamic_init(ENGINE *e) in dynamic_init()
282 * We always return failure - the "dynamic" engine itself can't be used in dynamic_init()
288 static int dynamic_finish(ENGINE *e) in dynamic_finish()
297 static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) in dynamic_ctrl()
306 initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1); in dynamic_ctrl()
307 /* All our control commands require the ENGINE to be uninitialised */ in dynamic_ctrl()
314 /* a NULL 'p' or a string of zero-length is the same thing */ in dynamic_ctrl()
317 OPENSSL_free(ctx->DYNAMIC_LIBNAME); in dynamic_ctrl()
319 ctx->DYNAMIC_LIBNAME = OPENSSL_strdup(p); in dynamic_ctrl()
321 ctx->DYNAMIC_LIBNAME = NULL; in dynamic_ctrl()
322 return (ctx->DYNAMIC_LIBNAME ? 1 : 0); in dynamic_ctrl()
324 ctx->no_vcheck = ((i == 0) ? 0 : 1); in dynamic_ctrl()
327 /* a NULL 'p' or a string of zero-length is the same thing */ in dynamic_ctrl()
330 OPENSSL_free(ctx->engine_id); in dynamic_ctrl()
332 ctx->engine_id = OPENSSL_strdup(p); in dynamic_ctrl()
334 ctx->engine_id = NULL; in dynamic_ctrl()
335 return (ctx->engine_id ? 1 : 0); in dynamic_ctrl()
341 ctx->list_add_value = (int)i; in dynamic_ctrl()
350 ctx->dir_load = (int)i; in dynamic_ctrl()
353 /* a NULL 'p' or a string of zero-length is the same thing */ in dynamic_ctrl()
364 if (!sk_OPENSSL_STRING_push(ctx->dirs, tmp_str)) { in dynamic_ctrl()
382 if ((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, in int_load()
383 ctx->DYNAMIC_LIBNAME, NULL, in int_load()
387 if (!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1) in int_load()
390 const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop); in int_load()
391 char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s); in int_load()
394 if (DSO_load(ctx->dynamic_dso, merge, NULL, 0)) { in int_load()
407 * an engine that is built for openssl 1.1.x will cause a fatal
411 * as an indication that the engine will be incompatible.
418 ret = DSO_bind_func(ctx->dynamic_dso, "EVP_PKEY_base_id") != NULL; in using_libcrypto_11()
424 static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) in dynamic_load()
426 ENGINE cpy; in dynamic_load()
429 if (ctx->dynamic_dso == NULL) in dynamic_load()
430 ctx->dynamic_dso = DSO_new(); in dynamic_load()
431 if (ctx->dynamic_dso == NULL) in dynamic_load()
433 if (!ctx->DYNAMIC_LIBNAME) { in dynamic_load()
434 if (!ctx->engine_id) in dynamic_load()
436 DSO_ctrl(ctx->dynamic_dso, DSO_CTRL_SET_FLAGS, in dynamic_load()
438 ctx->DYNAMIC_LIBNAME = in dynamic_load()
439 DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id); in dynamic_load()
443 DSO_free(ctx->dynamic_dso); in dynamic_load()
444 ctx->dynamic_dso = NULL; in dynamic_load()
449 (ctx->bind_engine = in dynamic_load()
450 (dynamic_bind_engine) DSO_bind_func(ctx->dynamic_dso, in dynamic_load()
451 ctx->DYNAMIC_F2))) { in dynamic_load()
452 ctx->bind_engine = NULL; in dynamic_load()
453 DSO_free(ctx->dynamic_dso); in dynamic_load()
454 ctx->dynamic_dso = NULL; in dynamic_load()
459 if (!ctx->no_vcheck) { in dynamic_load()
465 ctx->v_check = in dynamic_load()
466 (dynamic_v_check_fn) DSO_bind_func(ctx->dynamic_dso, in dynamic_load()
467 ctx->DYNAMIC_F1); in dynamic_load()
468 if (ctx->v_check) in dynamic_load()
469 vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION); in dynamic_load()
473 * old. Also fail if this is engine for openssl 1.1.x. in dynamic_load()
477 ctx->bind_engine = NULL; in dynamic_load()
478 ctx->v_check = NULL; in dynamic_load()
479 DSO_free(ctx->dynamic_dso); in dynamic_load()
480 ctx->dynamic_dso = NULL; in dynamic_load()
486 * First binary copy the ENGINE structure so that we can roll back if the in dynamic_load()
487 * hand-over fails in dynamic_load()
489 memcpy(&cpy, e, sizeof(ENGINE)); in dynamic_load()
493 * engine.h, much of this would be simplified if each area of code in dynamic_load()
501 * Now that we've loaded the dynamic engine, make sure no "dynamic" in dynamic_load()
502 * ENGINE elements will show through. in dynamic_load()
506 /* Try to bind the ENGINE onto our own ENGINE structure */ in dynamic_load()
507 if (!engine_add_dynamic_id(e, (ENGINE_DYNAMIC_ID)ctx->bind_engine, 1) in dynamic_load()
508 || !ctx->bind_engine(e, ctx->engine_id, &fns)) { in dynamic_load()
510 ctx->bind_engine = NULL; in dynamic_load()
511 ctx->v_check = NULL; in dynamic_load()
512 DSO_free(ctx->dynamic_dso); in dynamic_load()
513 ctx->dynamic_dso = NULL; in dynamic_load()
515 /* Copy the original ENGINE structure back */ in dynamic_load()
516 memcpy(e, &cpy, sizeof(ENGINE)); in dynamic_load()
519 /* Do we try to add this ENGINE to the internal list too? */ in dynamic_load()
520 if (ctx->list_add_value > 0) { in dynamic_load()
523 if (ctx->list_add_value > 1) { in dynamic_load()
525 * Fail - NB: By this time, it's too late to rollback, and in dynamic_load()
528 * the ENGINE has changed. in dynamic_load()