-
Notifications
You must be signed in to change notification settings - Fork 2
/
attestation_statement_packed_test.go
63 lines (55 loc) · 2.41 KB
/
attestation_statement_packed_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
package webauthn
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestVerifyPackedAttestationStatement(t *testing.T) {
t.Run("valid", func(t *testing.T) {
for _, name := range []string{"Packed", "Packed512", "Windows"} {
response := readTestAuthenticatorAttestationResponse(t, name)
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
clientDataJSONHash := response.GetClientDataJSONHash()
t.Run(name, func(t *testing.T) {
_, err = VerifyAttestationStatement(attestationObject, clientDataJSONHash)
assert.NoError(t, err)
})
}
})
t.Run("invalid format", func(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "None")
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
clientDataJSONHash := response.GetClientDataJSONHash()
_, err = VerifyPackedAttestationStatement(attestationObject, clientDataJSONHash)
assert.ErrorIs(t, err, ErrInvalidAttestationStatement)
})
t.Run("invalid certificate", func(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "Packed")
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
clientDataJSONHash := response.GetClientDataJSONHash()
attestationObject.Statement["x5c"] = []byte("INVALID")
_, err = VerifyPackedAttestationStatement(attestationObject, clientDataJSONHash)
assert.ErrorIs(t, err, ErrInvalidAttestationStatement)
})
t.Run("invalid authenticator data", func(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "Packed")
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
clientDataJSONHash := response.GetClientDataJSONHash()
attestationObject.AuthData = []byte("INVALID")
_, err = VerifyPackedAttestationStatement(attestationObject, clientDataJSONHash)
assert.ErrorIs(t, err, ErrInvalidAttestationStatement)
})
t.Run("invalid signature", func(t *testing.T) {
response := readTestAuthenticatorAttestationResponse(t, "Packed")
attestationObject, err := response.UnmarshalAttestationObject()
require.NoError(t, err)
clientDataJSONHash := response.GetClientDataJSONHash()
attestationObject.Statement["sig"] = []byte("INVALID")
_, err = VerifyPackedAttestationStatement(attestationObject, clientDataJSONHash)
assert.ErrorIs(t, err, ErrInvalidAttestationStatement)
})
}