I have followed this tutorial https://webauthn.guide/#registration
I am working with a yubico nfc key and I nearly managed to enroll the security key. I send a random byte challenge from the server to enroll the key, and other data.
When I register the key I managed to decode the clientDataJson and the authentication response to retrieve a lot of information. However I cannot figure out what to do with the credentialId et authData buffers, I tried decoding them, decrypt them but I always got somme strange data and nothing that looks like a credentialId or a public key.
Here is the code I got so far
var createCredentialDefaultArgs = {
publicKey: {
// Relying Party (a.k.a. - Service):
rp: {
name: 'Dummy'
},
// User:
user: {
id: new Uint8Array(16),
name: 'John Doe',
displayName: 'Mr Doe'
},
pubKeyCredParams: [{
type: "public-key",
alg: -7
}],
attestation: "direct",
timeout: 60000,
challenge: new Uint8Array(/* stuff*/).buffer
}
};
$('[data-register-webauthn]')
.on('click', function () {
// register / create a new credential
navigator.credentials.create(createCredentialDefaultArgs)
.then((cred) => {
console.log("NEW CREDENTIAL", cred);
const utf8Decoder = new TextDecoder('utf-8');
const decodedClientData = utf8Decoder.decode(cred.response.clientDataJSON);
// parse the string as an object
const clientDataObj = JSON.parse(decodedClientData);
const decodedAttestationObj = CBOR.decode(cred.response.attestationObject);
const {authData} = decodedAttestationObj;
// get the length of the credential ID
const dataView = new DataView(new ArrayBuffer(2));
const idLenBytes = authData.slice(53, 55);
idLenBytes.forEach(
(value, index) => dataView.setUint8(
index, value)
);
const credentialIdLength = dataView.getUint16();
// get the credential ID
const credentialId = authData.slice(
55, credentialIdLength);
// get the public key object
const publicKeyBytes = authData.slice(
55 + credentialIdLength);
// the publicKeyBytes are encoded again as CBOR
const publicKeyObject = CBOR.decode(
publicKeyBytes.buffer);
console.log(publicKeyObject)
})
.catch((err) => {
console.log("ERROR", err);
});
})
In the end, I don't know what to do with the public key object and the credentialId. Deconding seems useless.
Any idea ?