diff --git a/core/src/apps/webauthn/__init__.py b/core/src/apps/webauthn/__init__.py index b1c3637d05..3f72e26ad5 100644 --- a/core/src/apps/webauthn/__init__.py +++ b/core/src/apps/webauthn/__init__.py @@ -1,6 +1,6 @@ -def boot() -> None: +def boot(mutex) -> None: from trezor import loop import usb from .fido2 import handle_reports - loop.schedule(handle_reports(usb.iface_webauthn)) + loop.schedule(handle_reports(usb.iface_webauthn, mutex)) diff --git a/core/src/apps/webauthn/fido2.py b/core/src/apps/webauthn/fido2.py index 8e0f64fb50..5c1ee4c4da 100644 --- a/core/src/apps/webauthn/fido2.py +++ b/core/src/apps/webauthn/fido2.py @@ -538,7 +538,7 @@ def send_cmd_sync(cmd: Cmd, iface: HID) -> None: seq += 1 -async def handle_reports(iface: HID) -> None: +async def handle_reports(iface: HID, mutex) -> None: dialog_mgr = DialogManager(iface) while True: @@ -546,10 +546,14 @@ async def handle_reports(iface: HID) -> None: req = await _read_cmd(iface) if req is None: continue - if not dialog_mgr.allow_cid(req.cid): + if mutex is not None and mutex.get_busy(iface.iface_num()): resp: Cmd | None = cmd_error(req.cid, _ERR_CHANNEL_BUSY) else: - resp = _dispatch_cmd(req, dialog_mgr) + mutex.set_busy(iface.iface_num()) + if not dialog_mgr.allow_cid(req.cid): + resp: Cmd | None = cmd_error(req.cid, _ERR_CHANNEL_BUSY) + else: + resp = _dispatch_cmd(req, dialog_mgr) if resp is not None: await send_cmd(resp, iface) except Exception as e: diff --git a/core/src/session.py b/core/src/session.py index 9777905866..b96c938eab 100644 --- a/core/src/session.py +++ b/core/src/session.py @@ -7,10 +7,12 @@ import usb apps.base.boot() +mutex = Mutex() + if not utils.BITCOIN_ONLY and usb.ENABLE_IFACE_WEBAUTHN: import apps.webauthn - apps.webauthn.boot() + apps.webauthn.boot(mutex) if __debug__: import apps.debug @@ -22,8 +24,6 @@ apps.base.set_homescreen() workflow.start_default() -mutex = Mutex() - mutex.add(usb.iface_wire.iface_num()) mutex.add(usb.iface_debug.iface_num())