-
Notifications
You must be signed in to change notification settings - Fork 15
communication/u2fhid: prepend 0 byte to packet #73
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
Conversation
Issue opened upstream: karalabe/usb#30 |
communication/u2fhid/u2fhid.go
Outdated
if runtime.GOOS != "windows" { | ||
// packets have a 0 byte report ID in front. The karalabe usb library adds it | ||
// automatically for windows, and not for unix, as there, it is stripped by the signal11 | ||
// hid library. We have to add it (to be stripped by signal11), otherwise a a zero that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo otherwise a a zero
tACK on Linux! 👍 |
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 harddcoded to `0xff000000`. 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.
The CID in the response is compared against the hardcoded 0xff000000 CID. It should however parse and compare it to the const `cid`. This allows us to change the CID (i.e. make it random) and not break parsing.
After more consideration, I think this is the wrong location to add the fix. This library doesn't even depend on If the fix was merged here, I assume bitbox02-api-js via WebHID would break: https://github.com/digitalbitbox/bitbox02-api-js/blob/8205a813a58fa3effb86be6ce5c99a3c0561e551/gowrapper/main.go#L183 |
Split the first commit into a new PR, as that one is still useful: #75 |
Closing in favor of BitBoxSwiss/bitbox-wallet-app#1809 |
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 harddcoded to0xff000000
. 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.