bitbox-wallet-app icon indicating copy to clipboard operation
bitbox-wallet-app copied to clipboard

backend/usb/hid: prepend 0 byte to packet

Open benma opened this issue 3 years ago • 1 comments

If a USB packet starts with a zero byte, that byte will be stripped by the C USB library (i.e. signal11 on Linux), leading to a broken package.

We only need to add it if not on Windows, as karalabel/usb prepends this zero byte already for Windows (I think this is a bug in karalabe/usb and karalabe/hid, which didn't consider that a packet could start with a zero byte right after the report ID).

Currently we don't observe a bug because the first byte in each packet is the cid (channel identifier), which is currnetly harddcoded to 0xff000000 in bitbox02-api-go. If we start using a random CID, and it starts with a zero byte, the packet will be corrupted and the BitBox02 will not be able to parse it.

The same fix was also added to the bitbox01 in the BitBoxApp (https://github.com/digitalbitbox/bitbox-wallet-app/blob/bd70f6c400268355cee94891397447796f02fbde/backend/devices/bitbox/communication.go#L235-L241), where it was crucial because packets in the bitbox01 are padded with zero bytes to the left. We can remove the fix there, as it uses the same hid functions as the BitBox02.

benma avatar Oct 26 '22 13:10 benma

I need to test this on bitbox01 (bootloader, firmware) and bitbox02 (bootloader, firmware) on all supported platforms.

benma avatar Oct 26 '22 13:10 benma