Skip to content

Commit 2b2a0e0

Browse files
dottspinafabiobaltieri
authored andcommitted
west: blobs: verify fetched blobs after downloading
Running 'west blobs fetch' does not verify the digest of downloaded files: 1. if the checksum of the previously downloaded file does match that in the blob metadata (status BLOB_PRESENT), do nothing 2. if the checksum of the previously downloaded file does not match that in the blob metadata (status BLOB_OUTDATED), download the "up to date" file 3. if the blob has not yet been downloaded (status BLOB_NOT_PRESENT), download it None of the 2) and 3) code paths will verify that the checksum of the file just downloaded actually matches the digest in the blob's metadata. In the event that the metadata of a module is incorrect, then the user will not notice anything, and may rely on an unexpected binary, e.g. a static library for a different architecture. According to the Binary Blobs documentation [1], the expected behavior is to check the blob digest after downloading. [1] Fetching blobs, Zephyr 3.6.0 (still applies to Zephyr 3.7.0rc3) docs.zephyrproject.org/3.6.0/contribute/bin_blobs.html#fetching-blobs Signed-off-by: Christophe Dufaza <[email protected]>
1 parent ae9326c commit 2b2a0e0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/west_commands/blobs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ def fetch_blob(self, url, path):
119119
self.ensure_folder(path)
120120
inst.fetch(url, path)
121121

122+
# Compare the checksum of a file we've just downloaded
123+
# to the digest in blob metadata, warn user if they differ.
124+
def verify_blob(self, blob):
125+
log.dbg('Verifying blob {module}: {abspath}'.format(**blob))
126+
127+
status = zephyr_module.get_blob_status(blob['abspath'], blob['sha256'])
128+
if status == zephyr_module.BLOB_OUTDATED:
129+
log.err(textwrap.dedent(
130+
f'''\
131+
The checksum of the downloaded file does not match that
132+
in the blob metadata:
133+
- if it is not certain that the download was successful,
134+
try running 'west blobs fetch {blob['module']}'
135+
to re-download the file
136+
- if the error persists, please consider contacting
137+
the maintainers of the module so that they can check
138+
the corresponding blob metadata
139+
140+
Module: {blob['module']}
141+
Blob: {blob['path']}
142+
URL: {blob['url']}
143+
Info: {blob['description']}'''))
144+
122145
def fetch(self, args):
123146
blobs = self.get_blobs(args)
124147
for blob in blobs:
@@ -127,6 +150,7 @@ def fetch(self, args):
127150
continue
128151
log.inf('Fetching blob {module}: {abspath}'.format(**blob))
129152
self.fetch_blob(blob['url'], blob['abspath'])
153+
self.verify_blob(blob)
130154

131155
def clean(self, args):
132156
blobs = self.get_blobs(args)

0 commit comments

Comments
 (0)