1ENGINE_ADD(3)                       OpenSSL                      ENGINE_ADD(3)
2
3
4

NAME

6       ENGINE_get_DH, ENGINE_get_DSA, ENGINE_by_id, ENGINE_get_cipher_engine,
7       ENGINE_get_default_DH, ENGINE_get_default_DSA, ENGINE_get_default_RAND,
8       ENGINE_get_default_RSA, ENGINE_get_digest_engine, ENGINE_get_first,
9       ENGINE_get_last, ENGINE_get_next, ENGINE_get_prev, ENGINE_new,
10       ENGINE_get_ciphers, ENGINE_get_ctrl_function, ENGINE_get_digests,
11       ENGINE_get_destroy_function, ENGINE_get_finish_function,
12       ENGINE_get_init_function, ENGINE_get_load_privkey_function,
13       ENGINE_get_load_pubkey_function, ENGINE_load_private_key,
14       ENGINE_load_public_key, ENGINE_get_RAND, ENGINE_get_RSA, ENGINE_get_id,
15       ENGINE_get_name, ENGINE_get_cmd_defns, ENGINE_get_cipher,
16       ENGINE_get_digest, ENGINE_add, ENGINE_cmd_is_executable, ENGINE_ctrl,
17       ENGINE_ctrl_cmd, ENGINE_ctrl_cmd_string, ENGINE_finish, ENGINE_free,
18       ENGINE_get_flags, ENGINE_init, ENGINE_register_DH, ENGINE_register_DSA,
19       ENGINE_register_RAND, ENGINE_register_RSA,
20       ENGINE_register_all_complete, ENGINE_register_ciphers,
21       ENGINE_register_complete, ENGINE_register_digests, ENGINE_remove,
22       ENGINE_set_DH, ENGINE_set_DSA, ENGINE_set_RAND, ENGINE_set_RSA,
23       ENGINE_set_ciphers, ENGINE_set_cmd_defns, ENGINE_set_ctrl_function,
24       ENGINE_set_default, ENGINE_set_default_DH, ENGINE_set_default_DSA,
25       ENGINE_set_default_RAND, ENGINE_set_default_RSA,
26       ENGINE_set_default_ciphers, ENGINE_set_default_digests,
27       ENGINE_set_default_string, ENGINE_set_destroy_function,
28       ENGINE_set_digests, ENGINE_set_finish_function, ENGINE_set_flags,
29       ENGINE_set_id, ENGINE_set_init_function,
30       ENGINE_set_load_privkey_function, ENGINE_set_load_pubkey_function,
31       ENGINE_set_name, ENGINE_up_ref, ENGINE_get_table_flags, ENGINE_cleanup,
32       ENGINE_load_builtin_engines, ENGINE_register_all_DH,
33       ENGINE_register_all_DSA, ENGINE_register_all_RAND,
34       ENGINE_register_all_RSA, ENGINE_register_all_ciphers,
35       ENGINE_register_all_digests, ENGINE_set_table_flags,
36       ENGINE_unregister_DH, ENGINE_unregister_DSA, ENGINE_unregister_RAND,
37       ENGINE_unregister_RSA, ENGINE_unregister_ciphers,
38       ENGINE_unregister_digests - ENGINE cryptographic module support
39

SYNOPSIS

