webauthn.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // Package webauthn provides the Chrome DevTools Protocol
  2. // commands, types, and events for the WebAuthn domain.
  3. //
  4. // This domain allows configuring virtual authenticators to test the WebAuthn
  5. // API.
  6. //
  7. // Generated by the cdproto-gen command.
  8. package webauthn
  9. // Code generated by cdproto-gen. DO NOT EDIT.
  10. import (
  11. "context"
  12. "github.com/chromedp/cdproto/cdp"
  13. )
  14. // EnableParams enable the WebAuthn domain and start intercepting credential
  15. // storage and retrieval with a virtual authenticator.
  16. type EnableParams struct {
  17. EnableUI bool `json:"enableUI"` // Whether to enable the WebAuthn user interface. Enabling the UI is recommended for debugging and demo purposes, as it is closer to the real experience. Disabling the UI is recommended for automated testing. Supported at the embedder's discretion if UI is available. Defaults to false.
  18. }
  19. // Enable enable the WebAuthn domain and start intercepting credential
  20. // storage and retrieval with a virtual authenticator.
  21. //
  22. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-enable
  23. //
  24. // parameters:
  25. func Enable() *EnableParams {
  26. return &EnableParams{
  27. EnableUI: false,
  28. }
  29. }
  30. // WithEnableUI whether to enable the WebAuthn user interface. Enabling the
  31. // UI is recommended for debugging and demo purposes, as it is closer to the
  32. // real experience. Disabling the UI is recommended for automated testing.
  33. // Supported at the embedder's discretion if UI is available. Defaults to false.
  34. func (p EnableParams) WithEnableUI(enableUI bool) *EnableParams {
  35. p.EnableUI = enableUI
  36. return &p
  37. }
  38. // Do executes WebAuthn.enable against the provided context.
  39. func (p *EnableParams) Do(ctx context.Context) (err error) {
  40. return cdp.Execute(ctx, CommandEnable, p, nil)
  41. }
  42. // DisableParams disable the WebAuthn domain.
  43. type DisableParams struct{}
  44. // Disable disable the WebAuthn domain.
  45. //
  46. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-disable
  47. func Disable() *DisableParams {
  48. return &DisableParams{}
  49. }
  50. // Do executes WebAuthn.disable against the provided context.
  51. func (p *DisableParams) Do(ctx context.Context) (err error) {
  52. return cdp.Execute(ctx, CommandDisable, nil, nil)
  53. }
  54. // AddVirtualAuthenticatorParams creates and adds a virtual authenticator.
  55. type AddVirtualAuthenticatorParams struct {
  56. Options *VirtualAuthenticatorOptions `json:"options"`
  57. }
  58. // AddVirtualAuthenticator creates and adds a virtual authenticator.
  59. //
  60. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-addVirtualAuthenticator
  61. //
  62. // parameters:
  63. //
  64. // options
  65. func AddVirtualAuthenticator(options *VirtualAuthenticatorOptions) *AddVirtualAuthenticatorParams {
  66. return &AddVirtualAuthenticatorParams{
  67. Options: options,
  68. }
  69. }
  70. // AddVirtualAuthenticatorReturns return values.
  71. type AddVirtualAuthenticatorReturns struct {
  72. AuthenticatorID AuthenticatorID `json:"authenticatorId,omitempty,omitzero"`
  73. }
  74. // Do executes WebAuthn.addVirtualAuthenticator against the provided context.
  75. //
  76. // returns:
  77. //
  78. // authenticatorID
  79. func (p *AddVirtualAuthenticatorParams) Do(ctx context.Context) (authenticatorID AuthenticatorID, err error) {
  80. // execute
  81. var res AddVirtualAuthenticatorReturns
  82. err = cdp.Execute(ctx, CommandAddVirtualAuthenticator, p, &res)
  83. if err != nil {
  84. return "", err
  85. }
  86. return res.AuthenticatorID, nil
  87. }
  88. // SetResponseOverrideBitsParams resets parameters isBogusSignature, isBadUV,
  89. // isBadUP to false if they are not present.
  90. type SetResponseOverrideBitsParams struct {
  91. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  92. IsBogusSignature bool `json:"isBogusSignature"` // If isBogusSignature is set, overrides the signature in the authenticator response to be zero. Defaults to false.
  93. IsBadUV bool `json:"isBadUV"` // If isBadUV is set, overrides the UV bit in the flags in the authenticator response to be zero. Defaults to false.
  94. IsBadUP bool `json:"isBadUP"` // If isBadUP is set, overrides the UP bit in the flags in the authenticator response to be zero. Defaults to false.
  95. }
  96. // SetResponseOverrideBits resets parameters isBogusSignature, isBadUV,
  97. // isBadUP to false if they are not present.
  98. //
  99. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setResponseOverrideBits
  100. //
  101. // parameters:
  102. //
  103. // authenticatorID
  104. func SetResponseOverrideBits(authenticatorID AuthenticatorID) *SetResponseOverrideBitsParams {
  105. return &SetResponseOverrideBitsParams{
  106. AuthenticatorID: authenticatorID,
  107. IsBogusSignature: false,
  108. IsBadUV: false,
  109. IsBadUP: false,
  110. }
  111. }
  112. // WithIsBogusSignature if isBogusSignature is set, overrides the signature
  113. // in the authenticator response to be zero. Defaults to false.
  114. func (p SetResponseOverrideBitsParams) WithIsBogusSignature(isBogusSignature bool) *SetResponseOverrideBitsParams {
  115. p.IsBogusSignature = isBogusSignature
  116. return &p
  117. }
  118. // WithIsBadUV if isBadUV is set, overrides the UV bit in the flags in the
  119. // authenticator response to be zero. Defaults to false.
  120. func (p SetResponseOverrideBitsParams) WithIsBadUV(isBadUV bool) *SetResponseOverrideBitsParams {
  121. p.IsBadUV = isBadUV
  122. return &p
  123. }
  124. // WithIsBadUP if isBadUP is set, overrides the UP bit in the flags in the
  125. // authenticator response to be zero. Defaults to false.
  126. func (p SetResponseOverrideBitsParams) WithIsBadUP(isBadUP bool) *SetResponseOverrideBitsParams {
  127. p.IsBadUP = isBadUP
  128. return &p
  129. }
  130. // Do executes WebAuthn.setResponseOverrideBits against the provided context.
  131. func (p *SetResponseOverrideBitsParams) Do(ctx context.Context) (err error) {
  132. return cdp.Execute(ctx, CommandSetResponseOverrideBits, p, nil)
  133. }
  134. // RemoveVirtualAuthenticatorParams removes the given authenticator.
  135. type RemoveVirtualAuthenticatorParams struct {
  136. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  137. }
  138. // RemoveVirtualAuthenticator removes the given authenticator.
  139. //
  140. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-removeVirtualAuthenticator
  141. //
  142. // parameters:
  143. //
  144. // authenticatorID
  145. func RemoveVirtualAuthenticator(authenticatorID AuthenticatorID) *RemoveVirtualAuthenticatorParams {
  146. return &RemoveVirtualAuthenticatorParams{
  147. AuthenticatorID: authenticatorID,
  148. }
  149. }
  150. // Do executes WebAuthn.removeVirtualAuthenticator against the provided context.
  151. func (p *RemoveVirtualAuthenticatorParams) Do(ctx context.Context) (err error) {
  152. return cdp.Execute(ctx, CommandRemoveVirtualAuthenticator, p, nil)
  153. }
  154. // AddCredentialParams adds the credential to the specified authenticator.
  155. type AddCredentialParams struct {
  156. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  157. Credential *Credential `json:"credential"`
  158. }
  159. // AddCredential adds the credential to the specified authenticator.
  160. //
  161. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-addCredential
  162. //
  163. // parameters:
  164. //
  165. // authenticatorID
  166. // credential
  167. func AddCredential(authenticatorID AuthenticatorID, credential *Credential) *AddCredentialParams {
  168. return &AddCredentialParams{
  169. AuthenticatorID: authenticatorID,
  170. Credential: credential,
  171. }
  172. }
  173. // Do executes WebAuthn.addCredential against the provided context.
  174. func (p *AddCredentialParams) Do(ctx context.Context) (err error) {
  175. return cdp.Execute(ctx, CommandAddCredential, p, nil)
  176. }
  177. // GetCredentialParams returns a single credential stored in the given
  178. // virtual authenticator that matches the credential ID.
  179. type GetCredentialParams struct {
  180. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  181. CredentialID string `json:"credentialId"`
  182. }
  183. // GetCredential returns a single credential stored in the given virtual
  184. // authenticator that matches the credential ID.
  185. //
  186. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-getCredential
  187. //
  188. // parameters:
  189. //
  190. // authenticatorID
  191. // credentialID
  192. func GetCredential(authenticatorID AuthenticatorID, credentialID string) *GetCredentialParams {
  193. return &GetCredentialParams{
  194. AuthenticatorID: authenticatorID,
  195. CredentialID: credentialID,
  196. }
  197. }
  198. // GetCredentialReturns return values.
  199. type GetCredentialReturns struct {
  200. Credential *Credential `json:"credential,omitempty,omitzero"`
  201. }
  202. // Do executes WebAuthn.getCredential against the provided context.
  203. //
  204. // returns:
  205. //
  206. // credential
  207. func (p *GetCredentialParams) Do(ctx context.Context) (credential *Credential, err error) {
  208. // execute
  209. var res GetCredentialReturns
  210. err = cdp.Execute(ctx, CommandGetCredential, p, &res)
  211. if err != nil {
  212. return nil, err
  213. }
  214. return res.Credential, nil
  215. }
  216. // GetCredentialsParams returns all the credentials stored in the given
  217. // virtual authenticator.
  218. type GetCredentialsParams struct {
  219. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  220. }
  221. // GetCredentials returns all the credentials stored in the given virtual
  222. // authenticator.
  223. //
  224. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-getCredentials
  225. //
  226. // parameters:
  227. //
  228. // authenticatorID
  229. func GetCredentials(authenticatorID AuthenticatorID) *GetCredentialsParams {
  230. return &GetCredentialsParams{
  231. AuthenticatorID: authenticatorID,
  232. }
  233. }
  234. // GetCredentialsReturns return values.
  235. type GetCredentialsReturns struct {
  236. Credentials []*Credential `json:"credentials,omitempty,omitzero"`
  237. }
  238. // Do executes WebAuthn.getCredentials against the provided context.
  239. //
  240. // returns:
  241. //
  242. // credentials
  243. func (p *GetCredentialsParams) Do(ctx context.Context) (credentials []*Credential, err error) {
  244. // execute
  245. var res GetCredentialsReturns
  246. err = cdp.Execute(ctx, CommandGetCredentials, p, &res)
  247. if err != nil {
  248. return nil, err
  249. }
  250. return res.Credentials, nil
  251. }
  252. // RemoveCredentialParams removes a credential from the authenticator.
  253. type RemoveCredentialParams struct {
  254. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  255. CredentialID string `json:"credentialId"`
  256. }
  257. // RemoveCredential removes a credential from the authenticator.
  258. //
  259. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-removeCredential
  260. //
  261. // parameters:
  262. //
  263. // authenticatorID
  264. // credentialID
  265. func RemoveCredential(authenticatorID AuthenticatorID, credentialID string) *RemoveCredentialParams {
  266. return &RemoveCredentialParams{
  267. AuthenticatorID: authenticatorID,
  268. CredentialID: credentialID,
  269. }
  270. }
  271. // Do executes WebAuthn.removeCredential against the provided context.
  272. func (p *RemoveCredentialParams) Do(ctx context.Context) (err error) {
  273. return cdp.Execute(ctx, CommandRemoveCredential, p, nil)
  274. }
  275. // ClearCredentialsParams clears all the credentials from the specified
  276. // device.
  277. type ClearCredentialsParams struct {
  278. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  279. }
  280. // ClearCredentials clears all the credentials from the specified device.
  281. //
  282. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-clearCredentials
  283. //
  284. // parameters:
  285. //
  286. // authenticatorID
  287. func ClearCredentials(authenticatorID AuthenticatorID) *ClearCredentialsParams {
  288. return &ClearCredentialsParams{
  289. AuthenticatorID: authenticatorID,
  290. }
  291. }
  292. // Do executes WebAuthn.clearCredentials against the provided context.
  293. func (p *ClearCredentialsParams) Do(ctx context.Context) (err error) {
  294. return cdp.Execute(ctx, CommandClearCredentials, p, nil)
  295. }
  296. // SetUserVerifiedParams sets whether User Verification succeeds or fails for
  297. // an authenticator. The default is true.
  298. type SetUserVerifiedParams struct {
  299. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  300. IsUserVerified bool `json:"isUserVerified"`
  301. }
  302. // SetUserVerified sets whether User Verification succeeds or fails for an
  303. // authenticator. The default is true.
  304. //
  305. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setUserVerified
  306. //
  307. // parameters:
  308. //
  309. // authenticatorID
  310. // isUserVerified
  311. func SetUserVerified(authenticatorID AuthenticatorID, isUserVerified bool) *SetUserVerifiedParams {
  312. return &SetUserVerifiedParams{
  313. AuthenticatorID: authenticatorID,
  314. IsUserVerified: isUserVerified,
  315. }
  316. }
  317. // Do executes WebAuthn.setUserVerified against the provided context.
  318. func (p *SetUserVerifiedParams) Do(ctx context.Context) (err error) {
  319. return cdp.Execute(ctx, CommandSetUserVerified, p, nil)
  320. }
  321. // SetAutomaticPresenceSimulationParams sets whether tests of user presence
  322. // will succeed immediately (if true) or fail to resolve (if false) for an
  323. // authenticator. The default is true.
  324. type SetAutomaticPresenceSimulationParams struct {
  325. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  326. Enabled bool `json:"enabled"`
  327. }
  328. // SetAutomaticPresenceSimulation sets whether tests of user presence will
  329. // succeed immediately (if true) or fail to resolve (if false) for an
  330. // authenticator. The default is true.
  331. //
  332. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setAutomaticPresenceSimulation
  333. //
  334. // parameters:
  335. //
  336. // authenticatorID
  337. // enabled
  338. func SetAutomaticPresenceSimulation(authenticatorID AuthenticatorID, enabled bool) *SetAutomaticPresenceSimulationParams {
  339. return &SetAutomaticPresenceSimulationParams{
  340. AuthenticatorID: authenticatorID,
  341. Enabled: enabled,
  342. }
  343. }
  344. // Do executes WebAuthn.setAutomaticPresenceSimulation against the provided context.
  345. func (p *SetAutomaticPresenceSimulationParams) Do(ctx context.Context) (err error) {
  346. return cdp.Execute(ctx, CommandSetAutomaticPresenceSimulation, p, nil)
  347. }
  348. // SetCredentialPropertiesParams allows setting credential properties.
  349. // https://w3c.github.io/webauthn/#sctn-automation-set-credential-properties.
  350. type SetCredentialPropertiesParams struct {
  351. AuthenticatorID AuthenticatorID `json:"authenticatorId"`
  352. CredentialID string `json:"credentialId"`
  353. BackupEligibility bool `json:"backupEligibility"`
  354. BackupState bool `json:"backupState"`
  355. }
  356. // SetCredentialProperties allows setting credential properties.
  357. // https://w3c.github.io/webauthn/#sctn-automation-set-credential-properties.
  358. //
  359. // See: https://chromedevtools.github.io/devtools-protocol/tot/WebAuthn#method-setCredentialProperties
  360. //
  361. // parameters:
  362. //
  363. // authenticatorID
  364. // credentialID
  365. func SetCredentialProperties(authenticatorID AuthenticatorID, credentialID string) *SetCredentialPropertiesParams {
  366. return &SetCredentialPropertiesParams{
  367. AuthenticatorID: authenticatorID,
  368. CredentialID: credentialID,
  369. BackupEligibility: false,
  370. BackupState: false,
  371. }
  372. }
  373. // WithBackupEligibility [no description].
  374. func (p SetCredentialPropertiesParams) WithBackupEligibility(backupEligibility bool) *SetCredentialPropertiesParams {
  375. p.BackupEligibility = backupEligibility
  376. return &p
  377. }
  378. // WithBackupState [no description].
  379. func (p SetCredentialPropertiesParams) WithBackupState(backupState bool) *SetCredentialPropertiesParams {
  380. p.BackupState = backupState
  381. return &p
  382. }
  383. // Do executes WebAuthn.setCredentialProperties against the provided context.
  384. func (p *SetCredentialPropertiesParams) Do(ctx context.Context) (err error) {
  385. return cdp.Execute(ctx, CommandSetCredentialProperties, p, nil)
  386. }
  387. // Command names.
  388. const (
  389. CommandEnable = "WebAuthn.enable"
  390. CommandDisable = "WebAuthn.disable"
  391. CommandAddVirtualAuthenticator = "WebAuthn.addVirtualAuthenticator"
  392. CommandSetResponseOverrideBits = "WebAuthn.setResponseOverrideBits"
  393. CommandRemoveVirtualAuthenticator = "WebAuthn.removeVirtualAuthenticator"
  394. CommandAddCredential = "WebAuthn.addCredential"
  395. CommandGetCredential = "WebAuthn.getCredential"
  396. CommandGetCredentials = "WebAuthn.getCredentials"
  397. CommandRemoveCredential = "WebAuthn.removeCredential"
  398. CommandClearCredentials = "WebAuthn.clearCredentials"
  399. CommandSetUserVerified = "WebAuthn.setUserVerified"
  400. CommandSetAutomaticPresenceSimulation = "WebAuthn.setAutomaticPresenceSimulation"
  401. CommandSetCredentialProperties = "WebAuthn.setCredentialProperties"
  402. )