First draft

This commit is contained in:
varjolintu 2022-10-13 20:23:38 +03:00
parent 4a3eb6b84b
commit 653cca7419
4 changed files with 62 additions and 10 deletions

View file

@ -247,5 +247,7 @@ kpxcEvent.messageHandlers = {
'username_field_detected': kpxcEvent.onUsernameFieldDetected,
'save_settings': kpxcEvent.onSaveSettings,
'update_available_keepassxc': kpxcEvent.onUpdateAvailableKeePassXC,
'update_context_menu': page.updateContextMenu
'update_context_menu': page.updateContextMenu,
'webauthn-get': keepass.webauthnGet,
'webauthn-register': keepass.webauthnRegister
};

View file

@ -33,7 +33,9 @@ const kpActions = {
GET_DATABASE_GROUPS: 'get-database-groups',
CREATE_NEW_GROUP: 'create-new-group',
GET_TOTP: 'get-totp',
REQUEST_AUTOTYPE: 'request-autotype'
REQUEST_AUTOTYPE: 'request-autotype',
WEBAUTHN_REGISTER: 'webauthn-register',
WEBAUTHN_GET: 'webauthn-get'
};
browser.storage.local.get({ 'latestKeePassXC': { 'version': '', 'lastChecked': null }, 'keyRing': {} }).then((item) => {
@ -622,6 +624,40 @@ keepass.requestAutotype = async function(tab, args = []) {
}
};
keepass.webauthnRegister = async function(tab, publicKey) {
try {
const taResponse = await keepass.testAssociation(tab, [ false ]);
if (!taResponse || !keepass.isConnected) {
browserAction.showDefault(tab);
return [];
}
const kpAction = kpActions.WEBAUTHN_REGISTER;
const nonce = keepassClient.getNonce();
const messageData = {
action: kpAction,
publicKey: JSON.parse(JSON.stringify(publicKey))
};
const response = await keepassClient.sendMessage(kpAction, tab, messageData, nonce);
if (response) {
return [];
}
browserAction.showDefault(tab);
return [];
} catch (err) {
logError(`webauthnRegister failed: ${err}`);
return [];
}
};
keepass.webauthnGet = async function(tab) {
return [];
};
//--------------------------------------------------------------------------
// Keyring
//--------------------------------------------------------------------------

View file

@ -852,9 +852,12 @@ document.documentElement.appendChild(webauthn);
window.addEventListener('message', (ev) => {
if (ev.data.action === 'webauthn-create') {
console.log('Request from: ', ev.origin);
console.log(ev.data.publicKey);
// Send a test response after a delay
setInterval(() => {
sendMessage('webauthn-register', ev.data.publicKey);
// Send a test response after a delay. webauthn.js should wait for this.
setTimeout(() => {
window.postMessage({ action: 'webauthn-create-response' }, window.location.origin);
}, 2000);
}

View file

@ -1,15 +1,26 @@
'use strict';
(async () => {
const webauthnCredentials = {
async create(options) {
console.log('Overridden create');
console.log('Overridden create');
//await browser.runtime.sendMessage({ action: 'request_autotype', args: [ window.location.hostname ] });
window.postMessage({ action: 'webauthn-create' }, window.location.origin);
await waitForCreateResponse();
const publicKey = {};
publicKey.attestation = options.publicKey.attestation;
publicKey.authenticatorSelection = options.publicKey.authenticatorSelection;
publicKey.challenge = new Uint8Array(options.publicKey.challenge).toString();
publicKey.pubKeyCredParams = options.publicKey.pubKeyCredParams;
publicKey.rp = options.publicKey.rp;
publicKey.timeout = options.publicKey.timeout;
publicKey.user = options.publicKey.user;
publicKey.user.id = options.publicKey.user.id.toString();
/*const credential = await navigator.credentials.create({
publicKey: publicKey
});*/
window.postMessage({ action: 'webauthn-create', publicKey: publicKey }, window.location.origin);
//await waitForCreateResponse();
},
async get(options) {
console.log('Overridden get');