Skip to content

Commit 9b7dae4

Browse files
committed
Support loading arbitrary engines via ENGINE_by_id()
Use ENGINE_by_id() for any engine name that doesn't contain a dot, assuming it's an engine ID. If the name includes a dot (e.g., a file extension), treat it as a path to a dynamic engine module. See mtrojnar#436 for discussion.
1 parent 6243890 commit 9b7dae4

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

osslsigncode.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4166,21 +4166,6 @@ static ENGINE *engine_dynamic(GLOBAL_OPTIONS *options)
41664166
return engine;
41674167
}
41684168

4169-
/*
4170-
* Load a pkcs11 engine
4171-
* [in] none
4172-
* [returns] pointer to ENGINE
4173-
*/
4174-
static ENGINE *engine_pkcs11(void)
4175-
{
4176-
ENGINE *engine = ENGINE_by_id("pkcs11");
4177-
if (!engine) {
4178-
fprintf(stderr, "Failed to find and load 'pkcs11' engine\n");
4179-
return NULL; /* FAILED */
4180-
}
4181-
return engine; /* OK */
4182-
}
4183-
41844169
/*
41854170
* Load the private key and the signer certificate from a security token
41864171
* [in, out] options: structure holds the input data
@@ -4260,12 +4245,18 @@ static int read_token(GLOBAL_OPTIONS *options, ENGINE *engine)
42604245

42614246
static int engine_load(GLOBAL_OPTIONS *options)
42624247
{
4248+
const char *id = options->p11engine ? options->p11engine : "pkcs11";
42634249
ENGINE *engine;
42644250

4265-
if (options->p11engine)
4251+
if (strchr(id, '.')) {
4252+
/* Treat strings with a dot as paths to dynamic engine modules */
42664253
engine = engine_dynamic(options);
4267-
else
4268-
engine = engine_pkcs11();
4254+
} else {
4255+
/* Treat strings without a dot as engine IDs */
4256+
engine = ENGINE_by_id(id);
4257+
if (!engine)
4258+
fprintf(stderr, "Failed to find and load '%s' engine\n", id);
4259+
}
42694260
if (!engine)
42704261
return 0; /* FAILED */
42714262
printf("Engine \"%s\" set.\n", ENGINE_get_id(engine));

0 commit comments

Comments
 (0)