我已按照本教程https://webauthn.guide/#registration
我正在使用 yubico nfc 密钥,我几乎设法注册了安全密钥。我从服务器发送一个随机字节质询来注册密钥和其他数据。
当我注册密钥时,我设法解码了 clientDataJson 和身份验证响应以检索大量信息。但是,我无法弄清楚如何处理 credentialId 和 authData 缓冲区,我尝试对它们进行解码、解密,但我总是得到一些奇怪的数据,而且没有任何东西看起来像 credentialId 或公钥。
这是我到目前为止得到的代码
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);
});
})
最后,我不知道如何处理公钥对象和credentialId。解压似乎没用。
任何想法 ?