-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
285 lines (254 loc) · 12.6 KB
/
struct.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package ctap
import (
"github.com/fxamacker/cbor/v2"
"github.com/tpc3/go-fido"
"github.com/veraison/go-cose"
)
const AuthenticatorMakeCredentialCommandId uint8 = 0x01
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorMakeCredentialRequest struct {
// Required
ClientDataHash []byte `cbor:"1,keyasint"`
// Required
RP fido.PublicKeyCredentialRpEntity `cbor:"2,keyasint"`
// Required
User fido.PublicKeyCredentialUserEntity `cbor:"3,keyasint"`
// Required
PubKeyCredParams []fido.PublicKeyCredentialParameters `cbor:"4,keyasint"`
// Optional
ExcludeList []fido.PublicKeyCredentialDescriptor `cbor:"5,keyasint,omitempty"`
// Optional
Extensions map[string]interface{} `cbor:"6,keyasint,omitempty"`
// Optional
Options AuthenticatorMakeCredentialRequestOptions `cbor:"7,keyasint,omitempty"`
// Optional
PinUvAuthParam []byte `cbor:"8,keyasint,omitempty"`
// Optional
PinUvAuthProtocol uint `cbor:"9,keyasint,omitempty"`
// Optional
EnterpriseAttestation uint `cbor:"10,keyasint,omitempty"`
}
type AuthenticatorMakeCredentialRequestOptions struct {
RK bool `cbor:"rk,omitempty"`
UP bool `cbor:"up,omitempty"`
UV *bool `cbor:"uv,omitempty"`
}
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorMakeCredentialResponse struct {
// Required
Fmt string `cbor:"1,keyasint"`
// Required
// Can be Decoded by AuthenticatorData.UnmarshalBinary()
AuthData []byte `cbor:"2,keyasint"`
// Required
AttStmt cbor.RawMessage `cbor:"3,keyasint"`
// Optional
EpAtt bool `cbor:"4,keyasint,omitempty"`
// Optional
LargeBlobKey []byte `cbor:"5,keyasint,omitempty"`
}
const AuthenticatorGetAssertionCommandId uint8 = 0x02
const AuthenticatorGetNextAssertionCommandId uint8 = 0x08
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorGetAssertionRequest struct {
// Required
RPID string `cbor:"1,keyasint"`
// Required
ClientDataHash []byte `cbor:"2,keyasint"`
// Optional
AllowList []fido.PublicKeyCredentialDescriptor `cbor:"3,keyasint,omitempty"`
// Optional
Extensions map[string]interface{} `cbor:"4,keyasint,omitempty"`
// Optional
Options AuthenticatorGetAssertionRequestOptions `cbor:"5,keyasint,omitempty"`
// Optional
PinUvAuthParam []byte `cbor:"6,keyasint,omitempty"`
// Optional
PinUvAuthProtocol uint `cbor:"7,keyasint,omitempty"`
}
type AuthenticatorGetAssertionRequestOptions struct {
UP bool `cbor:"up,omitempty"`
UV *bool `cbor:"uv,omitempty"`
}
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorGetAssertionResponse struct {
// Required
Credential fido.PublicKeyCredentialDescriptor `cbor:"1,keyasint"`
// Required
// Can be Decoded by AuthenticatorData.UnmarshalBinary()
AuthData []byte `cbor:"2,keyasint"`
// Required
Signature []byte `cbor:"3,keyasint"`
// Optional
User fido.PublicKeyCredentialUserEntity `cbor:"4,keyasint,omitempty"`
// Optional
NumberOfCredentials int `cbor:"5,keyasint,omitempty"`
// Optional
UserSelected bool `cbor:"6,keyasint,omitempty"`
// Optional
LargeBlobKey []byte `cbor:"7,keyasint,omitempty"`
}
const AuthenticatorGetInfoCommandId uint8 = 0x04
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorGetInfoResponse struct {
// Required
Version []string `cbor:"1,keyasint"`
// Optional
Extensions []string `cbor:"2,keyasint,omitempty"`
// Required
AAGUID []byte `cbor:"3,keyasint"`
// Optional
Options map[AuthenticatorGetInfoResopnseOptionID]bool `cbor:"4,keyasint,omitempty"`
// Optional
MaxMsgSize uint `cbor:"5,keyasint,omitempty"`
// Optional
PinUvAuthProtocols []uint `cbor:"6,keyasint,omitempty"`
// Optional
MaxCredentialCountInList uint `cbor:"7,keyasint,omitempty"`
// Optional
MaxCredentialIdLength uint `cbor:"8,keyasint,omitempty"`
// Optional
Transports []string `cbor:"9,keyasint,omitempty"`
// Optional
Algorithms []fido.PublicKeyCredentialParameters `cbor:"10,keyasint,omitempty"`
// Optional
MaxSerializedLargeBlobArray uint `cbor:"11,keyasint,omitempty"`
// Optional
ForcePINChange bool `cbor:"12,keyasint,omitempty"`
// Optional
MinPINLength uint `cbor:"13,keyasint,omitempty"`
// Optional
FirmwareVersion uint `cbor:"14,keyasint,omitempty"`
// Optional
MaxCredBlobLength uint `cbor:"15,keyasint,omitempty"`
// Optional
MaxRPIDsForSetMinPINLength uint `cbor:"16,keyasint,omitempty"`
// Optional
PreferredPlatformUvAttempts uint `cbor:"17,keyasint,omitempty"`
// Optional
UvModality uint `cbor:"18,keyasint,omitempty"`
// Optional
Certifications map[any]any `cbor:"19,keyasint,omitempty"`
// Optional
RemainingDiscoverableCredentials uint `cbor:"20,keyasint,omitempty"`
// Optional
VendorPrototypeConfigCommands []uint `cbor:"21,keyasint,omitempty"`
// WIP
}
func (i *AuthenticatorGetInfoResponse) IsOptionTrue(option AuthenticatorGetInfoResopnseOptionID) bool {
opt, ok := i.Options[option]
return ok && opt
}
type AuthenticatorCTAPVersion string
const (
AuthenticatorCTAPVersion1 AuthenticatorCTAPVersion = "U2F_V2"
AuthenticatorCTAPVersion2_0 AuthenticatorCTAPVersion = "FIDO_2_0"
AuthenticatorCTAPVersion2_1_PRE AuthenticatorCTAPVersion = "FIDO_2_1_PRE"
AuthenticatorCTAPVersion2_1 AuthenticatorCTAPVersion = "FIDO_2_1"
)
type AuthenticatorGetInfoResopnseOptionID string
const AuthenticatorClientPINCommandId uint8 = 0x06
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorClientPINRequest struct {
// Optional
PinUvAuthProtocol uint `cbor:"1,keyasint,omitempty"`
// Required
SubCommand AuthenticatorClientPINRequestSubCommand `cbor:"2,keyasint"`
// Optional
KeyAgreement *PinUvAuthProtocolKey `cbor:"3,keyasint,omitempty"`
// Optional
PinUvAuthParam []byte `cbor:"4,keyasint,omitempty"`
// Optional
NewPinEnc []byte `cbor:"5,keyasint,omitempty"`
// Optional
PinHashEnc []byte `cbor:"6,keyasint,omitempty"`
// Optional
Permissions PinUvAuthTokenPermission `cbor:"4,keyasint,omitempty"`
// Optional
RPID string `cbor:"10,keyasint,omitempty"`
}
type AuthenticatorClientPINRequestSubCommand uint
const (
AuthenticatorClientPINRequestSubCommandGetPINRetries AuthenticatorClientPINRequestSubCommand = 0x01
AuthenticatorClientPINRequestSubCommandGetKeyAgreement AuthenticatorClientPINRequestSubCommand = 0x02
AuthenticatorClientPINRequestSubCommandSetPIN AuthenticatorClientPINRequestSubCommand = 0x03
AuthenticatorClientPINRequestSubCommandChangePIN AuthenticatorClientPINRequestSubCommand = 0x04
AuthenticatorClientPINRequestSubCommandGetPINToken AuthenticatorClientPINRequestSubCommand = 0x05
AuthenticatorClientPINRequestSubCommandGetPinUvAuthTokenUsingUvWithPermissions AuthenticatorClientPINRequestSubCommand = 0x06
AuthenticatorClientPINRequestSubCommandGetUVRetries AuthenticatorClientPINRequestSubCommand = 0x07
AuthenticatorClientPINRequestSubCommandGetPinUvAuthTokenUsingPinWithPermissions AuthenticatorClientPINRequestSubCommand = 0x09
)
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#gettingPinUvAuthToken
type PinUvAuthTokenPermission uint
const (
PinUvAuthTokenPermissionMakeCredential PinUvAuthTokenPermission = 0x01
PinUvAuthTokenPermissionGetAssertion PinUvAuthTokenPermission = 0x02
PinUvAuthTokenPermissionCredentialManagement PinUvAuthTokenPermission = 0x04
PinUvAuthTokenPermissionBioEnrollment PinUvAuthTokenPermission = 0x08
PinUvAuthTokenPermissionLargeBlobWrite PinUvAuthTokenPermission = 0x10
PinUvAuthTokenPermissionAuthenticatorConfiguration PinUvAuthTokenPermission = 0x20
)
type AuthenticatorClientPINRequestOptions struct {
UP bool `cbor:"up,omitempty"`
UV *bool `cbor:"uv,omitempty"`
}
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorClientPINResponse struct {
// Optional
KeyAgreement *PinUvAuthProtocolKey `cbor:"1,keyasint,omitempty"`
// Optional
PinUvAuthToken []byte `cbor:"2,keyasint,omitempty"`
// Optional
PinRetries uint `cbor:"3,keyasint,omitempty"`
// Optional
PowerCycleState bool `cbor:"4,keyasint,omitempty"`
// Optional
UvRetries uint `cbor:"5,keyasint,omitempty"`
}
type PinUvAuthProtocolKey struct {
*cose.Key
}
func (k *PinUvAuthProtocolKey) UnmarshalCBOR(data []byte) error {
// Ignore error because their alg is -25(invalid)
k.Key = &cose.Key{}
k.Key.UnmarshalCBOR(data)
return nil
}
const AuthenticatorCredentialManagementCommandId uint8 = 0x0A
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorCredentialManagementRequest struct {
SubCommand AuthenticatorCredentialManagementRequestSubCommand `cbor:"1,keyasint"`
SubCommandParams *AuthenticatorCredentialManagementRequestSubCommandParams `cbor:"2,keyasint,omitempty"`
PinUvAuthProtocol uint `cbor:"3,keyasint,omitempty"`
PinUvAuthParam []byte `cbor:"4,keyasint,omitempty"`
}
type AuthenticatorCredentialManagementRequestSubCommand uint
const (
AuthenticatorCredentialManagementRequestSubCommandGetCredsMetadata AuthenticatorCredentialManagementRequestSubCommand = 0x01
AuthenticatorCredentialManagementRequestSubCommandEnumlateRPsBegin AuthenticatorCredentialManagementRequestSubCommand = 0x02
AuthenticatorCredentialManagementRequestSubCommandEnumlateRPsGetNextRP AuthenticatorCredentialManagementRequestSubCommand = 0x03
AuthenticatorCredentialManagementRequestSubCommandEnumlateCredentialsBegin AuthenticatorCredentialManagementRequestSubCommand = 0x04
AuthenticatorCredentialManagementRequestSubCommandEnumlateCredentialsGetNextCredential AuthenticatorCredentialManagementRequestSubCommand = 0x05
AuthenticatorCredentialManagementRequestSubCommandDeleteCredential AuthenticatorCredentialManagementRequestSubCommand = 0x06
AuthenticatorCredentialManagementRequestSubCommandUpdateUserInformation AuthenticatorCredentialManagementRequestSubCommand = 0x07
)
type AuthenticatorCredentialManagementRequestSubCommandParams struct {
RPIDHash []byte `cbor:"1,keyasint,omitempty"`
CredentialID *fido.PublicKeyCredentialDescriptor `cbor:"2,keyasint,omitempty"`
User *fido.PublicKeyCredentialUserEntity `cbor:"3,keyasint,omitempty"`
}
// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorMakeCredential
type AuthenticatorCredentialManagementResponse struct {
ExistingResidentCredentialsCount uint `cbor:"1,keyasint,omitempty"`
MaxPossibleRemainingResidentCredentialsCount uint `cbor:"2,keyasint,omitempty"`
RP fido.PublicKeyCredentialRpEntity `cbor:"3,keyasint,omitempty"`
RPIDHash []byte `cbor:"4,keyasint,omitempty"`
TotalRPs uint `cbor:"5,keyasint,omitempty"`
User fido.PublicKeyCredentialUserEntity `cbor:"6,keyasint,omitempty"`
CredentialID fido.PublicKeyCredentialDescriptor `cbor:"7,keyasint,omitempty"`
PublicKey *cose.Key `cbor:"8,keyasint,omitempty"`
TotalCredentials uint `cbor:"9,keyasint,omitempty"`
CredProtect uint `cbor:"10,keyasint,omitempty"`
LargeBlobKey []byte `cbor:"11,keyasint,omitempty"`
ThirdPartyPayment bool `cbor:"12,keyasint,omitempty"`
}