/
webauthn.go
332 lines (289 loc) · 10.8 KB
/
webauthn.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Package webauthn provides the Chrome DevTools Protocol
// commands, types, and events for the WebAuthn domain.
//
// This domain allows configuring virtual authenticators to test the WebAuthn
// API.
//
// Generated by the cdproto-gen command.
package webauthn
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"context"
"github.com/goconnectx/cdproto/cdp"
)
// EnableParams enable the WebAuthn domain and start intercepting credential
// storage and retrieval with a virtual authenticator.
type EnableParams struct{}
// Enable enable the WebAuthn domain and start intercepting credential
// storage and retrieval with a virtual authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-enable
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes WebAuthn.enable against the provided context.
func (p *EnableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandEnable, nil, nil)
}
// DisableParams disable the WebAuthn domain.
type DisableParams struct{}
// Disable disable the WebAuthn domain.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-disable
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes WebAuthn.disable against the provided context.
func (p *DisableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandDisable, nil, nil)
}
// AddVirtualAuthenticatorParams creates and adds a virtual authenticator.
type AddVirtualAuthenticatorParams struct {
Options *VirtualAuthenticatorOptions `json:"options"`
}
// AddVirtualAuthenticator creates and adds a virtual authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-addVirtualAuthenticator
//
// parameters:
// options
func AddVirtualAuthenticator(options *VirtualAuthenticatorOptions) *AddVirtualAuthenticatorParams {
return &AddVirtualAuthenticatorParams{
Options: options,
}
}
// AddVirtualAuthenticatorReturns return values.
type AddVirtualAuthenticatorReturns struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId,omitempty"`
}
// Do executes WebAuthn.addVirtualAuthenticator against the provided context.
//
// returns:
// authenticatorID
func (p *AddVirtualAuthenticatorParams) Do(ctx context.Context) (authenticatorID AuthenticatorID, err error) {
// execute
var res AddVirtualAuthenticatorReturns
err = cdp.Execute(ctx, CommandAddVirtualAuthenticator, p, &res)
if err != nil {
return "", err
}
return res.AuthenticatorID, nil
}
// RemoveVirtualAuthenticatorParams removes the given authenticator.
type RemoveVirtualAuthenticatorParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
}
// RemoveVirtualAuthenticator removes the given authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-removeVirtualAuthenticator
//
// parameters:
// authenticatorID
func RemoveVirtualAuthenticator(authenticatorID AuthenticatorID) *RemoveVirtualAuthenticatorParams {
return &RemoveVirtualAuthenticatorParams{
AuthenticatorID: authenticatorID,
}
}
// Do executes WebAuthn.removeVirtualAuthenticator against the provided context.
func (p *RemoveVirtualAuthenticatorParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandRemoveVirtualAuthenticator, p, nil)
}
// AddCredentialParams adds the credential to the specified authenticator.
type AddCredentialParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
Credential *Credential `json:"credential"`
}
// AddCredential adds the credential to the specified authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-addCredential
//
// parameters:
// authenticatorID
// credential
func AddCredential(authenticatorID AuthenticatorID, credential *Credential) *AddCredentialParams {
return &AddCredentialParams{
AuthenticatorID: authenticatorID,
Credential: credential,
}
}
// Do executes WebAuthn.addCredential against the provided context.
func (p *AddCredentialParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandAddCredential, p, nil)
}
// GetCredentialParams returns a single credential stored in the given
// virtual authenticator that matches the credential ID.
type GetCredentialParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
CredentialID string `json:"credentialId"`
}
// GetCredential returns a single credential stored in the given virtual
// authenticator that matches the credential ID.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-getCredential
//
// parameters:
// authenticatorID
// credentialID
func GetCredential(authenticatorID AuthenticatorID, credentialID string) *GetCredentialParams {
return &GetCredentialParams{
AuthenticatorID: authenticatorID,
CredentialID: credentialID,
}
}
// GetCredentialReturns return values.
type GetCredentialReturns struct {
Credential *Credential `json:"credential,omitempty"`
}
// Do executes WebAuthn.getCredential against the provided context.
//
// returns:
// credential
func (p *GetCredentialParams) Do(ctx context.Context) (credential *Credential, err error) {
// execute
var res GetCredentialReturns
err = cdp.Execute(ctx, CommandGetCredential, p, &res)
if err != nil {
return nil, err
}
return res.Credential, nil
}
// GetCredentialsParams returns all the credentials stored in the given
// virtual authenticator.
type GetCredentialsParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
}
// GetCredentials returns all the credentials stored in the given virtual
// authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-getCredentials
//
// parameters:
// authenticatorID
func GetCredentials(authenticatorID AuthenticatorID) *GetCredentialsParams {
return &GetCredentialsParams{
AuthenticatorID: authenticatorID,
}
}
// GetCredentialsReturns return values.
type GetCredentialsReturns struct {
Credentials []*Credential `json:"credentials,omitempty"`
}
// Do executes WebAuthn.getCredentials against the provided context.
//
// returns:
// credentials
func (p *GetCredentialsParams) Do(ctx context.Context) (credentials []*Credential, err error) {
// execute
var res GetCredentialsReturns
err = cdp.Execute(ctx, CommandGetCredentials, p, &res)
if err != nil {
return nil, err
}
return res.Credentials, nil
}
// RemoveCredentialParams removes a credential from the authenticator.
type RemoveCredentialParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
CredentialID string `json:"credentialId"`
}
// RemoveCredential removes a credential from the authenticator.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-removeCredential
//
// parameters:
// authenticatorID
// credentialID
func RemoveCredential(authenticatorID AuthenticatorID, credentialID string) *RemoveCredentialParams {
return &RemoveCredentialParams{
AuthenticatorID: authenticatorID,
CredentialID: credentialID,
}
}
// Do executes WebAuthn.removeCredential against the provided context.
func (p *RemoveCredentialParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandRemoveCredential, p, nil)
}
// ClearCredentialsParams clears all the credentials from the specified
// device.
type ClearCredentialsParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
}
// ClearCredentials clears all the credentials from the specified device.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-clearCredentials
//
// parameters:
// authenticatorID
func ClearCredentials(authenticatorID AuthenticatorID) *ClearCredentialsParams {
return &ClearCredentialsParams{
AuthenticatorID: authenticatorID,
}
}
// Do executes WebAuthn.clearCredentials against the provided context.
func (p *ClearCredentialsParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandClearCredentials, p, nil)
}
// SetUserVerifiedParams sets whether User Verification succeeds or fails for
// an authenticator. The default is true.
type SetUserVerifiedParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
IsUserVerified bool `json:"isUserVerified"`
}
// SetUserVerified sets whether User Verification succeeds or fails for an
// authenticator. The default is true.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setUserVerified
//
// parameters:
// authenticatorID
// isUserVerified
func SetUserVerified(authenticatorID AuthenticatorID, isUserVerified bool) *SetUserVerifiedParams {
return &SetUserVerifiedParams{
AuthenticatorID: authenticatorID,
IsUserVerified: isUserVerified,
}
}
// Do executes WebAuthn.setUserVerified against the provided context.
func (p *SetUserVerifiedParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandSetUserVerified, p, nil)
}
// SetAutomaticPresenceSimulationParams sets whether tests of user presence
// will succeed immediately (if true) or fail to resolve (if false) for an
// authenticator. The default is true.
type SetAutomaticPresenceSimulationParams struct {
AuthenticatorID AuthenticatorID `json:"authenticatorId"`
Enabled bool `json:"enabled"`
}
// SetAutomaticPresenceSimulation sets whether tests of user presence will
// succeed immediately (if true) or fail to resolve (if false) for an
// authenticator. The default is true.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setAutomaticPresenceSimulation
//
// parameters:
// authenticatorID
// enabled
func SetAutomaticPresenceSimulation(authenticatorID AuthenticatorID, enabled bool) *SetAutomaticPresenceSimulationParams {
return &SetAutomaticPresenceSimulationParams{
AuthenticatorID: authenticatorID,
Enabled: enabled,
}
}
// Do executes WebAuthn.setAutomaticPresenceSimulation against the provided context.
func (p *SetAutomaticPresenceSimulationParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandSetAutomaticPresenceSimulation, p, nil)
}
// Command names.
const (
CommandEnable = "WebAuthn.enable"
CommandDisable = "WebAuthn.disable"
CommandAddVirtualAuthenticator = "WebAuthn.addVirtualAuthenticator"
CommandRemoveVirtualAuthenticator = "WebAuthn.removeVirtualAuthenticator"
CommandAddCredential = "WebAuthn.addCredential"
CommandGetCredential = "WebAuthn.getCredential"
CommandGetCredentials = "WebAuthn.getCredentials"
CommandRemoveCredential = "WebAuthn.removeCredential"
CommandClearCredentials = "WebAuthn.clearCredentials"
CommandSetUserVerified = "WebAuthn.setUserVerified"
CommandSetAutomaticPresenceSimulation = "WebAuthn.setAutomaticPresenceSimulation"
)