From 02f06724d07bea709d4d6a1c9530d55bec1a804c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 1 Feb 2022 11:26:00 +0100 Subject: [PATCH] don't block reenabling 4s if already enabled --- src/matrix/Session.js | 3 ++- src/matrix/e2ee/megolm/keybackup/Curve25519.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 868a743b..3404a6aa 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -195,7 +195,8 @@ export class Session { throw new Error("olm required"); } if (this._keyBackup.get()) { - return false; + this._keyBackup.get().dispose(); + this._keyBackup.set(undefined); } const key = await ssssKeyFromCredential(type, credential, this._storage, this._platform, this._olm); // and create key backup, which needs to read from accountData diff --git a/src/matrix/e2ee/megolm/keybackup/Curve25519.ts b/src/matrix/e2ee/megolm/keybackup/Curve25519.ts index 8007d422..7d2ebac7 100644 --- a/src/matrix/e2ee/megolm/keybackup/Curve25519.ts +++ b/src/matrix/e2ee/megolm/keybackup/Curve25519.ts @@ -41,8 +41,8 @@ export type SessionData = { export class BackupEncryption { constructor( - private readonly encryption: Olm.PkEncryption, - private readonly decryption: Olm.PkDecryption + private encryption?: Olm.PkEncryption, + private decryption?: Olm.PkDecryption ) {} static fromAuthData(authData: AuthData, privateKey: Uint8Array, olm: Olm): BackupEncryption { @@ -63,7 +63,7 @@ export class BackupEncryption { } decryptRoomKey(sessionData: SessionData): SessionKeyInfo { - const sessionInfo = this.decryption.decrypt( + const sessionInfo = this.decryption!.decrypt( sessionData.ephemeral, sessionData.mac, sessionData.ciphertext, @@ -79,11 +79,13 @@ export class BackupEncryption { forwarding_curve25519_key_chain: [], session_key: sessionKey }; - return this.encryption.encrypt(JSON.stringify(sessionInfo)) as SessionData; + return this.encryption!.encrypt(JSON.stringify(sessionInfo)) as SessionData; } dispose() { - this.decryption.free(); - this.encryption.free(); + this.decryption?.free(); + this.decryption = undefined; + this.encryption?.free(); + this.encryption = undefined; } }