41        #include <openssl/engine.h>
42
43        ENGINE *ENGINE_get_first(void);
44        ENGINE *ENGINE_get_last(void);
45        ENGINE *ENGINE_get_next(ENGINE *e);
46        ENGINE *ENGINE_get_prev(ENGINE *e);
47
48        int ENGINE_add(ENGINE *e);
49        int ENGINE_remove(ENGINE *e);
50
51        ENGINE *ENGINE_by_id(const char *id);
52
53        int ENGINE_init(ENGINE *e);
54        int ENGINE_finish(ENGINE *e);
55
56        void ENGINE_load_builtin_engines(void);
57
58        ENGINE *ENGINE_get_default_RSA(void);
59        ENGINE *ENGINE_get_default_DSA(void);
60        ENGINE *ENGINE_get_default_DH(void);
61        ENGINE *ENGINE_get_default_RAND(void);
62        ENGINE *ENGINE_get_cipher_engine(int nid);
63        ENGINE *ENGINE_get_digest_engine(int nid);
64
65        int ENGINE_set_default_RSA(ENGINE *e);
66        int ENGINE_set_default_DSA(ENGINE *e);
67        int ENGINE_set_default_DH(ENGINE *e);
68        int ENGINE_set_default_RAND(ENGINE *e);
69        int ENGINE_set_default_ciphers(ENGINE *e);
70        int ENGINE_set_default_digests(ENGINE *e);
71        int ENGINE_set_default_string(ENGINE *e, const char *list);
72
73        int ENGINE_set_default(ENGINE *e, unsigned int flags);
74
75        unsigned int ENGINE_get_table_flags(void);
76        void ENGINE_set_table_flags(unsigned int flags);
77
78        int ENGINE_register_RSA(ENGINE *e);
79        void ENGINE_unregister_RSA(ENGINE *e);
80        void ENGINE_register_all_RSA(void);
81        int ENGINE_register_DSA(ENGINE *e);
82        void ENGINE_unregister_DSA(ENGINE *e);
83        void ENGINE_register_all_DSA(void);
84        int ENGINE_register_DH(ENGINE *e);
85        void ENGINE_unregister_DH(ENGINE *e);
86        void ENGINE_register_all_DH(void);
87        int ENGINE_register_RAND(ENGINE *e);
88        void ENGINE_unregister_RAND(ENGINE *e);
89        void ENGINE_register_all_RAND(void);
90        int ENGINE_register_ciphers(ENGINE *e);
91        void ENGINE_unregister_ciphers(ENGINE *e);
92        void ENGINE_register_all_ciphers(void);
93        int ENGINE_register_digests(ENGINE *e);
94        void ENGINE_unregister_digests(ENGINE *e);
95        void ENGINE_register_all_digests(void);
96        int ENGINE_register_complete(ENGINE *e);
97        int ENGINE_register_all_complete(void);
98
99        int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
100        int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
101        int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
102                            long i, void *p, void (*f)(void), int cmd_optional);
103        int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
104                                   int cmd_optional);
105
106        ENGINE *ENGINE_new(void);
107        int ENGINE_free(ENGINE *e);
108        int ENGINE_up_ref(ENGINE *e);
109
110        int ENGINE_set_id(ENGINE *e, const char *id);
111        int ENGINE_set_name(ENGINE *e, const char *name);
112        int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
113        int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
114        int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
115        int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
116        int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
117        int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
118        int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
119        int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
120        int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
121        int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
122        int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
123        int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
124        int ENGINE_set_flags(ENGINE *e, int flags);
125        int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
126
127        const char *ENGINE_get_id(const ENGINE *e);
128        const char *ENGINE_get_name(const ENGINE *e);
129        const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
130        const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
131        const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
132        const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
133        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
134        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
135        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
136        ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
137        ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
138        ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
139        ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
140        ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
141        const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
142        const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
143        int ENGINE_get_flags(const ENGINE *e);
144        const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
145
146        EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
147                                          UI_METHOD *ui_method, void *callback_data);
148        EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
149                                         UI_METHOD *ui_method, void *callback_data);
150
151       Deprecated:
152
153        #if OPENSSL_API_COMPAT < 0x10100000L
154        void ENGINE_cleanup(void)
155        #endif
156

DESCRIPTION

