From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Sascha Hauer <sascha@saschahauer.de>,
"Claude Opus 4.6" <noreply@anthropic.com>
Subject: [PATCH] scripts: bareboxtlv-generator: add PKCS#11 engine support
Date: Thu, 5 Mar 2026 07:57:03 +0100 [thread overview]
Message-ID: <20260305065703.3417243-1-s.hauer@pengutronix.de> (raw)
From: Sascha Hauer <sascha@saschahauer.de>
When a PKCS#11 URI (pkcs11:...) is passed as the signing key, the
openssl pkey and pkeyutl invocations need extra engine arguments to
route key operations through the pkcs11 engine. Detect pkcs11: URIs
and add -engine pkcs11 with the appropriate key format flag (-inform
for pkey, -keyform for pkeyutl).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
.../bareboxtlv-generator/bareboxtlv-generator.py | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/scripts/bareboxtlv-generator/bareboxtlv-generator.py b/scripts/bareboxtlv-generator/bareboxtlv-generator.py
index 2eba0aeb23..5b51fb53d8 100755
--- a/scripts/bareboxtlv-generator/bareboxtlv-generator.py
+++ b/scripts/bareboxtlv-generator/bareboxtlv-generator.py
@@ -65,7 +65,14 @@ class PrivateKey:
sys.exit(127)
self.inkey = path
- self.public_key = serialization.load_pem_public_key(openssl(["pkey", "-pubout", "-in", self.inkey]));
+ self.is_pkcs11 = path.startswith("pkcs11:")
+ if self.is_pkcs11:
+ pkey_args = ["-engine", "pkcs11", "-inform", "engine"]
+ self.pkeyutl_args = ["-engine", "pkcs11", "-keyform", "engine"]
+ else:
+ pkey_args = []
+ self.pkeyutl_args = []
+ self.public_key = serialization.load_pem_public_key(openssl(["pkey"] + pkey_args + ["-pubout", "-in", self.inkey]));
def sign(self, message: bytes) -> bytes:
"""
@@ -75,8 +82,8 @@ class PrivateKey:
from cryptography.hazmat.primitives.asymmetric import rsa, ec
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
- # Access private keys only via the openssl cli so that any configured provider, such as pkcs11, can be used.
- sig = openssl(["pkeyutl", "-sign", "-rawin", "-digest", "sha256", "-inkey", self.inkey], stdin = message)
+ # Access private keys only via the openssl cli so that any configured engine/provider, such as pkcs11, can be used.
+ sig = openssl(["pkeyutl"] + self.pkeyutl_args + ["-sign", "-rawin", "-digest", "sha256", "-inkey", self.inkey], stdin = message)
if isinstance(self.public_key, rsa.RSAPublicKey):
return sig
--
2.47.3
next reply other threads:[~2026-03-05 6:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 6:57 Sascha Hauer [this message]
2026-03-09 13:54 ` Jan Lübbe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260305065703.3417243-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
--cc=sascha@saschahauer.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox