Skip to main content

cdp_driver/protocol/
web_authn.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! This domain allows configuring virtual authenticators to test the WebAuthn
5//! API.
6//!
7//! Types, command parameters and event payloads for the `WebAuthn`
8//! domain. The method-name constants for the same domain are in
9//! [`crate::methods`].
10//!
11//! This domain is experimental and may change without notice.
12
13use serde::{Deserialize, Serialize};
14
15pub type AuthenticatorId = String;
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
18pub enum AuthenticatorProtocol {
19    /// `u2f`
20    #[serde(rename = "u2f")]
21    U2f,
22    /// `ctap2`
23    #[serde(rename = "ctap2")]
24    Ctap2,
25    /// A value this vendored schema does not list. Chrome adds values ahead of
26    /// the published protocol, so an unrecognised one is kept as it arrived
27    /// rather than failing the payload it came in.
28    #[serde(untagged)]
29    Unrecognized(String),
30}
31
32#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
33pub enum Ctap2Version {
34    /// `ctap2_0`
35    #[serde(rename = "ctap2_0")]
36    Ctap20,
37    /// `ctap2_1`
38    #[serde(rename = "ctap2_1")]
39    Ctap21,
40    /// `ctap2_2`
41    #[serde(rename = "ctap2_2")]
42    Ctap22,
43    /// A value this vendored schema does not list. Chrome adds values ahead of
44    /// the published protocol, so an unrecognised one is kept as it arrived
45    /// rather than failing the payload it came in.
46    #[serde(untagged)]
47    Unrecognized(String),
48}
49
50/// LINT.IfChange(AuthenticatorTransport)
51#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
52pub enum AuthenticatorTransport {
53    /// `usb`
54    #[serde(rename = "usb")]
55    Usb,
56    /// `nfc`
57    #[serde(rename = "nfc")]
58    Nfc,
59    /// `ble`
60    #[serde(rename = "ble")]
61    Ble,
62    /// `cable`
63    #[serde(rename = "cable")]
64    Cable,
65    /// `hybrid`
66    #[serde(rename = "hybrid")]
67    Hybrid,
68    /// `smart-card`
69    #[serde(rename = "smart-card")]
70    SmartCard,
71    /// `internal`
72    #[serde(rename = "internal")]
73    Internal,
74    /// A value this vendored schema does not list. Chrome adds values ahead of
75    /// the published protocol, so an unrecognised one is kept as it arrived
76    /// rather than failing the payload it came in.
77    #[serde(untagged)]
78    Unrecognized(String),
79}
80
81#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
82pub struct VirtualAuthenticatorOptions {
83    pub protocol: AuthenticatorProtocol,
84    /// Defaults to ctap2_0. Ignored if |protocol| == u2f.
85    #[serde(
86        rename = "ctap2Version",
87        default,
88        skip_serializing_if = "Option::is_none"
89    )]
90    pub ctap2_version: Option<Ctap2Version>,
91    pub transport: AuthenticatorTransport,
92    /// Defaults to false.
93    #[serde(
94        rename = "hasResidentKey",
95        default,
96        skip_serializing_if = "Option::is_none"
97    )]
98    pub has_resident_key: Option<bool>,
99    /// Defaults to false.
100    #[serde(
101        rename = "hasUserVerification",
102        default,
103        skip_serializing_if = "Option::is_none"
104    )]
105    pub has_user_verification: Option<bool>,
106    /// If set to true, the authenticator will support the largeBlob extension.
107    /// <https://w3c.github.io/webauthn#largeBlob> Defaults to false.
108    #[serde(
109        rename = "hasLargeBlob",
110        default,
111        skip_serializing_if = "Option::is_none"
112    )]
113    pub has_large_blob: Option<bool>,
114    /// If set to true, the authenticator will support the credBlob extension.
115    /// <https://fidoalliance.org/specs/fido-v2.1-rd-20201208/fido-client-to-authenticator-protocol-v2.1-rd-20201208.html#sctn-credBlob-extension>
116    /// Defaults to false.
117    #[serde(
118        rename = "hasCredBlob",
119        default,
120        skip_serializing_if = "Option::is_none"
121    )]
122    pub has_cred_blob: Option<bool>,
123    /// If set to true, the authenticator will support the minPinLength extension.
124    /// <https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-minpinlength-extension>
125    /// Defaults to false.
126    #[serde(
127        rename = "hasMinPinLength",
128        default,
129        skip_serializing_if = "Option::is_none"
130    )]
131    pub has_min_pin_length: Option<bool>,
132    /// If set to true, the authenticator will support the prf extension.
133    /// <https://w3c.github.io/webauthn/#prf-extension> Defaults to false.
134    #[serde(rename = "hasPrf", default, skip_serializing_if = "Option::is_none")]
135    pub has_prf: Option<bool>,
136    /// If set to true, the authenticator will support the hmac-secret extension.
137    /// <https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#sctn-hmac-secret-extension>
138    /// Defaults to false.
139    #[serde(
140        rename = "hasHmacSecret",
141        default,
142        skip_serializing_if = "Option::is_none"
143    )]
144    pub has_hmac_secret: Option<bool>,
145    /// If set to true, the authenticator will support the hmac-secret-mc
146    /// extension.
147    /// <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>
148    /// Defaults to false.
149    #[serde(
150        rename = "hasHmacSecretMc",
151        default,
152        skip_serializing_if = "Option::is_none"
153    )]
154    pub has_hmac_secret_mc: Option<bool>,
155    /// If set to true, the authenticator will support the cmtgKey (Credential
156    /// Manager Trust Group Key) extension.
157    /// <https://github.com/w3c/webauthn/pull/2377> Defaults to false.
158    #[serde(
159        rename = "hasCmtgKey",
160        default,
161        skip_serializing_if = "Option::is_none"
162    )]
163    pub has_cmtg_key: Option<bool>,
164    /// If set to true, tests of user presence will succeed immediately.
165    /// Otherwise, they will not be resolved. Defaults to true.
166    #[serde(
167        rename = "automaticPresenceSimulation",
168        default,
169        skip_serializing_if = "Option::is_none"
170    )]
171    pub automatic_presence_simulation: Option<bool>,
172    /// Sets whether User Verification succeeds or fails for an authenticator.
173    /// Defaults to false.
174    #[serde(
175        rename = "isUserVerified",
176        default,
177        skip_serializing_if = "Option::is_none"
178    )]
179    pub is_user_verified: Option<bool>,
180    /// Credentials created by this authenticator will have the backup eligibility
181    /// (BE) flag set to this value. Defaults to false.
182    /// <https://w3c.github.io/webauthn/#sctn-credential-backup>
183    #[serde(
184        rename = "defaultBackupEligibility",
185        default,
186        skip_serializing_if = "Option::is_none"
187    )]
188    pub default_backup_eligibility: Option<bool>,
189    /// Credentials created by this authenticator will have the backup state (BS)
190    /// flag set to this value. Defaults to false.
191    /// <https://w3c.github.io/webauthn/#sctn-credential-backup>
192    #[serde(
193        rename = "defaultBackupState",
194        default,
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub default_backup_state: Option<bool>,
198}
199
200#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
201pub struct Credential {
202    #[serde(rename = "credentialId")]
203    pub credential_id: String,
204    #[serde(rename = "isResidentCredential")]
205    pub is_resident_credential: bool,
206    /// Relying Party ID the credential is scoped to. Must be set when adding a
207    /// credential.
208    #[serde(rename = "rpId", default, skip_serializing_if = "Option::is_none")]
209    pub rp_id: Option<String>,
210    /// The ECDSA P-256 private key in PKCS#8 format. (Encoded as a base64 string
211    /// when passed over JSON)
212    #[serde(rename = "privateKey")]
213    pub private_key: String,
214    /// An opaque byte sequence with a maximum size of 64 bytes mapping the
215    /// credential to a specific user. (Encoded as a base64 string when passed
216    /// over JSON)
217    #[serde(
218        rename = "userHandle",
219        default,
220        skip_serializing_if = "Option::is_none"
221    )]
222    pub user_handle: Option<String>,
223    /// Signature counter. Must be equal to or greater than -1. If -1, the
224    /// credential won't have an associated signature counter, and every assertion
225    /// operation will report a value of 0. See
226    /// <https://w3c.github.io/webauthn/#signature-counter>
227    #[serde(rename = "signCount")]
228    pub sign_count: f64,
229    /// The large blob associated with the credential. See
230    /// <https://w3c.github.io/webauthn/#sctn-large-blob-extension> (Encoded as a
231    /// base64 string when passed over JSON)
232    #[serde(rename = "largeBlob", default, skip_serializing_if = "Option::is_none")]
233    pub large_blob: Option<String>,
234    /// Assertions returned by this credential will have the backup eligibility
235    /// (BE) flag set to this value. Defaults to the authenticator's
236    /// defaultBackupEligibility value.
237    #[serde(
238        rename = "backupEligibility",
239        default,
240        skip_serializing_if = "Option::is_none"
241    )]
242    pub backup_eligibility: Option<bool>,
243    /// Assertions returned by this credential will have the backup state (BS)
244    /// flag set to this value. Defaults to the authenticator's defaultBackupState
245    /// value.
246    #[serde(
247        rename = "backupState",
248        default,
249        skip_serializing_if = "Option::is_none"
250    )]
251    pub backup_state: Option<bool>,
252    /// The credential's user.name property. Equivalent to empty if not set.
253    /// <https://w3c.github.io/webauthn/#dom-publickeycredentialentity-name>
254    #[serde(rename = "userName", default, skip_serializing_if = "Option::is_none")]
255    pub user_name: Option<String>,
256    /// The credential's user.displayName property. Equivalent to empty if not
257    /// set.
258    /// <https://w3c.github.io/webauthn/#dom-publickeycredentialuserentity-displayname>
259    #[serde(
260        rename = "userDisplayName",
261        default,
262        skip_serializing_if = "Option::is_none"
263    )]
264    pub user_display_name: Option<String>,
265    /// The CMTG keys associated with the credential.
266    #[serde(rename = "cmtgKeys", default, skip_serializing_if = "Option::is_none")]
267    pub cmtg_keys: Option<Vec<String>>,
268    /// The 0-based index of the active key in cmtgKeys.
269    #[serde(
270        rename = "activeCmtgKeyIndex",
271        default,
272        skip_serializing_if = "Option::is_none"
273    )]
274    pub active_cmtg_key_index: Option<i64>,
275    /// If true, the authenticator will generate a new CMTG key on the next
276    /// operation.
277    #[serde(
278        rename = "generateCmtgKeyOnNextOperation",
279        default,
280        skip_serializing_if = "Option::is_none"
281    )]
282    pub generate_cmtg_key_on_next_operation: Option<bool>,
283}
284
285/// Enable the WebAuthn domain and start intercepting credential storage and
286/// retrieval with a virtual authenticator.
287///
288/// Parameters of `WebAuthn.enable`.
289#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
290pub struct EnableParams {
291    /// Whether to enable the WebAuthn user interface. Enabling the UI is
292    /// recommended for debugging and demo purposes, as it is closer to the real
293    /// experience. Disabling the UI is recommended for automated testing.
294    /// Supported at the embedder's discretion if UI is available. Defaults to
295    /// false.
296    #[serde(rename = "enableUI", default, skip_serializing_if = "Option::is_none")]
297    pub enable_ui: Option<bool>,
298}
299
300impl crate::typed::Command for EnableParams {
301    const METHOD: &'static str = "WebAuthn.enable";
302    type Returns = crate::typed::NoReturns;
303}
304
305/// Disable the WebAuthn domain.
306///
307/// Parameters of `WebAuthn.disable`.
308#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
309pub struct DisableParams {}
310
311impl crate::typed::Command for DisableParams {
312    const METHOD: &'static str = "WebAuthn.disable";
313    type Returns = crate::typed::NoReturns;
314}
315
316/// Creates and adds a virtual authenticator.
317///
318/// Parameters of `WebAuthn.addVirtualAuthenticator`.
319#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
320pub struct AddVirtualAuthenticatorParams {
321    pub options: VirtualAuthenticatorOptions,
322}
323
324/// What `WebAuthn.addVirtualAuthenticator` answers with.
325#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
326pub struct AddVirtualAuthenticatorReturns {
327    #[serde(rename = "authenticatorId")]
328    pub authenticator_id: AuthenticatorId,
329}
330
331impl crate::typed::Command for AddVirtualAuthenticatorParams {
332    const METHOD: &'static str = "WebAuthn.addVirtualAuthenticator";
333    type Returns = AddVirtualAuthenticatorReturns;
334}
335
336/// Resets parameters isBogusSignature, isBadUV, isBadUP to false if they are
337/// not present.
338///
339/// Parameters of `WebAuthn.setResponseOverrideBits`.
340#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
341pub struct SetResponseOverrideBitsParams {
342    #[serde(rename = "authenticatorId")]
343    pub authenticator_id: AuthenticatorId,
344    /// If isBogusSignature is set, overrides the signature in the authenticator
345    /// response to be zero. Defaults to false.
346    #[serde(
347        rename = "isBogusSignature",
348        default,
349        skip_serializing_if = "Option::is_none"
350    )]
351    pub is_bogus_signature: Option<bool>,
352    /// If isBadUV is set, overrides the UV bit in the flags in the authenticator
353    /// response to be zero. Defaults to false.
354    #[serde(rename = "isBadUV", default, skip_serializing_if = "Option::is_none")]
355    pub is_bad_uv: Option<bool>,
356    /// If isBadUP is set, overrides the UP bit in the flags in the authenticator
357    /// response to be zero. Defaults to false.
358    #[serde(rename = "isBadUP", default, skip_serializing_if = "Option::is_none")]
359    pub is_bad_up: Option<bool>,
360}
361
362impl crate::typed::Command for SetResponseOverrideBitsParams {
363    const METHOD: &'static str = "WebAuthn.setResponseOverrideBits";
364    type Returns = crate::typed::NoReturns;
365}
366
367/// Removes the given authenticator.
368///
369/// Parameters of `WebAuthn.removeVirtualAuthenticator`.
370#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
371pub struct RemoveVirtualAuthenticatorParams {
372    #[serde(rename = "authenticatorId")]
373    pub authenticator_id: AuthenticatorId,
374}
375
376impl crate::typed::Command for RemoveVirtualAuthenticatorParams {
377    const METHOD: &'static str = "WebAuthn.removeVirtualAuthenticator";
378    type Returns = crate::typed::NoReturns;
379}
380
381/// Adds the credential to the specified authenticator.
382///
383/// Parameters of `WebAuthn.addCredential`.
384#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
385pub struct AddCredentialParams {
386    #[serde(rename = "authenticatorId")]
387    pub authenticator_id: AuthenticatorId,
388    pub credential: Credential,
389}
390
391impl crate::typed::Command for AddCredentialParams {
392    const METHOD: &'static str = "WebAuthn.addCredential";
393    type Returns = crate::typed::NoReturns;
394}
395
396/// Returns a single credential stored in the given virtual authenticator that
397/// matches the credential ID.
398///
399/// Parameters of `WebAuthn.getCredential`.
400#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
401pub struct GetCredentialParams {
402    #[serde(rename = "authenticatorId")]
403    pub authenticator_id: AuthenticatorId,
404    #[serde(rename = "credentialId")]
405    pub credential_id: String,
406}
407
408/// What `WebAuthn.getCredential` answers with.
409#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
410pub struct GetCredentialReturns {
411    pub credential: Credential,
412}
413
414impl crate::typed::Command for GetCredentialParams {
415    const METHOD: &'static str = "WebAuthn.getCredential";
416    type Returns = GetCredentialReturns;
417}
418
419/// Returns all the credentials stored in the given virtual authenticator.
420///
421/// Parameters of `WebAuthn.getCredentials`.
422#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
423pub struct GetCredentialsParams {
424    #[serde(rename = "authenticatorId")]
425    pub authenticator_id: AuthenticatorId,
426}
427
428/// What `WebAuthn.getCredentials` answers with.
429#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
430pub struct GetCredentialsReturns {
431    pub credentials: Vec<Credential>,
432}
433
434impl crate::typed::Command for GetCredentialsParams {
435    const METHOD: &'static str = "WebAuthn.getCredentials";
436    type Returns = GetCredentialsReturns;
437}
438
439/// Removes a credential from the authenticator.
440///
441/// Parameters of `WebAuthn.removeCredential`.
442#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
443pub struct RemoveCredentialParams {
444    #[serde(rename = "authenticatorId")]
445    pub authenticator_id: AuthenticatorId,
446    #[serde(rename = "credentialId")]
447    pub credential_id: String,
448}
449
450impl crate::typed::Command for RemoveCredentialParams {
451    const METHOD: &'static str = "WebAuthn.removeCredential";
452    type Returns = crate::typed::NoReturns;
453}
454
455/// Clears all the credentials from the specified device.
456///
457/// Parameters of `WebAuthn.clearCredentials`.
458#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
459pub struct ClearCredentialsParams {
460    #[serde(rename = "authenticatorId")]
461    pub authenticator_id: AuthenticatorId,
462}
463
464impl crate::typed::Command for ClearCredentialsParams {
465    const METHOD: &'static str = "WebAuthn.clearCredentials";
466    type Returns = crate::typed::NoReturns;
467}
468
469/// Sets whether User Verification succeeds or fails for an authenticator. The
470/// default is true.
471///
472/// Parameters of `WebAuthn.setUserVerified`.
473#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
474pub struct SetUserVerifiedParams {
475    #[serde(rename = "authenticatorId")]
476    pub authenticator_id: AuthenticatorId,
477    #[serde(rename = "isUserVerified")]
478    pub is_user_verified: bool,
479}
480
481impl crate::typed::Command for SetUserVerifiedParams {
482    const METHOD: &'static str = "WebAuthn.setUserVerified";
483    type Returns = crate::typed::NoReturns;
484}
485
486/// Sets whether tests of user presence will succeed immediately (if true) or
487/// fail to resolve (if false) for an authenticator. The default is true.
488///
489/// Parameters of `WebAuthn.setAutomaticPresenceSimulation`.
490#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
491pub struct SetAutomaticPresenceSimulationParams {
492    #[serde(rename = "authenticatorId")]
493    pub authenticator_id: AuthenticatorId,
494    pub enabled: bool,
495}
496
497impl crate::typed::Command for SetAutomaticPresenceSimulationParams {
498    const METHOD: &'static str = "WebAuthn.setAutomaticPresenceSimulation";
499    type Returns = crate::typed::NoReturns;
500}
501
502/// Allows setting credential properties.
503/// <https://w3c.github.io/webauthn/#sctn-automation-set-credential-properties>
504///
505/// Parameters of `WebAuthn.setCredentialProperties`.
506#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
507pub struct SetCredentialPropertiesParams {
508    #[serde(rename = "authenticatorId")]
509    pub authenticator_id: AuthenticatorId,
510    #[serde(rename = "credentialId")]
511    pub credential_id: String,
512    #[serde(
513        rename = "backupEligibility",
514        default,
515        skip_serializing_if = "Option::is_none"
516    )]
517    pub backup_eligibility: Option<bool>,
518    #[serde(
519        rename = "backupState",
520        default,
521        skip_serializing_if = "Option::is_none"
522    )]
523    pub backup_state: Option<bool>,
524    #[serde(
525        rename = "activeCmtgKeyIndex",
526        default,
527        skip_serializing_if = "Option::is_none"
528    )]
529    pub active_cmtg_key_index: Option<i64>,
530    #[serde(
531        rename = "generateCmtgKeyOnNextOperation",
532        default,
533        skip_serializing_if = "Option::is_none"
534    )]
535    pub generate_cmtg_key_on_next_operation: Option<bool>,
536    /// Must be equal to or greater than -1. If -1, the signature counter is
537    /// removed from the credential, and every assertion operation will report a
538    /// value of 0. See <https://w3c.github.io/webauthn/#signature-counter>
539    #[serde(rename = "signCount", default, skip_serializing_if = "Option::is_none")]
540    pub sign_count: Option<f64>,
541}
542
543impl crate::typed::Command for SetCredentialPropertiesParams {
544    const METHOD: &'static str = "WebAuthn.setCredentialProperties";
545    type Returns = crate::typed::NoReturns;
546}
547
548/// Triggered when a credential is added to an authenticator.
549///
550/// Payload of the `WebAuthn.credentialAdded` event.
551#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
552pub struct CredentialAddedEvent {
553    #[serde(rename = "authenticatorId")]
554    pub authenticator_id: AuthenticatorId,
555    pub credential: Credential,
556}
557
558impl crate::typed::Event for CredentialAddedEvent {
559    const METHOD: &'static str = "WebAuthn.credentialAdded";
560}
561
562/// Triggered when a credential is deleted, e.g. through
563/// PublicKeyCredential.signalUnknownCredential().
564///
565/// Payload of the `WebAuthn.credentialDeleted` event.
566#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
567pub struct CredentialDeletedEvent {
568    #[serde(rename = "authenticatorId")]
569    pub authenticator_id: AuthenticatorId,
570    #[serde(rename = "credentialId")]
571    pub credential_id: String,
572}
573
574impl crate::typed::Event for CredentialDeletedEvent {
575    const METHOD: &'static str = "WebAuthn.credentialDeleted";
576}
577
578/// Triggered when a credential is updated, e.g. through
579/// PublicKeyCredential.signalCurrentUserDetails().
580///
581/// Payload of the `WebAuthn.credentialUpdated` event.
582#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
583pub struct CredentialUpdatedEvent {
584    #[serde(rename = "authenticatorId")]
585    pub authenticator_id: AuthenticatorId,
586    pub credential: Credential,
587}
588
589impl crate::typed::Event for CredentialUpdatedEvent {
590    const METHOD: &'static str = "WebAuthn.credentialUpdated";
591}
592
593/// Triggered when a credential is used in a webauthn assertion.
594///
595/// Payload of the `WebAuthn.credentialAsserted` event.
596#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
597pub struct CredentialAssertedEvent {
598    #[serde(rename = "authenticatorId")]
599    pub authenticator_id: AuthenticatorId,
600    pub credential: Credential,
601}
602
603impl crate::typed::Event for CredentialAssertedEvent {
604    const METHOD: &'static str = "WebAuthn.credentialAsserted";
605}