1engine(3)                           OpenSSL                          engine(3)
2
3
4

NAME

6       engine - ENGINE cryptographic module support
7

SYNOPSIS

9        #include <openssl/engine.h>
10
11        ENGINE *ENGINE_get_first(void);
12        ENGINE *ENGINE_get_last(void);
13        ENGINE *ENGINE_get_next(ENGINE *e);
14        ENGINE *ENGINE_get_prev(ENGINE *e);
15
16        int ENGINE_add(ENGINE *e);
17        int ENGINE_remove(ENGINE *e);
18
19        ENGINE *ENGINE_by_id(const char *id);
20
21        int ENGINE_init(ENGINE *e);
22        int ENGINE_finish(ENGINE *e);
23
24        void ENGINE_load_openssl(void);
25        void ENGINE_load_dynamic(void);
26        #ifndef OPENSSL_NO_STATIC_ENGINE
27        void ENGINE_load_4758cca(void);
28        void ENGINE_load_aep(void);
29        void ENGINE_load_atalla(void);
30        void ENGINE_load_chil(void);
31        void ENGINE_load_cswift(void);
32        void ENGINE_load_gmp(void);
33        void ENGINE_load_nuron(void);
34        void ENGINE_load_sureware(void);
35        void ENGINE_load_ubsec(void);
36        #endif
37        void ENGINE_load_cryptodev(void);
38        void ENGINE_load_builtin_engines(void);
39
40        void ENGINE_cleanup(void);
41
42        ENGINE *ENGINE_get_default_RSA(void);
43        ENGINE *ENGINE_get_default_DSA(void);
44        ENGINE *ENGINE_get_default_ECDH(void);
45        ENGINE *ENGINE_get_default_ECDSA(void);
46        ENGINE *ENGINE_get_default_DH(void);
47        ENGINE *ENGINE_get_default_RAND(void);
48        ENGINE *ENGINE_get_cipher_engine(int nid);
49        ENGINE *ENGINE_get_digest_engine(int nid);
50
51        int ENGINE_set_default_RSA(ENGINE *e);
52        int ENGINE_set_default_DSA(ENGINE *e);
53        int ENGINE_set_default_ECDH(ENGINE *e);
54        int ENGINE_set_default_ECDSA(ENGINE *e);
55        int ENGINE_set_default_DH(ENGINE *e);
56        int ENGINE_set_default_RAND(ENGINE *e);
57        int ENGINE_set_default_ciphers(ENGINE *e);
58        int ENGINE_set_default_digests(ENGINE *e);
59        int ENGINE_set_default_string(ENGINE *e, const char *list);
60
61        int ENGINE_set_default(ENGINE *e, unsigned int flags);
62
63        unsigned int ENGINE_get_table_flags(void);
64        void ENGINE_set_table_flags(unsigned int flags);
65
66        int ENGINE_register_RSA(ENGINE *e);
67        void ENGINE_unregister_RSA(ENGINE *e);
68        void ENGINE_register_all_RSA(void);
69        int ENGINE_register_DSA(ENGINE *e);
70        void ENGINE_unregister_DSA(ENGINE *e);
71        void ENGINE_register_all_DSA(void);
72        int ENGINE_register_ECDH(ENGINE *e);
73        void ENGINE_unregister_ECDH(ENGINE *e);
74        void ENGINE_register_all_ECDH(void);
75        int ENGINE_register_ECDSA(ENGINE *e);
76        void ENGINE_unregister_ECDSA(ENGINE *e);
77        void ENGINE_register_all_ECDSA(void);
78        int ENGINE_register_DH(ENGINE *e);
79        void ENGINE_unregister_DH(ENGINE *e);
80        void ENGINE_register_all_DH(void);
81        int ENGINE_register_RAND(ENGINE *e);
82        void ENGINE_unregister_RAND(ENGINE *e);
83        void ENGINE_register_all_RAND(void);
84        int ENGINE_register_STORE(ENGINE *e);
85        void ENGINE_unregister_STORE(ENGINE *e);
86        void ENGINE_register_all_STORE(void);
87        int ENGINE_register_ciphers(ENGINE *e);
88        void ENGINE_unregister_ciphers(ENGINE *e);
89        void ENGINE_register_all_ciphers(void);
90        int ENGINE_register_digests(ENGINE *e);
91        void ENGINE_unregister_digests(ENGINE *e);
92        void ENGINE_register_all_digests(void);
93        int ENGINE_register_complete(ENGINE *e);
94        int ENGINE_register_all_complete(void);
95
96        int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
97        int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
98        int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
99                long i, void *p, void (*f)(void), int cmd_optional);
100        int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
101                int cmd_optional);
102
103        int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
104        void *ENGINE_get_ex_data(const ENGINE *e, int idx);
105
106        int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
107                CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
108
109        ENGINE *ENGINE_new(void);
110        int ENGINE_free(ENGINE *e);
111        int ENGINE_up_ref(ENGINE *e);
112
113        int ENGINE_set_id(ENGINE *e, const char *id);
114        int ENGINE_set_name(ENGINE *e, const char *name);
115        int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
116        int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
117        int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *dh_meth);
118        int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *dh_meth);
119        int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
120        int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
121        int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *rand_meth);
122        int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
123        int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
124        int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
125        int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
126        int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
127        int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
128        int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
129        int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
130        int ENGINE_set_flags(ENGINE *e, int flags);
131        int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
132
133        const char *ENGINE_get_id(const ENGINE *e);
134        const char *ENGINE_get_name(const ENGINE *e);
135        const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
136        const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
137        const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
138        const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
139        const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
140        const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
141        const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
142        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
143        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
144        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
145        ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
146        ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
147        ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
148        ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
149        ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
150        const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
151        const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
152        int ENGINE_get_flags(const ENGINE *e);
153        const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
154
155        EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
156            UI_METHOD *ui_method, void *callback_data);
157        EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
158            UI_METHOD *ui_method, void *callback_data);
159
160        void ENGINE_add_conf_module(void);
161

DESCRIPTION

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

SEE ALSO

607       rsa(3), dsa(3), dh(3), rand(3)
608
609
610
6110.9.8b                            2004-06-17                         engine(3)
Impressum