fit: allow signing with an OpenSSL engine
v3 cover fit: allow signing with an OpenSSL engine
I have a couple of products whose U-Boot FIT is signed via a proprietary OpenSSL engine which only expects the name of a "slot" to select the key to sign data with.
Currently mkimage fit support expects either a key-dir (-k) or a key-file (-G) as a toggle for signing, however this doesn't apply to our usecase because we use an OpenSSL engine (so no key-file to provide) which doesn't mimic a directory layout like key-dir implies. Moreover, binman really expects private keys (.key extension) to be available in this key-dir directory, which we of course cannot provide.
This series allows to sign a FIT image with mkimage (and binman) with an OpenSSL engine, including PKCS11 and custom engines. If a key-dir needs to be passed (which is typical for PKCS11), one can do so by using fit,engine-keydir.
Note that the public key (.crt extension) still needs to be available if one wants to embed it for signature verification (which is probably what one wants to do :) ). It is probably possible to use the engine for getting the public key instead of storing it on disk, but this needs to be added to fdt_add_pubkey and then binman, through a mechanism different from fit,engine*.
One issue though is that since binman resolves key paths absolutely and that I don't believe an OpenSSL engine would happen to have the exact same key_id value than a local absolute path, fit,encrypt and fit,engine cannot cohabit. An issue for the next person who wants an OpenSSL engine AND encrypt the same FIT image, I don't.
Note that LibreSSL supports neither engines nor providers as far as I could tell (engine support has been explicitly removed).
Note that OpenSSL engines have been deprecated since 3.0 (Q3-2021), however note that OpenSSL 3.5 still seems to support engines (git grep) and is EOL end of Q1 2030.
+Cc Eddie who's working on OpenSSL provider support, maybe we can work together on supporting both engines and providers via the same API we expose to the user?
+Cc Wolfgang who seems interested in signing with PKCS11 engine which should now be supported.
+Cc Peter who seems interested according to v1
If anyone has an idea on how to test PKCS11 with SOftHSMv2 with id= passed in fit,engine-keydir, I'm all ears.
I'm also wondering if the explanation around fit,engine-keydir aren't too much. After all, they are passed verbatim to mkimage as -k argument and the special cases are all specific to mkimage and not binman.
This depends on https://lore.kernel.org/all/[email protected]/T/#u
---
Changes in v3:
- did NOT add T-b and R-B on patch 3 and 4 since there's been some
rework,
- added R-b on patch 2,
- reworded commit log of patch 3,
- reworded documentation of fit,engine and the special case of pkcs11 to hopefully be easier to digest,
- put fit,engine and fit,engine-keydir extraction into a separate
function,
- fixed issues due to modification of the environment in tests failing other tests, by using unittest.mock.patch.dict() on os.environ as suggested by the unittest.mock doc,
- added test for fit,encrypt + fit,engine raising an issue to keep 100% coverage for fit etype,
- fixed issue when running binman with only one process (-T or -P 1) by renaming uniquely files and directories created in the input dir in individual tests as it is shared among all tests run by a process,
- removed apt-get install of the lib packages in the test as Bintool.apt_install() is racey (apt itself is...) and would fail when running binman with multiple processes. The package is now part of the
CI container (well, in a different series). If it's not detected, the test is skipped.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- added R-b on patch 1,
- did NOT add T-b and R-B on patch 3 since there's been some rework,
- added binman test for signing with dummy RSA engine,
- added binman test for signing with SoftHSMv2 PKCS11 engine,
- added binman test for signing with SoftHSMv2 PKCS11 engine and
specific keydir (which contains an object= to tackle that special
case)
- added dummy RSA engine for binman test,
- renamed property to fit,engine as my hunch is that it could be used
for encrypting as well (from the same engine with the same keydir but likely a different key-name-hint so that a different keypair is used)
- added fit,engine-keydir to easily support PKCS11 with arguments other than object= taken from key-name-hint,
- Link to v1: https://patch.msgid.link/[email protected]
---
Quentin Schulz (4):
fit: support signing with only an engine_id
tools: binman: mkimage: add support for passing the engine
tools: binman: fit: add support for OpenSSL engines
tools: binman: fit: add tests for signing with an OpenSSL engine
tools/binman/btool/mkimage.py | 5 +- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/entries.rst | 54 ++++- tools/binman/etype/fit.py | 93 ++++++++- tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ tools/fit_image.c | 3 +- tools/image-host.c | 4 +- 16 files changed, 1001 insertions(+), 12 deletions(-)
---
base-commit: a642f401d700034c82128defc2d6f9c18065de1f
change-id: 20251030-binman-engine-e349b02696d0
Best regards,
Signature · 1 line
Quentin Schulz <[email protected]>
PATCH v3 1/4 fit: support signing with only an engine_id
From: Quentin Schulz <[email protected]>
Currently, when one wants to use an OpenSSL engine to sign a FIT image, one needs to pass a keydir (via -k) to mkimage which will then be prepended to the value of the key-name-hint before being passed as key_id argument to the OpenSSL Engine API, or pass a keyfile (via -G) to mkimage.
My OpenSSL engine only has "slots" which are not mapped like directories, so using keydir is not proper, though I could simply have -k '' I guess but this won't work currently with binman anyway.
Additionally, passing a keyfile (-G) when using an engine doesn't make sense as the key is stored in the engine.
Let simply allow FIT images be signed if both keydir and keyfile are missing but an engine is to be used.
The keyname member is already filled by looking at key-name-hint property in the FIT and passed to the engine, which is exactly what is needed here.
--- tools/fit_image.c | 3 ++- tools/image-host.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/fit_image.c +2 -1
@@ -26,7 +26,8 @@ static struct legacy_img_hdr header;static int fit_estimate_hash_sig_size (struct image_tool_params *params,const char *fname) { -bool signing =IMAGE_ENABLE_SIGN && (params->keydir || params->keyfile); +bool signing =IMAGE_ENABLE_SIGN && + (params->keydir || params->keyfile || params->engine_id);struct stat sbuf;void *fdt;int fd;
tools/image-host.c +2 -2
@@ -696,7 +696,7 @@ int fit_image_add_verification_data(const char *keydir, const char *keyfile, strlen(FIT_HASH_NODENAME))) { ret =fit_image_process_hash (fit, image_name, noffset, data, size); - } else if (IMAGE_ENABLE_SIGN && (keydir || keyfile) && + } else if (IMAGE_ENABLE_SIGN && (keydir || keyfile || engine_id) && !strncmp(node_name, FIT_SIG_NODENAME,strlen (FIT_SIG_NODENAME ))) { ret = fit_image_process_sig(keydir, keyfile, keydest,
@@ -1366,7 +1366,7 @@ int fit_add_verification_data(const char *keydir, const char *keyfile, }/* If there are no keys, we can't sign configurations */ -if (!IMAGE_ENABLE_SIGN || !(keydir || keyfile)) +if (!IMAGE_ENABLE_SIGN || !(keydir || keyfile || engine_id))return 0 ;/* Find configurations parent node offset */
Signature · 1 line
2.51.1
PATCH v3 2/4 tools: binman: mkimage: add support for passing the engine
In reply to Quentin SchulzFrom: Quentin Schulz <[email protected]>
mkimage has support for OpenSSL engines but binman currently doesn't for direct callers of mkimage (e.g. the fit etype). This prepares for adding support for OpenSSL engines for signing elements of a FIT image, which will done in the next commit.
--- tools/binman/btool/mkimage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/binman/btool/mkimage.py +4 -1
@@ -22,7 +22,7 @@ class Bintoolmkimage(bintool.Bintool): # pylint: disable=R0913 def run(self, reset_timestamp=False, output_fname=None, external=False, - pad=None, align=None, keys_dir=None): + pad=None, align=None, keys_dir=None, engine=None): """Run mkimage Args:
@@ -35,6 +35,7 @@ class Bintoolmkimage(bintool.Bintool): signatures align: Bytes to use for alignment of the FIT and its external data keys_dir: Path to directory containing private and encryption keys + engine: Name of the OpenSSL engine to use """ args = [] if external:
@@ -49,6 +50,8 @@ class Bintoolmkimage(bintool.Bintool): args += ['-k', f'{keys_dir}'] if output_fname: args += ['-F', output_fname] + if engine: + args += ['-N', engine] return self.run_cmd(*args) def fetch(self, method):
Signature · 1 line
2.51.1
PATCH v3 3/4 tools: binman: fit: add support for OpenSSL engines
In reply to Quentin SchulzFrom: Quentin Schulz <[email protected]>
This adds support for using an OpenSSL engine for signing a FIT image. To use it, one should set the fit,engine property at the FIT node level with the engine to use. This will in turn call mkimage with the -N option.
The -k argument to mkimage can be specified via fit,engine-keydir. If not specified, -k is not passed to mkimage. This property is especially useful for pkcs11 engine to specify slots, token label, etc...
As far as I could tell, mkimage encrypts and signs a FIT in one go, thus the -k argument applies to both signing and encrypting. Considering we reuse the -k argument for two different meanings (info to pass to the engine when using an engine otherwise the directory where keys are stored), we cannot reasonably encrypt using local keys and signing with an engine, hence the enforced check. I believe it should be possible to support encrypting and signing with the same engine (using different key pairs of course, via different key-name-hint likely), but this is left for the next person to implement.
This is why the property is named fit,engine and not fit,sign-engine. Ditto for fit,engine-keydir.
The public key (with .crt extension) is still required if it needs to be embedded in the SPL DTB for example. We could probably support retrieving the public key from an engine, but this is a change to make to fdt_add_pubkey.c.
--- tools/binman/entries.rst | 54 +++++++++++++++++++++++++-- tools/binman/etype/fit.py | 93 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 7 deletions(-)
tools/binman/entries.rst +51 -3
@@ -885,9 +885,10 @@ The top-level 'fit' node supports the following special properties: fit,sign Enable signing FIT images via mkimage as described in - verified-boot.rst. If the property is found, the private keys path - is detected among binman include directories and passed to mkimage - via -k flag. All the keys required for signing FIT must be + verified-boot.rst. + If the property is found and fit,engine is not set, the private + keys path is detected among binman include directories and passed to + mkimage via -k flag. All the keys required for signing FIT must be available at time of signing and must be located in single include directory.
@@ -898,6 +899,53 @@ The top-level 'fit' node supports the following special properties: required for encrypting the FIT must be available at the time of encrypting and must be located in a single include directory. + Incompatible with fit,engine. + + fit,engine + Indicates the OpenSSL engine to use for signing the FIT image. This + is passed to mkimage via the `-N` flag. Example:: + + fit,engine = "my-engine"; + + A `-k` argument for mkimage may be passed via `fit,engine-keydir`. + + When `fit,engine` is set to `pkcs11`, the following applies: + + - If `fit,engine-keydir` is absent, the value of `key-name-hint` is + prefixed with `pkcs11:object=` before being passed to the OpenSSL + engine API:: + + pkcs11:object=<key-name-hint> + + - If `fit,engine-keydir` contains either `object=` or `id=`, its + value is passed verbatim to the OpenSSL engine API, + + - Otherwise, the value of `fit,engine-keydir` is followed by + `;object=` and the value of `key-name-hint` before being passed + to the OpenSSL engine API:: + + <fit,engine-keydir>;object=<key-name-hint> + + If `fit,engine` is set to something different than `pkcs11`, the + value of `key-name-hint` (prefixed with the value of + `fit,engine-keydir` if present) and passed verbatim to the OpenSSL + engine API. + + Depends on fit,sign. + + Incompatible with fit,encrypt. + + fit,engine-keydir + Indicates the `-k` argument to pass to mkimage if an OpenSSL engine + is to be used for signing the FIT image. Example:: + + fit,engine-keydir = "pkcs11:model=xxx;manufacturer=xxx"; + + Read `fit,engine` documentation for more info on special cases when + using `pkcs11` as engine. + + Depends on fit,engine. + Substitutions ~~~~~~~~~~~~~
tools/binman/etype/fit.py +89 -4
117 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v3 3/4] tools: binman: fit: add support for OpenSSL engines
Hi Quentin,
Quoted 234 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds support for using an OpenSSL engine for signing a FIT image. To use it, one should set the fit,engine property at the FIT node level with the engine to use. This will in turn call mkimage with the -N option.
The -k argument to mkimage can be specified via fit,engine-keydir. If not specified, -k is not passed to mkimage. This property is especially useful for pkcs11 engine to specify slots, token label, etc...
As far as I could tell, mkimage encrypts and signs a FIT in one go, thus the -k argument applies to both signing and encrypting. Considering we reuse the -k argument for two different meanings (info to pass to the engine when using an engine otherwise the directory where keys are stored), we cannot reasonably encrypt using local keys and signing with an engine, hence the enforced check. I believe it should be possible to support encrypting and signing with the same engine (using different key pairs of course, via different key-name-hint likely), but this is left for the next person to implement.
This is why the property is named fit,engine and not fit,sign-engine. Ditto for fit,engine-keydir.The public key (with .crt extension) is still required if it needs to be embedded in the SPL DTB for example. We could probably support retrieving the public key from an engine, but this is a change to make to
fdt_add_pubkey.c.Signed-off-by Quentin Schulz <[email protected]>--- tools/binman/entries.rst | 54 +++++++++++++++++++++++++-- tools/binman/etype/fit.py | 93 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 7 deletions(-)tools/binman/entries.rst +51
-3@@ -885,9 +885,10 @@ The top-level 'fit' node supports the following special properties: fit,sign Enable signing FIT images via mkimage as described in - verified-boot.rst. If the property is found, the private keys path - is detected among binman include directories and passed to mkimage - via -k flag. All the keys required for signing FIT must be + verified-boot.rst. + If the property is found and fit,engine is not set, the private + keys path is detected among binman include directories and passed to + mkimage via -k flag. All the keys required for signing FIT must be available at time of signing and must be located in single include directory.@@ -898,6 +899,53 @@ The top-level 'fit' node supports the following special properties: required for encrypting the FIT must be available at the time of encrypting and must be located in a single include directory. + Incompatible with fit,engine. + + fit,engine + Indicates the OpenSSL engine to use for signing the FIT image. This + is passed to mkimage via the `-N` flag. Example:: + + fit,engine = "my-engine"; + + A `-k` argument for mkimage may be passed via `fit,engine-keydir`. + + When `fit,engine` is set to `pkcs11`, the following applies: + + - If `fit,engine-keydir` is absent, the value of `key-name-hint` is + prefixed with `pkcs11:object=` before being passed to the OpenSSL + engine API:: + + pkcs11:object=<key-name-hint> + + - If `fit,engine-keydir` contains either `object=` or `id=`, its + value is passed verbatim to the OpenSSL engine API, + + - Otherwise, the value of `fit,engine-keydir` is followed by + `;object=` and the value of `key-name-hint` before being passed + to the OpenSSL engine API:: + + <fit,engine-keydir>;object=<key-name-hint> + + If `fit,engine` is set to something different than `pkcs11`, the + value of `key-name-hint` (prefixed with the value of + `fit,engine-keydir` if present) and passed verbatim to the OpenSSL + engine API. + + Depends on fit,sign. + + Incompatible with fit,encrypt. + + fit,engine-keydir + Indicates the `-k` argument to pass to mkimage if an OpenSSL engine + is to be used for signing the FIT image. Example:: + + fit,engine-keydir = "pkcs11:model=xxx;manufacturer=xxx"; + + Read `fit,engine` documentation for more info on special cases when + using `pkcs11` as engine. + + Depends on fit,engine. + Substitutions ~~~~~~~~~~~~~tools/binman/etype/fit.py +89
-5@@ -104,9 +104,10 @@ class Entry_fit(Entry_section): fit,sign Enable signing FIT images via mkimage as described in - verified-boot.rst. If the property is found, the private keys path - is detected among binman include directories and passed to mkimage - via -k flag. All the keys required for signing FIT must be + verified-boot.rst. + If the property is found and fit,engine is not set, the private + keys path is detected among binman include directories and passed to + mkimage via -k flag. All the keys required for signing FIT must be available at time of signing and must be located in single include directory.@@ -117,6 +118,53 @@ class Entry_fit(Entry_section): required for encrypting the FIT must be available at the time of encrypting and must be located in a single include directory. + Incompatible with fit,engine. + + fit,engine + Indicates the OpenSSL engine to use for signing the FIT image. This + is passed to mkimage via the `-N` flag. Example:: + + fit,engine = "my-engine"; + + A `-k` argument for mkimage may be passed via `fit,engine-keydir`. + + When `fit,engine` is set to `pkcs11`, the following applies: + + - If `fit,engine-keydir` is absent, the value of `key-name-hint` is + prefixed with `pkcs11:object=` before being passed to the OpenSSL + engine API:: + + pkcs11:object=<key-name-hint> + + - If `fit,engine-keydir` contains either `object=` or `id=`, its + value is passed verbatim to the OpenSSL engine API, + + - Otherwise, the value of `fit,engine-keydir` is followed by + `;object=` and the value of `key-name-hint` before being passed to + the OpenSSL engine API:: + + <fit,engine-keydir>;object=<key-name-hint> + + If `fit,engine` is set to something different than `pkcs11`, the + value of `key-name-hint` (prefixed with the value of + `fit,engine-keydir` if present) and passed verbatim to the OpenSSL + engine API. + + Depends on fit,sign. + + Incompatible with fit,encrypt. + + fit,engine-keydir + Indicates the `-k` argument to pass to mkimage if an OpenSSL engine + is to be used for signing the FIT image. Example:: + + fit,engine-keydir = "pkcs11:model=xxx;manufacturer=xxx"; + + Read `fit,engine` documentation for more info on special cases when + using `pkcs11` as engine. + + Depends on fit,engine. + Substitutions ~~~~~~~~~~~~~@@ -588,6 +636,29 @@ class Entry_fit(Entry_section): return paths[0] if len(paths) else None + def _get_fit_engine(self): + """Detect whether an OpenSSL engine is to be used for the FIT + + Returns: + Tuple(str, str): Name of the engine to use, as first element of the + Tuple. None if no engine to use. + keydir arguments to pass with the engine to the + OpenSSL API, as second element of the Tuple. None + if no keydir to pass. + """ + engine = None + engine_keydir = None + + prop = self._fit_props.get('fit,engine') + if prop is not None: + engine = prop.value + + prop = self._fit_props.get('fit,engine-keydir') + if prop is not None: + engine_keydir = prop.value + + return engine, engine_keydir + def BuildSectionData(self, required): """Build FIT entry contents@@ -620,7 +691,21 @@ class Entry_fit(Entry_section): args.update({'align': fdt_util.fdt32_to_cpu(align.value)}) if (self._fit_props.get('fit,sign') is not None or self._fit_props.get('fit,encrypt') is not None): - args.update({'keys_dir': self._get_keys_dir(data)}) + engine = None + keydir = None + + # Engine only supported for signing for now + if self._fit_props.get('fit,sign') is not None: + engine, keydir = self._get_fit_engine() + + args.update({'engine': engine}) + # If no engine, keys must exist locally, find them + if engine is None: + keydir = self._get_keys_dir(data) + elif self._fit_props.get('fit,encrypt') is not None: + self.Raise('fit,engine currently does not support encryption') + + args.update({'keys_dir': keydir}) if self.mkimage.run(reset_timestamp=True, output_fname=output_fname, **args) is None: if not self.GetAllowMissing(): --
Quoted 2 lines
2.51.1
Were there any changes on this one? It looks OK to me.
You should be able to do: if 'fit,sign' not in self._fit_props
Regards,
Simon
Re: [PATCH v3 3/4] tools: binman: fit: add support for OpenSSL engines
Hi Simon,
Quoted 236 lines · Simon Glass
Hi Quentin,
Quoted 233 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds support for using an OpenSSL engine for signing a FIT image. To use it, one should set the fit,engine property at the FIT node level with the engine to use. This will in turn call mkimage with the -N option.
The -k argument to mkimage can be specified via fit,engine-keydir. If not specified, -k is not passed to mkimage. This property is especially useful for pkcs11 engine to specify slots, token label, etc...
As far as I could tell, mkimage encrypts and signs a FIT in one go, thus the -k argument applies to both signing and encrypting. Considering we reuse the -k argument for two different meanings (info to pass to the engine when using an engine otherwise the directory where keys are stored), we cannot reasonably encrypt using local keys and signing with an engine, hence the enforced check. I believe it should be possible to support encrypting and signing with the same engine (using different key pairs of course, via different key-name-hint likely), but this is left for the next person to implement.
This is why the property is named fit,engine and not fit,sign-engine. Ditto for fit,engine-keydir.The public key (with .crt extension) is still required if it needs to be embedded in the SPL DTB for example. We could probably support retrieving the public key from an engine, but this is a change to make to
fdt_add_pubkey.c.Signed-off-by Quentin Schulz <[email protected]>--- tools/binman/entries.rst | 54 +++++++++++++++++++++++++-- tools/binman/etype/fit.py | 93 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 7 deletions(-)tools/binman/entries.rst +51
-3@@ -885,9 +885,10 @@ The top-level 'fit' node supports the following special properties: fit,sign Enable signing FIT images via mkimage as described in - verified-boot.rst. If the property is found, the private keys path - is detected among binman include directories and passed to mkimage - via -k flag. All the keys required for signing FIT must be + verified-boot.rst. + If the property is found and fit,engine is not set, the private + keys path is detected among binman include directories and passed to + mkimage via -k flag. All the keys required for signing FIT must be available at time of signing and must be located in single include directory.@@ -898,6 +899,53 @@ The top-level 'fit' node supports the following special properties: required for encrypting the FIT must be available at the time of encrypting and must be located in a single include directory. + Incompatible with fit,engine. + + fit,engine + Indicates the OpenSSL engine to use for signing the FIT image. This + is passed to mkimage via the `-N` flag. Example:: + + fit,engine = "my-engine"; + + A `-k` argument for mkimage may be passed via `fit,engine-keydir`. + + When `fit,engine` is set to `pkcs11`, the following applies: + + - If `fit,engine-keydir` is absent, the value of `key-name-hint` is + prefixed with `pkcs11:object=` before being passed to the OpenSSL + engine API:: + + pkcs11:object=<key-name-hint> + + - If `fit,engine-keydir` contains either `object=` or `id=`, its + value is passed verbatim to the OpenSSL engine API, + + - Otherwise, the value of `fit,engine-keydir` is followed by + `;object=` and the value of `key-name-hint` before being passed + to the OpenSSL engine API:: + + <fit,engine-keydir>;object=<key-name-hint> + + If `fit,engine` is set to something different than `pkcs11`, the + value of `key-name-hint` (prefixed with the value of + `fit,engine-keydir` if present) and passed verbatim to the OpenSSL + engine API. + + Depends on fit,sign. + + Incompatible with fit,encrypt. + + fit,engine-keydir + Indicates the `-k` argument to pass to mkimage if an OpenSSL engine + is to be used for signing the FIT image. Example:: + + fit,engine-keydir = "pkcs11:model=xxx;manufacturer=xxx"; + + Read `fit,engine` documentation for more info on special cases when + using `pkcs11` as engine. + + Depends on fit,engine. + Substitutions ~~~~~~~~~~~~~tools/binman/etype/fit.py +89
-4@@ -104,9 +104,10 @@ class Entry_fit(Entry_section): fit,sign Enable signing FIT images via mkimage as described in - verified-boot.rst. If the property is found, the private keys path - is detected among binman include directories and passed to mkimage - via -k flag. All the keys required for signing FIT must be + verified-boot.rst. + If the property is found and fit,engine is not set, the private + keys path is detected among binman include directories and passed to + mkimage via -k flag. All the keys required for signing FIT must be available at time of signing and must be located in single include directory.@@ -117,6 +118,53 @@ class Entry_fit(Entry_section): required for encrypting the FIT must be available at the time of encrypting and must be located in a single include directory. + Incompatible with fit,engine. + + fit,engine + Indicates the OpenSSL engine to use for signing the FIT image. This + is passed to mkimage via the `-N` flag. Example:: + + fit,engine = "my-engine"; + + A `-k` argument for mkimage may be passed via `fit,engine-keydir`. + + When `fit,engine` is set to `pkcs11`, the following applies: + + - If `fit,engine-keydir` is absent, the value of `key-name-hint` is + prefixed with `pkcs11:object=` before being passed to the OpenSSL + engine API:: + + pkcs11:object=<key-name-hint> + + - If `fit,engine-keydir` contains either `object=` or `id=`, its + value is passed verbatim to the OpenSSL engine API, + + - Otherwise, the value of `fit,engine-keydir` is followed by + `;object=` and the value of `key-name-hint` before being passed to + the OpenSSL engine API:: + + <fit,engine-keydir>;object=<key-name-hint> + + If `fit,engine` is set to something different than `pkcs11`, the + value of `key-name-hint` (prefixed with the value of + `fit,engine-keydir` if present) and passed verbatim to the OpenSSL + engine API. + + Depends on fit,sign. + + Incompatible with fit,encrypt. + + fit,engine-keydir + Indicates the `-k` argument to pass to mkimage if an OpenSSL engine + is to be used for signing the FIT image. Example:: + + fit,engine-keydir = "pkcs11:model=xxx;manufacturer=xxx"; + + Read `fit,engine` documentation for more info on special cases when + using `pkcs11` as engine. + + Depends on fit,engine. + Substitutions ~~~~~~~~~~~~~@@ -588,6 +636,29 @@ class Entry_fit(Entry_section): return paths[0] if len(paths) else None + def _get_fit_engine(self): + """Detect whether an OpenSSL engine is to be used for the FIT + + Returns: + Tuple(str, str): Name of the engine to use, as first element of the + Tuple. None if no engine to use. + keydir arguments to pass with the engine to the + OpenSSL API, as second element of the Tuple. None + if no keydir to pass. + """ + engine = None + engine_keydir = None + + prop = self._fit_props.get('fit,engine') + if prop is not None: + engine = prop.value + + prop = self._fit_props.get('fit,engine-keydir') + if prop is not None: + engine_keydir = prop.value + + return engine, engine_keydir + def BuildSectionData(self, required): """Build FIT entry contents@@ -620,7 +691,21 @@ class Entry_fit(Entry_section): args.update({'align': fdt_util.fdt32_to_cpu(align.value)}) if (self._fit_props.get('fit,sign') is not None or self._fit_props.get('fit,encrypt') is not None): - args.update({'keys_dir': self._get_keys_dir(data)}) + engine = None + keydir = None + + # Engine only supported for signing for now + if self._fit_props.get('fit,sign') is not None: + engine, keydir = self._get_fit_engine() + + args.update({'engine': engine}) + # If no engine, keys must exist locally, find them + if engine is None: + keydir = self._get_keys_dir(data) + elif self._fit_props.get('fit,encrypt') is not None: + self.Raise('fit,engine currently does not support encryption') + + args.update({'keys_dir': keydir}) if self.mkimage.run(reset_timestamp=True, output_fname=output_fname, **args) is None: if not self.GetAllowMissing():
Quoted 6 lines
Quoted 3 lines
--
2.51.1Were there any changes on this one? It looks OK to me.
Yes. You can see the git-range-diff between both versions with:
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#t
Also see cover letter where I list the changes made to the v3 compared to v2 and why I decided to not add your and Wolfgang's trailers.
Quoted 2 lines
You should be able to do: if 'fit,sign' not in self._fit_props
$ git grep "in self._fit_props" tools/binman/etype/fit.py
returns nothing. I would rather have the same logic to get properties within a given file.
Cheers,
Quentin
PATCH v3 4/4 tools: binman: fit: add tests for signing with an OpenSSL engine
In reply to Quentin SchulzFrom: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with fit_check_sign.
OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the OPENSSL_ENGINES environment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.
For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test MKIMAGE_SIGN_PIN env variable while we're at it.
Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via SOFTHSM2_CONF env variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).
Once signed, it's checked with fit_check_sign with the associated certificate.
Finally, a new softhsm2_util bintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)
tools/binman/btool/softhsm2_util.py new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright 2025 Cherry Embedded Solutions GmbH +# +"""Bintool implementation for SoftHSMv2 (softhsm2-util)""" + +from binman import bintool + + +class Bintoolsofthsm2_util(bintool.Bintool): + """SoftHSMv2 -- support tool for libsofthsm2""" + def __init__(self, name): + super().__init__('softhsm2-util', + 'SoftHSMv2 support tool for libsofthsm2', + version_args='-v') + + def fetch(self, method): + """Install softhsm2-util via APT """ + if method != bintool.FETCH_BIN: + return None + + return self.apt_install('softhsm2')
tools/binman/ftest.py +223 -0
229 lines not on this page · raw message
tools/binman/test/340_dummy-rsa4096.crt new file +31 -0
@@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFZTCCA02gAwIBAgIUHBvjPF93z8GaT9YkFleXIvBtt+8wDQYJKoZIhvcNAQEL +BQAwQjELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UE +CgwTRGVmYXVsdCBDb21wYW55IEx0ZDAeFw0yNTExMTQxMDAxNDRaFw0yNTEyMTQx +MDAxNDRaMEIxCzAJBgNVBAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAa +BgNVBAoME0RlZmF1bHQgQ29tcGFueSBMdGQwggIiMA0GCSqGSIb3DQEBAQUAA4IC +DwAwggIKAoICAQC6cUpK5P8J7E+flOwYFI2vh4qQ2mNbDvNfLG0DYMbMuWvWjwd5 +j88UuPCGdptLUL9QGsA0ZreewA3zBh2hAei0ryieYBSq6ez9kG6pAYcI6+c9VCro +jH9Tv+w/UEtNQUsn40j5c8koAqizEqGpwThM+gm+ftWBVCQHDscI9JXac4V/69OE +Oegf8NI4FoC/EQqLDVNxlVaSwxFC9ATEEuO9++rdaHiicmGnt27UOsgM9WO+gZpk +BgicLUp05qFymCwSPsiM6ELT9QYSxAMUi5u6gX2V5d444lSicaaZ2nRQXzOBqnsN +KQksObV2MiJ//jr3/M83TE23eJun6lACvu/5G/sJzJ+aqzBdpHx1DIGYKkQU5jA7 +n/FrHNAWVdyDhLYfaLOZKq7I/pcOzsjYFAjVbPnbVXqujuYj5YXsFttIo+PXTRzY +WBsEcBojqxOhEw8SpQOoeVYgvksKrw3u5RDO7XxkogMRuyO/DuBfm0dDvDf3Anlb +BjCsHHoJAuuOUKidGMkIK37lR6N6NcdZ4g3aSXvjl785/jCzQBl9HnrrGQV5rLHn +PYQkNAXrW+bXil4m4LB07e0/4aUrV8A/5SMolzWpfSjeFuLliZzBlAORNmtfKmT+ +F1WrNNnzUa11iRKe9JA7X+dBtC/nbxB2liBwzl8KdWNZOAAP5zQdcJQFMQIDAQAB +o1MwUTAdBgNVHQ4EFgQUy7zUkFMKw/hlJjHqjOYbClVCM3AwHwYDVR0jBBgwFoAU +y7zUkFMKw/hlJjHqjOYbClVCM3AwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0B +AQsFAAOCAgEAGpsQ5klxd4itvbjVCCf9usItnwlhrf6GxwvGpDBEa8oJbkcQNI+9 +GHVVE+/RO3jx/hjBItLUruKK7mmauO1K2qPLKK8nwcGYV2oMTxTbhZD93a61YBVO +KSWKi5czN8qCU2vkCc9LJM0y2aZzTjVDZCO6b7lYxCZTZcX2Ygcmt3Zv5sv3wrAF +9h0nv8CD4soqsE31GZmfuSiZ/lfBdX7Awr9WI6t++zOKBSZmxmLhfG+Fplak10Xv +TR+yOXHmy+aLegUbrsNgH8ktDAyvM7Aq6+EvbTD6lT06T328cA+AWrKRzYcEGjE0 +wdohmfaKoOch3oZNaXR4fiXDuwTBZ6xHsDpa0RDhvu/YhBP50CxQSqQNuURhFYJB +qBq3E0tpM4cCABBDA8ci2i1ilYb1AeL1LMqYQJXdIa8X5YP1NMdNyMO+4Aizc1J6 +wNvBqItgShvLjBWoQGYWKiiqgz8UoWWMjp0VuKmv0fu/71rbBarg2JDMsC7U5yno +rsfCDgcLGhemFe2EpvlLd8j+rmzjl4Kx1UGKC0EbqBFFaGj8ZlCu20KHpPYiOzNd +p2dU6LpeQYvOfQOCMjNe6BPKCxE4FEkQpdXuF2aKq9rlbZtcVeo1W/NDn2JHaDZ2 +BhHQfv/vugdB9E6JtqoQsME4rDkE3+0AxA7qvVkWFnI0cFtHsqZD+N4= +-----END CERTIFICATE-----
tools/binman/test/340_fit_signature_engine.dts new file +99 -0
99 lines not on this page · raw message
tools/binman/test/340_fit_signature_engine_encrypt.dts new file +100 -0
100 lines not on this page · raw message
tools/binman/test/340_fit_signature_engine_pkcs11.dts new file +99 -0
99 lines not on this page · raw message
tools/binman/test/340_fit_signature_engine_pkcs11_object.dts new file +100 -0
100 lines not on this page · raw message
tools/binman/test/340_openssl.conf new file +10 -0
@@ -0,0 +1,10 @@ +openssl_conf = openssl_init + +[openssl_init] +engines = engine_section + +[engine_section] +pkcs11 = pkcs11_section + +[pkcs11_section] +PIN=1111
tools/binman/test/340_softhsm2.conf new file +16 -0
@@ -0,0 +1,16 @@ +# SoftHSM v2 configuration file + +# directories.tokendir = /path/to/binman/test/softhsm2.tokens/ +objectstore.backend = file + +# ERROR, WARNING, INFO, DEBUG +log.level = ERROR + +# If CKF_REMOVABLE_DEVICE flag should be set +slots.removable = false + +# Enable and disable PKCS#11 mechanisms using slots.mechanisms. +slots.mechanisms = ALL + +# If the library should reset the state on fork +library.reset_on_fork = false
tools/binman/test/Makefile +5 -1
@@ -35,7 +35,8 @@ LDS_BLOB := -T $(SRC)blob_syms.lds TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr bss_data bss_data_zero \ u_boot_binman_syms u_boot_binman_syms.bin u_boot_binman_syms_bad \ u_boot_binman_syms_size u_boot_binman_syms_x86 embed_data \ - u_boot_binman_embed u_boot_binman_embed_sm elf_sections blob_syms.bin + u_boot_binman_embed u_boot_binman_embed_sm elf_sections blob_syms.bin \ + dummy-rsa-engine.so all: $(TARGETS)
@@ -84,6 +85,9 @@ blob_syms: blob_syms.c elf_sections: CFLAGS += $(LDS_EFL_SECTIONS) elf_sections: elf_sections.c +dummy-rsa-engine.so: dummy-rsa-engine.c + $(CC) -fPIC -shared -lcrypto -lssl -o $@ $< + clean: rm -f $(TARGETS)
tools/binman/test/dummy-rsa-engine.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.51.1
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>
Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)
Not sure of the changes from last time, but I assume the test coverage is finished.
Not important, but I think instead of:
+ self.assertIsNotNone(signature)
we typically do: self.assertTrue(signature)
and for:
+ self.assertIsNotNone(signature.props.get('value'))
self.assertIn('value', signature.props)
Regards,
Simon
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)
Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#t
will show you the git-range-diff between both versions for a given commit.
Yes, both the tests (parallel by default) and test coverage (single thread/process) pass now. You can verify this for yourself by fetching the code with
$ b4 shazam https://lore.kernel.org/u-boot/[email protected]/T/\#t
and follow the instructions from the .gitlab-ci.yml file in the job named "Run binman, buildman, dtoc, Kconfig and patman testsuites" up till "./tools/binman/binman ${TOOLPATH} test -T" from within the CI container. e.g.
podman run -it --rm --userns=keep-id -w $PWD -v $PWD:$PWD --pull always docker.io/trini/u-boot-gitlab-ci-runner:noble-20251001-14Nov2025
Quoted 4 lines
Not important, but I think instead of:
+
self.assertIsNotNone(signature)
Quoted 8 lines
we typically do:
self.assertTrue(signature)and for:
+ self.assertIsNotNone(signature.props.get('value'))
self.assertIn('value', signature.props)
Both copied from testFitSignSimple() which uses self.assertIsNotNone(). I like having the "shared" code implemented the same way so that if there's an issue in one test we can hopefully easily spot the same error in others and fix them in one go. It's also seldom used on nodes in tools/binman/ftest.py, 3 out of the 29 times it appears in the file. self.assertIsNotNone() is used on nodes 17 out of the 26 times it appears in the file.
Cheers,
Quentin
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Hi Quentin,
Quoted 67 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
Quoted 6 lines
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#twill show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the patch as well.
Quoted 5 lines
Yes, both the tests (parallel by default) and test coverage (single thread/process) pass now. You can verify this for yourself by fetching the code with
OK great!
Quoted 24 lines
$ b4 shazam https://lore.kernel.org/u-boot/[email protected]/T/\#tand follow the instructions from the .gitlab-ci.yml file in the job named "Run binman, buildman, dtoc,
Kconfigand patman testsuites" up till "./tools/binman/binman${TOOLPATH} test -T" from within the CI container. e.g.podman run -it --rm --userns=keep-id -w $PWD -v $PWD:$PWD --pull always docker.io/trini/u-boot-gitlab-ci-runner:noble-20251001-14Nov2025
Quoted 4 lines
Not important, but I think instead of:
+
self.assertIsNotNone(signature)Quoted 8 lines
we typically do:
self.assertTrue(signature)and for:
+ self.assertIsNotNone(signature.props.get('value'))
self.assertIn('value', signature.props)
Quoted 7 lines
Both copied from
testFitSignSimple()which usesself.assertIsNotNone(). I like having the "shared" code implemented the same way so that if there's an issue in one test we can hopefully easily spot the same error in others and fix them in one go. It's also seldom used on nodes intools/binman/ftest.py, 3 out of the 29 times it appears in the file.self.assertIsNotNone()is used on nodes 17 out of the 26 times it appears in the file.
That's fine.
Regards,
Simon
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Quoted 75 lines · Simon Glass
Hi Quentin,
Quoted 72 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#t
Quoted 6 lines
Quoted 1 line
will show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the patch as well.
The cover letter is just an email. Perhaps a handy tips bit of documentation (and external ref to the general b4 docs) would be helpful, especially since b4 is a common and widely used tool these days.
Signature · 1 line
Tom
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Hi Tom,
Quoted 83 lines · Tom Rini
Quoted 75 lines · Simon Glass
Hi Quentin,
Quoted 72 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#tQuoted 6 lines
Quoted 1 line
will show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the patch as well.
Quoted 5 lines
The cover letter is just an email. Perhaps a handy tips bit of documentation (and external ref to the general b4 docs) would be helpful, especially since b4 is a common and widely used tool these days.
I can do that, what do you have in mind? What should we add to the docs?
Cheers,
Quentin
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Quoted 86 lines · Quentin Schulz
Hi Tom,
Quoted 83 lines · Tom Rini
Quoted 81 lines · Simon Glass
Hi Quentin,
Quoted 67 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
Quoted 6 lines
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#twill show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the patch as well.
Quoted 6 lines
Quoted 4 lines
The cover letter is just an email. Perhaps a handy tips bit of documentation (and external ref to the general b4 docs) would be helpful, especially since b4 is a common and widely used tool these days.
I can do that, what do you have in mind? What should we add to the docs?
Honestly, whatever you've found useful as a contributor and reviewer. I'll follow-up with some handy things for custodians (mainly patchwork integration and that cover letters are so important because it's an automatic useful merge commit message). Thanks!
Signature · 1 line
Tom
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
In reply to Tom RiniHi Tom,
Quoted 84 lines · Tom Rini
Quoted 75 lines · Simon Glass
Hi Quentin,
Quoted 72 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T/\#tQuoted 6 lines
Quoted 1 line
will show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the patch as well.
Quoted 4 lines
The cover letter is just an email. Perhaps a handy tips bit of documentation (and external ref to the general b4 docs) would be helpful, especially since b4 is a common and widely used tool these days.
Well in that case, just put the change log in each patch as well as the cover letter. It should not be difficult to support that in b4...I think patman has supported it for 10 years now. We are the humans and the tools should work for us!
Regards,
Simon
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
In reply to Simon GlassHi Simon
Quoted 72 lines · Simon Glass
Hi Quentin,
Quoted 69 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
Quoted 8 lines
Quoted 4 lines
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T//#twill show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the
What do you mean by "your log argument"?
Quoted 2 lines
patch as well.
We already had that discussion 7 months ago. See https://lore.kernel.org/u-boot/CAFLszTh49HqGC4P2=nefc8vgdWrLe_p6HoyoEZ=FkadNBLsp3Q@mail.gmail.com/ and the exchange afterwards. b4 expects you to put the changes made in the series in the cover letter. It doesn't forbid you from adding some to individual commits underneath "---" but I also don't think it syncs them with the cover letter (which is a feature Tom told you you could bring up to the b4 maintainer).
Cheers,
Quentin
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Hi Quentin,
Quoted 79 lines · Quentin Schulz
Hi Simon
Quoted 75 lines · Simon Glass
Hi Quentin,
Quoted 72 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T//#t
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
will show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the
What do you mean by "your log argument"?
Basically this is an email review flow. It is true that sometimes we apply patches to look into them in detail, but as I said I am often on a machine where I cannot.
Quoted 11 lines
Quoted 3 lines
patch as well.
We already had that discussion 7 months ago. See
https://lore.kernel.org/u-boot/CAFLszTh49HqGC4P2=nefc8vgdWrLe_p6HoyoEZ=FkadNBLsp3Q@mail.gmail.com/
and the exchange afterwards. b4 expects you to put the changes made in the series in the cover letter. It doesn't forbid you from adding some to individual commits underneath "---" but I also don't think it syncs them with the cover letter (which is a feature Tom told you you could bring up to the b4 maintainer).
OK I see. Well in this case I just assume that the next version solves anything I might have mentioned last time.
Regards,
Simon
Re: [PATCH v3 4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
Quoted 88 lines · Simon Glass
Hi Quentin,
Quoted 85 lines · Quentin Schulz
Hi Simon
Quoted 80 lines · Simon Glass
Hi Quentin,
Quoted 67 lines · Quentin Schulz
Hi Simon,
Quoted 59 lines · Simon Glass
Hi Quentin,
Quoted 42 lines · Quentin Schulz
From: Quentin Schulz <[email protected]>
This adds a test that signs a FIT and verifies the signature with
fit_check_sign.OpenSSL engines are typically for signing with external HW so it's not that straight-forward to simulate.
For a simple RSA OpenSSL engine, a dummy engine with a hardcoded RSA 4096 private key is made available. It can be selected by setting the OpenSSL engine argument to dummy-rsa-engine. This can only be done if the engine is detected by OpenSSL, which works by setting the
OPENSSL_ENGINESenvironment variable. I have no clue if dummy-rsa-engine is properly implementing what is expected from an RSA engine, but it seems to be enough for testing.For a simple PKCS11 engine, SoftHSMv2 is used, which allows to do PKCS11 without specific hardware. The keypairs and tokens are generated on the fly. The "prod" token is generated with a different PIN (1234 instead of 1111) to also test
MKIMAGE_SIGN_PINenv variable while we're at it.Binman will not mess with the local SoftHSMv2 setup as it will only use tokens from a per-test temporary directory enforced via the temporary configuration file set via
SOFTHSM2_CONFenv variable in the tests. The files created in the input dir should NOT be named the same as it is shared between all tests in the same process (which is all tests when running binman with -P 1 or with -T).Once signed, it's checked with
fit_check_signwith the associated certificate.Finally, a new
softhsm2_utilbintool is added so that we can initialize the token and import keypairs. On Debian, the package also brings libsofthsm2 which is required for OpenSSL to interact with SoftHSMv2. It is not the only package required though, as it also needs p11-kit and libengine-pkcs11-openssl (the latter bringing the former). We can detect if it's properly installed by running openssl engine dynamic -c pkcs11. If that fails, we simply skip the test.
The package is installed in the CI container by default.Signed-off-by Quentin Schulz <[email protected]>Quoted 13 lines
--- tools/binman/btool/softhsm2_util.py | 21 ++ tools/binman/ftest.py | 223 +++++++++++++++++++++ tools/binman/test/340_dummy-rsa4096.crt | 31 +++ tools/binman/test/340_fit_signature_engine.dts | 99 +++++++++ .../test/340_fit_signature_engine_encrypt.dts | 100 +++++++++ .../test/340_fit_signature_engine_pkcs11.dts | 99 +++++++++ .../340_fit_signature_engine_pkcs11_object.dts | 100 +++++++++ tools/binman/test/340_openssl.conf | 10 + tools/binman/test/340_softhsm2.conf | 16 ++ tools/binman/test/Makefile | 6 +- tools/binman/test/dummy-rsa-engine.c | 149 ++++++++++++++ 11 files changed, 853 insertions(+), 1 deletion(-)Quoted 3 lines
Not sure of the changes from last time, but I assume the test coverage is finished.
Quoted 6 lines
They are listed in the cover letter in the Changes section.
$ b4 diff -v 2 3 -- https://lore.kernel.org/u-boot/[email protected]/T//#twill show you the git-range-diff between both versions for a given commit.
I normally review just in email (often on a Chromebook) so I don't have that. It is also an extra step and I don't know where your log argument comes from. It would be better to put the change log in the
Quoted 5 lines
Quoted 1 line
What do you mean by "your log argument"?
Basically this is an email review flow. It is true that sometimes we apply patches to look into them in detail, but as I said I am often on a machine where I cannot.
Please keep in mind that the biggest email review flow project in history is currently the linux kernel, where this tool originates from. Suggestions are welcome by the upstream maintainer, please go make them.
Signature · 1 line
Tom
Quoted 4 lines · Quentin Schulz
I have a couple of products whose U-Boot FIT is signed via a proprietary OpenSSL engine which only expects the name of a "slot" to select the key to sign data with.
Quoted 8 lines
Currently mkimage fit support expects either a key-dir (-k) or a key-file (-G) as a toggle for signing, however this doesn't apply to our usecase because we use an OpenSSL engine (so no key-file to provide) which doesn't mimic a directory layout like key-dir implies. Moreover, binman really expects private keys (.key extension) to be available in this key-dir directory, which we of course cannot provide.
[...]
Applied to u-boot/next, thanks!
[1/4] fit: support signing with only an engine_id
commit: 5207e1ff20ff26e0f3969b13701bb38610183c6a
[2/4] tools: binman: mkimage: add support for passing the engine
commit: 9f9de386c1e54e6b009e5510ff335ab339a89a62
[3/4] tools: binman: fit: add support for OpenSSL engines
commit: fc75d216f0162d4a85b60fefa9938b8690480e27
[4/4] tools: binman: fit: add tests for signing with an OpenSSL engine
commit: 564c6682fa9689e408e6b795cc8c8c40e5e60e81Signature · 1 line
Tom