tools: binman: Test signing an encrypted FIT with a preload header
PATCH v2 1/3 tools: binman: Test signing an encrypted FIT with a preload header
From: Paul HENRYS <[email protected]>
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes for v2:
- Rename test file as 351_pre_load_fit_encrypted.dts
- Update the commit message according to the remarks made
tools/binman/ftest.py | 17 +++++ .../test/351_pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/binman/test/351_pre_load_fit_encrypted.dts
tools/binman/ftest.py +17 -0
@@ -5894,6 +5894,23 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('236_pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = self._DoReadFileDtb( + '351_pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[os.path.join(self._binman_dir, 'test')])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/351_pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/3 binman: Generate preload header and sign data only once
From: Paul HENRYS <[email protected]>
To optimize preload generation, generate the header and signatures only after all data has been collected. This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), set the preload header size in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects the size changed from 0 to header_size.
This reduces unnecessary repacking and signing operations.
---
Changes for v2:
- Set contents_size knowing header_size in ObtainContents()
tools/binman/etype/pre_load.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +6 -6
@@ -152,14 +152,14 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Only set the known size of the preload header. The data will be + generated later on in ProcessContents() when the data from every entries + can be retrieved. + """ + self.contents_size = self.header_size return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.43.0
Re: [PATCH v2 2/3] binman: Generate preload header and sign data only once
Quoted 10 lines · yan wang
binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected. This avoids signing the data multiple times.
Since
header_sizeis known upfront (from__init__), set the preload header size inObtainContents()to avoid an extra packing pass whenProcessContentsUpdate()detects the size changed from 0 toheader_size.
Quoted 6 lines
This reduces unnecessary repacking and signing operations.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/etype/pre_load.py| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)
PATCH v2 3/3 binman: collection: Set build_done on referenced entries
In reply to yan wangThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes for v2:
- Refactor GetContentsByPhandle() to return both the entry object and its data
tools/binman/etype/collection.py | 8 ++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +6 -2
@@ -45,12 +45,16 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + entry.build_done = True + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.43.0
Re: [PATCH v2 3/3] binman: collection: Set build_done on referenced entries
Quoted 9 lines · yan wang
binman: collection: Set
build_doneon referenced entriesThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with
build_doneto avoid rebuilding the same entry data multiple times.This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Quoted 8 lines
Refactor
GetContentsByPhandle()to return both the entry object and its data.Signed-off-by yan wang <[email protected]>
tools/binman/etype/collection.py| 8 ++++++--tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
Quoted 12 lines · yan wang
From: Paul HENRYS <[email protected]>
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>---
Changes for v2:
- Rename test file as351_pre_load_fit_encrypted.dts
- Update the commit message according to the remarks made
Quoted 4 lines
tools/binman/ftest.py | 17 +++++ .../test/351_pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/binman/test/351_pre_load_fit_encrypted.dts
This should be against next, and we stopped using a numeric prefix on test files and instead put them in to appropriate directories there (so tools/binman/test/fit in this case), thanks.
Signature · 1 line
Tom
PATCH v3 1/3 tools: binman: Test signing an encrypted FIT with a preload header
In reply to yan wangAdd a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes for v3:
- Rebase against 'next' branch
- Move test in tools/binman/test/fit without a numeric prefix
- Update encryption key path passed to _DoReadFileDtb()
tools/binman/ftest.py | 21 +++++++ .../test/fit/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tools/binman/test/fit/pre_load_fit_encrypted.dts
tools/binman/ftest.py +21 -0
@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'fit/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/fit/pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 2/3 binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected. This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), set the preload header size in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects the size changed from 0 to header_size.
This reduces unnecessary repacking and signing operations.
---
Changes for v3:
- Rebase against 'next' branch
tools/binman/etype/pre_load.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +6 -6
@@ -152,14 +152,14 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Only set the known size of the preload header. The data will be + generated later on in ProcessContents() when the data from every entries + can be retrieved. + """ + self.contents_size = self.header_size return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.43.0
PATCH v3 3/3 binman: collection: Set build_done on referenced entries
In reply to Paul HENRYSFrom: yan wang <[email protected]>
The collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes for v3:
- Rebase against 'next' branch
tools/binman/etype/collection.py | 8 ++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +6 -2
@@ -45,12 +45,16 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + entry.build_done = True + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.43.0
Hi Tom,
Just after pushing the v3 I realized that this test would better go under tools/binman/test/security/ instead of tools/binman/test/fit/. I am going to push a v4 with this change. Sorry for the inconvenience.
Kind regards,
Paul
Quoted 117 lines · Paul HENRYS
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>---
Changes for v3:
- Rebase against 'next' branch
- Move test intools/binman/test/fitwithout a numeric prefix
- Update encryption key path passed to_DoReadFileDtb()tools/binman/ftest.py | 21 +++++++ .../test/fit/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+)create mode 100644
tools/binman/test/fit/pre_load_fit_encrypted.dtstools/binman/ftest.py +21
-0@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'fit/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:tools/binman/test/fit/pre_load_fit_encrypted.dts new file +63
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + pre-load { + content = <&image>; + algo-name = "sha256,rsa2048"; + key-name = "dev.key"; + header-size = <4096>; + version = <0x11223344>; + }; + + image: fit { + fit,encrypt; + description = "Test a FIT with encrypted data and signed with a preload"; + #address-cells = <1>; + + images { + u-boot { + description = "U-Boot"; + type = "firmware"; + arch = "arm64"; + os = "U-Boot"; + compression = "none"; + load = <00000000>; + entry = <00000000>; + cipher { + algo = "aes256"; + key-name-hint = "aes256"; + }; + u-boot-nodtb { + }; + }; + fdt-1 { + description = "Flattened Device Tree blob"; + type = "flat_dt"; + arch = "arm64"; + compression = "none"; + cipher { + algo = "aes256"; + key-name-hint = "aes256"; + }; + u-boot-dtb { + }; + }; + }; + + configurations { + default = "conf-1"; + conf-1 { + description = "Boot U-Boot with FDT blob"; + firmware = "u-boot"; + fdt = "fdt-1"; + }; + }; + }; + }; +};
Quoted 5 lines · Paul HENRYS
Hi Tom,
Just after pushing the v3 I realized that this test would better go under
tools/binman/test/security/instead oftools/binman/test/fit/. I am going to push a v4 with this change. Sorry for the inconvenience.
Thanks. It looks like there might be a v5, so please add a cover letter too, this will be used as part of merging the series.
Signature · 1 line
Tom
PATCH v4 1/3 tools: binman: Test signing an encrypted FIT with a preload header
In reply to Paul HENRYSAdd a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes for v4:
- Move test in tools/binman/test/security
tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
tools/binman/ftest.py +21 -0
@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'security/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/security/pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 2/3 binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected. This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), set the preload header size in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects the size changed from 0 to header_size.
This reduces unnecessary repacking and signing operations.
---
Changes for v4:
- No change
tools/binman/etype/pre_load.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +6 -6
@@ -152,14 +152,14 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Only set the known size of the preload header. The data will be + generated later on in ProcessContents() when the data from every entries + can be retrieved. + """ + self.contents_size = self.header_size return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.43.0
Re: [PATCH v4 2/3] binman: Generate preload header and sign data only once
Hi Paul,
Quoted 16 lines · Paul HENRYS
binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected. This avoids signing the data multiple times.
Since
header_sizeis known upfront (from__init__), set the preload header size inObtainContents()to avoid an extra packing pass whenProcessContentsUpdate()detects the size changed from 0 toheader_size.This reduces unnecessary repacking and signing operations.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/etype/pre_load.py class Entry_pre_load(Entry_collection): · line 158
Quoted 7 lines
tools/binman/etype/pre_load.py +7
-0@@ -152,14 +152,14 @@ class Entry_pre_load(Entry_collection): + def ObtainContents(self): + """Only set the known size of the preload header. The data will be + generated later on in ProcessContents() when the data from every entries + can be retrieved. + """ + self.contents_size = self.header_size + return True
Setting contents_size without calling SetContents() is unusual. Most entry types provide placeholder data so GetData() returns something valid rather than None. While section.py handles None by substituting pad bytes, this feels like relying on a side-effect.
Please can you call SetContents() with placeholder data of header_size length instead, similar to image_header? That would be more consistent with other entry types.
Also the docstring should have the summary on the first line per Python conventions.
Regards,
Simon
PATCH v4 3/3 binman: collection: Set build_done on referenced entries
In reply to Paul HENRYSFrom: yan wang <[email protected]>
The collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes for v4:
- No change
tools/binman/etype/collection.py | 8 ++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +6 -2
@@ -45,12 +45,16 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + entry.build_done = True + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.43.0
Re: [PATCH v4 3/3] binman: collection: Set build_done on referenced entries
Quoted 9 lines · Paul HENRYS
binman: collection: Set
build_doneon referenced entriesThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with
build_doneto avoid rebuilding the same entry data multiple times.This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Quoted 8 lines
Refactor
GetContentsByPhandle()to return both the entry object and its data.Signed-off-by yan wang <[email protected]>
tools/binman/etype/collection.py| 8 ++++++--tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
v5 cover binman: Fix preload signing with encrypted FIT
In reply to Paul HENRYSThis series improves the reliability and efficiency of binman preload header generation and test it against an encrypted FIT image signed with a preload header.
When a preload header references other entries (e.g. an encrypted FIT) through the collection etype, the referenced entries may be rebuilt multiple times during binman processing. This becomes problematic when the referenced entry produces non-deterministic output, such as FIT encryption using random IVs or timestamps, since rebuilding the entry changes the data.
This series ensures that referenced entries are built only once and that preload signing is performed after all data is collected. It also avoids unnecessary repacking or repeated signing operations by the preload.
The changes include:
* generate preload header placeholders in ObtainContents() and sign data only once in ProcessContentsUpdate()
* mark referenced entries as build_done in the collection etype to avoid rebuilding data
* add a functional test for signing an encrypted FIT with a preload header
Changes in v5:
- Generate preload placeholder in ObtainContents() to avoid unnecessary repacking
- Move functional test patch to the end of the series
Paul HENRYS (2):
binman: Generate preload header and sign data only once
tools: binman: Test signing an encrypted FIT with a preload header
Yan Wang (1):
binman: collection: Set build_done on referenced entries
tools/binman/etype/collection.py | 8 ++- tools/binman/etype/pre_load.py | 9 +-- tools/binman/etype/section.py | 5 +- tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
Signature · 1 line
2.43.0
PATCH v5 1/3 binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected in ProcessContentsUpdate(). This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), create a placeholder in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects a size change.
This reduces unnecessary repacking and signing operations.
---
Changes in v5:
- Generate a placeholder in ObtainContents() to avoid unnecessary repack
tools/binman/etype/pre_load.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +3 -6
@@ -152,14 +152,11 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Create a placeholder for the header""" + self.SetContents(tools.get_bytes(0, self.header_size)) return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.43.0
Re: [PATCH v5 1/3] binman: Generate preload header and sign data only once
Quoted 10 lines · Paul HENRYS
binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected in
ProcessContentsUpdate(). This avoids signing the data multiple times.Since
header_sizeis known upfront (from__init__), create a placeholder inObtainContents()to avoid an extra packing pass whenProcessContentsUpdate()detects a size change.
Quoted 6 lines
This reduces unnecessary repacking and signing operations.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/etype/pre_load.py| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)
PATCH v5 2/3 binman: collection: Set build_done on referenced entries
In reply to Paul HENRYSFrom: yan wang <[email protected]>
The collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes in v5:
- No changes
tools/binman/etype/collection.py | 8 ++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +6 -2
@@ -45,12 +45,16 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + entry.build_done = True + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.43.0
Re: [PATCH v5 2/3] binman: collection: Set build_done on referenced entries
Hi Yan,
Quoted 20 lines · Paul HENRYS
binman: collection: Set
build_doneon referenced entriesThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with
build_doneto avoid rebuilding the same entry data multiple times.This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor
GetContentsByPhandle()to return both the entry object and its data.Signed-off-by yan wang <[email protected]>
tools/binman/etype/collection.py| 8 ++++++--tools/binman/etype/section.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py class Entry_collection(Entry): · line 46
Quoted 2 lines
tools/binman/etype/collection.py +2
-0@@ -45,12 +45,16 @@ class Entry_collection(Entry): + # Mark referenced entries as build_done to avoid rebuilding + entry.build_done = True
Just a thought - have you tested this against testCollectionSection and testMkimageCollection?
An alternative would be to set build_done only when required=True, so it happens during ProcessContents() rather than ObtainContents():
if required:
entry.build_done = True
What do you think?
At some point we should try to come up with a better algorithm for when Binman rebuilds the contents of an entry.
Regards,
Simon
v6 cover binman: Fix preload signing with encrypted FIT
In reply to Paul HENRYSThis series improves the reliability and efficiency of binman preload header generation and test it against an encrypted FIT image signed with a preload header.
When a preload header references other entries (e.g. an encrypted FIT) through the collection etype, the referenced entries may be rebuilt multiple times during binman processing. This becomes problematic when the referenced entry produces non-deterministic output, such as FIT encryption using random IVs or timestamps, since rebuilding the entry changes the data.
This series ensures that referenced entries are built only once and that preload signing is performed after all data is collected. It also avoids unnecessary repacking or repeated signing operations by the preload.
The changes include:
* generate preload header placeholders in ObtainContents() and sign data only once in ProcessContentsUpdate()
* mark referenced entries as build_done in the collection etype to avoid rebuilding data
* add a functional test for signing an encrypted FIT with a preload header
Changes in v6:
- set build_done only when required=True, so it happens during ProcessContents() rather than ObtainContents()
Paul HENRYS (2):
binman: Generate preload header and sign data only once
tools: binman: Test signing an encrypted FIT with a preload header
yan wang (1):
binman: collection: Set build_done on referenced entries
tools/binman/etype/collection.py | 9 ++- tools/binman/etype/pre_load.py | 9 +-- tools/binman/etype/section.py | 5 +- tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 5 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
Signature · 1 line
2.25.1
PATCH v6 1/3 binman: Generate preload header and sign data only once
From: Paul HENRYS <[email protected]>
To optimize preload generation, generate the header and signatures only after all data has been collected in ProcessContentsUpdate(). This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), create a placeholder in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects a size change.
This reduces unnecessary repacking and signing operations.
---
Changes in v6:
- No changes
tools/binman/etype/pre_load.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +3 -6
@@ -152,14 +152,11 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Create a placeholder for the header""" + self.SetContents(tools.get_bytes(0, self.header_size)) return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.25.1
Re: [PATCH v6 1/3] binman: Generate preload header and sign data only once
Quoted 10 lines · Yan WANG
binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected in
ProcessContentsUpdate(). This avoids signing the data multiple times.Since
header_sizeis known upfront (from__init__), create a placeholder inObtainContents()to avoid an extra packing pass whenProcessContentsUpdate()detects a size change.
Quoted 6 lines
This reduces unnecessary repacking and signing operations.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/etype/pre_load.py| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)
PATCH v6 2/3 binman: collection: Set build_done on referenced entries
In reply to Yan WANGFrom: yan wang <[email protected]>
The collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes in v6:
- set build_done only when required=True, so it happens during ProcessContents() rather than ObtainContents()
tools/binman/etype/collection.py | 9 +++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +7 -2
@@ -45,12 +45,17 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + if required: + entry.build_done = True + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.25.1
Re: [PATCH v6 2/3] binman: collection: Set build_done on referenced entries
Hi Yan,
Quoted 20 lines · Yan WANG
binman: collection: Set
build_doneon referenced entriesThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with
build_doneto avoid rebuilding the same entry data multiple times.This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor
GetContentsByPhandle()to return both the entry object and its data.Signed-off-by yan wang <[email protected]>
tools/binman/etype/collection.py| 9 +++++++--tools/binman/etype/section.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py class Entry_collection(Entry): · line 47
Quoted 3 lines
tools/binman/etype/collection.py +3
-0@@ -45,12 +45,17 @@ class Entry_collection(Entry): + # Mark referenced entries as build_done to avoid rebuilding + if required: + entry.build_done = True
I believe this should use mark_build_done() instead, as it recursively marks child entries in sections.
Regards,
Simon
v7 cover binman: Fix preload signing with encrypted FIT
In reply to Yan WANGThis series improves the reliability and efficiency of binman preload header generation and test it against an encrypted FIT image signed with a preload header.
When a preload header references other entries (e.g. an encrypted FIT) through the collection etype, the referenced entries may be rebuilt multiple times during binman processing. This becomes problematic when the referenced entry produces non-deterministic output, such as FIT encryption using random IVs or timestamps, since rebuilding the entry changes the data.
This series ensures that referenced entries are built only once and that preload signing is performed after all data is collected. It also avoids unnecessary repacking or repeated signing operations by the preload.
The changes include:
* generate preload header placeholders in ObtainContents() and sign data only once in ProcessContentsUpdate()
* mark referenced entries as build_done in the collection etype to avoid rebuilding data
* add a functional test for signing an encrypted FIT with a preload header
Changes in v7:
- use mark_build_done() to recursively mark child entries
Paul HENRYS (2):
binman: Generate preload header and sign data only once
tools: binman: Test signing an encrypted FIT with a preload header
yan wang (1):
binman: collection: Set build_done on referenced entries
tools/binman/etype/collection.py | 9 ++- tools/binman/etype/pre_load.py | 9 +-- tools/binman/etype/section.py | 5 +- tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 5 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
Signature · 1 line
2.25.1
PATCH v7 1/3 binman: Generate preload header and sign data only once
From: Paul HENRYS <[email protected]>
To optimize preload generation, generate the header and signatures only after all data has been collected in ProcessContentsUpdate(). This avoids signing the data multiple times.
Since header_size is known upfront (from __init__), create a placeholder in ObtainContents() to avoid an extra packing pass when ProcessContentsUpdate() detects a size change.
This reduces unnecessary repacking and signing operations.
---
Changes in v7:
- No changes
tools/binman/etype/pre_load.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
tools/binman/etype/pre_load.py +3 -6
@@ -152,14 +152,11 @@ class Entry_pre_load(Entry_collection): return data + pad def ObtainContents(self): - """Obtain a placeholder for the header contents""" - # wait that the image is available - self.image = self.GetContents(False) - if self.image is None: - return False - self.SetContents(self._CreateHeader()) + """Create a placeholder for the header""" + self.SetContents(tools.get_bytes(0, self.header_size)) return True def ProcessContents(self): + self.image = self.GetContents(True) data = self._CreateHeader() return self.ProcessContentsUpdate(data)
Signature · 1 line
2.25.1
Re: [PATCH v7 1/3] binman: Generate preload header and sign data only once
Quoted 10 lines · Yan WANG
binman: Generate preload header and sign data only once
To optimize preload generation, generate the header and signatures only after all data has been collected in
ProcessContentsUpdate(). This avoids signing the data multiple times.Since
header_sizeis known upfront (from__init__), create a placeholder inObtainContents()to avoid an extra packing pass whenProcessContentsUpdate()detects a size change.
Quoted 6 lines
This reduces unnecessary repacking and signing operations.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/etype/pre_load.py| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)
PATCH v7 2/3 binman: collection: Set build_done on referenced entries
In reply to Yan WANGFrom: yan wang <[email protected]>
The collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with build_done to avoid rebuilding the same entry data multiple times.
This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Refactor GetContentsByPhandle() to return both the entry object and its data.
---
Changes in v7:
- use mark_build_done() to recursively mark child entries
tools/binman/etype/collection.py | 9 +++++++-- tools/binman/etype/section.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-)
tools/binman/etype/collection.py +7 -2
@@ -45,12 +45,17 @@ class Entry_collection(Entry): self.Info('Getting contents, required=%s' % required) data = bytearray() for entry_phandle in self.content: - entry_data = self.section.GetContentsByPhandle(entry_phandle, self, - required) + entry, entry_data = self.section.GetContentsByPhandle( + entry_phandle, self, required) if not required and entry_data is None: self.Info('Contents not available yet') # Data not available yet return None + + # Mark referenced entries as build_done to avoid rebuilding + if required: + entry.mark_build_done() + data += entry_data self.Info('Returning contents size %x' % len(data))
tools/binman/etype/section.py +3 -2
@@ -557,7 +557,8 @@ class Entry_section(Entry): return None Returns: - data from associated entry (as a string), or None if not found + tuple: (entry, data) where entry is the Entry object and data is + from that entry (as a string), or (entry, None) if data not found """ node = self._node.GetFdt().LookupPhandle(phandle) if not node:
@@ -565,7 +566,7 @@ class Entry_section(Entry): entry = self.FindEntryByNode(node) if not entry: source_entry.Raise("Cannot find entry for node '%s'" % node.name) - return entry.GetData(required) + return entry, entry.GetData(required) def LookupEntry(self, entries, sym_name, msg): """Look up the entry for a binman symbol
Signature · 1 line
2.25.1
Re: [PATCH v7 2/3] binman: collection: Set build_done on referenced entries
Quoted 9 lines · Yan WANG
binman: collection: Set
build_doneon referenced entriesThe collection etype uses phandles in the 'content' property to reference other entries. Mark each referenced entry with
build_doneto avoid rebuilding the same entry data multiple times.This is important for cases where rebuilding may change the data content, e.g. due to timestamps or random IVs in encryption.
Quoted 8 lines
Refactor
GetContentsByPhandle()to return both the entry object and its data.Signed-off-by yan wang <[email protected]>
tools/binman/etype/collection.py| 9 +++++++--tools/binman/etype/section.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-)
PATCH v7 3/3 tools: binman: Test signing an encrypted FIT with a preload header
In reply to Yan WANGFrom: Paul HENRYS <[email protected]>
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes in v7:
- No changes
tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
tools/binman/ftest.py +21 -0
@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'security/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/security/pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 11 lines · Yan WANG
tools: binman: Test signing an encrypted FIT with a preload header
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/ftest.py| 21 ++++++++.../test/security/pre_load_fit_encrypted.dts | 63 ++++++++++++++++++++++ 2 files changed, 84 insertions(+)
Re: [PATCH v7 0/3] binman: Fix preload signing with encrypted FIT
In reply to Yan WANGQuoted 4 lines · Yan WANG
This series improves the reliability and efficiency of binman preload header generation and test it against an encrypted FIT image signed with a preload header.
Quoted 8 lines
When a preload header references other entries (e.g. an encrypted FIT) through the collection etype, the referenced entries may be rebuilt multiple times during binman processing. This becomes problematic when the referenced entry produces non-deterministic output, such as FIT encryption using random IVs or timestamps, since rebuilding the entry changes the data.
[...]
Applied to u-boot/master, thanks!
[1/3] binman: Generate preload header and sign data only once
commit: 5006121b44a2d147e7e426c74537b3566407e853
[2/3] binman: collection: Set build_done on referenced entries
commit: 9ff82a771c44a8cf38bd52b556f685ddbc6f1a55
[3/3] tools: binman: Test signing an encrypted FIT with a preload header
commit: b20d69e5f57bee299380bb30112856e51d8f26b0Signature · 1 line
Tom
PATCH v6 3/3 tools: binman: Test signing an encrypted FIT with a preload header
In reply to Yan WANGFrom: Paul HENRYS <[email protected]>
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes in v6:
- No changes
tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
tools/binman/ftest.py +21 -0
@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'security/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/security/pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 11 lines · Yan WANG
tools: binman: Test signing an encrypted FIT with a preload header
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/ftest.py| 21 ++++++++.../test/security/pre_load_fit_encrypted.dts | 63 ++++++++++++++++++++++ 2 files changed, 84 insertions(+)
PATCH v5 3/3 tools: binman: Test signing an encrypted FIT with a preload header
In reply to Paul HENRYSAdd a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
---
Changes in v5:
- No changes
tools/binman/ftest.py | 21 +++++++ .../test/security/pre_load_fit_encrypted.dts | 63 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tools/binman/test/security/pre_load_fit_encrypted.dts
tools/binman/ftest.py +21 -0
@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('security/pre_load_invalid_key.dts', entry_args=entry_args) + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header""" + entry_args = { + 'pre-load-key-path': os.path.join(self._binman_dir, 'test'), + } + data = tools.read_file(self.TestFile("fit/aes256.bin")) + self._MakeInputFile("keys/aes256.bin", data) + + keys_subdir = os.path.join(self._indir, "keys") + data = self._DoReadFileDtb( + 'security/pre_load_fit_encrypted.dts', entry_args=entry_args, + extra_indirs=[keys_subdir])[0] + + image_fname = tools.get_output_filename('image.bin') + is_signed = self._CheckPreload(image_fname, self.TestFile("dev.key")) + + self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)]) + self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)]) + self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)]) + self.assertEqual(is_signed, True) + def _CheckSafeUniqueNames(self, *images): """Check all entries of given images for unsafe unique names""" for image in images:
tools/binman/test/security/pre_load_fit_encrypted.dts new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 11 lines · Paul HENRYS
tools: binman: Test signing an encrypted FIT with a preload header
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>
tools/binman/ftest.py| 21 ++++++++.../test/security/pre_load_fit_encrypted.dts | 63 ++++++++++++++++++++++ 2 files changed, 84 insertions(+)
Hi Paul,
tools/binman/ftest.py fdt fdtmap Extract the devicetree blob from the fdtmap · line 5896
Quoted 12 lines · Paul HENRYS
tools: binman: Test signing an encrypted FIT with a preload header
Add a test to verify the preload header correctly signs an encrypted FIT. This test exercises the case where encryption uses random IVs that would change between mkimage calls.
Signed-off-by Paul HENRYS <[email protected]>tools/binman/ftest.py +2
-0@@ -5895,6 +5895,27 @@ fdt fdtmap Extract the devicetree blob from the fdtmap + def testPreLoadEncryptedFit(self): + """Test an encrypted FIT image with a pre-load header"""
nit: for bisectability this should come last, since it relies on fixes in patches 2/3 and 3/3.
Regards,
Simon