forked from tstranex/u2f
-
Notifications
You must be signed in to change notification settings - Fork 2
/
virtualkey_test.go
67 lines (53 loc) · 1.48 KB
/
virtualkey_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Go FIDO U2F Library
// Copyright 2015 The Go FIDO U2F Library Authors. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package u2f
import (
"fmt"
"testing"
)
func TestVirtualKey(t *testing.T) {
vk, err := NewVirtualKey()
if err != nil {
t.Error(err)
t.FailNow()
}
var app_id string = "http://localhost"
var registrations []Registration
// Generate registration request
c1, _ := NewChallenge(app_id, []string{app_id}, registrations)
registerReq := c1.RegisterRequest()
// Pass to virtual token
resp, err := vk.HandleRegisterRequest(*registerReq)
if err != nil {
t.Error(err)
t.FailNow()
}
// Register virtual token
// Attestation cert is self signed, so skip checking that
reg, err := c1.Register(*resp, &RegistrationConfig{SkipAttestationVerify: true})
if err != nil {
t.Error(err)
t.FailNow()
}
// Send authentication request to the browser / token.
registrations = append(registrations, *reg)
c2, _ := NewChallenge(app_id, []string{app_id}, registrations)
signReq := c2.SignRequest()
// Pass to virtual token
signResp, err := vk.HandleAuthenticationRequest(*signReq)
if err != nil {
t.Error(err)
t.FailNow()
}
// Read response from the browser / token.
authReg, err := c2.Authenticate(*signResp)
if err != nil {
t.Error(err)
t.FailNow()
}
if authReg.Counter != 1 {
t.Error(fmt.Errorf("Registration count mismatch, expected %d received %d", 1, authReg.Counter))
}
}