MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

Parsing the attestation data explicitly #560

Closed wparad closed 7 months ago

wparad commented 7 months ago

We would like to easily parse the attestation data, but the library does not expose an explicitly method to do this. Right now that means we need to almost fake calling verifyRegistrationResponse again with the right inputs whenever we want this. It would be really great to have the method to parse the attestation data available on the exposed interface.

MasterKale commented 7 months ago

Check out decodeAttestationObject() and parseAuthenticatorData() exported from @simplewebauthn/server/helpers. Do either of those help you achieve your goals? There are many other helpers exported from there that you might find interesting too:

https://github.com/MasterKale/SimpleWebAuthn/blob/b299b51a0b4cd2731aa4ee2e5644ee13bab9843f/packages/server/src/helpers/index.ts#L18-L38

wparad commented 7 months ago

Hmmm, I didn't realize it was a separate export in the package.json. Maybe there is a better way to do this, but this seems a bit annoying:

parseAuthenticatorData(
    decodeAttestationObject(
        new Uint8Array(base64url.toBuffer(attestation))
    ).get('authData'));

And I will also add that depending on the usage, callers of the library might need to explicitly exclude lint issues with:

"node/no-missing-require": ["error", {
      "allowModules": ["@simplewebauthn/server"]
    }]

Link to issue with require statements in eslint

I would have expected a single method that takes in the attestation in the same format as verifyRegistrationResponse which is base64url and returns the same object that is the response RegistrationData without needing to stack these methods or know to convert to a Uint8Array.

But I guess this is technically already supported, so we can close it.

MasterKale commented 7 months ago

Thanks for the feedback @wparad. These helpers are used internally by the various option-generation and response-verification methods that represent the core methods of the @simplewebauthn/server package. I make them available via the helpers import for those who are intrepid enough to break out of the core WebAuthn use cases, so a bit of extra work should always be expected when using them.