On startup after 30+ days, delete local encryption info

This commit is contained in:
Scott Nonnenberg 2019-10-02 13:52:20 -07:00
parent 2481784ab2
commit 9cda14c4f2

View file

@ -430,6 +430,15 @@
await storage.put('indexeddb-delete-needed', true);
}
const currentStartup = Date.now();
const lastStartup = storage.get('lastStartup');
await storage.put('lastStartup', currentStartup);
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
if (lastStartup > 0 && currentStartup - lastStartup > THIRTY_DAYS) {
await unlinkAndDisconnect();
}
const currentVersion = window.getVersion();
const lastVersion = storage.get('version');
newVersion = !lastVersion || currentVersion !== lastVersion;
@ -1662,15 +1671,7 @@
return message;
}
async function onError(ev) {
const { error } = ev;
window.log.error('background onError:', Errors.toLogFormat(error));
if (
error &&
error.name === 'HTTPError' &&
(error.code === 401 || error.code === 403)
) {
async function unlinkAndDisconnect() {
Whisper.events.trigger('unauthorized');
if (messageReceiver) {
@ -1695,9 +1696,7 @@
const IS_MIGRATION_COMPLETE_KEY = 'attachmentMigration_isComplete';
const previousNumberId = textsecure.storage.get(NUMBER_ID_KEY);
const lastProcessedIndex = textsecure.storage.get(
LAST_PROCESSED_INDEX_KEY
);
const lastProcessedIndex = textsecure.storage.get(LAST_PROCESSED_INDEX_KEY);
const isMigrationComplete = textsecure.storage.get(
IS_MIGRATION_COMPLETE_KEY
);
@ -1729,7 +1728,18 @@
eraseError && eraseError.stack ? eraseError.stack : eraseError
);
}
}
async function onError(ev) {
const { error } = ev;
window.log.error('background onError:', Errors.toLogFormat(error));
if (
error &&
error.name === 'HTTPError' &&
(error.code === 401 || error.code === 403)
) {
await unlinkAndDisconnect();
return;
}