From a1d3eda2ca47087390a1f1d3511fbcd01e35fa7f Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Mon, 29 May 2017 17:45:15 +0200 Subject: [PATCH] apps.fido_u2f: return correct cid on chan cancellation --- src/apps/fido_u2f/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/apps/fido_u2f/__init__.py b/src/apps/fido_u2f/__init__.py index b376b7d2..a6457687 100644 --- a/src/apps/fido_u2f/__init__.py +++ b/src/apps/fido_u2f/__init__.py @@ -181,7 +181,6 @@ def read_cmd(iface: int) -> Cmd: log.debug(__name__, 'read init %s', buf) ifrm = overlay_struct(buf, desc_init) - cid = ifrm.cid bcnt = ifrm.bcnt data = ifrm.data datalen = len(data) @@ -206,22 +205,28 @@ def read_cmd(iface: int) -> Cmd: cfrm = overlay_struct(buf, desc_cont) if cfrm.seq == _CMD_INIT: + # _CMD_INIT frame, cancels current channel ifrm = overlay_struct(buf, desc_init) data = ifrm.data[:ifrm.bcnt] break - if cfrm.cid != cid: + if cfrm.cid != ifrm.cid: + # cont frame for a different channel, reply with BUSY and skip + log.warning(__name__, '_ERR_CHANNEL_BUSY') send_cmd(cmd_error(cfrm.cid, _ERR_CHANNEL_BUSY), iface) continue if cfrm.seq != seq: + # cont frame for this channel, but incorrect seq number, abort + # current msg + log.warning(__name__, '_ERR_INVALID_SEQ') send_cmd(cmd_error(cfrm.cid, _ERR_INVALID_SEQ), iface) - raise Exception(_ERR_INVALID_SEQ) + return None datalen += utils.memcpy(data, datalen, cfrm.data, 0, bcnt - datalen) seq += 1 - return Cmd(cid, ifrm.cmd, data) + return Cmd(ifrm.cid, ifrm.cmd, data) def send_cmd(cmd: Cmd, iface: int):