webauthn.go 16 KB

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