Page MenuHomePhabricator

D10065.id33941.diff
No OneTemporary

D10065.id33941.diff

diff --git a/lib/flow-typed/web-crypto-common.js b/lib/flow-typed/web-crypto-common.js
--- a/lib/flow-typed/web-crypto-common.js
+++ b/lib/flow-typed/web-crypto-common.js
@@ -20,7 +20,16 @@
| 'wrapKey'
| 'unwrapKey';
-declare type CryptoKey = SubtleCrypto$JsonWebKey;
+declare type CryptoKey = {
+ +algorithm:
+ | SubtleCrypto$AesKeyGenParams
+ | SubtleCrypto$RsaHashedKeyGenParams
+ | SubtleCrypto$EcKeyGenParams
+ | SubtleCrypto$HmacKeyGenParams,
+ +extractable: boolean,
+ +type: CryptoKey$Type,
+ +usages: $ReadOnlyArray<CryptoKey$Usages>,
+};
type SubtleCrypto$KeyFormatWithoutJwk = 'pkcs8' | 'raw' | 'spki';
type SubtleCrypto$KeyFormat = 'jwk' | SubtleCrypto$KeyFormatWithoutJwk;
diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js
--- a/web/account/account-hooks.js
+++ b/web/account/account-hooks.js
@@ -229,11 +229,13 @@
);
const persistEncryptionKeyPromise = (async () => {
- let cryptoKeyPersistentForm = encryptionKey;
+ let cryptoKeyPersistentForm;
if (isDesktopSafari) {
// Safari doesn't support structured clone algorithm in service
// worker context so we have to store CryptoKey as JSON
cryptoKeyPersistentForm = await exportKeyToJWK(encryptionKey);
+ } else {
+ cryptoKeyPersistentForm = encryptionKey;
}
await localforage.setItem(
diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js
--- a/web/push-notif/notif-crypto-utils.js
+++ b/web/push-notif/notif-crypto-utils.js
@@ -52,15 +52,21 @@
const { id, encryptedPayload } = encryptedNotification;
const retrieveEncryptionKeyPromise: Promise<?CryptoKey> = (async () => {
- const persistedCryptoKey = await localforage.getItem<CryptoKey>(
- NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY,
- );
- if (isDesktopSafari && persistedCryptoKey) {
- // Safari doesn't support structured clone algorithm in service
- // worker context so we have to store CryptoKey as JSON
- return await importJWKKey(persistedCryptoKey);
+ if (!isDesktopSafari) {
+ return await localforage.getItem<CryptoKey>(
+ NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY,
+ );
+ }
+ // Safari doesn't support structured clone algorithm in service
+ // worker context so we have to store CryptoKey as JSON
+ const persistedCryptoKey =
+ await localforage.getItem<SubtleCrypto$JsonWebKey>(
+ NOTIFICATIONS_OLM_DATA_ENCRYPTION_KEY,
+ );
+ if (!persistedCryptoKey) {
+ return null;
}
- return persistedCryptoKey;
+ return await importJWKKey(persistedCryptoKey);
})();
const [encryptedOlmData, encryptionKey, utilsData] = await Promise.all([

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 2:41 AM (20 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573575
Default Alt Text
D10065.id33941.diff (2 KB)

Event Timeline