don't throw when trying to restore session from backup, check sender key

This commit is contained in:
Bruno Windels 2020-09-17 17:57:52 +02:00
parent a205ae8841
commit 915925d6ee

View file

@ -137,39 +137,45 @@ export class RoomEncryption {
let eventIds = this._eventIdsByMissingSession.get(key); let eventIds = this._eventIdsByMissingSession.get(key);
// new missing session // new missing session
if (!eventIds) { if (!eventIds) {
this._requestMissingSessionFromBackup(sessionId).catch(err => { this._requestMissingSessionFromBackup(senderKey, sessionId);
console.error(`Could not get session ${sessionId} from backup`, err);
});
eventIds = new Set(); eventIds = new Set();
this._eventIdsByMissingSession.set(key, eventIds); this._eventIdsByMissingSession.set(key, eventIds);
} }
eventIds.add(event.event_id); eventIds.add(event.event_id);
} }
async _requestMissingSessionFromBackup(sessionId) { async _requestMissingSessionFromBackup(senderKey, sessionId) {
if (!this._sessionBackup) { if (!this._sessionBackup) {
// somehow prompt for passphrase here this._notifyMissingMegolmSession();
return; return;
} }
const session = await this._sessionBackup.getSession(this._room.id, sessionId); try {
if (session?.algorithm === MEGOLM_ALGORITHM) { const session = await this._sessionBackup.getSession(this._room.id, sessionId);
const txn = await this._storage.readWriteTxn([this._storage.storeNames.inboundGroupSessions]); if (session?.algorithm === MEGOLM_ALGORITHM) {
let roomKey; if (session["sender_key"] !== senderKey) {
try { console.warn("Got session key back from backup with different sender key, ignoring", {session, senderKey});
roomKey = await this._megolmDecryption.addRoomKeyFromBackup( return;
this._room.id, sessionId, session, txn); }
} catch (err) { const txn = await this._storage.readWriteTxn([this._storage.storeNames.inboundGroupSessions]);
txn.abort(); let roomKey;
throw err; try {
} roomKey = await this._megolmDecryption.addRoomKeyFromBackup(
await txn.complete(); this._room.id, sessionId, session, txn);
} catch (err) {
txn.abort();
throw err;
}
await txn.complete();
if (roomKey) { if (roomKey) {
// this will call into applyRoomKeys below // this will call into applyRoomKeys below
await this._room.notifyRoomKeys([roomKey]); await this._room.notifyRoomKeys([roomKey]);
}
} else if (session?.algorithm) {
console.info(`Backed-up session of unknown algorithm: ${session.algorithm}`);
} }
} else if (session?.algorithm) { } catch (err) {
console.info(`Backed-up session of unknown algorithm: ${session.algorithm}`); console.error(`Could not get session ${sessionId} from backup`, err);
} }
} }