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

CLI len(response) < 2 - USB Disconnect? #57

Closed
Tracked by #14007
chillyvee opened this issue Apr 20, 2022 · 2 comments
Closed
Tracked by #14007

CLI len(response) < 2 - USB Disconnect? #57

chillyvee opened this issue Apr 20, 2022 · 2 comments

Comments

@chillyvee
Copy link

chillyvee commented Apr 20, 2022

Often on CLI TX signing with ledger I get the following error:

Error: len(response) < 2

The ledger device may or may not display the TX information. (50/50 chance)

Is there a portion of this project we should look into to help improve?

Or is this related to needing to change the protocol used to establish a better connection with the USB device on ledger? (U2F vs HID which might take a significant amount of work?)

@chillyvee
Copy link
Author

chillyvee commented Apr 21, 2022

This error occurs on OS X on both X64 and M1/ARM64

TLDR -> problem starts in zondax/hid but might be caused by:
LedgerNanoX + Ledger-Cosmos + OSX + USB HID + CLI combination.

We note a compile warning on junod
../gopath/pkg/mod/github.com/zondax/[email protected]/hidapi/mac/hid.c:693:34: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]

We think that error message comes from:
https://github.com/cosmos/ledger-go/blob/master/ledger.go#L210

Which is a response problem from UnwrapResponseAPDU()
https://github.com/cosmos/ledger-go/blob/master/apduWrapper.go#L138

Adding a little more information to the error, we arrive at the following from time to time:
ledger nano S: len(response) < 2, "Invalid channel"

This is due to an APDU of all zeros being read every so often:
https://github.com/chillyvee/ledger-go/blob/debug/apduWrapper.go#L143

UnwrapResponseAPDU 0x101, [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], 0x40

In some cases, disposing of this 0 packet will yield the proper packet (sequenceInt = 0) on the next read. In other cases, the first packet seems to be gone forever.

Which may point to a problem in the upstream https://github.com/Zondax/hid READ() where the C.hid_read somehow returns 64 bytes read, but returns a zero filled buffer.
https://github.com/Zondax/hid/blob/master/hid_enabled.go#L216
C.hid_read [64] => [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Noted the core problem at zondax/hid:
Zondax/hid#6

@ftheirs
Copy link
Contributor

ftheirs commented Jan 3, 2023

Related to: Zondax/ledger-go#23

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

No branches or pull requests

2 participants