mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Support sas verification with other users
This commit is contained in:
parent
660db4ced3
commit
49db9d810a
@ -55,6 +55,24 @@ export class SessionViewModel extends ViewModel {
|
|||||||
})));
|
})));
|
||||||
this._setupNavigation();
|
this._setupNavigation();
|
||||||
this._setupForcedLogoutOnAccessTokenInvalidation();
|
this._setupForcedLogoutOnAccessTokenInvalidation();
|
||||||
|
this.addTestCode__REMOVE();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addTestCode__REMOVE() {
|
||||||
|
window.run = (userId) => {
|
||||||
|
return this.logger.run("testRun", async (log) => {
|
||||||
|
const crossSigning = this._client.session.crossSigning.get();
|
||||||
|
const room = this.currentRoomViewModel.room;
|
||||||
|
const sas = crossSigning.startVerification(userId, room, log);
|
||||||
|
sas.on("EmojiGenerated", async (stage) => {
|
||||||
|
console.log("emoji", stage.emoji);
|
||||||
|
await new Promise(r => setTimeout(r, 2000));
|
||||||
|
await stage.setEmojiMatch(true);
|
||||||
|
});
|
||||||
|
console.log("sas", sas);
|
||||||
|
await sas.verify();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_setupNavigation() {
|
_setupNavigation() {
|
||||||
|
@ -19,6 +19,7 @@ import {BaseObservableValue, RetainedObservableValue} from "../../observable/val
|
|||||||
import {pkSign} from "./common";
|
import {pkSign} from "./common";
|
||||||
import {SASVerification} from "./SAS/SASVerification";
|
import {SASVerification} from "./SAS/SASVerification";
|
||||||
import {ToDeviceChannel} from "./SAS/channel/ToDeviceChannel";
|
import {ToDeviceChannel} from "./SAS/channel/ToDeviceChannel";
|
||||||
|
import {RoomChannel} from "./SAS/channel/RoomChannel";
|
||||||
import {VerificationEventType} from "./SAS/channel/types";
|
import {VerificationEventType} from "./SAS/channel/types";
|
||||||
import {ObservableMap} from "../../observable/map";
|
import {ObservableMap} from "../../observable/map";
|
||||||
import {SASRequest} from "./SAS/SASRequest";
|
import {SASRequest} from "./SAS/SASRequest";
|
||||||
@ -31,6 +32,8 @@ import type {Account} from "../e2ee/Account";
|
|||||||
import type {ILogItem} from "../../logging/types";
|
import type {ILogItem} from "../../logging/types";
|
||||||
import type {DeviceMessageHandler} from "../DeviceMessageHandler.js";
|
import type {DeviceMessageHandler} from "../DeviceMessageHandler.js";
|
||||||
import type {SignedValue, DeviceKey} from "../e2ee/common";
|
import type {SignedValue, DeviceKey} from "../e2ee/common";
|
||||||
|
import type {Room} from "../room/Room.js";
|
||||||
|
import type {IChannel} from "./SAS/channel/IChannel";
|
||||||
import type * as OlmNamespace from "@matrix-org/olm";
|
import type * as OlmNamespace from "@matrix-org/olm";
|
||||||
|
|
||||||
type Olm = typeof OlmNamespace;
|
type Olm = typeof OlmNamespace;
|
||||||
@ -177,23 +180,38 @@ export class CrossSigning {
|
|||||||
return this._isMasterKeyTrusted;
|
return this._isMasterKeyTrusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
startVerification(requestOrUserId: SASRequest, log: ILogItem): SASVerification | undefined;
|
startVerification(requestOrUserId: SASRequest, logOrRoom: ILogItem): SASVerification | undefined;
|
||||||
startVerification(requestOrUserId: string, log: ILogItem): SASVerification | undefined;
|
startVerification(requestOrUserId: string, logOrRoom: ILogItem): SASVerification | undefined;
|
||||||
startVerification(requestOrUserId: string | SASRequest, log: ILogItem): SASVerification | undefined {
|
startVerification(requestOrUserId: SASRequest, logOrRoom: Room, _log: ILogItem): SASVerification | undefined;
|
||||||
|
startVerification(requestOrUserId: string, logOrRoom: Room, _log: ILogItem): SASVerification | undefined;
|
||||||
|
startVerification(requestOrUserId: string | SASRequest, logOrRoom: Room | ILogItem, _log?: ILogItem): SASVerification | undefined {
|
||||||
if (this.sasVerificationInProgress && !this.sasVerificationInProgress.finished) {
|
if (this.sasVerificationInProgress && !this.sasVerificationInProgress.finished) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const otherUserId = requestOrUserId instanceof SASRequest ? requestOrUserId.sender : requestOrUserId;
|
const otherUserId = requestOrUserId instanceof SASRequest ? requestOrUserId.sender : requestOrUserId;
|
||||||
const startingMessage = requestOrUserId instanceof SASRequest ? requestOrUserId.startingMessage : undefined;
|
const startingMessage = requestOrUserId instanceof SASRequest ? requestOrUserId.startingMessage : undefined;
|
||||||
const channel = new ToDeviceChannel({
|
const log = _log ?? logOrRoom;
|
||||||
deviceTracker: this.deviceTracker,
|
let channel: IChannel;
|
||||||
hsApi: this.hsApi,
|
if (otherUserId === this.ownUserId) {
|
||||||
otherUserId,
|
channel = new ToDeviceChannel({
|
||||||
clock: this.platform.clock,
|
deviceTracker: this.deviceTracker,
|
||||||
deviceMessageHandler: this.deviceMessageHandler,
|
hsApi: this.hsApi,
|
||||||
ourUserDeviceId: this.deviceId,
|
otherUserId,
|
||||||
log
|
clock: this.platform.clock,
|
||||||
}, startingMessage);
|
deviceMessageHandler: this.deviceMessageHandler,
|
||||||
|
ourUserDeviceId: this.deviceId,
|
||||||
|
log
|
||||||
|
}, startingMessage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
channel = new RoomChannel({
|
||||||
|
room: logOrRoom,
|
||||||
|
otherUserId,
|
||||||
|
ourUserId: this.ownUserId,
|
||||||
|
ourUserDeviceId: this.deviceId,
|
||||||
|
log,
|
||||||
|
}, startingMessage);
|
||||||
|
}
|
||||||
|
|
||||||
this.sasVerificationInProgress = new SASVerification({
|
this.sasVerificationInProgress = new SASVerification({
|
||||||
olm: this.olm,
|
olm: this.olm,
|
||||||
|
@ -27,6 +27,7 @@ import {getRelatedEventId, createReference} from "../../../room/timeline/relatio
|
|||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
otherUserId: string;
|
otherUserId: string;
|
||||||
|
ourUserId: string;
|
||||||
log: ILogItem;
|
log: ILogItem;
|
||||||
ourUserDeviceId: string;
|
ourUserDeviceId: string;
|
||||||
room: Room;
|
room: Room;
|
||||||
@ -40,6 +41,7 @@ export class RoomChannel extends Disposables implements IChannel {
|
|||||||
private readonly waitMap: Map<string, Deferred<any>> = new Map();
|
private readonly waitMap: Map<string, Deferred<any>> = new Map();
|
||||||
private readonly log: ILogItem;
|
private readonly log: ILogItem;
|
||||||
private readonly room: Room;
|
private readonly room: Room;
|
||||||
|
private readonly ourUserId: string;
|
||||||
public otherUserDeviceId: string;
|
public otherUserDeviceId: string;
|
||||||
public startMessage: any;
|
public startMessage: any;
|
||||||
/**
|
/**
|
||||||
@ -56,6 +58,7 @@ export class RoomChannel extends Disposables implements IChannel {
|
|||||||
constructor(options: Options, startingMessage?: any) {
|
constructor(options: Options, startingMessage?: any) {
|
||||||
super();
|
super();
|
||||||
this.otherUserId = options.otherUserId;
|
this.otherUserId = options.otherUserId;
|
||||||
|
this.ourUserId = options.ourUserId;
|
||||||
this.ourDeviceId = options.ourUserDeviceId;
|
this.ourDeviceId = options.ourUserDeviceId;
|
||||||
this.log = options.log;
|
this.log = options.log;
|
||||||
this.room = options.room;
|
this.room = options.room;
|
||||||
@ -143,16 +146,17 @@ export class RoomChannel extends Disposables implements IChannel {
|
|||||||
|
|
||||||
private async handleRoomMessage(entry: EventEntry) {
|
private async handleRoomMessage(entry: EventEntry) {
|
||||||
const type = entry.content.msgtype ?? entry.eventType;
|
const type = entry.content.msgtype ?? entry.eventType;
|
||||||
if (!type.startsWith("m.key.verification")) {
|
if (!type.startsWith("m.key.verification") || entry.sender === this.ourUserId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("entry", entry);
|
||||||
await this.log.wrap("RoomChannel.handleRoomMessage", async (log) => {
|
await this.log.wrap("RoomChannel.handleRoomMessage", async (log) => {
|
||||||
console.log("entry", entry);
|
console.log("entry", entry);
|
||||||
log.log({ l: "entry", entry });
|
log.log({ l: "entry", entry });
|
||||||
if (!this.id) {
|
if (!this.id) {
|
||||||
throw new Error("Couldn't find event-id of request message!");
|
throw new Error("Couldn't find event-id of request message!");
|
||||||
}
|
}
|
||||||
if (getRelatedEventId(entry) !== this.id) {
|
if (getRelatedEventId(entry.event) !== this.id) {
|
||||||
/**
|
/**
|
||||||
* When a device receives an unknown transaction_id, it should send an appropriate
|
* When a device receives an unknown transaction_id, it should send an appropriate
|
||||||
* m.key.verification.cancel message to the other device indicating as such.
|
* m.key.verification.cancel message to the other device indicating as such.
|
||||||
@ -220,9 +224,11 @@ export class RoomChannel extends Disposables implements IChannel {
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
setStartMessage(event) {
|
setStartMessage(entry) {
|
||||||
this.startMessage = event;
|
const clone = entry.clone();
|
||||||
this._initiatedByUs = event.content.from_device === this.ourDeviceId;
|
clone.content["m.relates_to"] = clone.event.content["m.relates_to"];
|
||||||
|
this.startMessage = clone;
|
||||||
|
this._initiatedByUs = entry.content.from_device === this.ourDeviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get initiatedByUs(): boolean {
|
get initiatedByUs(): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user