Deprecate storageServiceKey in SyncMessage.Keys
This commit is contained in:
parent
37b3a6de4b
commit
d7b53f3d27
8 changed files with 62 additions and 26 deletions
|
@ -189,6 +189,7 @@ import {
|
|||
getCallIdFromEra,
|
||||
updateLocalGroupCallHistoryTimestamp,
|
||||
} from './util/callDisposition';
|
||||
import { deriveStorageServiceKey } from './Crypto';
|
||||
|
||||
export function isOverHourIntoPast(timestamp: number): boolean {
|
||||
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
|
||||
|
@ -1350,22 +1351,6 @@ export async function startApp(): Promise<void> {
|
|||
|
||||
async function runStorageService() {
|
||||
StorageService.enableStorageService();
|
||||
|
||||
if (window.ConversationController.areWePrimaryDevice()) {
|
||||
log.warn(
|
||||
'background/runStorageService: We are primary device; not sending key sync request'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await singleProtoJobQueue.add(MessageSender.getRequestKeySyncMessage());
|
||||
} catch (error) {
|
||||
log.error(
|
||||
'runStorageService: Failed to queue sync message',
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function start() {
|
||||
|
@ -1821,6 +1806,26 @@ export async function startApp(): Promise<void> {
|
|||
}
|
||||
|
||||
if (firstRun === true && deviceId !== 1) {
|
||||
if (!window.storage.get('masterKey')) {
|
||||
const lastSent = window.storage.get('masterKeyLastRequestTime') ?? 0;
|
||||
const now = Date.now();
|
||||
|
||||
// If we last attempted sync one day in the past, or if we time
|
||||
// traveled.
|
||||
if (isOlderThan(lastSent, DAY) || lastSent > now) {
|
||||
log.warn('connect: masterKey not captured, requesting sync');
|
||||
await singleProtoJobQueue.add(
|
||||
MessageSender.getRequestKeySyncMessage()
|
||||
);
|
||||
await window.storage.put('masterKeyLastRequestTime', now);
|
||||
} else {
|
||||
log.warn(
|
||||
'connect: masterKey not captured, but sync requested recently.' +
|
||||
'Not running'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const hasThemeSetting = Boolean(window.storage.get('theme-setting'));
|
||||
if (
|
||||
!hasThemeSetting &&
|
||||
|
@ -3046,7 +3051,17 @@ export async function startApp(): Promise<void> {
|
|||
async function onKeysSync(ev: KeysEvent) {
|
||||
ev.confirm();
|
||||
|
||||
const { storageServiceKey } = ev;
|
||||
const { masterKey } = ev;
|
||||
let { storageServiceKey } = ev;
|
||||
|
||||
if (masterKey == null) {
|
||||
log.info('onKeysSync: deleting window.masterKey');
|
||||
await window.storage.remove('masterKey');
|
||||
} else {
|
||||
// Override provided storageServiceKey because it is deprecated.
|
||||
storageServiceKey = deriveStorageServiceKey(masterKey);
|
||||
await window.storage.put('masterKey', Bytes.toBase64(masterKey));
|
||||
}
|
||||
|
||||
if (storageServiceKey == null) {
|
||||
log.info('onKeysSync: deleting window.storageKey');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue