/
models.go
132 lines (113 loc) · 4.57 KB
/
models.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package webauthn
type (
// RegistrationParts is the object sent back to the Javascript
RegistrationParts struct {
PublicKey PublicKeyCredentialOptions `json:"publicKey"`
}
// PublicKeyCredentialOptions credentails needed for
// https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptions
PublicKeyCredentialOptions struct {
RP RpEntity `json:"rp"`
User UserEntity `json:"user"`
PubKeyCredParams []Parameters `json:"pubKeyCredParams"`
Timeout uint `json:"timeout"`
// Exclude Credentials
// authenticatorSelection - https://w3c.github.io/webauthn/#dictdef-authenticatorselectioncriteria
Attestation AttestationConveyancePreference `json:"attestation"`
// extensions
// This will need to be changed to an ArrayBuffer in JavaScript
Challenge []byte `json:"challenge"`
}
//RpEntity is the Relying Party entity
// https://w3c.github.io/webauthn/#dictdef-publickeycredentialrpentity
RpEntity struct {
// The ID is the hosts domain name - https://w3c.github.io/webauthn/#relying-party-identifier
ID string `json:"id,omitempty"` // In Spec, but not required in chrome
Name string `json:"name"` // Not in spec, but required in chrome
}
// UserEntity TODO
UserEntity struct {
ID []byte `json:"id"` // In Spec, but not required in chrome
Name string `json:"name"` // Not in spec, but required in chrome
DisplayName string `json:"displayName"` // Not in spec, but required in chrome
}
// Parameters TODO
Parameters struct {
// https://w3c.github.io/webauthn/#enumdef-publickeycredentialtype
Type PublicKeyCredentialType `json:"type"`
//https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
Alg int `json:"alg"`
}
// PublicKeyCredentialType emun - https://w3c.github.io/webauthn/#enumdef-publickeycredentialtype
PublicKeyCredentialType string
// AttestationConveyancePreference enum - https://w3c.github.io/webauthn/#enumdef-attestationconveyancepreference
AttestationConveyancePreference string
)
// PublicKeyCredentialResponse from the response of a navigator.credentials.create/navigator.credentials.get;
type (
PublicKeyCredentialResponse struct {
// Used in registration
ClientDataJSON Base64EncodedString `json:"clientDataJSON"`
AttestationObject Base64EncodedString `json:"attestationObject"`
// Used in authentication
AuthenticatorData Base64EncodedString `json:"authenticatorData"`
Signature Base64EncodedString `json:"signature"`
UserHandle Base64EncodedString `json:"userHandle"`
}
//PublicKeyCredential - https://w3c.github.io/webauthn/#publickeycredential
PublicKeyCredential struct {
ID string `json:"id"`
RawID Base64EncodedString `json:"rawId"`
Response PublicKeyCredentialResponse `json:"response"`
Type string `json:"type"`
}
)
type (
// Attestation Object that can be decoded from the response from `navigator.credentials.create()`
// https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAttestationResponse/attestationObject
Attestation struct {
Fmt string `json:"fmt"`
AuthData []byte `json:"authData"`
AttStmt AttStmt `json:"attStmt"`
}
// AttStmt attestation statement
AttStmt struct {
Sig []uint8 `json:"sig"`
X5c []interface{} `json:"x5c"`
}
)
type (
// CollectedClientData represents the contextual bindings of both the WebAuthn Relying Party and the client platform
// https://w3c.github.io/webauthn/#dictdef-collectedclientdata
CollectedClientData struct {
Type string `json:"type"`
Challenge string `json:"challenge"`
Origin string `json:"origin"`
TokenBinding TokenBinding `json:"tokenBinding"`
}
// TokenBinding is an OPTIONAL member that contains information about the state of the Token Binding protocol used when communicating with the Relying Party. Its absence indicates that the client doesn’t support token binding.
// https://w3c.github.io/webauthn/#dictdef-tokenbinding
TokenBinding struct {
ID string `json:"id"`
Status TokenBindingStatus `json:"status"`
}
// TokenBindingStatus is an enum for TokenBindingStatus values
TokenBindingStatus string
)
type (
// AuthenticatorData TODO
AuthenticatorData struct {
rpIDHash string
flags AuthenticatorDataFlags
signCount uint32
//attestedCredentialData
// extensions
}
// AuthenticatorDataFlags TODO
AuthenticatorDataFlags struct {
userPresent bool
userVerified bool
hasAttestedCredentialData bool
hasExtensions bool
}
)