github.com/transparency-dev/armored-witness-os@v0.1.3-0.20240514084412-27eef7325168/cmd/witnessctl/usb.go (about) 1 // Copyright 2022 The Armored Witness OS authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build !tamago 16 // +build !tamago 17 18 package main 19 20 import ( 21 "fmt" 22 23 flynn_hid "github.com/flynn/hid" 24 "github.com/flynn/u2f/u2fhid" 25 26 "github.com/transparency-dev/armored-witness-os/api" 27 ) 28 29 // detect looks for connected witness devices 30 func detect() ([]Device, error) { 31 devices, err := flynn_hid.Devices() 32 if err != nil { 33 return nil, err 34 } 35 36 devs := []Device{} 37 for _, d := range devices { 38 if d.UsagePage == api.HIDUsagePage && 39 d.VendorID == api.VendorID && 40 d.ProductID == api.ProductID { 41 42 dev, err := u2fhid.Open(d) 43 if err != nil { 44 return nil, fmt.Errorf("u2fhid.Open(%q): %v", d.Path, err) 45 } 46 47 devs = append(devs, Device{usb: d, u2f: dev}) 48 } 49 } 50 51 return devs, nil 52 }