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

Support discovering USB HID devices on linux #1

Closed
marshallbrekka opened this issue Jan 22, 2017 · 4 comments · Fixed by #10
Closed

Support discovering USB HID devices on linux #1

marshallbrekka opened this issue Jan 22, 2017 · 4 comments · Fixed by #10

Comments

@marshallbrekka
Copy link
Owner

Use this firefox extension as a reference.

https://github.com/prefiks/u2f4moz/blob/master/c_src/libu2f-host/devs.c#L117-L142

samhanes-fs pushed a commit to samhanes-fs/go-u2fhost that referenced this issue Aug 16, 2019
samhanes-fs pushed a commit to samhanes-fs/go-u2fhost that referenced this issue Aug 16, 2019
@VictorDenisov
Copy link

I'm trying to use this library on linux, but it filters out my keys due to this line: https://github.com/marshallbrekka/go-u2fhost/blob/master/hid/hid.go#L46
If you look at the doc for UsagePage and Usage you can see that those values are only for mac and windows. On linux they are zeroes. Why are you using those values?

@marshallbrekka
Copy link
Owner Author

marshallbrekka commented Apr 28, 2020

@VictorDenisov this has been long on my personal backlog of issues to resolve.
I'd love some help on this, as it appears the solve exists outside the context of just this project.

Short answer:

usage and usage page are available on linux, but they are not accessible given the current way that hidapi uses libusb.

Longer Answer

I had done some research a while ago, but can't seem to find it, so sorry if my notes are a little sparse, or not as correct as they should be.

libusb currently has the code disabled for grabbing the full usage page. This is probably a fine choice as most users may not need it. In our case it would be ideal to be able to access it when needed to validate the device is u2f compatible.

There is another usability issue. The karalabe/hid project chooses to use the libusb backend on linux, as opposed to the hidraw backend.
As far as I remember, the hidraw backend could interact with the u2f devices without any special permissions, but the libusb backend required the end user to add udev rules.

Fortunately we can look at what Firefox has done, via their rust library.

I'm not 100% sure what the best path is to move forward, as it seems some decent changes would be required outside of this project.

Can the usage page check just be removed entirely?

Honestly I'm not sure what kind of dangers might arise by issuing commands to non-u2f devices. I'd be very open to exploring that if you have the bandwidth to do that research.

@VictorDenisov
Copy link

Thanks for your reply. I'll be looking into this problem as it's a more or less pressing issue for me. Though it looks like if I want a tool that works just for me I can just do the custom build of the tool that is using your library.

@marshallbrekka
Copy link
Owner Author

Also looks like there is some progress on making it more accessible on linux libusb/hidapi#139

ocraviotto added a commit to ocraviotto/go-u2fhost that referenced this issue Dec 29, 2020
Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
marshallbrekka#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module name in go.mod.
ocraviotto added a commit to ocraviotto/go-u2fhost that referenced this issue Dec 29, 2020
Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
marshallbrekka#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module name in go.mod.
ocraviotto added a commit to ocraviotto/go-u2fhost that referenced this issue Dec 30, 2020
Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
marshallbrekka#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module directive in go.mod and adds the
vendor directory resulting from executing "go mod vendor"
ocraviotto added a commit to ocraviotto/go-u2fhost that referenced this issue Dec 30, 2020
Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
marshallbrekka#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module directive in go.mod and adds the
vendor directory resulting from executing "go mod vendor"
ocraviotto added a commit to ocraviotto/go-u2fhost that referenced this issue Dec 30, 2020
Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
marshallbrekka#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module directive in go.mod and adds the
vendor directory resulting from executing "go mod vendor"
marshallbrekka pushed a commit that referenced this issue Jan 11, 2021
Optional support for discovering USB HID devices on Linux

Requires passing "-tags=hidraw" when building to enable the fix.

This commit changes the hid library used for accessing u2f USB devices
from karalabe/hid to bearsh/hid. bearsh/hid has updated karalabe's
libusb and hidapi code base with upstream libusb/libusb and
libusb/hidapi, which among other things incorporate the changes in
libusb/hidapi to support Usage Page and Usage on Linux with hidraw.
(see https://github.com/libusb/hidapi/pull/139/files) that fix
#1 when built with
"-tags=hidraw", while maintaining the old behaviour when built without
it. The fork includes fixes and enhancements related to vendoring
modules.

The commit also fixes the module directive in go.mod and adds the
vendor directory resulting from executing "go mod vendor"

* Remove vendor folder

The vendor folder had been initially added to allow interoperation
with older versions of Go and to make sure we had a copy of all deps
living under the same file tree.

Depending on the module users Go version, the first part may not
hold. As for making sure we keep a copy of the dependencies, it
should not be a problem if dependency repositories are not
completely removed.

Neither of these seem to be/should be an issue, so based on comment
#10 (comment)
this commit removes vendor/

Co-authored-by: Brendan Roy <[email protected]>
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 a pull request may close this issue.

2 participants