SFT-8255: report unavailable update state without a fatal error
What changed, and why it matters
This commit changes the Passport hardware wallet's firmware update flow so that a specific internal error while reading the firmware header is shown to the user as a recoverable error message instead of crashing the device with a fatal error. It also adds a test to confirm the device can recover from this situation without getting stuck.
Review whether any other native calls in the update flow can raise RuntimeError and should be handled similarly; ensure the ErrorPage text does not leak sensitive state information.
Security signals we found
Change converts an unhandled fatal exception into a recoverable user-facing error
Native firmware-state error is now handled in the UI flow rather than crashing
New test verifies recovery path and absence of update_header selection after failure
Evidence from the diff
The patch adds a RuntimeError handler around passport.verify_update_header() in update_firmware_flow.py’s show_firmware_details(). Previously, a RuntimeError raised by the native module (for example when the secure element cannot provide the firmware timestamp/state) would propagate as an unhandled fatal error. Now it displays an ErrorPage (‘Firmware update cannot continue.’) and cleanly sets the flow result to False. A new unit test extracts the method via AST and mocks the RuntimeError to assert the flow recovers and does not set update_header.
Changed components
ports/stm32/boards/Passport/modules/flows/update_firmware_flow.pyports/stm32/boards/Passport/modules/tests/test_firmware_timestamp.pyInspect captured patch +45 / −0
### ports/stm32/boards/Passport/modules/flows/update_firmware_flow.py
@@ -87,6 +87,10 @@ async def show_firmware_details(self):
await ErrorPage(text='Firmware update is invalid.\n\n{}'.format(str(e))).show()
self.set_result(False)
return
+ except RuntimeError as e:
+ await ErrorPage(text='Firmware update cannot continue.\n\n{}'.format(str(e))).show()
+ self.set_result(False)
+ return
if is_user_signed:
pubkey_result, pubkey = read_user_firmware_pubkey()
### ports/stm32/boards/Passport/modules/tests/test_firmware_timestamp.py
@@ -3,11 +3,16 @@
"""Exercise native firmware-state checks with controlled SE responses."""
+import ast
+import asyncio
+from contextlib import nullcontext
import hashlib
import os
from pathlib import Path
import shlex
import subprocess
+import sys
+from types import SimpleNamespace
import pytest
@@ -208,3 +213,39 @@ def test_update_timestamp_failure_handling(tmp_path, production):
'STATIC mp_obj_t mod_passport_verify_update_signatures(']:
wrapper = function(native, name)
assert wrapper.index('get_minimum_firmware_timestamp()') < wrapper.index('foundation_firmware_verify_')
+
+
+def test_header_state_failure_is_recoverable(tmp_path, monkeypatch):
+ source = ast.parse((BOARD / 'modules/flows/update_firmware_flow.py').read_text())
+ flow_class = next(node for node in source.body if isinstance(node, ast.ClassDef))
+ method = next(node for node in flow_class.body if node.name == 'show_firmware_details')
+ messages, results = [], []
+
+ class ErrorPage:
+ def __init__(self, text):
+ messages.append(text)
+
+ async def show(self):
+ return True
+
+ def verify_header(_):
+ raise RuntimeError('Unable to read firmware timestamp.')
+
+ header_size = 2048
+ path = tmp_path / 'firmware.bin'
+ path.write_bytes(bytes(header_size))
+ flow = SimpleNamespace(update_file_path=str(path), set_result=results.append)
+ monkeypatch.setitem(sys.modules, 'common', SimpleNamespace())
+ namespace = {
+ 'CardSlot': nullcontext,
+ 'ErrorPage': ErrorPage,
+ 'FW_HEADER_SIZE': header_size,
+ 'FW_MAX_SIZE': header_size,
+ 'passport': SimpleNamespace(InvalidFirmwareUpdate=ValueError, verify_update_header=verify_header),
+ }
+ isolated = ast.Module(body=[method], type_ignores=[])
+ exec(compile(isolated, 'update_firmware_flow.py', 'exec'), namespace)
+ asyncio.run(namespace['show_firmware_details'](flow))
+ assert results == [False]
+ assert messages == ['Firmware update cannot continue.\n\nUnable to read firmware timestamp.']
+ assert not hasattr(flow, 'update_header')Why this scored 45/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.