Skip to content

Conversation

@maroueneboubakri
Copy link
Contributor

As discussed in issue #551, an application may statically link against the OpenSSL library. Consequently, using a dynamically loadable engine may present challenges. This PR proposes modifying the build system to enable the creation of a static PKCS11 engine library instead (libpkcs11.a).

The library exposes the bind_engine() function, which allows the application to load and register the engine directly within the application:

extern int bind_engine(ENGINE *e, const char *id);

Below is a sample code snippet demonstrating how to load and register the engine:

ENGINE *e = NULL;
e = ENGINE_new();
if (e == NULL) {
	error("Error creating new engine instance: %s\n",
	      ERR_reason_error_string(ERR_get_error()));
	return 0;
}

/* Bind the engine using the bind_engine function */
if (!bind_engine(e, "pkcs11")) {
	error("Error binding pkcs11 engine: %s\n",
	      ERR_reason_error_string(ERR_get_error()));
	ENGINE_free(e);
	return 0;
}

As discussed in issue OpenSC#551, an application may statically link against
the OpenSSL library. Consequently, using a dynamically loadable engine
may present challenges. This PR proposes modifying the build system to
enable the creation of a static PKCS11 engine library instead
(libpkcs11.a).

The library exposes the `bind_engine()` function, which allows the
application to load and register the engine directly within the
application:

	extern int bind_engine(ENGINE *e, const char *id);

Below is a sample code snippet demonstrating how to load and register
the engine:

	ENGINE *e = NULL;
	e = ENGINE_new();
	if (e == NULL) {
		error("Error creating new engine instance: %s\n",
		      ERR_reason_error_string(ERR_get_error()));
		return 0;
	}

	/* Bind the engine using the bind_engine function */
	if (!bind_engine(e, "pkcs11")) {
		error("Error binding pkcs11 engine: %s\n",
		      ERR_reason_error_string(ERR_get_error()));
		ENGINE_free(e);
		return 0;
	}

Signed-off-by: Marouene Boubakri <[email protected]>
@maroueneboubakri
Copy link
Contributor Author

@mtrojnar FYI.

@mtrojnar mtrojnar merged commit 214b271 into OpenSC:master Nov 19, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants