diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 4c961a6..1c7699a 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -856,7 +856,7 @@ window.addEventListener('message', async (ev) => { const ret = await sendMessage('webauthn-register', [ ev.data.publicKey, ev.origin ]); if (ret.response) { - window.postMessage({ action: 'webauthn-create-response', data: ret.response.response }, window.location.origin); + window.postMessage({ action: 'webauthn-create-response', data: ret.response }, window.location.origin); } } }); diff --git a/keepassxc-browser/content/webauthn.js b/keepassxc-browser/content/webauthn.js index e500ab9..3e8b372 100644 --- a/keepassxc-browser/content/webauthn.js +++ b/keepassxc-browser/content/webauthn.js @@ -9,7 +9,7 @@ const postMessageToExtension = function(request) { const handler = (msg) => { if (msg && msg.data && msg.data.action === messageRequest + '-response') { messageEvent.removeEventListener('message', listener); - resolve(msg.data); + resolve(msg.data.data); return; } }; @@ -22,6 +22,20 @@ const postMessageToExtension = function(request) { }); }; +const stringToArrayBuffer = function(str) { + const arr = Uint8Array.from(str, c => c.charCodeAt(0)); + return arr.buffer; +}; + +const arrayToArrayBuffer = function(arr) { + const buf = Uint8Array.from(arr); + return buf.buffer; +} + +const base64ToArrayBuffer = function(str) { + return stringToArrayBuffer(atob(str)); +}; + (async () => { const webauthnCredentials = { async create(options) { @@ -37,13 +51,16 @@ const postMessageToExtension = function(request) { publicKey.user = options.publicKey.user; publicKey.user.id = window.btoa(options.publicKey.user.id); // Use b64 instead - const response = await postMessageToExtension({ action: 'webauthn-create', publicKey: publicKey }); - console.log('Response: ', response); + const publicKeyCredential = await postMessageToExtension({ action: 'webauthn-create', publicKey: publicKey }); + console.log('Response: ', publicKeyCredential); // Parse the response and change needed variables from b64 to ArrayBuffer/UInt8Array etc. + publicKeyCredential.rawId = base64ToArrayBuffer(publicKeyCredential.id); + publicKeyCredential.response.attestationObject.authData = arrayToArrayBuffer(publicKeyCredential.response.attestationObject.authData); + publicKeyCredential.response.clientDataJSON = stringToArrayBuffer(JSON.stringify(publicKeyCredential.response.clientDataJSON)); - - return []; + console.log('Final response: ', publicKeyCredential); + return publicKeyCredential; }, async get(options) { console.log('Overridden get');