2020-01-17 11:43:35 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-10-22 22:23:32 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2022-02-22 12:18:08 +00:00
|
|
|
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
2022-02-24 14:39:25 +00:00
|
|
|
import { ClientEvent, EventType, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
2022-05-26 10:12:49 +00:00
|
|
|
import { SyncState } from "matrix-js-sdk/src/sync";
|
2021-10-22 22:23:32 +00:00
|
|
|
|
2021-06-29 12:11:58 +00:00
|
|
|
import { MatrixClientPeg } from './MatrixClientPeg';
|
2020-08-19 15:13:29 +00:00
|
|
|
import dis from "./dispatcher/dispatcher";
|
2020-05-22 12:29:53 +00:00
|
|
|
import {
|
|
|
|
hideToast as hideBulkUnverifiedSessionsToast,
|
2020-06-23 15:41:36 +00:00
|
|
|
showToast as showBulkUnverifiedSessionsToast,
|
2020-05-22 12:29:53 +00:00
|
|
|
} from "./toasts/BulkUnverifiedSessionsToast";
|
|
|
|
import {
|
|
|
|
hideToast as hideSetupEncryptionToast,
|
|
|
|
Kind as SetupKind,
|
2020-06-23 15:41:36 +00:00
|
|
|
showToast as showSetupEncryptionToast,
|
2020-05-22 12:29:53 +00:00
|
|
|
} from "./toasts/SetupEncryptionToast";
|
|
|
|
import {
|
|
|
|
hideToast as hideUnverifiedSessionsToast,
|
2020-06-23 15:41:36 +00:00
|
|
|
showToast as showUnverifiedSessionsToast,
|
2020-05-22 12:29:53 +00:00
|
|
|
} from "./toasts/UnverifiedSessionToast";
|
2022-02-22 12:18:08 +00:00
|
|
|
import { accessSecretStorage, isSecretStorageBeingAccessed } from "./SecurityManager";
|
2020-08-24 15:11:35 +00:00
|
|
|
import { isSecureBackupRequired } from './utils/WellKnownUtils';
|
2021-07-19 21:43:11 +00:00
|
|
|
import { ActionPayload } from "./dispatcher/payloads";
|
2022-02-11 13:00:37 +00:00
|
|
|
import { Action } from "./dispatcher/actions";
|
2022-03-24 21:33:09 +00:00
|
|
|
import { isLoggedIn } from "./utils/login";
|
2022-10-04 07:53:23 +00:00
|
|
|
import SdkConfig from "./SdkConfig";
|
|
|
|
import PlatformPeg from "./PlatformPeg";
|
2022-10-10 19:00:46 +00:00
|
|
|
import {
|
|
|
|
recordClientInformation,
|
|
|
|
removeClientInformation,
|
|
|
|
} from "./utils/device/clientInformation";
|
2022-10-04 07:53:23 +00:00
|
|
|
import SettingsStore, { CallbackFn } from "./settings/SettingsStore";
|
2020-01-17 11:43:35 +00:00
|
|
|
|
2020-01-25 16:52:12 +00:00
|
|
|
const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000;
|
2020-04-28 17:35:16 +00:00
|
|
|
|
2020-01-17 11:43:35 +00:00
|
|
|
export default class DeviceListener {
|
2020-08-19 15:13:29 +00:00
|
|
|
private dispatcherRef: string;
|
2020-05-22 11:54:03 +00:00
|
|
|
// device IDs for which the user has dismissed the verify toast ('Later')
|
|
|
|
private dismissed = new Set<string>();
|
|
|
|
// has the user dismissed any of the various nag toasts to setup encryption on this device?
|
|
|
|
private dismissedThisDeviceToast = false;
|
|
|
|
// cache of the key backup info
|
|
|
|
private keyBackupInfo: object = null;
|
|
|
|
private keyBackupFetchedAt: number = null;
|
2022-02-11 13:00:37 +00:00
|
|
|
private keyBackupStatusChecked = false;
|
2020-05-22 11:54:03 +00:00
|
|
|
// We keep a list of our own device IDs so we can batch ones that were already
|
|
|
|
// there the last time the app launched into a single toast, but display new
|
|
|
|
// ones in their own toasts.
|
|
|
|
private ourDeviceIdsAtStart: Set<string> = null;
|
|
|
|
// The set of device IDs we're currently displaying toasts for
|
|
|
|
private displayingToastsForDeviceIds = new Set<string>();
|
2022-05-26 10:12:49 +00:00
|
|
|
private running = false;
|
2022-10-04 07:53:23 +00:00
|
|
|
private shouldRecordClientInformation = false;
|
|
|
|
private deviceClientInformationSettingWatcherRef: string | undefined;
|
2020-01-25 16:52:12 +00:00
|
|
|
|
2022-05-26 10:12:49 +00:00
|
|
|
public static sharedInstance() {
|
2020-07-20 19:43:49 +00:00
|
|
|
if (!window.mxDeviceListener) window.mxDeviceListener = new DeviceListener();
|
|
|
|
return window.mxDeviceListener;
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 10:12:49 +00:00
|
|
|
public start() {
|
|
|
|
this.running = true;
|
2022-02-22 12:18:08 +00:00
|
|
|
MatrixClientPeg.get().on(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
|
|
|
|
MatrixClientPeg.get().on(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
|
|
|
|
MatrixClientPeg.get().on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
|
|
|
|
MatrixClientPeg.get().on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
|
|
|
MatrixClientPeg.get().on(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
|
|
|
|
MatrixClientPeg.get().on(ClientEvent.AccountData, this.onAccountData);
|
|
|
|
MatrixClientPeg.get().on(ClientEvent.Sync, this.onSync);
|
|
|
|
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
|
2022-10-04 07:53:23 +00:00
|
|
|
this.shouldRecordClientInformation = SettingsStore.getValue('deviceClientInformationOptIn');
|
|
|
|
this.deviceClientInformationSettingWatcherRef = SettingsStore.watchSetting(
|
|
|
|
'deviceClientInformationOptIn',
|
|
|
|
null,
|
|
|
|
this.onRecordClientInformationSettingChange,
|
|
|
|
);
|
2021-07-19 21:43:11 +00:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
this.recheck();
|
2022-10-10 19:00:46 +00:00
|
|
|
this.updateClientInformation();
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 10:12:49 +00:00
|
|
|
public stop() {
|
|
|
|
this.running = false;
|
2020-01-17 11:43:35 +00:00
|
|
|
if (MatrixClientPeg.get()) {
|
2022-02-22 12:18:08 +00:00
|
|
|
MatrixClientPeg.get().removeListener(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
|
|
|
|
MatrixClientPeg.get().removeListener(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
|
|
|
|
MatrixClientPeg.get().removeListener(
|
|
|
|
CryptoEvent.DeviceVerificationChanged,
|
|
|
|
this.onDeviceVerificationChanged,
|
|
|
|
);
|
|
|
|
MatrixClientPeg.get().removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
|
|
|
MatrixClientPeg.get().removeListener(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
|
|
|
|
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, this.onAccountData);
|
|
|
|
MatrixClientPeg.get().removeListener(ClientEvent.Sync, this.onSync);
|
|
|
|
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
2022-10-04 07:53:23 +00:00
|
|
|
if (this.deviceClientInformationSettingWatcherRef) {
|
|
|
|
SettingsStore.unwatchSetting(this.deviceClientInformationSettingWatcherRef);
|
|
|
|
}
|
2020-08-19 15:13:29 +00:00
|
|
|
if (this.dispatcherRef) {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
this.dispatcherRef = null;
|
|
|
|
}
|
2020-05-22 11:54:03 +00:00
|
|
|
this.dismissed.clear();
|
|
|
|
this.dismissedThisDeviceToast = false;
|
|
|
|
this.keyBackupInfo = null;
|
|
|
|
this.keyBackupFetchedAt = null;
|
2022-02-11 13:00:37 +00:00
|
|
|
this.keyBackupStatusChecked = false;
|
2020-05-22 11:54:03 +00:00
|
|
|
this.ourDeviceIdsAtStart = null;
|
|
|
|
this.displayingToastsForDeviceIds = new Set();
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 17:35:16 +00:00
|
|
|
/**
|
|
|
|
* Dismiss notifications about our own unverified devices
|
|
|
|
*
|
|
|
|
* @param {String[]} deviceIds List of device IDs to dismiss notifications for
|
|
|
|
*/
|
2022-05-26 10:12:49 +00:00
|
|
|
public async dismissUnverifiedSessions(deviceIds: Iterable<string>) {
|
2021-09-21 15:48:09 +00:00
|
|
|
logger.log("Dismissing unverified sessions: " + Array.from(deviceIds).join(','));
|
2020-04-28 17:35:16 +00:00
|
|
|
for (const d of deviceIds) {
|
2020-05-22 11:54:03 +00:00
|
|
|
this.dismissed.add(d);
|
2020-04-28 17:35:16 +00:00
|
|
|
}
|
2020-04-27 17:33:54 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-01-25 16:52:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 10:12:49 +00:00
|
|
|
public dismissEncryptionSetup() {
|
2020-05-22 11:54:03 +00:00
|
|
|
this.dismissedThisDeviceToast = true;
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private ensureDeviceIdsAtStartPopulated() {
|
2020-05-22 11:54:03 +00:00
|
|
|
if (this.ourDeviceIdsAtStart === null) {
|
2020-04-28 17:35:16 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2020-05-22 11:54:03 +00:00
|
|
|
this.ourDeviceIdsAtStart = new Set(
|
2020-04-28 17:35:16 +00:00
|
|
|
cli.getStoredDevicesForUser(cli.getUserId()).map(d => d.deviceId),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onWillUpdateDevices = async (users: string[], initialFetch?: boolean) => {
|
2020-04-29 16:33:18 +00:00
|
|
|
// If we didn't know about *any* devices before (ie. it's fresh login),
|
2020-04-29 16:16:04 +00:00
|
|
|
// then they are all pre-existing devices, so ignore this and set the
|
|
|
|
// devicesAtStart list to the devices that we see after the fetch.
|
|
|
|
if (initialFetch) return;
|
|
|
|
|
2020-04-28 17:35:16 +00:00
|
|
|
const myUserId = MatrixClientPeg.get().getUserId();
|
2021-07-19 21:43:11 +00:00
|
|
|
if (users.includes(myUserId)) this.ensureDeviceIdsAtStartPopulated();
|
2020-04-29 09:55:44 +00:00
|
|
|
|
|
|
|
// No need to do a recheck here: we just need to get a snapshot of our devices
|
2020-04-29 10:25:18 +00:00
|
|
|
// before we download any new ones.
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-04-28 17:35:16 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onDevicesUpdated = (users: string[]) => {
|
2020-01-17 11:43:35 +00:00
|
|
|
if (!users.includes(MatrixClientPeg.get().getUserId())) return;
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-01-17 11:43:35 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onDeviceVerificationChanged = (userId: string) => {
|
2020-01-29 21:55:27 +00:00
|
|
|
if (userId !== MatrixClientPeg.get().getUserId()) return;
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-01-25 16:52:12 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onUserTrustStatusChanged = (userId: string) => {
|
2020-01-25 16:52:12 +00:00
|
|
|
if (userId !== MatrixClientPeg.get().getUserId()) return;
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-01-25 16:52:12 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onCrossSingingKeysChanged = () => {
|
|
|
|
this.recheck();
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-04-09 11:43:51 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onAccountData = (ev: MatrixEvent) => {
|
2020-04-07 09:57:10 +00:00
|
|
|
// User may have:
|
|
|
|
// * migrated SSSS to symmetric
|
|
|
|
// * uploaded keys to secret storage
|
|
|
|
// * completed secret storage creation
|
|
|
|
// which result in account data changes affecting checks below.
|
|
|
|
if (
|
|
|
|
ev.getType().startsWith('m.secret_storage.') ||
|
2021-07-08 20:16:19 +00:00
|
|
|
ev.getType().startsWith('m.cross_signing.') ||
|
|
|
|
ev.getType() === 'm.megolm_backup.v1'
|
2020-04-07 09:57:10 +00:00
|
|
|
) {
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-03-20 18:53:31 +00:00
|
|
|
}
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-03-20 18:53:31 +00:00
|
|
|
|
2022-05-26 10:12:49 +00:00
|
|
|
private onSync = (state: SyncState, prevState?: SyncState) => {
|
|
|
|
if (state === 'PREPARED' && prevState === null) {
|
|
|
|
this.recheck();
|
|
|
|
}
|
2020-06-18 13:32:43 +00:00
|
|
|
};
|
2020-04-20 13:36:15 +00:00
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onRoomStateEvents = (ev: MatrixEvent) => {
|
2022-02-24 14:39:25 +00:00
|
|
|
if (ev.getType() !== EventType.RoomEncryption) return;
|
2020-09-15 16:37:05 +00:00
|
|
|
|
|
|
|
// If a room changes to encrypted, re-check as it may be our first
|
|
|
|
// encrypted room. This also catches encrypted room creation as well.
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2020-09-15 16:37:05 +00:00
|
|
|
};
|
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private onAction = ({ action }: ActionPayload) => {
|
2022-05-26 08:56:53 +00:00
|
|
|
if (action !== Action.OnLoggedIn) return;
|
2021-07-19 21:43:11 +00:00
|
|
|
this.recheck();
|
2022-10-10 19:00:46 +00:00
|
|
|
this.updateClientInformation();
|
2020-08-19 15:13:29 +00:00
|
|
|
};
|
|
|
|
|
2020-01-25 16:52:12 +00:00
|
|
|
// The server doesn't tell us when key backup is set up, so we poll
|
|
|
|
// & cache the result
|
2021-07-19 21:43:11 +00:00
|
|
|
private async getKeyBackupInfo() {
|
2020-01-25 16:52:12 +00:00
|
|
|
const now = (new Date()).getTime();
|
2020-05-22 11:54:03 +00:00
|
|
|
if (!this.keyBackupInfo || this.keyBackupFetchedAt < now - KEY_BACKUP_POLL_INTERVAL) {
|
|
|
|
this.keyBackupInfo = await MatrixClientPeg.get().getKeyBackupVersion();
|
|
|
|
this.keyBackupFetchedAt = now;
|
2020-01-25 16:52:12 +00:00
|
|
|
}
|
2020-05-22 11:54:03 +00:00
|
|
|
return this.keyBackupInfo;
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 20:40:32 +00:00
|
|
|
private shouldShowSetupEncryptionToast() {
|
2020-08-19 12:28:03 +00:00
|
|
|
// If we're in the middle of a secret storage operation, we're likely
|
|
|
|
// modifying the state involved here, so don't add new toasts to setup.
|
|
|
|
if (isSecretStorageBeingAccessed()) return false;
|
2020-09-16 11:25:02 +00:00
|
|
|
// Show setup toasts once the user is in at least one encrypted room.
|
2020-06-02 20:40:32 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
return cli && cli.getRooms().some(r => cli.isRoomEncrypted(r.roomId));
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
private async recheck() {
|
2022-05-26 10:12:49 +00:00
|
|
|
if (!this.running) return; // we have been stopped
|
2020-01-17 11:43:35 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
2021-09-21 15:48:09 +00:00
|
|
|
if (!(await cli.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing"))) return;
|
2020-03-12 18:03:18 +00:00
|
|
|
|
2020-01-25 16:52:12 +00:00
|
|
|
if (!cli.isCryptoEnabled()) return;
|
2020-04-20 13:36:15 +00:00
|
|
|
// don't recheck until the initial sync is complete: lots of account data events will fire
|
|
|
|
// while the initial sync is processing and we don't need to recheck on each one of them
|
|
|
|
// (we add a listener on sync to do once check after the initial sync is done)
|
|
|
|
if (!cli.isInitialSyncComplete()) return;
|
2020-03-23 18:36:37 +00:00
|
|
|
|
2020-03-24 13:03:07 +00:00
|
|
|
const crossSigningReady = await cli.isCrossSigningReady();
|
2020-08-21 17:22:05 +00:00
|
|
|
const secretStorageReady = await cli.isSecretStorageReady();
|
|
|
|
const allSystemsReady = crossSigningReady && secretStorageReady;
|
2020-03-23 18:36:37 +00:00
|
|
|
|
2020-08-21 17:22:05 +00:00
|
|
|
if (this.dismissedThisDeviceToast || allSystemsReady) {
|
2020-05-22 12:29:53 +00:00
|
|
|
hideSetupEncryptionToast();
|
2022-02-11 13:00:37 +00:00
|
|
|
|
|
|
|
this.checkKeyBackupStatus();
|
2020-06-02 20:40:32 +00:00
|
|
|
} else if (this.shouldShowSetupEncryptionToast()) {
|
2020-05-22 12:29:53 +00:00
|
|
|
// make sure our keys are finished downloading
|
|
|
|
await cli.downloadKeys([cli.getUserId()]);
|
|
|
|
// cross signing isn't enabled - nag to enable it
|
|
|
|
// There are 3 different toasts for:
|
2020-09-02 13:29:41 +00:00
|
|
|
if (
|
|
|
|
!cli.getCrossSigningId() &&
|
|
|
|
cli.getStoredCrossSigningForUser(cli.getUserId())
|
|
|
|
) {
|
2020-05-22 12:29:53 +00:00
|
|
|
// Cross-signing on account but this device doesn't trust the master key (verify this session)
|
|
|
|
showSetupEncryptionToast(SetupKind.VERIFY_THIS_SESSION);
|
2022-02-11 13:00:37 +00:00
|
|
|
this.checkKeyBackupStatus();
|
2020-05-22 12:29:53 +00:00
|
|
|
} else {
|
2021-07-19 21:43:11 +00:00
|
|
|
const backupInfo = await this.getKeyBackupInfo();
|
2020-05-22 12:29:53 +00:00
|
|
|
if (backupInfo) {
|
|
|
|
// No cross-signing on account but key backup available (upgrade encryption)
|
2020-06-02 20:40:32 +00:00
|
|
|
showSetupEncryptionToast(SetupKind.UPGRADE_ENCRYPTION);
|
2020-01-25 16:52:12 +00:00
|
|
|
} else {
|
2020-05-22 12:29:53 +00:00
|
|
|
// No cross-signing or key backup on account (set up encryption)
|
2020-08-24 15:11:35 +00:00
|
|
|
await cli.waitForClientWellKnown();
|
2020-08-19 15:13:29 +00:00
|
|
|
if (isSecureBackupRequired() && isLoggedIn()) {
|
|
|
|
// If we're meant to set up, and Secure Backup is required,
|
|
|
|
// trigger the flow directly without a toast once logged in.
|
|
|
|
hideSetupEncryptionToast();
|
|
|
|
accessSecretStorage();
|
|
|
|
} else {
|
|
|
|
showSetupEncryptionToast(SetupKind.SET_UP_ENCRYPTION);
|
|
|
|
}
|
2020-01-25 16:52:12 +00:00
|
|
|
}
|
2020-03-20 19:01:26 +00:00
|
|
|
}
|
2020-01-25 16:52:12 +00:00
|
|
|
}
|
2020-01-17 14:08:37 +00:00
|
|
|
|
2020-04-29 16:16:04 +00:00
|
|
|
// This needs to be done after awaiting on downloadKeys() above, so
|
|
|
|
// we make sure we get the devices after the fetch is done.
|
2021-07-19 21:43:11 +00:00
|
|
|
this.ensureDeviceIdsAtStartPopulated();
|
2020-04-29 16:16:04 +00:00
|
|
|
|
2020-04-28 17:35:16 +00:00
|
|
|
// Unverified devices that were there last time the app ran
|
|
|
|
// (technically could just be a boolean: we don't actually
|
|
|
|
// need to remember the device IDs, but for the sake of
|
|
|
|
// symmetry...).
|
2020-05-22 11:54:03 +00:00
|
|
|
const oldUnverifiedDeviceIds = new Set<string>();
|
2020-04-28 17:35:16 +00:00
|
|
|
// Unverified devices that have appeared since then
|
2020-05-22 11:54:03 +00:00
|
|
|
const newUnverifiedDeviceIds = new Set<string>();
|
2020-04-28 17:35:16 +00:00
|
|
|
|
2022-12-02 02:59:46 +00:00
|
|
|
const isCurrentDeviceTrusted = crossSigningReady &&
|
|
|
|
await (cli.checkDeviceTrust(cli.getUserId()!, cli.deviceId!)).isCrossSigningVerified();
|
|
|
|
|
2020-03-27 15:45:46 +00:00
|
|
|
// as long as cross-signing isn't ready,
|
|
|
|
// you can't see or dismiss any device toasts
|
|
|
|
if (crossSigningReady) {
|
2020-04-28 17:35:16 +00:00
|
|
|
const devices = cli.getStoredDevicesForUser(cli.getUserId());
|
2020-03-27 15:45:46 +00:00
|
|
|
for (const device of devices) {
|
2020-05-22 11:54:03 +00:00
|
|
|
if (device.deviceId === cli.deviceId) continue;
|
2020-01-17 11:43:35 +00:00
|
|
|
|
2022-12-02 02:59:46 +00:00
|
|
|
const deviceTrust = await cli.checkDeviceTrust(cli.getUserId()!, device.deviceId!);
|
2020-05-22 11:54:03 +00:00
|
|
|
if (!deviceTrust.isCrossSigningVerified() && !this.dismissed.has(device.deviceId)) {
|
|
|
|
if (this.ourDeviceIdsAtStart.has(device.deviceId)) {
|
2020-04-28 17:35:16 +00:00
|
|
|
oldUnverifiedDeviceIds.add(device.deviceId);
|
|
|
|
} else {
|
|
|
|
newUnverifiedDeviceIds.add(device.deviceId);
|
|
|
|
}
|
2020-03-27 15:45:46 +00:00
|
|
|
}
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
2020-04-28 17:35:16 +00:00
|
|
|
}
|
2020-01-25 17:08:31 +00:00
|
|
|
|
2022-03-02 14:30:04 +00:00
|
|
|
logger.debug("Old unverified sessions: " + Array.from(oldUnverifiedDeviceIds).join(','));
|
|
|
|
logger.debug("New unverified sessions: " + Array.from(newUnverifiedDeviceIds).join(','));
|
|
|
|
logger.debug("Currently showing toasts for: " + Array.from(this.displayingToastsForDeviceIds).join(','));
|
2021-09-03 14:14:44 +00:00
|
|
|
|
2020-04-28 17:35:16 +00:00
|
|
|
// Display or hide the batch toast for old unverified sessions
|
2022-12-02 02:59:46 +00:00
|
|
|
// don't show the toast if the current device is unverified
|
|
|
|
if (oldUnverifiedDeviceIds.size > 0 && isCurrentDeviceTrusted) {
|
2020-05-22 12:29:53 +00:00
|
|
|
showBulkUnverifiedSessionsToast(oldUnverifiedDeviceIds);
|
2020-04-28 17:35:16 +00:00
|
|
|
} else {
|
2020-05-22 12:29:53 +00:00
|
|
|
hideBulkUnverifiedSessionsToast();
|
2020-04-28 17:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show toasts for new unverified devices if they aren't already there
|
|
|
|
for (const deviceId of newUnverifiedDeviceIds) {
|
2020-05-22 12:29:53 +00:00
|
|
|
showUnverifiedSessionsToast(deviceId);
|
2020-04-28 17:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ...and hide any we don't need any more
|
2020-05-22 11:54:03 +00:00
|
|
|
for (const deviceId of this.displayingToastsForDeviceIds) {
|
2020-04-28 17:35:16 +00:00
|
|
|
if (!newUnverifiedDeviceIds.has(deviceId)) {
|
2022-03-02 14:30:04 +00:00
|
|
|
logger.debug("Hiding unverified session toast for " + deviceId);
|
2020-05-22 12:29:53 +00:00
|
|
|
hideUnverifiedSessionsToast(deviceId);
|
2020-03-27 15:45:46 +00:00
|
|
|
}
|
2020-01-25 17:08:31 +00:00
|
|
|
}
|
2020-04-28 17:35:16 +00:00
|
|
|
|
2020-05-22 11:54:03 +00:00
|
|
|
this.displayingToastsForDeviceIds = newUnverifiedDeviceIds;
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|
2022-02-11 13:00:37 +00:00
|
|
|
|
|
|
|
private checkKeyBackupStatus = async () => {
|
|
|
|
if (this.keyBackupStatusChecked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// returns null when key backup status hasn't finished being checked
|
|
|
|
const isKeyBackupEnabled = MatrixClientPeg.get().getKeyBackupEnabled();
|
|
|
|
this.keyBackupStatusChecked = isKeyBackupEnabled !== null;
|
|
|
|
|
|
|
|
if (isKeyBackupEnabled === false) {
|
|
|
|
dis.dispatch({ action: Action.ReportKeyBackupNotEnabled });
|
|
|
|
}
|
|
|
|
};
|
2022-10-04 07:53:23 +00:00
|
|
|
|
|
|
|
private onRecordClientInformationSettingChange: CallbackFn = (
|
|
|
|
_originalSettingName, _roomId, _level, _newLevel, newValue,
|
|
|
|
) => {
|
|
|
|
const prevValue = this.shouldRecordClientInformation;
|
|
|
|
|
|
|
|
this.shouldRecordClientInformation = !!newValue;
|
|
|
|
|
2022-10-10 19:00:46 +00:00
|
|
|
if (this.shouldRecordClientInformation !== prevValue) {
|
|
|
|
this.updateClientInformation();
|
2022-10-04 07:53:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-10 19:00:46 +00:00
|
|
|
private updateClientInformation = async () => {
|
2022-10-04 07:53:23 +00:00
|
|
|
try {
|
2022-10-10 19:00:46 +00:00
|
|
|
if (this.shouldRecordClientInformation) {
|
|
|
|
await recordClientInformation(
|
|
|
|
MatrixClientPeg.get(),
|
|
|
|
SdkConfig.get(),
|
|
|
|
PlatformPeg.get(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await removeClientInformation(MatrixClientPeg.get());
|
|
|
|
}
|
2022-10-04 07:53:23 +00:00
|
|
|
} catch (error) {
|
|
|
|
// this is a best effort operation
|
|
|
|
// log the error without rethrowing
|
2022-10-10 19:00:46 +00:00
|
|
|
logger.error('Failed to update client information', error);
|
2022-10-04 07:53:23 +00:00
|
|
|
}
|
|
|
|
};
|
2020-01-17 11:43:35 +00:00
|
|
|
}
|