diff --git a/ts/background.ts b/ts/background.ts index 6b4d3f320d..b582a417f0 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -1368,6 +1368,7 @@ export async function startApp(): Promise { async function runStorageService() { StorageService.enableStorageService(); + StorageService.runStorageServiceSyncJob(); } async function start() { diff --git a/ts/services/storage.ts b/ts/services/storage.ts index d00142dc75..debf4e4321 100644 --- a/ts/services/storage.ts +++ b/ts/services/storage.ts @@ -14,6 +14,7 @@ import { encryptProfile, decryptProfile, deriveMasterKeyFromGroupV1, + deriveStorageServiceKey, } from '../Crypto'; import { mergeAccountRecord, @@ -1725,7 +1726,18 @@ async function sync( ignoreConflicts = false ): Promise { if (!window.storage.get('storageKey')) { - throw new Error('storageService.sync: Cannot start; no storage key!'); + const masterKeyBase64 = window.storage.get('masterKey'); + if (!masterKeyBase64) { + throw new Error( + 'storageService.sync: Cannot start; no storage or master key!' + ); + } + + const masterKey = Bytes.fromBase64(masterKeyBase64); + const storageKeyBase64 = Bytes.toBase64(deriveStorageServiceKey(masterKey)); + await window.storage.put('storageKey', storageKeyBase64); + + log.warn('storageService.sync: fixed storage key'); } log.info( diff --git a/ts/textsecure/AccountManager.ts b/ts/textsecure/AccountManager.ts index b3033402c0..debb2ef596 100644 --- a/ts/textsecure/AccountManager.ts +++ b/ts/textsecure/AccountManager.ts @@ -32,6 +32,7 @@ import { getRandomBytes, decryptDeviceName, encryptDeviceName, + deriveStorageServiceKey, } from '../Crypto'; import { generateKeyPair, @@ -1237,6 +1238,10 @@ export default class AccountManager extends EventTarget { } if (masterKey) { await storage.put('masterKey', Bytes.toBase64(masterKey)); + await storage.put( + 'storageKey', + Bytes.toBase64(deriveStorageServiceKey(masterKey)) + ); } await storage.put('read-receipt-setting', Boolean(readReceipts));