don't block reenabling 4s if already enabled

This commit is contained in:
Bruno Windels 2022-02-01 11:26:00 +01:00
parent fd4eb6b50d
commit 02f06724d0
2 changed files with 10 additions and 7 deletions

View file

@ -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

View file

@ -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;
}
}