Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/usb/hid: prepend 0 byte to packet #1809

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benma
Copy link
Contributor

@benma benma commented Oct 26, 2022

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.

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
Copy link
Contributor Author

benma commented Oct 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant