Skip to content

Commit

Permalink
Support linux usb hid discovery (#10)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ocraviotto and bmon authored Jan 11, 2021
1 parent ee0c355 commit 3ccdec8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ At the moment only Mac OS, however nothing in the go codebase is platform specif
### Linux
If you are using a linux device you need to add [these udev rules](https://github.com/Yubico/libu2f-host/blob/master/70-u2f.rules).

To enable support for discovering USB HID devices on Linux, `go build` needs to be passed `-tags=hidraw`. This will build the `bearsh/hid` package with the `hidraw` backend for `hidapi`, instead of the default `libusb` used in previous versions and used by default when no tags are passed.
[Changes in the upstream libusb HIDAPI library](https://github.com/libusb/hidapi/pull/139/files) have made it possible to return Usage Page and Usage on Linux and so address [issue #1](https://github.com/marshallbrekka/go-u2fhost/issues/1), but this only works with hidraw.
Linux packages, therefore, should be built with `-tags=hidraw`.

### The interface seems too low level, why isn't it easier to use?
Mostly because I wasn't sure what a good high level API would look like, and opted to provide a more general purpose low level API.

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module marshallbrekka/go-u2fhost
module github.com/marshallbrekka/go-u2fhost

go 1.14

require (
github.com/karalabe/hid v1.0.0
github.com/marshallbrekka/go-u2fhost v0.0.0-20200114212649-cc764c209ee9
github.com/bearsh/hid v1.3.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/bearsh/hid v1.3.0 h1:GLNa8hvEzJxzQEEpheDUr2SivvH7iwTrJrDhFKutfX8=
github.com/bearsh/hid v1.3.0/go.mod h1:KbQByg8WfPr92v7aaKAHTtZUEVG7e2XRpcF8+TopQv8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down Expand Up @@ -42,8 +44,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karalabe/hid v1.0.0 h1:+/CIMNXhSU/zIJgnIvBD2nKHxS/bnRHhhs9xBryLpPo=
github.com/karalabe/hid v1.0.0/go.mod h1:Vr51f8rUOLYrfrWDFlV12GGQgM5AT8sVh+2fY4MPeu8=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand All @@ -54,8 +54,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/marshallbrekka/go-u2fhost v0.0.0-20200114212649-cc764c209ee9 h1:7dYglvg2+WRsvX//65GyQTYJyooO1HYKGVpKBlIAoms=
github.com/marshallbrekka/go-u2fhost v0.0.0-20200114212649-cc764c209ee9/go.mod h1:U9kRL9P37LGrkikKWuekWsReXRKe2fkZdRSXpI7pP3A=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down
2 changes: 1 addition & 1 deletion hid/hid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"io"

"github.com/karalabe/hid"
"github.com/bearsh/hid"
butil "github.com/marshallbrekka/go-u2fhost/bytes"
)

Expand Down
2 changes: 1 addition & 1 deletion hid/wrapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hid

import "github.com/karalabe/hid"
import "github.com/bearsh/hid"

type RawHidDevice struct {
Device *hid.DeviceInfo
Expand Down

0 comments on commit 3ccdec8

Please sign in to comment.