element-web/src/verification.ts
Travis Ralston fce36ec826
Delete groups (legacy communities system) (#8027)
* Remove deprecated feature_communities_v2_prototypes

* Update _components

* i18n

* delint

* Cut out a bit more dead code

* Carve into legacy components

* Carve into mostly the room list code

* Carve into instances of "groupId"

* Carve out more of what comes up with "groups"

* Carve out some settings

* ignore related groups state

* Remove instances of spacesEnabled

* Fix some obvious issues

* Remove now-unused css

* Fix variable naming for legacy components

* Update i18n

* Misc cleanup from manual review

* Update snapshot for changed flag

* Appease linters

* rethemedex

* Remove now-unused AddressPickerDialog

* Make ConfirmUserActionDialog's member a required prop

* Remove useless override from RightPanelStore

* Remove extraneous CSS

* Update i18n

* Demo: "Communities are now Spaces" landing page

* Restore linkify for group IDs

* Demo: Dialog on click for communities->spaces notice

* i18n for demos

* i18n post-merge

* Update copy

* Appease the linter

* Post-merge cleanup

* Re-add spaces_learn_more_url to the new SdkConfig place

* Round 1 of post-merge fixes

* i18n

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
2022-03-22 23:07:37 +00:00

133 lines
4.8 KiB
TypeScript

/*
Copyright 2019, 2020, 2021 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.
*/
import { User } from "matrix-js-sdk/src/models/user";
import { verificationMethods as VerificationMethods } from 'matrix-js-sdk/src/crypto';
import { RoomMember } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from './MatrixClientPeg';
import dis from "./dispatcher/dispatcher";
import Modal from './Modal';
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
import { findDMForUser } from './createRoom';
import { accessSecretStorage } from './SecurityManager';
import UntrustedDeviceDialog from "./components/views/dialogs/UntrustedDeviceDialog";
import { IDevice } from "./components/views/right_panel/UserInfo";
import ManualDeviceKeyVerificationDialog from "./components/views/dialogs/ManualDeviceKeyVerificationDialog";
import RightPanelStore from "./stores/right-panel/RightPanelStore";
import { IRightPanelCardState } from "./stores/right-panel/RightPanelStoreIPanelState";
async function enable4SIfNeeded() {
const cli = MatrixClientPeg.get();
if (!cli.isCryptoEnabled()) {
return false;
}
const usk = cli.getCrossSigningId("user_signing");
if (!usk) {
await accessSecretStorage();
return false;
}
return true;
}
export async function verifyDevice(user: User, device: IDevice) {
const cli = MatrixClientPeg.get();
if (cli.isGuest()) {
dis.dispatch({ action: 'require_registration' });
return;
}
// if cross-signing is not explicitly disabled, check if it should be enabled first.
if (cli.getCryptoTrustCrossSignedDevices()) {
if (!(await enable4SIfNeeded())) {
return;
}
}
Modal.createTrackedDialog("Verification warning", "unverified session", UntrustedDeviceDialog, {
user,
device,
onFinished: async (action) => {
if (action === "sas") {
const verificationRequestPromise = cli.legacyDeviceVerification(
user.userId,
device.deviceId,
VerificationMethods.SAS,
);
setRightPanel({ member: user, verificationRequestPromise });
} else if (action === "legacy") {
Modal.createTrackedDialog("Legacy verify session", "legacy verify session",
ManualDeviceKeyVerificationDialog,
{
userId: user.userId,
device,
},
);
}
},
});
}
export async function legacyVerifyUser(user: User) {
const cli = MatrixClientPeg.get();
if (cli.isGuest()) {
dis.dispatch({ action: 'require_registration' });
return;
}
// if cross-signing is not explicitly disabled, check if it should be enabled first.
if (cli.getCryptoTrustCrossSignedDevices()) {
if (!(await enable4SIfNeeded())) {
return;
}
}
const verificationRequestPromise = cli.requestVerification(user.userId);
setRightPanel({ member: user, verificationRequestPromise });
}
export async function verifyUser(user: User) {
const cli = MatrixClientPeg.get();
if (cli.isGuest()) {
dis.dispatch({ action: 'require_registration' });
return;
}
if (!(await enable4SIfNeeded())) {
return;
}
const existingRequest = pendingVerificationRequestForUser(user);
setRightPanel({ member: user, verificationRequest: existingRequest });
}
function setRightPanel(state: IRightPanelCardState) {
if (RightPanelStore.instance.roomPhaseHistory.some((card) => (card.phase == RightPanelPhases.RoomSummary))) {
RightPanelStore.instance.pushCard(
{ phase: RightPanelPhases.EncryptionPanel, state },
);
} else {
RightPanelStore.instance.setCards([
{ phase: RightPanelPhases.RoomSummary },
{ phase: RightPanelPhases.RoomMemberInfo, state: { member: state.member } },
{ phase: RightPanelPhases.EncryptionPanel, state },
]);
}
}
export function pendingVerificationRequestForUser(user: User | RoomMember) {
const cli = MatrixClientPeg.get();
const dmRoom = findDMForUser(cli, user.userId);
if (dmRoom) {
return cli.findVerificationRequestDMInProgress(dmRoom.roomId);
}
}