Skip to content

Commit a6caf94

Browse files
committed
Retry loading of the pickle key if the user is logged in.
If the Keyring is unavailable or not unlocked Element would start without being able to decrypt messages. This fix will ensure Element doesn't start unless it was able to retrieve the encryption key. Unlocking the Keyring at a later time would not result in the messages being decrypted. The app would need to be restarted to achieve this. This fixes https://github.com/vector-im/element-web/issues/17845
1 parent 0ba24ec commit a6caf94

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/Lifecycle.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,17 +418,21 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
418418
}
419419

420420
let decryptedAccessToken = accessToken;
421-
const pickleKey = await PlatformPeg.get().getPickleKey(userId, deviceId);
422-
if (pickleKey) {
423-
logger.log("Got pickle key");
424-
if (typeof accessToken !== "string") {
425-
const encrKey = await pickleKeyToAesKey(pickleKey);
426-
decryptedAccessToken = await decryptAES(accessToken, encrKey, "access_token");
427-
encrKey.fill(0);
421+
let pickleKey = null;
422+
do {
423+
pickleKey = await PlatformPeg.get().getPickleKey(userId, deviceId);
424+
if (pickleKey) {
425+
logger.log("Got pickle key");
426+
if (typeof accessToken !== "string") {
427+
const encrKey = await pickleKeyToAesKey(pickleKey);
428+
decryptedAccessToken = await decryptAES(accessToken, encrKey, "access_token");
429+
encrKey.fill(0);
430+
}
431+
} else {
432+
logger.log("No pickle key available. Waiting 1s and trying to read it again. (Hint: Is your Keyring unlocked?)");
433+
await new Promise(r => setTimeout(r, 1000));
428434
}
429-
} else {
430-
logger.log("No pickle key available");
431-
}
435+
} while(pickleKey == null);
432436

433437
const freshLogin = sessionStorage.getItem("mx_fresh_login") === "true";
434438
sessionStorage.removeItem("mx_fresh_login");

0 commit comments

Comments
 (0)