This commit is contained in:
RMidhunSuresh 2023-02-16 11:27:43 +05:30
parent 8c74e54f9d
commit 772d91f924
No known key found for this signature in database
4 changed files with 133 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import {LocalMedia} from "../../../matrix/calls/LocalMedia";
// this is a breaking SDK change though to make this option mandatory // this is a breaking SDK change though to make this option mandatory
import {tileClassForEntry as defaultTileClassForEntry} from "./timeline/tiles/index"; import {tileClassForEntry as defaultTileClassForEntry} from "./timeline/tiles/index";
import {joinRoom} from "../../../matrix/room/joinRoom"; import {joinRoom} from "../../../matrix/room/joinRoom";
import {SASVerification} from "../../../matrix/verification/SAS/SASVerification";
export class RoomViewModel extends ErrorReportViewModel { export class RoomViewModel extends ErrorReportViewModel {
constructor(options) { constructor(options) {
@ -49,6 +50,15 @@ export class RoomViewModel extends ErrorReportViewModel {
this._setupCallViewModel(); this._setupCallViewModel();
} }
async _startCrossSigning(otherUserId) {
await this.logAndCatch("startCrossSigning", async log => {
const session = this.getOption("session");
const { userId, deviceId } = session;
const sas = new SASVerification(this.room, { userId, deviceId }, otherUserId, log);
await sas.start();
});
}
_setupCallViewModel() { _setupCallViewModel() {
if (!this.features.calls) { if (!this.features.calls) {
return; return;

View File

@ -0,0 +1,33 @@
/*
Copyright 2023 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 {StartVerificationStage} from "./stages/StartVerificationStage";
import type {ILogItem} from "../../../logging/types";
import type {Room} from "../../room/Room.js";
import type {BaseSASVerificationStage, UserData} from "./stages/BaseSASVerificationStage";
export class SASVerification {
private stages: BaseSASVerificationStage[] = [];
constructor(private room: Room, private ourUser: UserData, otherUserId: string, log: ILogItem) {
this.stages.push(new StartVerificationStage(room, ourUser, otherUserId, log));
}
async start() {
for (const stage of this.stages) {
await stage.completeStage();
}
}
}

View File

@ -0,0 +1,35 @@
/*
Copyright 2023 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 type {ILogItem} from "../../../../lib.js";
import type {Room} from "../../../room/Room.js";
export type UserData = {
userId: string;
deviceId: string;
}
export abstract class BaseSASVerificationStage {
constructor(protected room: Room,
protected ourUser: UserData,
protected otherUserId: string,
protected log: ILogItem) {
}
abstract get type(): string;
abstract completeStage(): boolean | Promise<boolean>;
abstract get nextStage(): BaseSASVerificationStage;
}

View File

@ -0,0 +1,55 @@
/*
Copyright 2023 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 {BaseSASVerificationStage} from "./BaseSASVerificationStage";
// From element-web
// type KeyAgreement = "curve25519-hkdf-sha256" | "curve25519";
// type MacMethod = "hkdf-hmac-sha256.v2" | "org.matrix.msc3783.hkdf-hmac-sha256" | "hkdf-hmac-sha256" | "hmac-sha256";
// const KEY_AGREEMENT_LIST: KeyAgreement[] = ["curve25519-hkdf-sha256", "curve25519"];
// const HASHES_LIST = ["sha256"];
// const MAC_LIST: MacMethod[] = [
// "hkdf-hmac-sha256.v2",
// "org.matrix.msc3783.hkdf-hmac-sha256",
// "hkdf-hmac-sha256",
// "hmac-sha256",
// ];
// const SAS_LIST = Object.keys(sasGenerators);
export class StartVerificationStage extends BaseSASVerificationStage {
async completeStage() {
await this.log.wrap("StartVerificationStage.completeStage", async (log) => {
const content = {
"body": `${this.ourUser.userId} is requesting to verify your device, but your client does not support verification, so you may need to use a different verification method.`,
"from_device": this.ourUser.deviceId,
"methods": ["m.sas.v1"],
"msgtype": "m.key.verification.request",
"to": this.otherUserId,
};
await this.room.sendEvent("m.room.message", content, null, log);
});
return true;
}
get type() {
return "m.key.verification.request";
}
get nextStage(): BaseSASVerificationStage {
return this;
}
}