forked from mystiq/hydrogen-web
don't throw when trying to restore session from backup, check sender key
This commit is contained in:
parent
a205ae8841
commit
915925d6ee
1 changed files with 28 additions and 22 deletions
|
@ -137,22 +137,25 @@ 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;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const session = await this._sessionBackup.getSession(this._room.id, sessionId);
|
const session = await this._sessionBackup.getSession(this._room.id, sessionId);
|
||||||
if (session?.algorithm === MEGOLM_ALGORITHM) {
|
if (session?.algorithm === MEGOLM_ALGORITHM) {
|
||||||
|
if (session["sender_key"] !== senderKey) {
|
||||||
|
console.warn("Got session key back from backup with different sender key, ignoring", {session, senderKey});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const txn = await this._storage.readWriteTxn([this._storage.storeNames.inboundGroupSessions]);
|
const txn = await this._storage.readWriteTxn([this._storage.storeNames.inboundGroupSessions]);
|
||||||
let roomKey;
|
let roomKey;
|
||||||
try {
|
try {
|
||||||
|
@ -171,6 +174,9 @@ export class RoomEncryption {
|
||||||
} else if (session?.algorithm) {
|
} else if (session?.algorithm) {
|
||||||
console.info(`Backed-up session of unknown algorithm: ${session.algorithm}`);
|
console.info(`Backed-up session of unknown algorithm: ${session.algorithm}`);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Could not get session ${sessionId} from backup`, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue