Skip to main content

browser_protocol/webauthn/
mod.rs

1//! This domain allows configuring virtual authenticators to test the WebAuthn
2//! API.
3
4
5use serde::{Serialize, Deserialize};
6use serde_json::Value as JsonValue;
7use std::borrow::Cow;
8
9
10pub type AuthenticatorId<'a> = Cow<'a, str>;
11
12
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
14pub enum AuthenticatorProtocol {
15    #[default]
16    #[serde(rename = "u2f")]
17    U2f,
18    #[serde(rename = "ctap2")]
19    Ctap2,
20}
21
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
24pub enum Ctap2Version {
25    #[default]
26    #[serde(rename = "ctap2_0")]
27    Ctap20,
28    #[serde(rename = "ctap2_1")]
29    Ctap21,
30    #[serde(rename = "ctap2_2")]
31    Ctap22,
32}
33
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
36pub enum AuthenticatorTransport {
37    #[default]
38    #[serde(rename = "usb")]
39    Usb,
40    #[serde(rename = "nfc")]
41    Nfc,
42    #[serde(rename = "ble")]
43    Ble,
44    #[serde(rename = "cable")]
45    Cable,
46    #[serde(rename = "internal")]
47    Internal,
48}
49
50
51#[derive(Debug, Clone, Serialize, Deserialize, Default)]
52#[serde(rename_all = "camelCase")]
53pub struct VirtualAuthenticatorOptions {
54    protocol: AuthenticatorProtocol,
55    /// Defaults to ctap2_0. Ignored if |protocol| == u2f.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    ctap2Version: Option<Ctap2Version>,
58    transport: AuthenticatorTransport,
59    /// Defaults to false.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    hasResidentKey: Option<bool>,
62    /// Defaults to false.
63    #[serde(skip_serializing_if = "Option::is_none")]
64    hasUserVerification: Option<bool>,
65    /// If set to true, the authenticator will support the largeBlob extension.
66    /// https://w3c.github.io/webauthn#largeBlob
67    /// Defaults to false.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    hasLargeBlob: Option<bool>,
70    /// If set to true, the authenticator will support the credBlob extension.
71    /// https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-credBlob-extension
72    /// Defaults to false.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    hasCredBlob: Option<bool>,
75    /// If set to true, the authenticator will support the minPinLength extension.
76    /// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-minpinlength-extension
77    /// Defaults to false.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    hasMinPinLength: Option<bool>,
80    /// If set to true, the authenticator will support the prf extension.
81    /// https://w3c.github.io/webauthn/#prf-extension
82    /// Defaults to false.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    hasPrf: Option<bool>,
85    /// If set to true, the authenticator will support the hmac-secret extension.
86    /// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-hmac-secret-extension
87    /// Defaults to false.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    hasHmacSecret: Option<bool>,
90    /// If set to true, the authenticator will support the hmac-secret-mc extension.
91    /// https://fidoalliance.org/specs/fido-v2.2-rd-20241003/fido-client-to-authenticator-protocol-v2.2-rd-20241003.html#sctn-hmac-secret-make-cred-extension
92    /// Defaults to false.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    hasHmacSecretMc: Option<bool>,
95    /// If set to true, tests of user presence will succeed immediately.
96    /// Otherwise, they will not be resolved. Defaults to true.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    automaticPresenceSimulation: Option<bool>,
99    /// Sets whether User Verification succeeds or fails for an authenticator.
100    /// Defaults to false.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    isUserVerified: Option<bool>,
103    /// Credentials created by this authenticator will have the backup
104    /// eligibility (BE) flag set to this value. Defaults to false.
105    /// https://w3c.github.io/webauthn/#sctn-credential-backup
106    #[serde(skip_serializing_if = "Option::is_none")]
107    defaultBackupEligibility: Option<bool>,
108    /// Credentials created by this authenticator will have the backup state
109    /// (BS) flag set to this value. Defaults to false.
110    /// https://w3c.github.io/webauthn/#sctn-credential-backup
111    #[serde(skip_serializing_if = "Option::is_none")]
112    defaultBackupState: Option<bool>,
113}
114
115impl VirtualAuthenticatorOptions {
116    pub fn builder(protocol: AuthenticatorProtocol, transport: AuthenticatorTransport) -> VirtualAuthenticatorOptionsBuilder {
117        VirtualAuthenticatorOptionsBuilder {
118            protocol: protocol,
119            ctap2Version: None,
120            transport: transport,
121            hasResidentKey: None,
122            hasUserVerification: None,
123            hasLargeBlob: None,
124            hasCredBlob: None,
125            hasMinPinLength: None,
126            hasPrf: None,
127            hasHmacSecret: None,
128            hasHmacSecretMc: None,
129            automaticPresenceSimulation: None,
130            isUserVerified: None,
131            defaultBackupEligibility: None,
132            defaultBackupState: None,
133        }
134    }
135    pub fn protocol(&self) -> &AuthenticatorProtocol { &self.protocol }
136    pub fn ctap2Version(&self) -> Option<&Ctap2Version> { self.ctap2Version.as_ref() }
137    pub fn transport(&self) -> &AuthenticatorTransport { &self.transport }
138    pub fn hasResidentKey(&self) -> Option<bool> { self.hasResidentKey }
139    pub fn hasUserVerification(&self) -> Option<bool> { self.hasUserVerification }
140    pub fn hasLargeBlob(&self) -> Option<bool> { self.hasLargeBlob }
141    pub fn hasCredBlob(&self) -> Option<bool> { self.hasCredBlob }
142    pub fn hasMinPinLength(&self) -> Option<bool> { self.hasMinPinLength }
143    pub fn hasPrf(&self) -> Option<bool> { self.hasPrf }
144    pub fn hasHmacSecret(&self) -> Option<bool> { self.hasHmacSecret }
145    pub fn hasHmacSecretMc(&self) -> Option<bool> { self.hasHmacSecretMc }
146    pub fn automaticPresenceSimulation(&self) -> Option<bool> { self.automaticPresenceSimulation }
147    pub fn isUserVerified(&self) -> Option<bool> { self.isUserVerified }
148    pub fn defaultBackupEligibility(&self) -> Option<bool> { self.defaultBackupEligibility }
149    pub fn defaultBackupState(&self) -> Option<bool> { self.defaultBackupState }
150}
151
152
153pub struct VirtualAuthenticatorOptionsBuilder {
154    protocol: AuthenticatorProtocol,
155    ctap2Version: Option<Ctap2Version>,
156    transport: AuthenticatorTransport,
157    hasResidentKey: Option<bool>,
158    hasUserVerification: Option<bool>,
159    hasLargeBlob: Option<bool>,
160    hasCredBlob: Option<bool>,
161    hasMinPinLength: Option<bool>,
162    hasPrf: Option<bool>,
163    hasHmacSecret: Option<bool>,
164    hasHmacSecretMc: Option<bool>,
165    automaticPresenceSimulation: Option<bool>,
166    isUserVerified: Option<bool>,
167    defaultBackupEligibility: Option<bool>,
168    defaultBackupState: Option<bool>,
169}
170
171impl VirtualAuthenticatorOptionsBuilder {
172    /// Defaults to ctap2_0. Ignored if |protocol| == u2f.
173    pub fn ctap2Version(mut self, ctap2Version: Ctap2Version) -> Self { self.ctap2Version = Some(ctap2Version); self }
174    /// Defaults to false.
175    pub fn hasResidentKey(mut self, hasResidentKey: bool) -> Self { self.hasResidentKey = Some(hasResidentKey); self }
176    /// Defaults to false.
177    pub fn hasUserVerification(mut self, hasUserVerification: bool) -> Self { self.hasUserVerification = Some(hasUserVerification); self }
178    /// If set to true, the authenticator will support the largeBlob extension.
179    /// https://w3c.github.io/webauthn#largeBlob
180    /// Defaults to false.
181    pub fn hasLargeBlob(mut self, hasLargeBlob: bool) -> Self { self.hasLargeBlob = Some(hasLargeBlob); self }
182    /// If set to true, the authenticator will support the credBlob extension.
183    /// https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-credBlob-extension
184    /// Defaults to false.
185    pub fn hasCredBlob(mut self, hasCredBlob: bool) -> Self { self.hasCredBlob = Some(hasCredBlob); self }
186    /// If set to true, the authenticator will support the minPinLength extension.
187    /// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-minpinlength-extension
188    /// Defaults to false.
189    pub fn hasMinPinLength(mut self, hasMinPinLength: bool) -> Self { self.hasMinPinLength = Some(hasMinPinLength); self }
190    /// If set to true, the authenticator will support the prf extension.
191    /// https://w3c.github.io/webauthn/#prf-extension
192    /// Defaults to false.
193    pub fn hasPrf(mut self, hasPrf: bool) -> Self { self.hasPrf = Some(hasPrf); self }
194    /// If set to true, the authenticator will support the hmac-secret extension.
195    /// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-hmac-secret-extension
196    /// Defaults to false.
197    pub fn hasHmacSecret(mut self, hasHmacSecret: bool) -> Self { self.hasHmacSecret = Some(hasHmacSecret); self }
198    /// If set to true, the authenticator will support the hmac-secret-mc extension.
199    /// https://fidoalliance.org/specs/fido-v2.2-rd-20241003/fido-client-to-authenticator-protocol-v2.2-rd-20241003.html#sctn-hmac-secret-make-cred-extension
200    /// Defaults to false.
201    pub fn hasHmacSecretMc(mut self, hasHmacSecretMc: bool) -> Self { self.hasHmacSecretMc = Some(hasHmacSecretMc); self }
202    /// If set to true, tests of user presence will succeed immediately.
203    /// Otherwise, they will not be resolved. Defaults to true.
204    pub fn automaticPresenceSimulation(mut self, automaticPresenceSimulation: bool) -> Self { self.automaticPresenceSimulation = Some(automaticPresenceSimulation); self }
205    /// Sets whether User Verification succeeds or fails for an authenticator.
206    /// Defaults to false.
207    pub fn isUserVerified(mut self, isUserVerified: bool) -> Self { self.isUserVerified = Some(isUserVerified); self }
208    /// Credentials created by this authenticator will have the backup
209    /// eligibility (BE) flag set to this value. Defaults to false.
210    /// https://w3c.github.io/webauthn/#sctn-credential-backup
211    pub fn defaultBackupEligibility(mut self, defaultBackupEligibility: bool) -> Self { self.defaultBackupEligibility = Some(defaultBackupEligibility); self }
212    /// Credentials created by this authenticator will have the backup state
213    /// (BS) flag set to this value. Defaults to false.
214    /// https://w3c.github.io/webauthn/#sctn-credential-backup
215    pub fn defaultBackupState(mut self, defaultBackupState: bool) -> Self { self.defaultBackupState = Some(defaultBackupState); self }
216    pub fn build(self) -> VirtualAuthenticatorOptions {
217        VirtualAuthenticatorOptions {
218            protocol: self.protocol,
219            ctap2Version: self.ctap2Version,
220            transport: self.transport,
221            hasResidentKey: self.hasResidentKey,
222            hasUserVerification: self.hasUserVerification,
223            hasLargeBlob: self.hasLargeBlob,
224            hasCredBlob: self.hasCredBlob,
225            hasMinPinLength: self.hasMinPinLength,
226            hasPrf: self.hasPrf,
227            hasHmacSecret: self.hasHmacSecret,
228            hasHmacSecretMc: self.hasHmacSecretMc,
229            automaticPresenceSimulation: self.automaticPresenceSimulation,
230            isUserVerified: self.isUserVerified,
231            defaultBackupEligibility: self.defaultBackupEligibility,
232            defaultBackupState: self.defaultBackupState,
233        }
234    }
235}
236
237
238#[derive(Debug, Clone, Serialize, Deserialize, Default)]
239#[serde(rename_all = "camelCase")]
240pub struct Credential<'a> {
241    credentialId: Cow<'a, str>,
242    isResidentCredential: bool,
243    /// Relying Party ID the credential is scoped to. Must be set when adding a
244    /// credential.
245    #[serde(skip_serializing_if = "Option::is_none")]
246    rpId: Option<Cow<'a, str>>,
247    /// The ECDSA P-256 private key in PKCS#8 format. (Encoded as a base64 string when passed over JSON)
248    privateKey: Cow<'a, str>,
249    /// An opaque byte sequence with a maximum size of 64 bytes mapping the
250    /// credential to a specific user. (Encoded as a base64 string when passed over JSON)
251    #[serde(skip_serializing_if = "Option::is_none")]
252    userHandle: Option<Cow<'a, str>>,
253    /// Signature counter. This is incremented by one for each successful
254    /// assertion.
255    /// See https://w3c.github.io/webauthn/#signature-counter
256    signCount: u64,
257    /// The large blob associated with the credential.
258    /// See https://w3c.github.io/webauthn/#sctn-large-blob-extension (Encoded as a base64 string when passed over JSON)
259    #[serde(skip_serializing_if = "Option::is_none")]
260    largeBlob: Option<Cow<'a, str>>,
261    /// Assertions returned by this credential will have the backup eligibility
262    /// (BE) flag set to this value. Defaults to the authenticator's
263    /// defaultBackupEligibility value.
264    #[serde(skip_serializing_if = "Option::is_none")]
265    backupEligibility: Option<bool>,
266    /// Assertions returned by this credential will have the backup state (BS)
267    /// flag set to this value. Defaults to the authenticator's
268    /// defaultBackupState value.
269    #[serde(skip_serializing_if = "Option::is_none")]
270    backupState: Option<bool>,
271    /// The credential's user.name property. Equivalent to empty if not set.
272    /// https://w3c.github.io/webauthn/#dom-publickeycredentialentity-name
273    #[serde(skip_serializing_if = "Option::is_none")]
274    userName: Option<Cow<'a, str>>,
275    /// The credential's user.displayName property. Equivalent to empty if
276    /// not set.
277    /// https://w3c.github.io/webauthn/#dom-publickeycredentialuserentity-displayname
278    #[serde(skip_serializing_if = "Option::is_none")]
279    userDisplayName: Option<Cow<'a, str>>,
280}
281
282impl<'a> Credential<'a> {
283    pub fn builder(credentialId: impl Into<Cow<'a, str>>, isResidentCredential: bool, privateKey: impl Into<Cow<'a, str>>, signCount: u64) -> CredentialBuilder<'a> {
284        CredentialBuilder {
285            credentialId: credentialId.into(),
286            isResidentCredential: isResidentCredential,
287            rpId: None,
288            privateKey: privateKey.into(),
289            userHandle: None,
290            signCount: signCount,
291            largeBlob: None,
292            backupEligibility: None,
293            backupState: None,
294            userName: None,
295            userDisplayName: None,
296        }
297    }
298    pub fn credentialId(&self) -> &str { self.credentialId.as_ref() }
299    pub fn isResidentCredential(&self) -> bool { self.isResidentCredential }
300    pub fn rpId(&self) -> Option<&str> { self.rpId.as_deref() }
301    pub fn privateKey(&self) -> &str { self.privateKey.as_ref() }
302    pub fn userHandle(&self) -> Option<&str> { self.userHandle.as_deref() }
303    pub fn signCount(&self) -> u64 { self.signCount }
304    pub fn largeBlob(&self) -> Option<&str> { self.largeBlob.as_deref() }
305    pub fn backupEligibility(&self) -> Option<bool> { self.backupEligibility }
306    pub fn backupState(&self) -> Option<bool> { self.backupState }
307    pub fn userName(&self) -> Option<&str> { self.userName.as_deref() }
308    pub fn userDisplayName(&self) -> Option<&str> { self.userDisplayName.as_deref() }
309}
310
311
312pub struct CredentialBuilder<'a> {
313    credentialId: Cow<'a, str>,
314    isResidentCredential: bool,
315    rpId: Option<Cow<'a, str>>,
316    privateKey: Cow<'a, str>,
317    userHandle: Option<Cow<'a, str>>,
318    signCount: u64,
319    largeBlob: Option<Cow<'a, str>>,
320    backupEligibility: Option<bool>,
321    backupState: Option<bool>,
322    userName: Option<Cow<'a, str>>,
323    userDisplayName: Option<Cow<'a, str>>,
324}
325
326impl<'a> CredentialBuilder<'a> {
327    /// Relying Party ID the credential is scoped to. Must be set when adding a
328    /// credential.
329    pub fn rpId(mut self, rpId: impl Into<Cow<'a, str>>) -> Self { self.rpId = Some(rpId.into()); self }
330    /// An opaque byte sequence with a maximum size of 64 bytes mapping the
331    /// credential to a specific user. (Encoded as a base64 string when passed over JSON)
332    pub fn userHandle(mut self, userHandle: impl Into<Cow<'a, str>>) -> Self { self.userHandle = Some(userHandle.into()); self }
333    /// The large blob associated with the credential.
334    /// See https://w3c.github.io/webauthn/#sctn-large-blob-extension (Encoded as a base64 string when passed over JSON)
335    pub fn largeBlob(mut self, largeBlob: impl Into<Cow<'a, str>>) -> Self { self.largeBlob = Some(largeBlob.into()); self }
336    /// Assertions returned by this credential will have the backup eligibility
337    /// (BE) flag set to this value. Defaults to the authenticator's
338    /// defaultBackupEligibility value.
339    pub fn backupEligibility(mut self, backupEligibility: bool) -> Self { self.backupEligibility = Some(backupEligibility); self }
340    /// Assertions returned by this credential will have the backup state (BS)
341    /// flag set to this value. Defaults to the authenticator's
342    /// defaultBackupState value.
343    pub fn backupState(mut self, backupState: bool) -> Self { self.backupState = Some(backupState); self }
344    /// The credential's user.name property. Equivalent to empty if not set.
345    /// https://w3c.github.io/webauthn/#dom-publickeycredentialentity-name
346    pub fn userName(mut self, userName: impl Into<Cow<'a, str>>) -> Self { self.userName = Some(userName.into()); self }
347    /// The credential's user.displayName property. Equivalent to empty if
348    /// not set.
349    /// https://w3c.github.io/webauthn/#dom-publickeycredentialuserentity-displayname
350    pub fn userDisplayName(mut self, userDisplayName: impl Into<Cow<'a, str>>) -> Self { self.userDisplayName = Some(userDisplayName.into()); self }
351    pub fn build(self) -> Credential<'a> {
352        Credential {
353            credentialId: self.credentialId,
354            isResidentCredential: self.isResidentCredential,
355            rpId: self.rpId,
356            privateKey: self.privateKey,
357            userHandle: self.userHandle,
358            signCount: self.signCount,
359            largeBlob: self.largeBlob,
360            backupEligibility: self.backupEligibility,
361            backupState: self.backupState,
362            userName: self.userName,
363            userDisplayName: self.userDisplayName,
364        }
365    }
366}
367
368/// Enable the WebAuthn domain and start intercepting credential storage and
369/// retrieval with a virtual authenticator.
370
371#[derive(Debug, Clone, Serialize, Deserialize, Default)]
372#[serde(rename_all = "camelCase")]
373pub struct EnableParams {
374    /// Whether to enable the WebAuthn user interface. Enabling the UI is
375    /// recommended for debugging and demo purposes, as it is closer to the real
376    /// experience. Disabling the UI is recommended for automated testing.
377    /// Supported at the embedder's discretion if UI is available.
378    /// Defaults to false.
379    #[serde(skip_serializing_if = "Option::is_none")]
380    enableUI: Option<bool>,
381}
382
383impl EnableParams {
384    pub fn builder() -> EnableParamsBuilder {
385        EnableParamsBuilder {
386            enableUI: None,
387        }
388    }
389    pub fn enableUI(&self) -> Option<bool> { self.enableUI }
390}
391
392#[derive(Default)]
393pub struct EnableParamsBuilder {
394    enableUI: Option<bool>,
395}
396
397impl EnableParamsBuilder {
398    /// Whether to enable the WebAuthn user interface. Enabling the UI is
399    /// recommended for debugging and demo purposes, as it is closer to the real
400    /// experience. Disabling the UI is recommended for automated testing.
401    /// Supported at the embedder's discretion if UI is available.
402    /// Defaults to false.
403    pub fn enableUI(mut self, enableUI: bool) -> Self { self.enableUI = Some(enableUI); self }
404    pub fn build(self) -> EnableParams {
405        EnableParams {
406            enableUI: self.enableUI,
407        }
408    }
409}
410
411impl EnableParams { pub const METHOD: &'static str = "WebAuthn.enable"; }
412
413impl<'a> crate::CdpCommand<'a> for EnableParams {
414    const METHOD: &'static str = "WebAuthn.enable";
415    type Response = crate::EmptyReturns;
416}
417
418#[derive(Debug, Clone, Serialize, Deserialize, Default)]
419pub struct DisableParams {}
420
421impl DisableParams { pub const METHOD: &'static str = "WebAuthn.disable"; }
422
423impl<'a> crate::CdpCommand<'a> for DisableParams {
424    const METHOD: &'static str = "WebAuthn.disable";
425    type Response = crate::EmptyReturns;
426}
427
428/// Creates and adds a virtual authenticator.
429
430#[derive(Debug, Clone, Serialize, Deserialize, Default)]
431#[serde(rename_all = "camelCase")]
432pub struct AddVirtualAuthenticatorParams {
433    options: VirtualAuthenticatorOptions,
434}
435
436impl AddVirtualAuthenticatorParams {
437    pub fn builder(options: VirtualAuthenticatorOptions) -> AddVirtualAuthenticatorParamsBuilder {
438        AddVirtualAuthenticatorParamsBuilder {
439            options: options,
440        }
441    }
442    pub fn options(&self) -> &VirtualAuthenticatorOptions { &self.options }
443}
444
445
446pub struct AddVirtualAuthenticatorParamsBuilder {
447    options: VirtualAuthenticatorOptions,
448}
449
450impl AddVirtualAuthenticatorParamsBuilder {
451    pub fn build(self) -> AddVirtualAuthenticatorParams {
452        AddVirtualAuthenticatorParams {
453            options: self.options,
454        }
455    }
456}
457
458/// Creates and adds a virtual authenticator.
459
460#[derive(Debug, Clone, Serialize, Deserialize, Default)]
461#[serde(rename_all = "camelCase")]
462pub struct AddVirtualAuthenticatorReturns<'a> {
463    authenticatorId: AuthenticatorId<'a>,
464}
465
466impl<'a> AddVirtualAuthenticatorReturns<'a> {
467    pub fn builder(authenticatorId: AuthenticatorId<'a>) -> AddVirtualAuthenticatorReturnsBuilder<'a> {
468        AddVirtualAuthenticatorReturnsBuilder {
469            authenticatorId: authenticatorId,
470        }
471    }
472    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
473}
474
475
476pub struct AddVirtualAuthenticatorReturnsBuilder<'a> {
477    authenticatorId: AuthenticatorId<'a>,
478}
479
480impl<'a> AddVirtualAuthenticatorReturnsBuilder<'a> {
481    pub fn build(self) -> AddVirtualAuthenticatorReturns<'a> {
482        AddVirtualAuthenticatorReturns {
483            authenticatorId: self.authenticatorId,
484        }
485    }
486}
487
488impl AddVirtualAuthenticatorParams { pub const METHOD: &'static str = "WebAuthn.addVirtualAuthenticator"; }
489
490impl<'a> crate::CdpCommand<'a> for AddVirtualAuthenticatorParams {
491    const METHOD: &'static str = "WebAuthn.addVirtualAuthenticator";
492    type Response = AddVirtualAuthenticatorReturns<'a>;
493}
494
495/// Resets parameters isBogusSignature, isBadUV, isBadUP to false if they are not present.
496
497#[derive(Debug, Clone, Serialize, Deserialize, Default)]
498#[serde(rename_all = "camelCase")]
499pub struct SetResponseOverrideBitsParams<'a> {
500    authenticatorId: AuthenticatorId<'a>,
501    /// If isBogusSignature is set, overrides the signature in the authenticator response to be zero.
502    /// Defaults to false.
503    #[serde(skip_serializing_if = "Option::is_none")]
504    isBogusSignature: Option<bool>,
505    /// If isBadUV is set, overrides the UV bit in the flags in the authenticator response to
506    /// be zero. Defaults to false.
507    #[serde(skip_serializing_if = "Option::is_none")]
508    isBadUV: Option<bool>,
509    /// If isBadUP is set, overrides the UP bit in the flags in the authenticator response to
510    /// be zero. Defaults to false.
511    #[serde(skip_serializing_if = "Option::is_none")]
512    isBadUP: Option<bool>,
513}
514
515impl<'a> SetResponseOverrideBitsParams<'a> {
516    pub fn builder(authenticatorId: AuthenticatorId<'a>) -> SetResponseOverrideBitsParamsBuilder<'a> {
517        SetResponseOverrideBitsParamsBuilder {
518            authenticatorId: authenticatorId,
519            isBogusSignature: None,
520            isBadUV: None,
521            isBadUP: None,
522        }
523    }
524    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
525    pub fn isBogusSignature(&self) -> Option<bool> { self.isBogusSignature }
526    pub fn isBadUV(&self) -> Option<bool> { self.isBadUV }
527    pub fn isBadUP(&self) -> Option<bool> { self.isBadUP }
528}
529
530
531pub struct SetResponseOverrideBitsParamsBuilder<'a> {
532    authenticatorId: AuthenticatorId<'a>,
533    isBogusSignature: Option<bool>,
534    isBadUV: Option<bool>,
535    isBadUP: Option<bool>,
536}
537
538impl<'a> SetResponseOverrideBitsParamsBuilder<'a> {
539    /// If isBogusSignature is set, overrides the signature in the authenticator response to be zero.
540    /// Defaults to false.
541    pub fn isBogusSignature(mut self, isBogusSignature: bool) -> Self { self.isBogusSignature = Some(isBogusSignature); self }
542    /// If isBadUV is set, overrides the UV bit in the flags in the authenticator response to
543    /// be zero. Defaults to false.
544    pub fn isBadUV(mut self, isBadUV: bool) -> Self { self.isBadUV = Some(isBadUV); self }
545    /// If isBadUP is set, overrides the UP bit in the flags in the authenticator response to
546    /// be zero. Defaults to false.
547    pub fn isBadUP(mut self, isBadUP: bool) -> Self { self.isBadUP = Some(isBadUP); self }
548    pub fn build(self) -> SetResponseOverrideBitsParams<'a> {
549        SetResponseOverrideBitsParams {
550            authenticatorId: self.authenticatorId,
551            isBogusSignature: self.isBogusSignature,
552            isBadUV: self.isBadUV,
553            isBadUP: self.isBadUP,
554        }
555    }
556}
557
558impl<'a> SetResponseOverrideBitsParams<'a> { pub const METHOD: &'static str = "WebAuthn.setResponseOverrideBits"; }
559
560impl<'a> crate::CdpCommand<'a> for SetResponseOverrideBitsParams<'a> {
561    const METHOD: &'static str = "WebAuthn.setResponseOverrideBits";
562    type Response = crate::EmptyReturns;
563}
564
565/// Removes the given authenticator.
566
567#[derive(Debug, Clone, Serialize, Deserialize, Default)]
568#[serde(rename_all = "camelCase")]
569pub struct RemoveVirtualAuthenticatorParams<'a> {
570    authenticatorId: AuthenticatorId<'a>,
571}
572
573impl<'a> RemoveVirtualAuthenticatorParams<'a> {
574    pub fn builder(authenticatorId: AuthenticatorId<'a>) -> RemoveVirtualAuthenticatorParamsBuilder<'a> {
575        RemoveVirtualAuthenticatorParamsBuilder {
576            authenticatorId: authenticatorId,
577        }
578    }
579    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
580}
581
582
583pub struct RemoveVirtualAuthenticatorParamsBuilder<'a> {
584    authenticatorId: AuthenticatorId<'a>,
585}
586
587impl<'a> RemoveVirtualAuthenticatorParamsBuilder<'a> {
588    pub fn build(self) -> RemoveVirtualAuthenticatorParams<'a> {
589        RemoveVirtualAuthenticatorParams {
590            authenticatorId: self.authenticatorId,
591        }
592    }
593}
594
595impl<'a> RemoveVirtualAuthenticatorParams<'a> { pub const METHOD: &'static str = "WebAuthn.removeVirtualAuthenticator"; }
596
597impl<'a> crate::CdpCommand<'a> for RemoveVirtualAuthenticatorParams<'a> {
598    const METHOD: &'static str = "WebAuthn.removeVirtualAuthenticator";
599    type Response = crate::EmptyReturns;
600}
601
602/// Adds the credential to the specified authenticator.
603
604#[derive(Debug, Clone, Serialize, Deserialize, Default)]
605#[serde(rename_all = "camelCase")]
606pub struct AddCredentialParams<'a> {
607    authenticatorId: AuthenticatorId<'a>,
608    credential: Credential<'a>,
609}
610
611impl<'a> AddCredentialParams<'a> {
612    pub fn builder(authenticatorId: AuthenticatorId<'a>, credential: Credential<'a>) -> AddCredentialParamsBuilder<'a> {
613        AddCredentialParamsBuilder {
614            authenticatorId: authenticatorId,
615            credential: credential,
616        }
617    }
618    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
619    pub fn credential(&self) -> &Credential<'a> { &self.credential }
620}
621
622
623pub struct AddCredentialParamsBuilder<'a> {
624    authenticatorId: AuthenticatorId<'a>,
625    credential: Credential<'a>,
626}
627
628impl<'a> AddCredentialParamsBuilder<'a> {
629    pub fn build(self) -> AddCredentialParams<'a> {
630        AddCredentialParams {
631            authenticatorId: self.authenticatorId,
632            credential: self.credential,
633        }
634    }
635}
636
637impl<'a> AddCredentialParams<'a> { pub const METHOD: &'static str = "WebAuthn.addCredential"; }
638
639impl<'a> crate::CdpCommand<'a> for AddCredentialParams<'a> {
640    const METHOD: &'static str = "WebAuthn.addCredential";
641    type Response = crate::EmptyReturns;
642}
643
644/// Returns a single credential stored in the given virtual authenticator that
645/// matches the credential ID.
646
647#[derive(Debug, Clone, Serialize, Deserialize, Default)]
648#[serde(rename_all = "camelCase")]
649pub struct GetCredentialParams<'a> {
650    authenticatorId: AuthenticatorId<'a>,
651    credentialId: Cow<'a, str>,
652}
653
654impl<'a> GetCredentialParams<'a> {
655    pub fn builder(authenticatorId: AuthenticatorId<'a>, credentialId: impl Into<Cow<'a, str>>) -> GetCredentialParamsBuilder<'a> {
656        GetCredentialParamsBuilder {
657            authenticatorId: authenticatorId,
658            credentialId: credentialId.into(),
659        }
660    }
661    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
662    pub fn credentialId(&self) -> &str { self.credentialId.as_ref() }
663}
664
665
666pub struct GetCredentialParamsBuilder<'a> {
667    authenticatorId: AuthenticatorId<'a>,
668    credentialId: Cow<'a, str>,
669}
670
671impl<'a> GetCredentialParamsBuilder<'a> {
672    pub fn build(self) -> GetCredentialParams<'a> {
673        GetCredentialParams {
674            authenticatorId: self.authenticatorId,
675            credentialId: self.credentialId,
676        }
677    }
678}
679
680/// Returns a single credential stored in the given virtual authenticator that
681/// matches the credential ID.
682
683#[derive(Debug, Clone, Serialize, Deserialize, Default)]
684#[serde(rename_all = "camelCase")]
685pub struct GetCredentialReturns<'a> {
686    credential: Credential<'a>,
687}
688
689impl<'a> GetCredentialReturns<'a> {
690    pub fn builder(credential: Credential<'a>) -> GetCredentialReturnsBuilder<'a> {
691        GetCredentialReturnsBuilder {
692            credential: credential,
693        }
694    }
695    pub fn credential(&self) -> &Credential<'a> { &self.credential }
696}
697
698
699pub struct GetCredentialReturnsBuilder<'a> {
700    credential: Credential<'a>,
701}
702
703impl<'a> GetCredentialReturnsBuilder<'a> {
704    pub fn build(self) -> GetCredentialReturns<'a> {
705        GetCredentialReturns {
706            credential: self.credential,
707        }
708    }
709}
710
711impl<'a> GetCredentialParams<'a> { pub const METHOD: &'static str = "WebAuthn.getCredential"; }
712
713impl<'a> crate::CdpCommand<'a> for GetCredentialParams<'a> {
714    const METHOD: &'static str = "WebAuthn.getCredential";
715    type Response = GetCredentialReturns<'a>;
716}
717
718/// Returns all the credentials stored in the given virtual authenticator.
719
720#[derive(Debug, Clone, Serialize, Deserialize, Default)]
721#[serde(rename_all = "camelCase")]
722pub struct GetCredentialsParams<'a> {
723    authenticatorId: AuthenticatorId<'a>,
724}
725
726impl<'a> GetCredentialsParams<'a> {
727    pub fn builder(authenticatorId: AuthenticatorId<'a>) -> GetCredentialsParamsBuilder<'a> {
728        GetCredentialsParamsBuilder {
729            authenticatorId: authenticatorId,
730        }
731    }
732    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
733}
734
735
736pub struct GetCredentialsParamsBuilder<'a> {
737    authenticatorId: AuthenticatorId<'a>,
738}
739
740impl<'a> GetCredentialsParamsBuilder<'a> {
741    pub fn build(self) -> GetCredentialsParams<'a> {
742        GetCredentialsParams {
743            authenticatorId: self.authenticatorId,
744        }
745    }
746}
747
748/// Returns all the credentials stored in the given virtual authenticator.
749
750#[derive(Debug, Clone, Serialize, Deserialize, Default)]
751#[serde(rename_all = "camelCase")]
752pub struct GetCredentialsReturns<'a> {
753    credentials: Vec<Credential<'a>>,
754}
755
756impl<'a> GetCredentialsReturns<'a> {
757    pub fn builder(credentials: Vec<Credential<'a>>) -> GetCredentialsReturnsBuilder<'a> {
758        GetCredentialsReturnsBuilder {
759            credentials: credentials,
760        }
761    }
762    pub fn credentials(&self) -> &[Credential<'a>] { &self.credentials }
763}
764
765
766pub struct GetCredentialsReturnsBuilder<'a> {
767    credentials: Vec<Credential<'a>>,
768}
769
770impl<'a> GetCredentialsReturnsBuilder<'a> {
771    pub fn build(self) -> GetCredentialsReturns<'a> {
772        GetCredentialsReturns {
773            credentials: self.credentials,
774        }
775    }
776}
777
778impl<'a> GetCredentialsParams<'a> { pub const METHOD: &'static str = "WebAuthn.getCredentials"; }
779
780impl<'a> crate::CdpCommand<'a> for GetCredentialsParams<'a> {
781    const METHOD: &'static str = "WebAuthn.getCredentials";
782    type Response = GetCredentialsReturns<'a>;
783}
784
785/// Removes a credential from the authenticator.
786
787#[derive(Debug, Clone, Serialize, Deserialize, Default)]
788#[serde(rename_all = "camelCase")]
789pub struct RemoveCredentialParams<'a> {
790    authenticatorId: AuthenticatorId<'a>,
791    credentialId: Cow<'a, str>,
792}
793
794impl<'a> RemoveCredentialParams<'a> {
795    pub fn builder(authenticatorId: AuthenticatorId<'a>, credentialId: impl Into<Cow<'a, str>>) -> RemoveCredentialParamsBuilder<'a> {
796        RemoveCredentialParamsBuilder {
797            authenticatorId: authenticatorId,
798            credentialId: credentialId.into(),
799        }
800    }
801    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
802    pub fn credentialId(&self) -> &str { self.credentialId.as_ref() }
803}
804
805
806pub struct RemoveCredentialParamsBuilder<'a> {
807    authenticatorId: AuthenticatorId<'a>,
808    credentialId: Cow<'a, str>,
809}
810
811impl<'a> RemoveCredentialParamsBuilder<'a> {
812    pub fn build(self) -> RemoveCredentialParams<'a> {
813        RemoveCredentialParams {
814            authenticatorId: self.authenticatorId,
815            credentialId: self.credentialId,
816        }
817    }
818}
819
820impl<'a> RemoveCredentialParams<'a> { pub const METHOD: &'static str = "WebAuthn.removeCredential"; }
821
822impl<'a> crate::CdpCommand<'a> for RemoveCredentialParams<'a> {
823    const METHOD: &'static str = "WebAuthn.removeCredential";
824    type Response = crate::EmptyReturns;
825}
826
827/// Clears all the credentials from the specified device.
828
829#[derive(Debug, Clone, Serialize, Deserialize, Default)]
830#[serde(rename_all = "camelCase")]
831pub struct ClearCredentialsParams<'a> {
832    authenticatorId: AuthenticatorId<'a>,
833}
834
835impl<'a> ClearCredentialsParams<'a> {
836    pub fn builder(authenticatorId: AuthenticatorId<'a>) -> ClearCredentialsParamsBuilder<'a> {
837        ClearCredentialsParamsBuilder {
838            authenticatorId: authenticatorId,
839        }
840    }
841    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
842}
843
844
845pub struct ClearCredentialsParamsBuilder<'a> {
846    authenticatorId: AuthenticatorId<'a>,
847}
848
849impl<'a> ClearCredentialsParamsBuilder<'a> {
850    pub fn build(self) -> ClearCredentialsParams<'a> {
851        ClearCredentialsParams {
852            authenticatorId: self.authenticatorId,
853        }
854    }
855}
856
857impl<'a> ClearCredentialsParams<'a> { pub const METHOD: &'static str = "WebAuthn.clearCredentials"; }
858
859impl<'a> crate::CdpCommand<'a> for ClearCredentialsParams<'a> {
860    const METHOD: &'static str = "WebAuthn.clearCredentials";
861    type Response = crate::EmptyReturns;
862}
863
864/// Sets whether User Verification succeeds or fails for an authenticator.
865/// The default is true.
866
867#[derive(Debug, Clone, Serialize, Deserialize, Default)]
868#[serde(rename_all = "camelCase")]
869pub struct SetUserVerifiedParams<'a> {
870    authenticatorId: AuthenticatorId<'a>,
871    isUserVerified: bool,
872}
873
874impl<'a> SetUserVerifiedParams<'a> {
875    pub fn builder(authenticatorId: AuthenticatorId<'a>, isUserVerified: bool) -> SetUserVerifiedParamsBuilder<'a> {
876        SetUserVerifiedParamsBuilder {
877            authenticatorId: authenticatorId,
878            isUserVerified: isUserVerified,
879        }
880    }
881    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
882    pub fn isUserVerified(&self) -> bool { self.isUserVerified }
883}
884
885
886pub struct SetUserVerifiedParamsBuilder<'a> {
887    authenticatorId: AuthenticatorId<'a>,
888    isUserVerified: bool,
889}
890
891impl<'a> SetUserVerifiedParamsBuilder<'a> {
892    pub fn build(self) -> SetUserVerifiedParams<'a> {
893        SetUserVerifiedParams {
894            authenticatorId: self.authenticatorId,
895            isUserVerified: self.isUserVerified,
896        }
897    }
898}
899
900impl<'a> SetUserVerifiedParams<'a> { pub const METHOD: &'static str = "WebAuthn.setUserVerified"; }
901
902impl<'a> crate::CdpCommand<'a> for SetUserVerifiedParams<'a> {
903    const METHOD: &'static str = "WebAuthn.setUserVerified";
904    type Response = crate::EmptyReturns;
905}
906
907/// Sets whether tests of user presence will succeed immediately (if true) or fail to resolve (if false) for an authenticator.
908/// The default is true.
909
910#[derive(Debug, Clone, Serialize, Deserialize, Default)]
911#[serde(rename_all = "camelCase")]
912pub struct SetAutomaticPresenceSimulationParams<'a> {
913    authenticatorId: AuthenticatorId<'a>,
914    enabled: bool,
915}
916
917impl<'a> SetAutomaticPresenceSimulationParams<'a> {
918    pub fn builder(authenticatorId: AuthenticatorId<'a>, enabled: bool) -> SetAutomaticPresenceSimulationParamsBuilder<'a> {
919        SetAutomaticPresenceSimulationParamsBuilder {
920            authenticatorId: authenticatorId,
921            enabled: enabled,
922        }
923    }
924    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
925    pub fn enabled(&self) -> bool { self.enabled }
926}
927
928
929pub struct SetAutomaticPresenceSimulationParamsBuilder<'a> {
930    authenticatorId: AuthenticatorId<'a>,
931    enabled: bool,
932}
933
934impl<'a> SetAutomaticPresenceSimulationParamsBuilder<'a> {
935    pub fn build(self) -> SetAutomaticPresenceSimulationParams<'a> {
936        SetAutomaticPresenceSimulationParams {
937            authenticatorId: self.authenticatorId,
938            enabled: self.enabled,
939        }
940    }
941}
942
943impl<'a> SetAutomaticPresenceSimulationParams<'a> { pub const METHOD: &'static str = "WebAuthn.setAutomaticPresenceSimulation"; }
944
945impl<'a> crate::CdpCommand<'a> for SetAutomaticPresenceSimulationParams<'a> {
946    const METHOD: &'static str = "WebAuthn.setAutomaticPresenceSimulation";
947    type Response = crate::EmptyReturns;
948}
949
950/// Allows setting credential properties.
951/// https://w3c.github.io/webauthn/#sctn-automation-set-credential-properties
952
953#[derive(Debug, Clone, Serialize, Deserialize, Default)]
954#[serde(rename_all = "camelCase")]
955pub struct SetCredentialPropertiesParams<'a> {
956    authenticatorId: AuthenticatorId<'a>,
957    credentialId: Cow<'a, str>,
958    #[serde(skip_serializing_if = "Option::is_none")]
959    backupEligibility: Option<bool>,
960    #[serde(skip_serializing_if = "Option::is_none")]
961    backupState: Option<bool>,
962}
963
964impl<'a> SetCredentialPropertiesParams<'a> {
965    pub fn builder(authenticatorId: AuthenticatorId<'a>, credentialId: impl Into<Cow<'a, str>>) -> SetCredentialPropertiesParamsBuilder<'a> {
966        SetCredentialPropertiesParamsBuilder {
967            authenticatorId: authenticatorId,
968            credentialId: credentialId.into(),
969            backupEligibility: None,
970            backupState: None,
971        }
972    }
973    pub fn authenticatorId(&self) -> &AuthenticatorId<'a> { &self.authenticatorId }
974    pub fn credentialId(&self) -> &str { self.credentialId.as_ref() }
975    pub fn backupEligibility(&self) -> Option<bool> { self.backupEligibility }
976    pub fn backupState(&self) -> Option<bool> { self.backupState }
977}
978
979
980pub struct SetCredentialPropertiesParamsBuilder<'a> {
981    authenticatorId: AuthenticatorId<'a>,
982    credentialId: Cow<'a, str>,
983    backupEligibility: Option<bool>,
984    backupState: Option<bool>,
985}
986
987impl<'a> SetCredentialPropertiesParamsBuilder<'a> {
988    pub fn backupEligibility(mut self, backupEligibility: bool) -> Self { self.backupEligibility = Some(backupEligibility); self }
989    pub fn backupState(mut self, backupState: bool) -> Self { self.backupState = Some(backupState); self }
990    pub fn build(self) -> SetCredentialPropertiesParams<'a> {
991        SetCredentialPropertiesParams {
992            authenticatorId: self.authenticatorId,
993            credentialId: self.credentialId,
994            backupEligibility: self.backupEligibility,
995            backupState: self.backupState,
996        }
997    }
998}
999
1000impl<'a> SetCredentialPropertiesParams<'a> { pub const METHOD: &'static str = "WebAuthn.setCredentialProperties"; }
1001
1002impl<'a> crate::CdpCommand<'a> for SetCredentialPropertiesParams<'a> {
1003    const METHOD: &'static str = "WebAuthn.setCredentialProperties";
1004    type Response = crate::EmptyReturns;
1005}