Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Retry loading of the pickle key if the user is logged in.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ReneHollander committed Oct 23, 2021
1 parent 0ba24ec commit a6caf94
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,21 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }):
}

let decryptedAccessToken = accessToken;
const pickleKey = await PlatformPeg.get().getPickleKey(userId, deviceId);
if (pickleKey) {
logger.log("Got pickle key");
if (typeof accessToken !== "string") {
const encrKey = await pickleKeyToAesKey(pickleKey);
decryptedAccessToken = await decryptAES(accessToken, encrKey, "access_token");
encrKey.fill(0);
let pickleKey = null;
do {
pickleKey = await PlatformPeg.get().getPickleKey(userId, deviceId);
if (pickleKey) {
logger.log("Got pickle key");
if (typeof accessToken !== "string") {
const encrKey = await pickleKeyToAesKey(pickleKey);
decryptedAccessToken = await decryptAES(accessToken, encrKey, "access_token");
encrKey.fill(0);
}
} else {
logger.log("No pickle key available. Waiting 1s and trying to read it again. (Hint: Is your Keyring unlocked?)");
await new Promise(r => setTimeout(r, 1000));
}
} else {
logger.log("No pickle key available");
}
} while(pickleKey == null);

const freshLogin = sessionStorage.getItem("mx_fresh_login") === "true";
sessionStorage.removeItem("mx_fresh_login");
Expand Down

0 comments on commit a6caf94

Please sign in to comment.