cypresswebauthnchrome-devtools-protocol

Chrome DevTools Protocol WebAuthn.addCredential returns error


I am trying to call the Chrome DevTools Protocol WebAuthn.addCredential method inside a Cypress test.

credential = {
    credentialId:"myid",
    isResidentCredential: true,
    rpId:"localhost",
    userHandle: "bXl1c2VyaGFuZGxlDQo=",
    privateKey: "my_private_key",
    signCount: 0,
  }

Cypress.automation('remote:debugger:protocol', {
  command: 'WebAuthn.addCredential',
  params: {
    authenticatorId: authenticatorId,
    credential,
  },
})

However, this throws a very unhelpful error:

Error: An error occurred trying to create the credential
    at <embedded>:2262:577727
    at _._handleMessage (<embedded>:2262:580030)
    at A.<anonymous> (<embedded>:2262:579669)
    at A.emit (node:events:514:28)
    at f.U (<embedded>:2262:564853)
    at f.emit (node:events:514:28)
    at f.dataMessage (<embedded>:2262:545228)
    at f.getData (<embedded>:2262:544410)
    at f.startLoop (<embedded>:2262:541117)
    at f._write (<embedded>:2262:540472)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at f.write (node:internal/streams/writable:337:10)
    at Socket.W (<embedded>:2262:565539)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
From previous event:
    at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (http://localhost:5172/__cypress/runner/cypress_runner.js:3486:19)
    at Promise._then (http://localhost:5172/__cypress/runner/cypress_runner.js:1239:17)
    at Promise.then (http://localhost:5172/__cypress/runner/cypress_runner.js:1132:17)
    at next (http://localhost:5172/__cypress/runner/cypress_runner.js:144101:64)
    at http://localhost:5172/__cypress/runner/cypress_runner.js:144122:16
    at tryCatcher (http://localhost:5172/__cypress/runner/cypress_runner.js:1807:23)
    at Promise._settlePromiseFromHandler (http://localhost:5172/__cypress/runner/cypress_runner.js:1519:31)
    at Promise._settlePromise (http://localhost:5172/__cypress/runner/cypress_runner.js:1576:18)
    at Promise._settlePromise0 (http://localhost:5172/__cypress/runner/cypress_runner.js:1621:10)
    at Promise._settlePromises (http://localhost:5172/__cypress/runner/cypress_runner.js:1701:18)
    at http://localhost:5172/__cypress/runner/cypress_runner.js:2392:25

Any ideas what could be wrong? I created the private key with the instructions given here


Solution

  • Figured out what was wrong, it was something wrong with the private key, though I have no idea what. After trying to create a working pair of private-public keys through the Internet and failing, this is what I did:

    Using my Cypress test for signup with WebAuthn (which I had already done and was working), I created the credential using navigator.credentials.create(). Then I added an extra test step which got the Virtual Web Authenticator credentials using the Chrome DevTools Protocol WebAuthn.getCredentials command, and printed the result. That gave me the private key. Then, after completing the test, I went to my test database and checked the webauthn record created for the user that signed up with the test. That gave me the public key.