Skip to content

Commit 214b271

Browse files
maroueneboubakrimtrojnar
authored andcommitted
src/Makefile.am: Build static PKCS#11 engine library (libpkcs11.a)
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; } Signed-off-by: Marouene Boubakri <[email protected]>
1 parent 155455a commit 214b271

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EXTRA_DIST = Makefile.mak libp11.rc.in pkcs11.rc.in
66

77
noinst_HEADERS= libp11-int.h pkcs11.h p11_pthread.h
88
include_HEADERS= libp11.h p11_err.h
9-
lib_LTLIBRARIES = libp11.la
9+
lib_LTLIBRARIES = libp11.la libpkcs11.la
1010
enginesexec_LTLIBRARIES = pkcs11.la
1111
pkgconfig_DATA = libp11.pc
1212

@@ -49,6 +49,13 @@ pkcs11_la_LIBADD = $(libp11_la_OBJECTS) $(OPENSSL_LIBS)
4949
pkcs11_la_LDFLAGS = $(AM_LDFLAGS) -module -shared -shrext $(SHARED_EXT) \
5050
-avoid-version -export-symbols "$(srcdir)/pkcs11.exports"
5151

52+
# Create a static version of the engine as well to allow applications
53+
# to statically link into it.
54+
55+
libpkcs11_la_SOURCES = $(pkcs11_la_SOURCES)
56+
libpkcs11_la_CFLAGS = $(pkcs11_la_CFLAGS)
57+
libpkcs11_la_LIBADD = $(pkcs11_la_LIBADD)
58+
5259
# OpenSSL older than 1.1.0 expected libpkcs11.so instead of pkcs11.so
5360
check-local: $(LTLIBRARIES)
5461
cd .libs && $(LN_S) -f pkcs11$(SHARED_EXT) libpkcs11$(SHARED_EXT)

0 commit comments

Comments
 (0)