Skip to contentSkip to conversation

binman: x509_cert: add PKCS#11/HSM signing support

PATCH Superseded Sergio Prado 2 participants 3 messages Apr 16 – Apr 17 Kbuild

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 binman: x509_cert: add PKCS#11/HSM signing support

Allow X509 certificates used for K3/TI secure boot to be signed via an HSM using the PKCS#11 standard.

Two new make variables are introduced:

BINMAN_PKCS11_URI PKCS#11 URI identifying the signing key on the HSM
BINMAN_PKCS11_MODULE Path to the PKCS#11 shared library (.so)

When BINMAN_PKCS11_URI is set, it is passed to binman as the pkcs11-uri entry argument, which overrides the keyfile property at signing time.

The openssl bintool gains three helper methods:

_pkcs11_use_provider() detects whether the pkcs11 provider (OpenSSL

Quoted 1 line

= 3.1) or the legacy pkcs11 engine (libp11) is available.

_build_key_args() builds the appropriate -key/-provider/-engine
arguments for the openssl command line, appending ?pin-value=<pin> from the PKCS11_PIN environment variable when set.

_run_cmd_pkcs11() exports PKCS11_MODULE_PATH and PKCS11_PROVIDER_MODULE
before invoking openssl when a module path is provided.

Existing behavior is unchanged when neither BINMAN_PKCS11_URI nor BINMAN_PKCS11_MODULE is set.

Tested with SoftHSM2 and a Yubikey using the verdin-am62_a53_defconfig configuration.

---
 Makefile                        |   2 +
 tools/binman/binman.rst         |  18 ++++++
 tools/binman/btool/openssl.py   | 106 +++++++++++++++++++++++++++-----
 tools/binman/etype/x509_cert.py |  47 ++++++++++++--
 4 files changed, 153 insertions(+), 20 deletions(-)
Makefile +2 -0
index dfc95d314ddd..8d6c584b2731 100644
@@ -1701,6 +1701,8 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
 		-a vpl-dtb=$(CONFIG_VPL_OF_REAL) \
 		-a pre-load-key-path=${PRE_LOAD_KEY_PATH} \
 		-a of-spl-remove-props=$(CONFIG_OF_SPL_REMOVE_PROPS) \
