This adds 2 things to the ENGINE code.
* "ex_data" - a CRYPTO_EX_DATA structure in the ENGINE structure itself that allows an ENGINE to store its own information there rather than in global variables. It follows the declarations and implementations used in RSA code, for better or worse. However there's a problem when storing state with ENGINEs because, unlike related structure types in OpenSSL, there is no ENGINE-vs-ENGINE_METHOD separation. Because of what ENGINE is, it has method pointers as its structure elements ... which leads to; * ENGINE_FLAGS_BY_ID_COPY - if an ENGINE should not be used just as a reference to an "implementation" (eg. to get to a hardware device), but should also be able to maintain state, then this flag can be set by the ENGINE implementation. The result is that any call to ENGINE_by_id() will not result in the existing ENGINE being returned (with its structural reference count incremented) but instead a new copy of the ENGINE will be returned that can maintain its own state independantly of any other copies returned in the past or future. Eg. key-generation might involve a series of ENGINE-specific control commands to set algorithms, sizes, module-keys, ids, ACLs, etc. A final command could generate the key. An ENGINE doing this would *have* to declare ENGINE_FLAGS_BY_ID_COPY so that the state of that process can be maintained "per-handle" and unaffected by other code having a reference to the same ENGINE structure.
This commit is contained in:
@@ -108,6 +108,15 @@ typedef void DH_METHOD;
|
||||
* control commands on behalf of the ENGINE using their "cmd_defns" data. */
|
||||
#define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002
|
||||
|
||||
/* This flag is for ENGINEs who return new duplicate structures when found via
|
||||
* "ENGINE_by_id()". When an ENGINE must store state (eg. if ENGINE_ctrl()
|
||||
* commands are called in sequence as part of some stateful process like
|
||||
* key-generation setup and execution), it can set this flag - then each attempt
|
||||
* to obtain the ENGINE will result in it being copied into a new structure.
|
||||
* Normally, ENGINEs don't declare this flag so ENGINE_by_id() just increments
|
||||
* the existing ENGINE's structural reference count. */
|
||||
#define ENGINE_FLAGS_BY_ID_COPY (int)0x0004
|
||||
|
||||
/* ENGINEs can support their own command types, and these flags are used in
|
||||
* ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input each
|
||||
* command expects. Currently only numeric and string input is supported. If a
|
||||
@@ -349,6 +358,11 @@ int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
|
||||
/* Copies across all ENGINE methods and pointers. NB: This does *not* change
|
||||
* reference counts however. */
|
||||
int ENGINE_cpy(ENGINE *dest, const ENGINE *src);
|
||||
/* These functions (and the "get" function lower down) allow control over any
|
||||
* per-structure ENGINE data. */
|
||||
int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
|
||||
CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
|
||||
int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
|
||||
/* Cleans the internal engine structure. This should only be used when the
|
||||
* application is about to exit. */
|
||||
void ENGINE_cleanup(void);
|
||||
@@ -372,6 +386,7 @@ ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
|
||||
const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
|
||||
int ENGINE_get_flags(const ENGINE *e);
|
||||
void *ENGINE_get_ex_data(const ENGINE *e, int idx);
|
||||
|
||||
/* FUNCTIONAL functions. These functions deal with ENGINE structures
|
||||
* that have (or will) be initialised for use. Broadly speaking, the
|
||||
|
||||
Reference in New Issue
Block a user