Skip to content

Commit

Permalink
DeviceType (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel authored Sep 13, 2020
1 parent 1a1ca51 commit a1b4b14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions fido2.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ type DeviceInfo struct {
Protocols []byte
}

// DeviceType is latest type the device supports.
type DeviceType string

const (
// UnknownDevice ...
UnknownDevice DeviceType = ""
// FIDO2 ...
FIDO2 DeviceType = "fido2"
// U2F ...
U2F DeviceType = "u2f"
)

// RelyingParty ...
type RelyingParty struct {
ID string
Expand Down Expand Up @@ -267,6 +279,21 @@ func (d *Device) IsFIDO2() (bool, error) {
return isFIDO2, nil
}

// Type returns device type.
func (d *Device) Type() (DeviceType, error) {
dev, err := open(d.path)
if err != nil {
return UnknownDevice, err
}
defer close(dev)

isFIDO2 := bool(C.fido_dev_is_fido2(dev))
if isFIDO2 {
return FIDO2, nil
}
return U2F, nil
}

// Info represents authenticatorGetInfo (0x04).
// https://fidoalliance.org/specs/fido2/fido-client-to-authenticator-protocol-v2.1-rd-20191217.html#authenticatorGetInfo
func (d *Device) Info() (*DeviceInfo, error) {
Expand Down
4 changes: 4 additions & 0 deletions fido2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func TestDevices(t *testing.T) {
continue
}

typ, err := device.Type()
require.NoError(t, err)
require.Equal(t, libfido2.FIDO2, typ)

// Testing info twice (hid_osx issues in the past caused a delayed 2nd request to fail).
info, err := device.Info()
require.NoError(t, err)
Expand Down

0 comments on commit a1b4b14

Please sign in to comment.