go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

Investigation of USB wallets, linux / mac / windows

Open holiman opened this issue 1 year ago • 3 comments

This ticket is meant to soup up the information gathered when investigating https://github.com/ethereum/go-ethereum/pull/28516.

Linux

On linux, it enumerates three devices. NB: the ledger udev-rules must be applied for any of this to work.

  1. usb.DeviceInfo{Path:"2c97:4015:01", VendorID:0x2c97, ProductID:0x4015, Release:0x0, Serial:"", Manufacturer:"", Product:"", UsagePage:0x0, Usage:0x0, Interface:2, rawDevice:(*usb._Ctype_struct_libusb_device)(0x7c09bc009590), rawPort:(*uint8)(0xc0007ac050), rawReader:(*uint8)(0xc0007ac040), rawWriter:(*uint8)(0xc0007ac041)}
  2. usb.DeviceInfo{Path:"0001:0005:00", VendorID:0x2c97, ProductID:0x4015, Release:0x201, Serial:"0001", Manufacturer:"Ledger", Product:"Nano X", UsagePage:0x0, Usage:0x0, Interface:0, rawDevice:interface {}(nil), rawPort:(*uint8)(nil), rawReader:(*uint8)(nil), rawWriter:(*uint8)(nil)}
  3. usb.DeviceInfo{Path:"0001:0005:01", VendorID:0x2c97, ProductID:0x4015, Release:0x201, Serial:"0001", Manufacturer:"Ledger", Product:"Nano X", UsagePage:0x0, Usage:0x0, Interface:1, rawDevice:interface {}(nil), rawPort:(*uint8)(nil), rawReader:(*uint8)(nil), rawWriter:(*uint8)(nil)}

The enumeration covers both raw and hid, and the first device is a raw.

The selection process will select device number 1 (the hid device "0001:0005:00"),

  • ProductID 0x4015 is matched on all
  • hub.UsageID(0xffa0) == device.UsagePage(0x0) (not matched on any)
  • info.Interface 2,0,1 is matched to hub.endpointID=0 on device 1.

However, both devices 0 and 1 works fine, only the second HID does not work (derive accounts)

Device zero:

INFO [12-20|08:21:15.246] New wallet appeared                      url=ledger://2c97:4015:01 status="Ethereum app v1.9.19 online"

Device one:

INFO [12-20|08:22:26.688] New wallet appeared                      url=ledger://0001:0002:00 status="Ethereum app v1.9.19 online"

Mac

On mac, it also enumerates three devices, the first being a raw and latter two are hid.

  1. usb.DeviceInfo{Path:"2c97:4015:01", VendorID:0x2c97, ProductID:0x4015, Release:0x0, Serial:"", Manufacturer:"", Product:"", UsagePage:0x0, Usage:0x0, Interface:2, rawDevice:(*usb._Ctype_struct_libusb_device)(0x6000003cc3c0), rawPort:(*uint8)(0x140002e84a8), rawReader:(*uint8)(0x140002e8498), rawWriter:(*uint8)(0x140002e8499)}
  2. usb.DeviceInfo{Path:"", VendorID:0x2c97, ProductID:0x4015, Release:0x201, Serial:"0001", Manufacturer:"Ledger", Product:"Nano X", UsagePage:0xffa0, Usage:0x1, Interface:-1, rawDevice:interface {}(nil), rawPort:(*uint8)(nil), rawReader:(*uint8)(nil), rawWriter:(*uint8)(nil)}
  3. usb.DeviceInfo{Path:"", VendorID:0x2c97, ProductID:0x4015, Release:0x201, Serial:"0001", Manufacturer:"Ledger", Product:"Nano X", UsagePage:0xf1d0, Usage:0x1, Interface:-1, rawDevice:interface {}(nil), rawPort:(*uint8)(nil), rawReader:(*uint8)(nil), rawWriter:(*uint8)(nil)}

The selection process will select device 1:

  • ProductID 0x4015 is matched on all
  • hub.UsageID(0xffa0) == device.UsagePage matched on device 1.
  • hub.endpointID=0 == info.Interface is not matched on any (2,-1,-1).

@lightclient didn't you get the result that none were matched? Please help amend this.

On mac, only device 0, the raw device, works properly (open + derive addresses).

holiman avatar Dec 20 '23 09:12 holiman

Curious, I tested the https://github.com/todbot/hidapitester (based on hidapi), with the same Nano X plugged in

$ ./hidapitester --list-detail
2C97/4015: Ledger - Nano X
  vendorId:      0x2C97
  productId:     0x4015
  usagePage:     0xFFA0
  usage:         0x0001
  serial_number: 0001 
  interface:     0 
  path: /dev/hidraw0

2C97/4015: Ledger - Nano X
  vendorId:      0x2C97
  productId:     0x4015
  usagePage:     0xF1D0
  usage:         0x0001
  serial_number: 0001 
  interface:     1 
  path: /dev/hidraw1

It lists only the raw device, and also it obtains a UsagePage of 0xF1D0, which our lib does not.

holiman avatar Dec 20 '23 12:12 holiman

According to @lightclient , this PR https://github.com/karalabe/usb/pull/43 which contains an updated hid-library, fixes the problems on macosx14.

holiman avatar Dec 22 '23 08:12 holiman

To be clear, a short-term work around for someone needing this fixed immediately is https://github.com/ethereum/go-ethereum/pull/28516

However the correct solution is to fix karalabe/usb upstream.

lightclient avatar Jan 25 '24 18:01 lightclient