Home > Blockchain >  Producing the same signature with WebAuthn
Producing the same signature with WebAuthn

Time:01-11

I just started playing around with WebAuthn on localhost. I was given to understand that the signature value found in credentials.response.signature was signing credentials.response.clientDataJSON. However, for the same inputs / challenge for navigator.credentials.get I seem to be getting a different signature. My best guess is there is a timestamp or counter going somewhere into the value that is signed?

I can't seem to decode the signature or authenticatorData, which would really help me to visualize what's going on inside. I'm able to decode clientDataJSON as follows, anyone have sample code with which I code decode the other two aforementioned params?

String.fromCharCode.apply(null, new Uint8Array(credentials.response.clientDataJSON))

I also found when decoding clientDataJSON I get the occasional extra field in Chrome, which is a little annoying for my use case.

My goal is to get the user to produce the same signature or hash each time when authenticating the same PublicKeyCredential. Is there a way to do this? or are there other methods within the scrope of WebAuthn or outside of its scope to benefit from the biometric auth with which I can produce identical signatures or hashes from the same inputs?

Please forgive any misconceptions I might have about WebAuthn, I'm quite new to this amazing tech. I completely understand that this is not the original intended use of WebAuthn so a janky workaround may be needed.

CodePudding user response:

My goal is to get the user to produce the same signature or hash each time when authenticating the same PublicKeyCredential.

This is actually a really bad idea. The whole purpose of signing a message with a random challenge is to avoid replay attacks. Otherwise, if an attacker somehow intercepts an authentication message, that message could simply be reused to impersonate the user.

I was given to understand that the signature value found in credentials.response.signature was signing credentials.response.clientDataJSON

That is not accurate. The signature signs authenticatorData SHA256(clientDataJSON).

Both are variable. The authenticatorData contains a "counter" increasing each time the credential key was used to authenticate and clientDataJSON should (or must to be secure) contain a randomly server side generated challenge.

I can't seem to decode the signature or authenticatorData, which would really help me to visualize what's going on inside. I'm able to decode clientDataJSON as follows, anyone have sample code with which I code decode the other two aforementioned params?

The signature cannot be "decoded", it can only be "verified" given the adequate public key. For the other paramters authenticatorData and clientDataJSON , check out the following link at the bottom, it will decode them.

https://webauthn.passwordless.id/demos/playground.html

I also found when decoding clientDataJSON I get the occasional extra field in Chrome, which is a little annoying for my use case.

I'm not sure, I believe this is related to localhost testing.

CodePudding user response:

If you want a small, fixed bit of data associated with a credential then you may wish to investigate the credBlob or prf extensions. Not all authenticators will support them, however. Many more will support prf but support for that in Chromium won't appear for a few more months. So there's not a great answer here yet, but it may work better than trying to fix the signature.

  • Related