Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3396452
D11648.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11648.diff
View Options
diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js
--- a/lib/types/crypto-types.js
+++ b/lib/types/crypto-types.js
@@ -163,6 +163,11 @@
notificationsInitializationInfo: OlmSessionInitializationInfo,
keyserverID: string,
) => Promise<string>,
+ +reassignNotificationsSession?: (
+ prevCookie: ?string,
+ newCookie: ?string,
+ keyserverID: string,
+ ) => Promise<void>,
+getOneTimeKeys: (numberOfKeys: number) => Promise<OneTimeKeysResultValues>,
+validateAndUploadPrekeys: (authMetadata: AuthMetadata) => Promise<void>,
+signMessage: (message: string) => Promise<string>,
diff --git a/web/crypto/olm-api.js b/web/crypto/olm-api.js
--- a/web/crypto/olm-api.js
+++ b/web/crypto/olm-api.js
@@ -49,6 +49,7 @@
contentInboundSessionCreator: proxyToWorker('contentInboundSessionCreator'),
contentOutboundSessionCreator: proxyToWorker('contentOutboundSessionCreator'),
notificationsSessionCreator: proxyToWorker('notificationsSessionCreator'),
+ reassignNotificationsSession: proxyToWorker('reassignNotificationsSession'),
getOneTimeKeys: proxyToWorker('getOneTimeKeys'),
validateAndUploadPrekeys: proxyToWorker('validateAndUploadPrekeys'),
signMessage: proxyToWorker('signMessage'),
diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js
--- a/web/shared-worker/worker/worker-crypto.js
+++ b/web/shared-worker/worker/worker-crypto.js
@@ -360,6 +360,15 @@
}
}
+async function reassignLocalForageItem(source: string, destination: string) {
+ const value = await localforage.getItem<mixed>(source);
+ if (!value) {
+ return;
+ }
+ await localforage.setItem(destination, value);
+ await localforage.removeItem(source);
+}
+
const olmAPI: OlmAPI = {
async initializeCryptoAccount(): Promise<void> {
const sqliteQueryExecutor = getSQLiteQueryExecutor();
@@ -590,6 +599,39 @@
return initialNotificationsEncryptedMessage;
},
+ async reassignNotificationsSession(
+ prevCookie: ?string,
+ newCookie: ?string,
+ keyserverID: string,
+ ): Promise<void> {
+ const platformDetails = getPlatformDetails();
+ if (!platformDetails) {
+ throw new Error('Worker not initialized');
+ }
+
+ const prevPersistenceKeys = getNotifsPersistenceKeys(
+ prevCookie,
+ keyserverID,
+ platformDetails,
+ );
+
+ const newPersistenceKeys = getNotifsPersistenceKeys(
+ newCookie,
+ keyserverID,
+ platformDetails,
+ );
+
+ await Promise.all([
+ reassignLocalForageItem(
+ prevPersistenceKeys.notifsOlmDataContentKey,
+ newPersistenceKeys.notifsOlmDataContentKey,
+ ),
+ reassignLocalForageItem(
+ prevPersistenceKeys.notifsOlmDataEncryptionKeyDBLabel,
+ newPersistenceKeys.notifsOlmDataEncryptionKeyDBLabel,
+ ),
+ ]);
+ },
async getOneTimeKeys(numberOfKeys: number): Promise<OneTimeKeysResultValues> {
if (!cryptoStore) {
throw new Error('Crypto account not initialized');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 12:25 PM (21 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607591
Default Alt Text
D11648.diff (2 KB)
Attached To
Mode
D11648: [web] Create a function that reassigns notifs session
Attached
Detach File
Event Timeline
Log In to Comment