-
Notifications
You must be signed in to change notification settings - Fork 2
/
authenticator_attestation_response_test.go
90 lines (84 loc) · 3.39 KB
/
authenticator_attestation_response_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package webauthn
import (
"encoding/base64"
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuthenticatorAttestationResponse_GetClientDataJSONHash(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "None")
assert.Equal(t, ClientDataJSONHash{
0xab, 0x53, 0x3c, 0x7f, 0xf0, 0x07, 0xfd, 0xb8,
0x13, 0x8c, 0xda, 0x77, 0x1c, 0x2f, 0x75, 0x5d,
0x60, 0xed, 0xd2, 0x89, 0x16, 0x75, 0x4e, 0x05,
0x12, 0x79, 0x2a, 0x66, 0x6e, 0x61, 0x1e, 0x79,
}, response.GetClientDataJSONHash())
}
func TestAuthenticatorAttestationResponse_UnmarshalAttestationObject(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "None")
attestationObject, err := response.UnmarshalAttestationObject()
assert.NoError(t, err)
assert.Equal(t, &AttestationObject{
AuthData: []byte{
0x49, 0x96, 0x0d, 0xe5, 0x88, 0x0e, 0x8c, 0x68,
0x74, 0x34, 0x17, 0x0f, 0x64, 0x76, 0x60, 0x5b,
0x8f, 0xe4, 0xae, 0xb9, 0xa2, 0x86, 0x32, 0xc7,
0x99, 0x5c, 0xf3, 0xba, 0x83, 0x1d, 0x97, 0x63,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfe,
0x6a, 0x32, 0x63, 0xbe, 0x37, 0xd1, 0x01, 0xb1,
0x2e, 0x57, 0xca, 0x96, 0x6c, 0x00, 0x22, 0x93,
0xe4, 0x19, 0xc8, 0xcd, 0x01, 0x06, 0x23, 0x0b,
0xc6, 0x92, 0xe8, 0xcc, 0x77, 0x12, 0x21, 0xf1,
0xdb, 0x11, 0x5d, 0x41, 0x0f, 0x82, 0x6b, 0xdb,
0x98, 0xac, 0x64, 0x2e, 0xb1, 0xae, 0xb5, 0xa8,
0x03, 0xd1, 0xdb, 0xc1, 0x47, 0xef, 0x37, 0x1c,
0xfd, 0xb1, 0xce, 0xb0, 0x48, 0xcb, 0x2c, 0xa5,
0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58,
0x20, 0xa6, 0xd1, 0x09, 0x38, 0x5a, 0xc7, 0x8e,
0x5b, 0xf0, 0x3d, 0x1c, 0x2e, 0x08, 0x74, 0xbe,
0x6d, 0xbb, 0xa4, 0x0b, 0x4f, 0x2a, 0x5f, 0x2f,
0x11, 0x82, 0x45, 0x65, 0x65, 0x53, 0x4f, 0x67,
0x28, 0x22, 0x58, 0x20, 0x43, 0xe1, 0x08, 0x2a,
0xf3, 0x13, 0x5b, 0x40, 0x60, 0x93, 0x79, 0xac,
0x47, 0x42, 0x58, 0xaa, 0xb3, 0x97, 0xb8, 0x86,
0x1d, 0xe4, 0x41, 0xb4, 0x4e, 0x83, 0x08, 0x5d,
0x1c, 0x6b, 0xe0, 0xd0,
},
Format: "none",
Statement: AttestationStatement{},
}, attestationObject)
}
func TestAuthenticatorAttestationResponse_UnmarshalClientData(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "None")
clientData, err := response.UnmarshalClientData()
assert.NoError(t, err)
assert.Equal(t, &CollectedClientData{
Type: "webauthn.create",
Challenge: "-8OfJQc6LzKXCIdLZeD27v-ZLUhjTANxzqMjUNMlCmTKGYYK54hQ56AqAjlHotHll688d0ZRM6_L8lGOq3CZNw",
Origin: "https://localhost:44329",
}, clientData)
}
func readTestAuthenticatorAttestationResponse(t *testing.T, name string) *AuthenticatorAttestationResponse {
raw, err := os.ReadFile("testdata/attestation" + name + "Response.json")
require.NoError(t, err)
var obj struct {
Response struct {
AttestationObject string `json:"attestationObject"`
ClientDataJSON string `json:"clientDataJSON"`
} `json:"response"`
}
err = json.Unmarshal(raw, &obj)
require.NoError(t, err)
rawAttestationObject, err := base64.RawURLEncoding.DecodeString(obj.Response.AttestationObject)
require.NoError(t, err)
rawClientDataJSON, err := base64.RawURLEncoding.DecodeString(obj.Response.ClientDataJSON)
require.NoError(t, err)
return &AuthenticatorAttestationResponse{
AttestationObject: rawAttestationObject,
ClientDataJSON: rawClientDataJSON,
}
}