Merge pull request #2341 from element-hq/midhun/fix-encryption-basic-text

Enable plain text encryption early if we actually mean to use `basic_text` as backend
This commit is contained in:
R Midhun Suresh
2025-05-22 17:11:02 +05:30
committed by GitHub

View File

@@ -261,6 +261,12 @@ class Store extends ElectronStore<StoreData> {
return this.upgradeLinuxBackend2();
}
// The following enables plain text encryption if the backend used is basic_text.
// It has no significance for any other backend.
// We do this early so that in case we end up using the basic_text backend (either because that's the only one available
// or as a fallback when the configured backend lacks encryption support), encryption is already turned on.
safeStorage.setUsePlainTextEncryption(true);
// Whether we were using basic_text as a fallback before
const usingFallback = this.get("safeStorageBackendOverride") && safeStorageBackend === "basic_text";
@@ -343,12 +349,6 @@ class Store extends ElectronStore<StoreData> {
await clearDataAndRelaunch();
}
}
// We do not check allowPlaintextStorage here as it was already checked above if the storage is new
// and if the storage is existing then we should continue to honour the backend used to write the data
if (safeStorageBackend === "basic_text" && selectedSafeStorageBackend === safeStorageBackend) {
safeStorage.setUsePlainTextEncryption(true);
}
} else if (!safeStorageBackend) {
safeStorageBackend = this.mode === Mode.Encrypted ? "system" : "plaintext";
this.recordSafeStorageBackend(safeStorageBackend);