158       These functions create, manipulate, and use cryptographic modules in
159       the form of ENGINE objects. These objects act as containers for
160       implementations of cryptographic algorithms, and support a reference-
161       counted mechanism to allow them to be dynamically loaded in and out of
162       the running application.
163
164       The cryptographic functionality that can be provided by an ENGINE
165       implementation includes the following abstractions;
166
167        RSA_METHOD - for providing alternative RSA implementations
168        DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
169              - similarly for other OpenSSL APIs
170        EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
171        EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
172        key-loading - loading public and/or private EVP_PKEY keys
173
174   Reference counting and handles
175       Due to the modular nature of the ENGINE API, pointers to ENGINEs need
176       to be treated as handles - i.e. not only as pointers, but also as
177       references to the underlying ENGINE object. Ie. one should obtain a new
178       reference when making copies of an ENGINE pointer if the copies will be
179       used (and released) independently.
180
181       ENGINE objects have two levels of reference-counting to match the way
182       in which the objects are used. At the most basic level, each ENGINE
183       pointer is inherently a structural reference - a structural reference
184       is required to use the pointer value at all, as this kind of reference
185       is a guarantee that the structure can not be deallocated until the
186       reference is released.
187
188       However, a structural reference provides no guarantee that the ENGINE
189       is initialised and able to use any of its cryptographic
190       implementations. Indeed it's quite possible that most ENGINEs will not
191       initialise at all in typical environments, as ENGINEs are typically
192       used to support specialised hardware. To use an ENGINE's functionality,
193       you need a functional reference. This kind of reference can be
194       considered a specialised form of structural reference, because each
195       functional reference implicitly contains a structural reference as well
196       - however to avoid difficult-to-find programming bugs, it is
197       recommended to treat the two kinds of reference independently. If you
198       have a functional reference to an ENGINE, you have a guarantee that the
199       ENGINE has been initialised and is ready to perform cryptographic
200       operations, and will remain initialised until after you have released
201       your reference.
202
203       Structural references
204
205       This basic type of reference is used for instantiating new ENGINEs,
206       iterating across OpenSSL's internal linked-list of loaded ENGINEs,
207       reading information about an ENGINE, etc. Essentially a structural
208       reference is sufficient if you only need to query or manipulate the
209       data of an ENGINE implementation rather than use its functionality.
210
211       The ENGINE_new() function returns a structural reference to a new
212       (empty) ENGINE object. There are other ENGINE API functions that return
213       structural references such as; ENGINE_by_id(), ENGINE_get_first(),
214       ENGINE_get_last(), ENGINE_get_next(), ENGINE_get_prev(). All structural
215       references should be released by a corresponding to call to the
216       ENGINE_free() function - the ENGINE object itself will only actually be
217       cleaned up and deallocated when the last structural reference is
218       released.
219
220       It should also be noted that many ENGINE API function calls that accept
221       a structural reference will internally obtain another reference -
222       typically this happens whenever the supplied ENGINE will be needed by
223       OpenSSL after the function has returned. Eg. the function to add a new
224       ENGINE to OpenSSL's internal list is ENGINE_add() - if this function
225       returns success, then OpenSSL will have stored a new structural
226       reference internally so the caller is still responsible for freeing
227       their own reference with ENGINE_free() when they are finished with it.
228       In a similar way, some functions will automatically release the
229       structural reference passed to it if part of the function's job is to
230       do so. Eg. the ENGINE_get_next() and ENGINE_get_prev() functions are
231       used for iterating across the internal ENGINE list - they will return a
232       new structural reference to the next (or previous) ENGINE in the list
233       or NULL if at the end (or beginning) of the list, but in either case
234       the structural reference passed to the function is released on behalf
235       of the caller.
236
237       To clarify a particular function's handling of references, one should
238       always consult that function's documentation "man" page, or failing
239       that the openssl/engine.h header file includes some hints.
240
241       Functional references
242
243       As mentioned, functional references exist when the cryptographic
244       functionality of an ENGINE is required to be available. A functional
245       reference can be obtained in one of two ways; from an existing
246       structural reference to the required ENGINE, or by asking OpenSSL for
247       the default operational ENGINE for a given cryptographic purpose.
248
249       To obtain a functional reference from an existing structural reference,
250       call the ENGINE_init() function. This returns zero if the ENGINE was
251       not already operational and couldn't be successfully initialised (e.g.
252       lack of system drivers, no special hardware attached, etc), otherwise
253       it will return nonzero to indicate that the ENGINE is now operational
254       and will have allocated a new functional reference to the ENGINE. All
255       functional references are released by calling ENGINE_finish() (which
256       removes the implicit structural reference as well).
257
258       The second way to get a functional reference is by asking OpenSSL for a
259       default implementation for a given task, e.g. by
260       ENGINE_get_default_RSA(), ENGINE_get_default_cipher_engine(), etc.
261       These are discussed in the next section, though they are not usually
262       required by application programmers as they are used automatically when
263       creating and using the relevant algorithm-specific types in OpenSSL,
264       such as RSA, DSA, EVP_CIPHER_CTX, etc.
265
266   Default implementations
267       For each supported abstraction, the ENGINE code maintains an internal
268       table of state to control which implementations are available for a
269       given abstraction and which should be used by default. These
270       implementations are registered in the tables and indexed by an 'nid'
271       value, because abstractions like EVP_CIPHER and EVP_DIGEST support many
272       distinct algorithms and modes, and ENGINEs can support arbitrarily many
273       of them.  In the case of other abstractions like RSA, DSA, etc, there
274       is only one "algorithm" so all implementations implicitly register
275       using the same 'nid' index.
276
277       When a default ENGINE is requested for a given
278       abstraction/algorithm/mode, (e.g.  when calling RSA_new_method(NULL)),
279       a "get_default" call will be made to the ENGINE subsystem to process
280       the corresponding state table and return a functional reference to an
281       initialised ENGINE whose implementation should be used. If no ENGINE
282       should (or can) be used, it will return NULL and the caller will
283       operate with a NULL ENGINE handle - this usually equates to using the
284       conventional software implementation. In the latter case, OpenSSL will
285       from then on behave the way it used to before the ENGINE API existed.
286
287       Each state table has a flag to note whether it has processed this
288       "get_default" query since the table was last modified, because to
289       process this question it must iterate across all the registered ENGINEs
290       in the table trying to initialise each of them in turn, in case one of
291       them is operational. If it returns a functional reference to an ENGINE,
292       it will also cache another reference to speed up processing future
293       queries (without needing to iterate across the table). Likewise, it
294       will cache a NULL response if no ENGINE was available so that future
295       queries won't repeat the same iteration unless the state table changes.
296       This behaviour can also be changed; if the ENGINE_TABLE_FLAG_NOINIT
297       flag is set (using ENGINE_set_table_flags()), no attempted
298       initialisations will take place, instead the only way for the state
299       table to return a non-NULL ENGINE to the "get_default" query will be if
300       one is expressly set in the table. Eg.  ENGINE_set_default_RSA() does
301       the same job as ENGINE_register_RSA() except that it also sets the
302       state table's cached response for the "get_default" query. In the case
303       of abstractions like EVP_CIPHER, where implementations are indexed by
304       'nid', these flags and cached-responses are distinct for each 'nid'
305       value.
306
307   Application requirements
308       This section will explain the basic things an application programmer
309       should support to make the most useful elements of the ENGINE
310       functionality available to the user. The first thing to consider is
311       whether the programmer wishes to make alternative ENGINE modules
312       available to the application and user. OpenSSL maintains an internal
313       linked list of "visible" ENGINEs from which it has to operate - at
314       start-up, this list is empty and in fact if an application does not
315       call any ENGINE API calls and it uses static linking against openssl,
316       then the resulting application binary will not contain any alternative
317       ENGINE code at all. So the first consideration is whether any/all
318       available ENGINE implementations should be made visible to OpenSSL -
319       this is controlled by calling the various "load" functions.
320
321       The fact that ENGINEs are made visible to OpenSSL (and thus are linked
322       into the program and loaded into memory at run-time) does not mean they
323       are "registered" or called into use by OpenSSL automatically - that
324       behaviour is something for the application to control. Some
325       applications will want to allow the user to specify exactly which
326       ENGINE they want used if any is to be used at all. Others may prefer to
327       load all support and have OpenSSL automatically use at run-time any
328       ENGINE that is able to successfully initialise - i.e. to assume that
329       this corresponds to acceleration hardware attached to the machine or
330       some such thing. There are probably numerous other ways in which
331       applications may prefer to handle things, so we will simply illustrate
332       the consequences as they apply to a couple of simple cases and leave
333       developers to consider these and the source code to openssl's builtin
334       utilities as guides.
335
336       If no ENGINE API functions are called within an application, then
337       OpenSSL will not allocate any internal resources.  Prior to OpenSSL
338       1.1.0, however, if any ENGINEs are loaded, even if not registered or
339       used, it was necessary to call ENGINE_cleanup() before the program
340       exits.
341
342       Using a specific ENGINE implementation
343
344       Here we'll assume an application has been configured by its user or
345       admin to want to use the "ACME" ENGINE if it is available in the
346       version of OpenSSL the application was compiled with. If it is
347       available, it should be used by default for all RSA, DSA, and symmetric
348       cipher operations, otherwise OpenSSL should use its builtin software as
349       per usual. The following code illustrates how to approach this;
350
351        ENGINE *e;
352        const char *engine_id = "ACME";
353        ENGINE_load_builtin_engines();
354        e = ENGINE_by_id(engine_id);
355        if (!e)
356            /* the engine isn't available */
357            return;
358        if (!ENGINE_init(e)) {
359            /* the engine couldn't initialise, release 'e' */
360            ENGINE_free(e);
361            return;
362        }
363        if (!ENGINE_set_default_RSA(e))
364            /*
365             * This should only happen when 'e' can't initialise, but the previous
366             * statement suggests it did.
367             */
368            abort();
369        ENGINE_set_default_DSA(e);
370        ENGINE_set_default_ciphers(e);
371        /* Release the functional reference from ENGINE_init() */
372        ENGINE_finish(e);
373        /* Release the structural reference from ENGINE_by_id() */
374        ENGINE_free(e);
375
376       Automatically using builtin ENGINE implementations
377
378       Here we'll assume we want to load and register all ENGINE
379       implementations bundled with OpenSSL, such that for any cryptographic
380       algorithm required by OpenSSL - if there is an ENGINE that implements
381       it and can be initialised, it should be used. The following code
382       illustrates how this can work;
383
384        /* Load all bundled ENGINEs into memory and make them visible */
385        ENGINE_load_builtin_engines();
386        /* Register all of them for every algorithm they collectively implement */
387        ENGINE_register_all_complete();
388
389       That's all that's required. Eg. the next time OpenSSL tries to set up
390       an RSA key, any bundled ENGINEs that implement RSA_METHOD will be
391       passed to ENGINE_init() and if any of those succeed, that ENGINE will
392       be set as the default for RSA use from then on.
393
394   Advanced configuration support
395       There is a mechanism supported by the ENGINE framework that allows each
396       ENGINE implementation to define an arbitrary set of configuration
397       "commands" and expose them to OpenSSL and any applications based on
398       OpenSSL. This mechanism is entirely based on the use of name-value
399       pairs and assumes ASCII input (no unicode or UTF for now!), so it is
400       ideal if applications want to provide a transparent way for users to
401       provide arbitrary configuration "directives" directly to such ENGINEs.
402       It is also possible for the application to dynamically interrogate the
403       loaded ENGINE implementations for the names, descriptions, and input
404       flags of their available "control commands", providing a more flexible
405       configuration scheme. However, if the user is expected to know which
406       ENGINE device he/she is using (in the case of specialised hardware,
407       this goes without saying) then applications may not need to concern
408       themselves with discovering the supported control commands and simply
409       prefer to pass settings into ENGINEs exactly as they are provided by
410       the user.
411
412       Before illustrating how control commands work, it is worth mentioning
413       what they are typically used for. Broadly speaking there are two uses
414       for control commands; the first is to provide the necessary details to
415       the implementation (which may know nothing at all specific to the host
416       system) so that it can be initialised for use. This could include the
417       path to any driver or config files it needs to load, required network
418       addresses, smart-card identifiers, passwords to initialise protected
419       devices, logging information, etc etc. This class of commands typically
420       needs to be passed to an ENGINE before attempting to initialise it,
421       i.e. before calling ENGINE_init(). The other class of commands consist
422       of settings or operations that tweak certain behaviour or cause certain
423       operations to take place, and these commands may work either before or
424       after ENGINE_init(), or in some cases both. ENGINE implementations
425       should provide indications of this in the descriptions attached to
426       builtin control commands and/or in external product documentation.
427
428       Issuing control commands to an ENGINE
429
430       Let's illustrate by example; a function for which the caller supplies
431       the name of the ENGINE it wishes to use, a table of string-pairs for
432       use before initialisation, and another table for use after
433       initialisation. Note that the string-pairs used for control commands
434       consist of a command "name" followed by the command "parameter" - the
435       parameter could be NULL in some cases but the name can not. This
436       function should initialise the ENGINE (issuing the "pre" commands
437       beforehand and the "post" commands afterwards) and set it as the
438       default for everything except RAND and then return a boolean success or
439       failure.
440
441        int generic_load_engine_fn(const char *engine_id,
442                                   const char **pre_cmds, int pre_num,
443                                   const char **post_cmds, int post_num)
444        {
445            ENGINE *e = ENGINE_by_id(engine_id);
446            if (!e) return 0;
447            while (pre_num--) {
448                if (!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
449                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
450                            pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
451                    ENGINE_free(e);
452                    return 0;
453                }
454                pre_cmds += 2;
455            }
456            if (!ENGINE_init(e)) {
457                fprintf(stderr, "Failed initialisation\n");
458                ENGINE_free(e);
459                return 0;
460            }
461            /*
462             * ENGINE_init() returned a functional reference, so free the structural
463             * reference from ENGINE_by_id().
464             */
465            ENGINE_free(e);
466            while (post_num--) {
467                if (!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
468                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
469                            post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
470                    ENGINE_finish(e);
471                    return 0;
472                }
473                post_cmds += 2;
474            }
475            ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
476            /* Success */
477            return 1;
478        }
479
480       Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
481       relax the semantics of the function - if set nonzero it will only
482       return failure if the ENGINE supported the given command name but
483       failed while executing it, if the ENGINE doesn't support the command
484       name it will simply return success without doing anything. In this case
485       we assume the user is only supplying commands specific to the given
486       ENGINE so we set this to FALSE.
487
488       Discovering supported control commands
489
490       It is possible to discover at run-time the names, numerical-ids,
491       descriptions and input parameters of the control commands supported by
492       an ENGINE using a structural reference. Note that some control commands
493       are defined by OpenSSL itself and it will intercept and handle these
494       control commands on behalf of the ENGINE, i.e. the ENGINE's ctrl()
495       handler is not used for the control command.  openssl/engine.h defines
496       an index, ENGINE_CMD_BASE, that all control commands implemented by
497       ENGINEs should be numbered from. Any command value lower than this
498       symbol is considered a "generic" command is handled directly by the
499       OpenSSL core routines.
500
501       It is using these "core" control commands that one can discover the
502       control commands implemented by a given ENGINE, specifically the
503       commands:
504
505        ENGINE_HAS_CTRL_FUNCTION
506        ENGINE_CTRL_GET_FIRST_CMD_TYPE
507        ENGINE_CTRL_GET_NEXT_CMD_TYPE
508        ENGINE_CTRL_GET_CMD_FROM_NAME
509        ENGINE_CTRL_GET_NAME_LEN_FROM_CMD
510        ENGINE_CTRL_GET_NAME_FROM_CMD
511        ENGINE_CTRL_GET_DESC_LEN_FROM_CMD
512        ENGINE_CTRL_GET_DESC_FROM_CMD
513        ENGINE_CTRL_GET_CMD_FLAGS
514
515       Whilst these commands are automatically processed by the OpenSSL
516       framework code, they use various properties exposed by each ENGINE to
517       process these queries. An ENGINE has 3 properties it exposes that can
518       affect how this behaves; it can supply a ctrl() handler, it can specify
519       ENGINE_FLAGS_MANUAL_CMD_CTRL in the ENGINE's flags, and it can expose
520       an array of control command descriptions.  If an ENGINE specifies the
521       ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will simply pass all these
522       "core" control commands directly to the ENGINE's ctrl() handler (and
523       thus, it must have supplied one), so it is up to the ENGINE to reply to
524       these "discovery" commands itself. If that flag is not set, then the
525       OpenSSL framework code will work with the following rules:
526
527        if no ctrl() handler supplied;
528            ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
529            all other commands fail.
530        if a ctrl() handler was supplied but no array of control commands;
531            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
532            all other commands fail.
533        if a ctrl() handler and array of control commands was supplied;
534            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
535            all other commands proceed processing ...
536
537       If the ENGINE's array of control commands is empty then all other
538       commands will fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns
539       the identifier of the first command supported by the ENGINE,
540       ENGINE_GET_NEXT_CMD_TYPE takes the identifier of a command supported by
541       the ENGINE and returns the next command identifier or fails if there
542       are no more, ENGINE_CMD_FROM_NAME takes a string name for a command and
543       returns the corresponding identifier or fails if no such command name
544       exists, and the remaining commands take a command identifier and return
545       properties of the corresponding commands. All except
546       ENGINE_CTRL_GET_FLAGS return the string length of a command name or
547       description, or populate a supplied character buffer with a copy of the
548       command name or description. ENGINE_CTRL_GET_FLAGS returns a bitwise-
549       OR'd mask of the following possible values:
550
551        ENGINE_CMD_FLAG_NUMERIC
552        ENGINE_CMD_FLAG_STRING
553        ENGINE_CMD_FLAG_NO_INPUT
554        ENGINE_CMD_FLAG_INTERNAL
555
556       If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are
557       purely informational to the caller - this flag will prevent the command
558       being usable for any higher-level ENGINE functions such as
559       ENGINE_ctrl_cmd_string().  "INTERNAL" commands are not intended to be
560       exposed to text-based configuration by applications, administrations,
561       users, etc. These can support arbitrary operations via ENGINE_ctrl(),
562       including passing to and/or from the control commands data of any
563       arbitrary type. These commands are supported in the discovery
564       mechanisms simply to allow applications to determine if an ENGINE
565       supports certain specific commands it might want to use (e.g.
566       application "foo" might query various ENGINEs to see if they implement
567       "FOO_GET_VENDOR_LOGO_GIF" - and ENGINE could therefore decide whether
568       or not to support this "foo"-specific extension).
569

