Skip to content

Commit 54e4ec3

Browse files
authored
fix: improve filtering of supported devices (#24)
Co-authored-by: sebastian <sebastian>
1 parent eaadfbc commit 54e4ec3

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

pkg/plugin/fido2_utils.go

+34-5
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,52 @@ package plugin
22

33
import (
44
"errors"
5-
"github.com/keys-pub/go-libfido2"
5+
"slices"
66
"time"
7+
8+
"github.com/keys-pub/go-libfido2"
79
)
810

911
func FindDevice() (*libfido2.Device, error) {
1012
locs, err := libfido2.DeviceLocations()
11-
1213
if err != nil {
1314
return nil, err
1415
}
1516

16-
if len(locs) > 1 {
17+
devs := []*libfido2.Device{}
18+
for _, loc := range locs {
19+
dev, err := libfido2.NewDevice(loc.Path)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
isFido, err := dev.IsFIDO2()
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
if !isFido {
30+
continue
31+
}
32+
33+
info, err := dev.Info()
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
if !slices.Contains(info.Extensions, string(libfido2.HMACSecretExtension)) {
39+
continue
40+
}
41+
42+
devs = append(devs, dev)
43+
}
44+
45+
if len(devs) > 1 {
1746
return nil, errors.New("Too many devices")
1847
}
1948

20-
if len(locs) == 1 {
21-
return libfido2.NewDevice(locs[0].Path)
49+
if len(devs) == 1 {
50+
return devs[0], nil
2251
}
2352

2453
return nil, nil

0 commit comments

Comments
 (0)