+		$(if $(BINMAN_PKCS11_URI),-a pkcs11-uri="$(BINMAN_PKCS11_URI)") \
+		$(if $(BINMAN_PKCS11_MODULE),-a pkcs11-module="$(BINMAN_PKCS11_MODULE)") \
 		$(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
tools/binman/binman.rst +18 -0
index 3f725868c8bb..ea91199b1e22 100644
@@ -2165,6 +2165,24 @@ BINMAN_INDIRS
     Sets the search path for input files used by binman by adding one or more
     `-I` arguments. See :ref:`External blobs`.
 
+BINMAN_PKCS11_URI
+    PKCS#11 URI used to sign boot artifacts via an HSM instead of a PEM key
+    file on disk. When set, it is passed as ``-a pkcs11-uri=<uri>`` to binman,
+    which overrides the ``keyfile`` entry argument for all signing operations.
+    Example::
+
+        make BINMAN_PKCS11_URI="pkcs11:token=mytoken;object=mykey;type=private"
+
+BINMAN_PKCS11_MODULE
+    Path to the PKCS#11 shared library (.so) for HSM signing. When set, it is
+    passed as ``-a pkcs11-module=<path>`` to binman. Only needed when the
+    module is not already configured via ``openssl.cnf`` or the
+    ``PKCS11_MODULE_PATH`` environment variable. Typically used together with
+    ``BINMAN_PKCS11_URI``::
+
+        make BINMAN_PKCS11_URI="pkcs11:token=mytoken;object=mykey;type=private" \
+             BINMAN_PKCS11_MODULE="/usr/lib/pkcs11/libsofthsm2.so"
+
 BINMAN_TOOLPATHS
     Sets the search path for external tool used by binman by adding one or more
     `--toolpath` arguments. See :ref:`External tools`.
tools/binman/btool/openssl.py +90 -16

204 lines not on this page · raw message

tools/binman/etype/x509_cert.py +43 -4

101 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

Hi Sergio,

Quoted 30 lines · Sergio Prado

Allow X509 certificates used for K3/TI secure boot to be signed via an HSM using the PKCS#11 standard.

Two new make variables are introduced:

BINMAN_PKCS11_URI PKCS#11 URI identifying the signing key on the HSM
BINMAN_PKCS11_MODULE Path to the PKCS#11 shared library (.so)

When BINMAN_PKCS11_URI is set, it is passed to binman as the pkcs11-uri entry argument, which overrides the keyfile property at signing time.

The openssl bintool gains three helper methods:

_pkcs11_use_provider() detects whether the pkcs11 provider (OpenSSL

Quoted 1 line

= 3.1) or the legacy pkcs11 engine (libp11) is available.

_build_key_args() builds the appropriate -key/-provider/-engine
arguments for the openssl command line, appending ?pin-value=<pin> from the PKCS11_PIN environment variable when set.

_run_cmd_pkcs11() exports PKCS11_MODULE_PATH and PKCS11_PROVIDER_MODULE
before invoking openssl when a module path is provided.

Existing behavior is unchanged when neither BINMAN_PKCS11_URI nor BINMAN_PKCS11_MODULE is set.

Tested with SoftHSM2 and a Yubikey using the verdin-am62_a53_defconfig configuration.

Quoted 7 lines
---
 Makefile                        |   2 +
 tools/binman/binman.rst         |  18 ++++++
 tools/binman/btool/openssl.py   | 106 +++++++++++++++++++++++++++-----
 tools/binman/etype/x509_cert.py |  47 ++++++++++++--
 4 files changed, 153 insertions(+), 20 deletions(-)

For some reason I cannot see this in patchwork.

In any case, please can you add tests and check that the coverage is still 100% ?

Regards,
Simon

#2 lore raw

Hi Simon,

Quoted 1 line

For some reason I cannot see this in patchwork.

It seems my email is waiting for moderator approval. I received this email:
"Your message to U-Boot awaits moderator approval. The reason it is being
held: Post to moderated list".

Quoted 1 line

In any case, please can you add tests and check that the coverage is

still 100% ?
Good point. I will work on the test cases, validate test coverage and submit v2.

Best regards,

Sergio Prado

Em qui., 16 de abr. de 2026 às 18:35, Simon Glass <[email protected]> escreveu:

Quoted 50 lines

Hi Sergio,

Quoted 30 lines · Sergio Prado

Allow X509 certificates used for K3/TI secure boot to be signed via an HSM using the PKCS#11 standard.

Two new make variables are introduced:

BINMAN_PKCS11_URI PKCS#11 URI identifying the signing key on the HSM
BINMAN_PKCS11_MODULE Path to the PKCS#11 shared library (.so)

When BINMAN_PKCS11_URI is set, it is passed to binman as the pkcs11-uri entry argument, which overrides the keyfile property at signing time.

The openssl bintool gains three helper methods:

_pkcs11_use_provider() detects whether the pkcs11 provider (OpenSSL

Quoted 1 line

= 3.1) or the legacy pkcs11 engine (libp11) is available.

_build_key_args() builds the appropriate -key/-provider/-engine
arguments for the openssl command line, appending ?pin-value=<pin> from the PKCS11_PIN environment variable when set.

_run_cmd_pkcs11() exports PKCS11_MODULE_PATH and PKCS11_PROVIDER_MODULE
before invoking openssl when a module path is provided.

Existing behavior is unchanged when neither BINMAN_PKCS11_URI nor BINMAN_PKCS11_MODULE is set.

Tested with SoftHSM2 and a Yubikey using the verdin-am62_a53_defconfig configuration.

Quoted 7 lines
---
 Makefile                        |   2 +
 tools/binman/binman.rst         |  18 ++++++
 tools/binman/btool/openssl.py   | 106 +++++++++++++++++++++++++++-----
 tools/binman/etype/x509_cert.py |  47 ++++++++++++--
 4 files changed, 153 insertions(+), 20 deletions(-)

For some reason I cannot see this in patchwork.

In any case, please can you add tests and check that the coverage is still 100% ?

Regards,
Simon