ENVIRONMENT

571       OPENSSL_ENGINES
572           The path to the engines directory.  Ignored in set-user-ID and set-
573           group-ID programs.
574

RETURN VALUES

576       ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next() and
577       ENGINE_get_prev() return a valid ENGINE structure or NULL if an error
578       occurred.
579
580       ENGINE_add() and ENGINE_remove() return 1 on success or 0 on error.
581
582       ENGINE_by_id() returns a valid ENGINE structure or NULL if an error
583       occurred.
584
585       ENGINE_init() and ENGINE_finish() return 1 on success or 0 on error.
586
587       All ENGINE_get_default_TYPE() functions, ENGINE_get_cipher_engine() and
588       ENGINE_get_digest_engine() return a valid ENGINE structure on success
589       or NULL if an error occurred.
590
591       All ENGINE_set_default_TYPE() functions return 1 on success or 0 on
592       error.
593
594       ENGINE_set_default() returns 1 on success or 0 on error.
595
596       ENGINE_get_table_flags() returns an unsigned integer value representing
597       the global table flags which are used to control the registration
598       behaviour of ENGINE implementations.
599
600       All ENGINE_register_TYPE() functions return 1 on success or 0 on error.
601
602       ENGINE_register_complete() and ENGINE_register_all_complete() always
603       return 1.
604
605       ENGINE_ctrl() returns a positive value on success or others on error.
606
607       ENGINE_cmd_is_executable() returns 1 if cmd is executable or 0
608       otherwise.
609
610       ENGINE_ctrl_cmd() and ENGINE_ctrl_cmd_string() return 1 on success or 0
611       on error.
612
613       ENGINE_new() returns a valid ENGINE structure on success or NULL if an
614       error occurred.
615
616       ENGINE_free() always returns 1.
617
618       ENGINE_up_ref() returns 1 on success or 0 on error.
619
620       ENGINE_set_id() and ENGINE_set_name() return 1 on success or 0 on
621       error.
622
623       All other ENGINE_set_* functions return 1 on success or 0 on error.
624
625       ENGINE_get_id() and ENGINE_get_name() return a string representing the
626       identifier and the name of the ENGINE e respectively.
627
628       ENGINE_get_RSA(), ENGINE_get_DSA(), ENGINE_get_DH() and
629       ENGINE_get_RAND() return corresponding method structures for each
630       algorithms.
631
632       ENGINE_get_destroy_function(), ENGINE_get_init_function(),
633       ENGINE_get_finish_function(), ENGINE_get_ctrl_function(),
634       ENGINE_get_load_privkey_function(), ENGINE_get_load_pubkey_function(),
635       ENGINE_get_ciphers() and ENGINE_get_digests() return corresponding
636       function pointers of the callbacks.
637
638       ENGINE_get_cipher() returns a valid EVP_CIPHER structure on success or
639       NULL if an error occurred.
640
641       ENGINE_get_digest() returns a valid EVP_MD structure on success or NULL
642       if an error occurred.
643
644       ENGINE_get_flags() returns an integer representing the ENGINE flags
645       which are used to control various behaviours of an ENGINE.
646
647       ENGINE_get_cmd_defns() returns an ENGINE_CMD_DEFN structure or NULL if
648       it's not set.
649
650       ENGINE_load_private_key() and ENGINE_load_public_key() return a valid
651       EVP_PKEY structure on success or NULL if an error occurred.
652

SEE ALSO

654       OPENSSL_init_crypto(3), RSA_new_method(3), DSA_new(3), DH_new(3),
655       RAND_bytes(3), config(5)
656

HISTORY

658       ENGINE_cleanup() was deprecated in OpenSSL 1.1.0 by the automatic
659       cleanup done by OPENSSL_cleanup() and should not be used.
660
662       Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
663
664       Licensed under the OpenSSL license (the "License").  You may not use
665       this file except in compliance with the License.  You can obtain a copy
666       in the file LICENSE in the source distribution or at
667       <https://www.openssl.org/source/license.html>.
668
669
670
6711.1.1q                            2023-02-06                     ENGINE_ADD(3)
Impressum