I'm trying to implement webauthn, but am having trouble getting the signature verification to work. According to https://w3c.github.io/webauthn/#verifying-assertion I have to basically verify the signature over the following data:
authData || sha256(clientDataJSON)
The authData and the sha256 hash should be "binary concatenated". I have no idea what they mean with that, exactly, but I assume they just mean to stick the bytes next to each other, no idea what exactly would be "binary" about that though.
So, given a PublicKeyCredential named attestation, I can generate the data over which the signature is generated as follows:
var auth_data = new Uint8Array(attestation.response.authenticatorData);
var data_hash = sha256(new Uint8Array(attestation.response.clientDataJSON));
var signed = new Uint8Array(auth_data.length + data_hash.length);
signed.set(auth_data);
signed.set(data_hash, auth_data.length);
I have of course tried validating this 'signed' value directly, and I have tried hashing it as well. Neither of them validate. What am I doing wrong in calculating the data which is signed?
I have the equivalent code on the server side (in C++) where I build the same value and then verify it with OpenSSL. This signed calculation is only to show what I'm doing - I won't trust that value server-side of course.