Check the local storage fallback for crypto store
This adds additional consistency checks to examine the local storage fallback for the crypto store as well as the primary IndexedDB variant. Part of https://github.com/vector-im/riot-web/issues/9309
This commit is contained in:
parent
45e4948d9a
commit
4c65587469
1 changed files with 27 additions and 8 deletions
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import Matrix from 'matrix-js-sdk';
|
||||
import LocalStorageCryptoStore from 'matrix-js-sdk/lib/crypto/store/localStorage-crypto-store';
|
||||
import Analytics from '../Analytics';
|
||||
|
||||
const localStorage = window.localStorage;
|
||||
|
@ -78,15 +79,10 @@ export async function checkConsistency() {
|
|||
}
|
||||
|
||||
if (indexedDB) {
|
||||
try {
|
||||
dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists(
|
||||
indexedDB, CRYPTO_STORE_NAME,
|
||||
);
|
||||
log(`Crypto store contains data? ${dataInCryptoStore}`);
|
||||
} catch (e) {
|
||||
const results = await checkCryptoStore();
|
||||
dataInCryptoStore = results.exists;
|
||||
if (!results.healthy) {
|
||||
healthy = false;
|
||||
error("Crypto store inaccessible", e);
|
||||
track("Crypto store inaccessible");
|
||||
}
|
||||
} else {
|
||||
healthy = false;
|
||||
|
@ -111,3 +107,26 @@ export async function checkConsistency() {
|
|||
track("Consistency checks failed");
|
||||
}
|
||||
}
|
||||
|
||||
async function checkCryptoStore() {
|
||||
let exists = false;
|
||||
try {
|
||||
exists = await Matrix.IndexedDBCryptoStore.exists(
|
||||
indexedDB, CRYPTO_STORE_NAME,
|
||||
);
|
||||
log(`Crypto store using IndexedDB contains data? ${exists}`);
|
||||
return { exists, healthy: true };
|
||||
} catch (e) {
|
||||
error("Crypto store using IndexedDB inaccessible", e);
|
||||
track("Crypto store using IndexedDB inaccessible");
|
||||
}
|
||||
try {
|
||||
exists = await LocalStorageCryptoStore.exists(localStorage);
|
||||
log(`Crypto store using local storage contains data? ${exists}`);
|
||||
return { exists, healthy: true };
|
||||
} catch (e) {
|
||||
error("Crypto store using local storage inaccessible", e);
|
||||
track("Crypto store using local storage inaccessible");
|
||||
}
|
||||
return { exists, healthy: false };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue