From: "Jan Lübbe" <jlu@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
Barebox List <barebox@lists.infradead.org>
Cc: Sascha Hauer <sascha@saschahauer.de>,
"Claude Opus 4.6" <noreply@anthropic.com>
Subject: Re: [PATCH] scripts: bareboxtlv-generator: add PKCS#11 engine support
Date: Mon, 09 Mar 2026 14:54:55 +0100 [thread overview]
Message-ID: <cbec4991c8b6017b99bffec46a135b88f9a57629.camel@pengutronix.de> (raw)
In-Reply-To: <20260305065703.3417243-1-s.hauer@pengutronix.de>
On Thu, 2026-03-05 at 07:57 +0100, Sascha Hauer wrote:
> 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"]
This would break use of the PKCS#11 provider, which automatically handles
pkcs11: URIs when enabled via openssl.cnf. I'd suggest adding a --engine CLI
option to explicitly enable engine support.
Jan
> + 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
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2026-03-09 13:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 6:57 Sascha Hauer
2026-03-09 13:54 ` Jan Lübbe [this message]
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=cbec4991c8b6017b99bffec46a135b88f9a57629.camel@pengutronix.de \
--to=jlu@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
--cc=s.hauer@pengutronix.de \
--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