From f8e9e1d3bd36992786fd5c24bff0e43b2c4d16ed Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Thu, 19 Sep 2019 16:55:51 +1000 Subject: [PATCH] Remove rejected authorisation from database --- app/sql.js | 10 ++++++++++ js/background.js | 1 + js/modules/data.js | 8 ++++++++ libloki/storage.js | 5 +++++ 4 files changed, 24 insertions(+) diff --git a/app/sql.js b/app/sql.js index e9eeee34c..3d2fe1bae 100644 --- a/app/sql.js +++ b/app/sql.js @@ -74,6 +74,7 @@ module.exports = { removeAllContactSignedPreKeys, createOrUpdatePairingAuthorisation, + removePairingAuthorisationForSecondaryPubKey, getAuthorisationForPubKey, getSecondaryDevicesFor, getPrimaryDeviceFor, @@ -1412,6 +1413,15 @@ async function createOrUpdatePairingAuthorisation(data) { ); } +async function removePairingAuthorisationForSecondaryPubKey(pubKey) { + await db.run( + `DELETE FROM ${PAIRING_AUTHORISATIONS_TABLE} WHERE secondaryDevicePubKey = $secondaryDevicePubKey;`, + { + $secondaryDevicePubKey: pubKey, + } + ); +} + async function getSecondaryDevicesFor(primaryDevicePubKey) { const rows = await db.all( `SELECT secondaryDevicePubKey FROM ${PAIRING_AUTHORISATIONS_TABLE} WHERE primaryDevicePubKey = $primaryDevicePubKey AND isGranted = 1 ORDER BY secondaryDevicePubKey ASC;`, diff --git a/js/background.js b/js/background.js index 271b9de2e..b7c8b5295 100644 --- a/js/background.js +++ b/js/background.js @@ -823,6 +823,7 @@ Whisper.events.on('devicePairingRequestRejected', async pubKey => { await window.libloki.storage.removeContactPreKeyBundle(pubKey); + await window.libloki.storage.removePairingAuthorisationForSecondaryPubKey(pubKey); }); } diff --git a/js/modules/data.js b/js/modules/data.js index 65e8384d4..c2dca9695 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -90,6 +90,7 @@ module.exports = { removeAllContactSignedPreKeys, createOrUpdatePairingAuthorisation, + removePairingAuthorisationForSecondaryPubKey, getGrantAuthorisationForPubKey, getAuthorisationForPubKey, getSecondaryDevicesFor, @@ -607,6 +608,13 @@ async function createOrUpdatePairingAuthorisation(data) { }); } +async function removePairingAuthorisationForSecondaryPubKey(pubKey) { + if (!pubKey){ + return; + } + await channels.removePairingAuthorisationForSecondaryPubKey(pubKey); +} + async function getGrantAuthorisationForPubKey(pubKey) { const authorisation = await channels.getAuthorisationForPubKey(pubKey, { granted: true, diff --git a/libloki/storage.js b/libloki/storage.js index c33696c3a..b83545827 100644 --- a/libloki/storage.js +++ b/libloki/storage.js @@ -117,6 +117,10 @@ return window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); } + function removePairingAuthorisationForSecondaryPubKey(pubKey) { + return window.Signal.Data.removePairingAuthorisationForSecondaryPubKey(pubKey); + } + function getGrantAuthorisationForSecondaryPubKey(secondaryPubKey) { return window.Signal.Data.getGrantAuthorisationForPubKey(secondaryPubKey); } @@ -141,6 +145,7 @@ removeContactPreKeyBundle, verifyFriendRequestAcceptPreKey, savePairingAuthorisation, + removePairingAuthorisationForSecondaryPubKey, getGrantAuthorisationForSecondaryPubKey, getAuthorisationForSecondaryPubKey, getAllDevicePubKeysForPrimaryPubKey,