Fix "not attempting encryption" warning (#11899)
* Fix "not attempting encryption" warning Fixes https://github.com/vector-im/element-web/issues/26589 * Update src/utils/tokens/tokens.tspull/28788/head^2
parent
c968f11833
commit
7ca0cd13d0
|
@ -126,20 +126,21 @@ export async function persistTokenInStorage(
|
||||||
|
|
||||||
if (pickleKey) {
|
if (pickleKey) {
|
||||||
let encryptedToken: IEncryptedPayload | undefined;
|
let encryptedToken: IEncryptedPayload | undefined;
|
||||||
|
if (token) {
|
||||||
try {
|
try {
|
||||||
if (!token) {
|
|
||||||
throw new Error("No token: not attempting encryption");
|
|
||||||
}
|
|
||||||
// try to encrypt the access token using the pickle key
|
// try to encrypt the access token using the pickle key
|
||||||
const encrKey = await pickleKeyToAesKey(pickleKey);
|
const encrKey = await pickleKeyToAesKey(pickleKey);
|
||||||
encryptedToken = await encryptAES(token, encrKey, initializationVector);
|
encryptedToken = await encryptAES(token, encrKey, initializationVector);
|
||||||
encrKey.fill(0);
|
encrKey.fill(0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn("Could not encrypt access token", e);
|
// This is likely due to the browser not having WebCrypto or somesuch.
|
||||||
|
// Warn about it, but fall back to storing the unencrypted token.
|
||||||
|
logger.warn(`Could not encrypt token for ${storageKey}`, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// save either the encrypted access token, or the plain access
|
// Save either the encrypted access token, or the plain access
|
||||||
// token if we were unable to encrypt (e.g. if the browser doesn't
|
// token if there is no token or we were unable to encrypt (e.g. if the browser doesn't
|
||||||
// have WebCrypto).
|
// have WebCrypto).
|
||||||
await StorageManager.idbSave("account", storageKey, encryptedToken || token);
|
await StorageManager.idbSave("account", storageKey, encryptedToken || token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue