mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-02 07:31:38 +01:00
VerificationEventTypes -> VerificationEventType
This commit is contained in:
parent
225a778d1a
commit
ae60c30ab8
@ -10,7 +10,7 @@
|
|||||||
accept -> key -> mac -> done
|
accept -> key -> mac -> done
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {VerificationEventTypes} from "../../../matrix/verification/SAS/channel/types";
|
import {VerificationEventType} from "../../../matrix/verification/SAS/channel/types";
|
||||||
|
|
||||||
function generateResponses(userId: string, deviceId: string, txnId: string) {
|
function generateResponses(userId: string, deviceId: string, txnId: string) {
|
||||||
const readyMessage = {
|
const readyMessage = {
|
||||||
@ -125,7 +125,7 @@ export class SASFixtures {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixtures(): Map<VerificationEventTypes, any> {
|
fixtures(): Map<VerificationEventType, any> {
|
||||||
const responses = generateResponses(this.userId, this.deviceId, this.txnId);
|
const responses = generateResponses(this.userId, this.deviceId, this.txnId);
|
||||||
const array: any[] = [];
|
const array: any[] = [];
|
||||||
const addToArray = (type) => array.push([type, responses[type]]);
|
const addToArray = (type) => array.push([type, responses[type]]);
|
||||||
@ -134,14 +134,14 @@ export class SASFixtures {
|
|||||||
const item = this.order[i];
|
const item = this.order[i];
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case COMBINATIONS.YOU_SENT_REQUEST:
|
case COMBINATIONS.YOU_SENT_REQUEST:
|
||||||
addToArray(VerificationEventTypes.Ready);
|
addToArray(VerificationEventType.Ready);
|
||||||
break;
|
break;
|
||||||
case COMBINATIONS.THEY_SENT_START: {
|
case COMBINATIONS.THEY_SENT_START: {
|
||||||
addToArray(VerificationEventTypes.Start);
|
addToArray(VerificationEventType.Start);
|
||||||
const nextItem = this.order[i+1];
|
const nextItem = this.order[i+1];
|
||||||
if (nextItem === COMBINATIONS.YOU_SENT_START) {
|
if (nextItem === COMBINATIONS.YOU_SENT_START) {
|
||||||
if (this._youWinConflict) {
|
if (this._youWinConflict) {
|
||||||
addToArray(VerificationEventTypes.Accept);
|
addToArray(VerificationEventType.Accept);
|
||||||
i = i + 2;
|
i = i + 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ export class SASFixtures {
|
|||||||
const nextItem = this.order[i+1]
|
const nextItem = this.order[i+1]
|
||||||
if (nextItem === COMBINATIONS.THEY_SENT_START) {
|
if (nextItem === COMBINATIONS.THEY_SENT_START) {
|
||||||
if (this._youWinConflict) {
|
if (this._youWinConflict) {
|
||||||
addToArray(VerificationEventTypes.Accept);
|
addToArray(VerificationEventType.Accept);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -160,15 +160,15 @@ export class SASFixtures {
|
|||||||
if (this.order[i-1] === COMBINATIONS.THEY_SENT_START) {
|
if (this.order[i-1] === COMBINATIONS.THEY_SENT_START) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addToArray(VerificationEventTypes.Accept);
|
addToArray(VerificationEventType.Accept);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
addToArray(VerificationEventTypes.Key);
|
addToArray(VerificationEventType.Key);
|
||||||
addToArray(VerificationEventTypes.Mac);
|
addToArray(VerificationEventType.Mac);
|
||||||
addToArray(VerificationEventTypes.Done);
|
addToArray(VerificationEventType.Done);
|
||||||
return new Map(array);
|
return new Map(array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import type {ISignatures} from "./common";
|
|||||||
import {SASVerification} from "./SAS/SASVerification";
|
import {SASVerification} from "./SAS/SASVerification";
|
||||||
import {ToDeviceChannel} from "./SAS/channel/Channel";
|
import {ToDeviceChannel} from "./SAS/channel/Channel";
|
||||||
import type {DeviceMessageHandler} from "../DeviceMessageHandler.js";
|
import type {DeviceMessageHandler} from "../DeviceMessageHandler.js";
|
||||||
import {VerificationEventTypes} from "./SAS/channel/types";
|
import {VerificationEventType} from "./SAS/channel/types";
|
||||||
|
|
||||||
type Olm = typeof OlmNamespace;
|
type Olm = typeof OlmNamespace;
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ export class CrossSigning {
|
|||||||
)) {
|
)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (unencryptedEvent.type === VerificationEventTypes.Request ||
|
if (unencryptedEvent.type === VerificationEventType.Request ||
|
||||||
unencryptedEvent.type === VerificationEventTypes.Start) {
|
unencryptedEvent.type === VerificationEventType.Start) {
|
||||||
await this.platform.logger.run("Start verification from request", async (log) => {
|
await this.platform.logger.run("Start verification from request", async (log) => {
|
||||||
const sas = this.startVerification(unencryptedEvent.sender, unencryptedEvent, log);
|
const sas = this.startVerification(unencryptedEvent.sender, unencryptedEvent, log);
|
||||||
await sas?.start();
|
await sas?.start();
|
||||||
|
@ -21,7 +21,7 @@ import type {DeviceTracker} from "../../e2ee/DeviceTracker.js";
|
|||||||
import type * as OlmNamespace from "@matrix-org/olm";
|
import type * as OlmNamespace from "@matrix-org/olm";
|
||||||
import {IChannel} from "./channel/Channel";
|
import {IChannel} from "./channel/Channel";
|
||||||
import {HomeServerApi} from "../../net/HomeServerApi";
|
import {HomeServerApi} from "../../net/HomeServerApi";
|
||||||
import {CancelReason, VerificationEventTypes} from "./channel/types";
|
import {CancelReason, VerificationEventType} from "./channel/types";
|
||||||
import {SendReadyStage} from "./stages/SendReadyStage";
|
import {SendReadyStage} from "./stages/SendReadyStage";
|
||||||
import {SelectVerificationMethodStage} from "./stages/SelectVerificationMethodStage";
|
import {SelectVerificationMethodStage} from "./stages/SelectVerificationMethodStage";
|
||||||
import {VerificationCancelledError} from "./VerificationCancelledError";
|
import {VerificationCancelledError} from "./VerificationCancelledError";
|
||||||
@ -61,10 +61,10 @@ export class SASVerification extends EventEmitter<SASProgressEvents> {
|
|||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.setupCancelAfterTimeout(clock);
|
this.setupCancelAfterTimeout(clock);
|
||||||
const stageOptions = {...options, olmSas, eventEmitter: this};
|
const stageOptions = {...options, olmSas, eventEmitter: this};
|
||||||
if (channel.getReceivedMessage(VerificationEventTypes.Start)) {
|
if (channel.getReceivedMessage(VerificationEventType.Start)) {
|
||||||
this.startStage = new SelectVerificationMethodStage(stageOptions);
|
this.startStage = new SelectVerificationMethodStage(stageOptions);
|
||||||
}
|
}
|
||||||
else if (channel.getReceivedMessage(VerificationEventTypes.Request)) {
|
else if (channel.getReceivedMessage(VerificationEventType.Request)) {
|
||||||
this.startStage = new SendReadyStage(stageOptions);
|
this.startStage = new SendReadyStage(stageOptions);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -283,7 +283,7 @@ export function tests() {
|
|||||||
const receivedMessages = new SASFixtures(theirUserId, theirDeviceId, txnId)
|
const receivedMessages = new SASFixtures(theirUserId, theirDeviceId, txnId)
|
||||||
.theySentStart()
|
.theySentStart()
|
||||||
.fixtures();
|
.fixtures();
|
||||||
const startingMessage = receivedMessages.get(VerificationEventTypes.Start);
|
const startingMessage = receivedMessages.get(VerificationEventType.Start);
|
||||||
const { sas } = await createSASRequest(
|
const { sas } = await createSASRequest(
|
||||||
ourUserId,
|
ourUserId,
|
||||||
ourDeviceId,
|
ourDeviceId,
|
||||||
@ -404,7 +404,7 @@ export function tests() {
|
|||||||
.youSentStart()
|
.youSentStart()
|
||||||
.theyWinConflict()
|
.theyWinConflict()
|
||||||
.fixtures();
|
.fixtures();
|
||||||
const startingMessage = receivedMessages.get(VerificationEventTypes.Start);
|
const startingMessage = receivedMessages.get(VerificationEventType.Start);
|
||||||
console.log(receivedMessages);
|
console.log(receivedMessages);
|
||||||
const { sas } = await createSASRequest(
|
const { sas } = await createSASRequest(
|
||||||
ourUserId,
|
ourUserId,
|
||||||
@ -445,7 +445,7 @@ export function tests() {
|
|||||||
.youSentStart()
|
.youSentStart()
|
||||||
.youWinConflict()
|
.youWinConflict()
|
||||||
.fixtures();
|
.fixtures();
|
||||||
const startingMessage = receivedMessages.get(VerificationEventTypes.Start);
|
const startingMessage = receivedMessages.get(VerificationEventType.Start);
|
||||||
console.log(receivedMessages);
|
console.log(receivedMessages);
|
||||||
const { sas, logger } = await createSASRequest(
|
const { sas, logger } = await createSASRequest(
|
||||||
ourUserId,
|
ourUserId,
|
||||||
@ -600,7 +600,7 @@ export function tests() {
|
|||||||
.youSentRequest()
|
.youSentRequest()
|
||||||
.theySentStart()
|
.theySentStart()
|
||||||
.fixtures();
|
.fixtures();
|
||||||
receivedMessages.get(VerificationEventTypes.Start).content.key_agreement_protocols = ["foo"];
|
receivedMessages.get(VerificationEventType.Start).content.key_agreement_protocols = ["foo"];
|
||||||
const { sas } = await createSASRequest(
|
const { sas } = await createSASRequest(
|
||||||
ourUserId,
|
ourUserId,
|
||||||
ourDeviceId,
|
ourDeviceId,
|
||||||
|
@ -20,7 +20,7 @@ import type {ILogItem} from "../../../../logging/types";
|
|||||||
import type {Clock} from "../../../../platform/web/dom/Clock.js";
|
import type {Clock} from "../../../../platform/web/dom/Clock.js";
|
||||||
import type {DeviceMessageHandler} from "../../../DeviceMessageHandler.js";
|
import type {DeviceMessageHandler} from "../../../DeviceMessageHandler.js";
|
||||||
import {makeTxnId} from "../../../common.js";
|
import {makeTxnId} from "../../../common.js";
|
||||||
import {CancelReason, VerificationEventTypes} from "./types";
|
import {CancelReason, VerificationEventType} from "./types";
|
||||||
import {Disposables} from "../../../../utils/Disposables";
|
import {Disposables} from "../../../../utils/Disposables";
|
||||||
import {VerificationCancelledError} from "../VerificationCancelledError";
|
import {VerificationCancelledError} from "../VerificationCancelledError";
|
||||||
import {Deferred} from "../../../../utils/Deferred";
|
import {Deferred} from "../../../../utils/Deferred";
|
||||||
@ -42,8 +42,8 @@ const messageFromErrorType = {
|
|||||||
export interface IChannel {
|
export interface IChannel {
|
||||||
send(eventType: string, content: any, log: ILogItem): Promise<void>;
|
send(eventType: string, content: any, log: ILogItem): Promise<void>;
|
||||||
waitForEvent(eventType: string): Promise<any>;
|
waitForEvent(eventType: string): Promise<any>;
|
||||||
getSentMessage(event: VerificationEventTypes): any;
|
getSentMessage(event: VerificationEventType): any;
|
||||||
getReceivedMessage(event: VerificationEventTypes): any;
|
getReceivedMessage(event: VerificationEventType): any;
|
||||||
setStartMessage(content: any): void;
|
setStartMessage(content: any): void;
|
||||||
cancelVerification(cancellationType: CancelReason): Promise<void>;
|
cancelVerification(cancellationType: CancelReason): Promise<void>;
|
||||||
acceptMessage: any;
|
acceptMessage: any;
|
||||||
@ -70,8 +70,8 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
private readonly otherUserId: string;
|
private readonly otherUserId: string;
|
||||||
private readonly clock: Clock;
|
private readonly clock: Clock;
|
||||||
private readonly deviceMessageHandler: DeviceMessageHandler;
|
private readonly deviceMessageHandler: DeviceMessageHandler;
|
||||||
private readonly sentMessages: Map<VerificationEventTypes, any> = new Map();
|
private readonly sentMessages: Map<VerificationEventType, any> = new Map();
|
||||||
private readonly receivedMessages: Map<VerificationEventTypes, any> = new Map();
|
private readonly receivedMessages: Map<VerificationEventType, any> = new Map();
|
||||||
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;
|
||||||
public otherUserDeviceId: string;
|
public otherUserDeviceId: string;
|
||||||
@ -120,12 +120,12 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
return this._isCancelled;
|
return this._isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(eventType: VerificationEventTypes, content: any, log: ILogItem): Promise<void> {
|
async send(eventType: VerificationEventType, content: any, log: ILogItem): Promise<void> {
|
||||||
await log.wrap("ToDeviceChannel.send", async () => {
|
await log.wrap("ToDeviceChannel.send", async () => {
|
||||||
if (this.isCancelled) {
|
if (this.isCancelled) {
|
||||||
throw new VerificationCancelledError();
|
throw new VerificationCancelledError();
|
||||||
}
|
}
|
||||||
if (eventType === VerificationEventTypes.Request) {
|
if (eventType === VerificationEventType.Request) {
|
||||||
// Handle this case specially
|
// Handle this case specially
|
||||||
await this.handleRequestEventSpecially(eventType, content, log);
|
await this.handleRequestEventSpecially(eventType, content, log);
|
||||||
return;
|
return;
|
||||||
@ -143,7 +143,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleRequestEventSpecially(eventType: VerificationEventTypes, content: any, log: ILogItem) {
|
private async handleRequestEventSpecially(eventType: VerificationEventType, content: any, log: ILogItem) {
|
||||||
await log.wrap("ToDeviceChannel.handleRequestEventSpecially", async () => {
|
await log.wrap("ToDeviceChannel.handleRequestEventSpecially", async () => {
|
||||||
const timestamp = this.clock.now();
|
const timestamp = this.clock.now();
|
||||||
const txnId = makeTxnId();
|
const txnId = makeTxnId();
|
||||||
@ -161,17 +161,17 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getReceivedMessage(event: VerificationEventTypes) {
|
getReceivedMessage(event: VerificationEventType) {
|
||||||
return this.receivedMessages.get(event);
|
return this.receivedMessages.get(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSentMessage(event: VerificationEventTypes) {
|
getSentMessage(event: VerificationEventType) {
|
||||||
return this.sentMessages.get(event);
|
return this.sentMessages.get(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
get acceptMessage(): any {
|
get acceptMessage(): any {
|
||||||
return this.receivedMessages.get(VerificationEventTypes.Accept) ??
|
return this.receivedMessages.get(VerificationEventType.Accept) ??
|
||||||
this.sentMessages.get(VerificationEventTypes.Accept);
|
this.sentMessages.get(VerificationEventType.Accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -194,11 +194,11 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
log.log({ l: "event", event });
|
log.log({ l: "event", event });
|
||||||
this.resolveAnyWaits(event);
|
this.resolveAnyWaits(event);
|
||||||
this.receivedMessages.set(event.type, event);
|
this.receivedMessages.set(event.type, event);
|
||||||
if (event.type === VerificationEventTypes.Ready) {
|
if (event.type === VerificationEventType.Ready) {
|
||||||
this.handleReadyMessage(event, log);
|
this.handleReadyMessage(event, log);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.type === VerificationEventTypes.Cancel) {
|
if (event.type === VerificationEventType.Cancel) {
|
||||||
this._isCancelled = true;
|
this._isCancelled = true;
|
||||||
this.dispose();
|
this.dispose();
|
||||||
return;
|
return;
|
||||||
@ -223,7 +223,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
[this.otherUserId]: deviceMessages
|
[this.otherUserId]: deviceMessages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.hsApi.sendToDevice(VerificationEventTypes.Cancel, payload, makeTxnId(), { log }).response();
|
await this.hsApi.sendToDevice(VerificationEventType.Cancel, payload, makeTxnId(), { log }).response();
|
||||||
}
|
}
|
||||||
|
|
||||||
async cancelVerification(cancellationType: CancelReason) {
|
async cancelVerification(cancellationType: CancelReason) {
|
||||||
@ -242,7 +242,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.hsApi.sendToDevice(VerificationEventTypes.Cancel, payload, makeTxnId(), { log }).response();
|
await this.hsApi.sendToDevice(VerificationEventType.Cancel, payload, makeTxnId(), { log }).response();
|
||||||
this._isCancelled = true;
|
this._isCancelled = true;
|
||||||
this.dispose();
|
this.dispose();
|
||||||
});
|
});
|
||||||
@ -257,7 +257,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForEvent(eventType: VerificationEventTypes): Promise<any> {
|
waitForEvent(eventType: VerificationEventType): Promise<any> {
|
||||||
if (this._isCancelled) {
|
if (this._isCancelled) {
|
||||||
throw new VerificationCancelledError();
|
throw new VerificationCancelledError();
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import type {ILogItem} from "../../../../lib";
|
|||||||
import {createCalculateMAC} from "../mac";
|
import {createCalculateMAC} from "../mac";
|
||||||
import {VerificationCancelledError} from "../VerificationCancelledError";
|
import {VerificationCancelledError} from "../VerificationCancelledError";
|
||||||
import {IChannel} from "./Channel";
|
import {IChannel} from "./Channel";
|
||||||
import {CancelReason, VerificationEventTypes} from "./types";
|
import {CancelReason, VerificationEventType} from "./types";
|
||||||
import anotherjson from "another-json";
|
import anotherjson from "another-json";
|
||||||
|
|
||||||
interface ITestChannel extends IChannel {
|
interface ITestChannel extends IChannel {
|
||||||
@ -29,7 +29,7 @@ export class MockChannel implements ITestChannel {
|
|||||||
startingMessage?: any,
|
startingMessage?: any,
|
||||||
) {
|
) {
|
||||||
if (startingMessage) {
|
if (startingMessage) {
|
||||||
const eventType = startingMessage.content.method ? VerificationEventTypes.Start : VerificationEventTypes.Request;
|
const eventType = startingMessage.content.method ? VerificationEventType.Start : VerificationEventType.Request;
|
||||||
this.id = startingMessage.content.transaction_id;
|
this.id = startingMessage.content.transaction_id;
|
||||||
this.receivedMessages.set(eventType, startingMessage);
|
this.receivedMessages.set(eventType, startingMessage);
|
||||||
}
|
}
|
||||||
@ -54,10 +54,10 @@ export class MockChannel implements ITestChannel {
|
|||||||
else {
|
else {
|
||||||
await new Promise(() => {});
|
await new Promise(() => {});
|
||||||
}
|
}
|
||||||
if (eventType === VerificationEventTypes.Mac) {
|
if (eventType === VerificationEventType.Mac) {
|
||||||
await this.recalculateMAC();
|
await this.recalculateMAC();
|
||||||
}
|
}
|
||||||
if(eventType === VerificationEventTypes.Accept && this.startMessage) {
|
if(eventType === VerificationEventType.Accept && this.startMessage) {
|
||||||
}
|
}
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ export class MockChannel implements ITestChannel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {content} = this.startMessage;
|
const {content} = this.startMessage;
|
||||||
const {content: keyMessage} = this.fixtures.get(VerificationEventTypes.Key);
|
const {content: keyMessage} = this.fixtures.get(VerificationEventType.Key);
|
||||||
const key = keyMessage.key;
|
const key = keyMessage.key;
|
||||||
const commitmentStr = key + anotherjson.stringify(content);
|
const commitmentStr = key + anotherjson.stringify(content);
|
||||||
const olmUtil = new this.olm.Utility();
|
const olmUtil = new this.olm.Utility();
|
||||||
@ -86,7 +86,7 @@ export class MockChannel implements ITestChannel {
|
|||||||
this.ourUserId +
|
this.ourUserId +
|
||||||
this.ourUserDeviceId +
|
this.ourUserDeviceId +
|
||||||
this.id;
|
this.id;
|
||||||
const { content: macContent } = this.receivedMessages.get(VerificationEventTypes.Mac);
|
const { content: macContent } = this.receivedMessages.get(VerificationEventType.Mac);
|
||||||
const macMethod = this.acceptMessage.content.message_authentication_code;
|
const macMethod = this.acceptMessage.content.message_authentication_code;
|
||||||
const calculateMac = createCalculateMAC(this.olmSas, macMethod);
|
const calculateMac = createCalculateMAC(this.olmSas, macMethod);
|
||||||
const input = Object.keys(macContent.mac).sort().join(",");
|
const input = Object.keys(macContent.mac).sort().join(",");
|
||||||
@ -117,15 +117,15 @@ export class MockChannel implements ITestChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get acceptMessage(): any {
|
get acceptMessage(): any {
|
||||||
return this.receivedMessages.get(VerificationEventTypes.Accept) ??
|
return this.receivedMessages.get(VerificationEventType.Accept) ??
|
||||||
this.sentMessages.get(VerificationEventTypes.Accept);
|
this.sentMessages.get(VerificationEventType.Accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
getReceivedMessage(event: VerificationEventTypes) {
|
getReceivedMessage(event: VerificationEventType) {
|
||||||
return this.receivedMessages.get(event);
|
return this.receivedMessages.get(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSentMessage(event: VerificationEventTypes) {
|
getSentMessage(event: VerificationEventType) {
|
||||||
return this.sentMessages.get(event);
|
return this.sentMessages.get(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export const enum VerificationEventTypes {
|
export const enum VerificationEventType {
|
||||||
Request = "m.key.verification.request",
|
Request = "m.key.verification.request",
|
||||||
Ready = "m.key.verification.ready",
|
Ready = "m.key.verification.ready",
|
||||||
Start = "m.key.verification.start",
|
Start = "m.key.verification.start",
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
import anotherjson from "another-json";
|
import anotherjson from "another-json";
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
import {CancelReason, VerificationEventType} from "../channel/types";
|
||||||
import {generateEmojiSas} from "../generator";
|
import {generateEmojiSas} from "../generator";
|
||||||
import {ILogItem} from "../../../../logging/types";
|
import {ILogItem} from "../../../../logging/types";
|
||||||
import {SendMacStage} from "./SendMacStage";
|
import {SendMacStage} from "./SendMacStage";
|
||||||
@ -82,8 +82,8 @@ export class CalculateSASStage extends BaseSASVerificationStage {
|
|||||||
|
|
||||||
async verifyHashCommitment(log: ILogItem) {
|
async verifyHashCommitment(log: ILogItem) {
|
||||||
return await log.wrap("CalculateSASStage.verifyHashCommitment", async () => {
|
return await log.wrap("CalculateSASStage.verifyHashCommitment", async () => {
|
||||||
const acceptMessage = this.channel.getReceivedMessage(VerificationEventTypes.Accept).content;
|
const acceptMessage = this.channel.getReceivedMessage(VerificationEventType.Accept).content;
|
||||||
const keyMessage = this.channel.getReceivedMessage(VerificationEventTypes.Key).content;
|
const keyMessage = this.channel.getReceivedMessage(VerificationEventType.Key).content;
|
||||||
const commitmentStr = keyMessage.key + anotherjson.stringify(this.channel.startMessage.content);
|
const commitmentStr = keyMessage.key + anotherjson.stringify(this.channel.startMessage.content);
|
||||||
const receivedCommitment = acceptMessage.commitment;
|
const receivedCommitment = acceptMessage.commitment;
|
||||||
const hash = this.olmUtil.sha256(commitmentStr);
|
const hash = this.olmUtil.sha256(commitmentStr);
|
||||||
@ -136,7 +136,7 @@ export class CalculateSASStage extends BaseSASVerificationStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get theirKey(): string {
|
get theirKey(): string {
|
||||||
const {content} = this.channel.getReceivedMessage(VerificationEventTypes.Key);
|
const {content} = this.channel.getReceivedMessage(VerificationEventType.Key);
|
||||||
return content.key;
|
return content.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
import {CancelReason, VerificationEventType} from "../channel/types";
|
||||||
import {KEY_AGREEMENT_LIST, HASHES_LIST, MAC_LIST, SAS_LIST} from "./constants";
|
import {KEY_AGREEMENT_LIST, HASHES_LIST, MAC_LIST, SAS_LIST} from "./constants";
|
||||||
import {SendAcceptVerificationStage} from "./SendAcceptVerificationStage";
|
import {SendAcceptVerificationStage} from "./SendAcceptVerificationStage";
|
||||||
import {SendKeyStage} from "./SendKeyStage";
|
import {SendKeyStage} from "./SendKeyStage";
|
||||||
@ -27,8 +27,8 @@ export class SelectVerificationMethodStage extends BaseSASVerificationStage {
|
|||||||
async completeStage() {
|
async completeStage() {
|
||||||
await this.log.wrap("SelectVerificationMethodStage.completeStage", async (log) => {
|
await this.log.wrap("SelectVerificationMethodStage.completeStage", async (log) => {
|
||||||
this.eventEmitter.emit("SelectVerificationStage", this);
|
this.eventEmitter.emit("SelectVerificationStage", this);
|
||||||
const startMessage = this.channel.waitForEvent(VerificationEventTypes.Start);
|
const startMessage = this.channel.waitForEvent(VerificationEventType.Start);
|
||||||
const acceptMessage = this.channel.waitForEvent(VerificationEventTypes.Accept);
|
const acceptMessage = this.channel.waitForEvent(VerificationEventType.Accept);
|
||||||
const { content } = await Promise.race([startMessage, acceptMessage]);
|
const { content } = await Promise.race([startMessage, acceptMessage]);
|
||||||
if (content.method) {
|
if (content.method) {
|
||||||
// We received the start message
|
// We received the start message
|
||||||
@ -37,12 +37,12 @@ export class SelectVerificationMethodStage extends BaseSASVerificationStage {
|
|||||||
await this.resolveStartConflict(log);
|
await this.resolveStartConflict(log);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.channel.setStartMessage(this.channel.getReceivedMessage(VerificationEventTypes.Start));
|
this.channel.setStartMessage(this.channel.getReceivedMessage(VerificationEventType.Start));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We received the accept message
|
// We received the accept message
|
||||||
this.channel.setStartMessage(this.channel.getSentMessage(VerificationEventTypes.Start));
|
this.channel.setStartMessage(this.channel.getSentMessage(VerificationEventType.Start));
|
||||||
}
|
}
|
||||||
if (this.channel.initiatedByUs) {
|
if (this.channel.initiatedByUs) {
|
||||||
await acceptMessage;
|
await acceptMessage;
|
||||||
@ -57,8 +57,8 @@ export class SelectVerificationMethodStage extends BaseSASVerificationStage {
|
|||||||
|
|
||||||
private async resolveStartConflict(log: ILogItem) {
|
private async resolveStartConflict(log: ILogItem) {
|
||||||
await log.wrap("resolveStartConflict", async () => {
|
await log.wrap("resolveStartConflict", async () => {
|
||||||
const receivedStartMessage = this.channel.getReceivedMessage(VerificationEventTypes.Start);
|
const receivedStartMessage = this.channel.getReceivedMessage(VerificationEventType.Start);
|
||||||
const sentStartMessage = this.channel.getSentMessage(VerificationEventTypes.Start);
|
const sentStartMessage = this.channel.getSentMessage(VerificationEventType.Start);
|
||||||
if (receivedStartMessage.content.method !== sentStartMessage.content.method) {
|
if (receivedStartMessage.content.method !== sentStartMessage.content.method) {
|
||||||
/**
|
/**
|
||||||
* If the two m.key.verification.start messages do not specify the same verification method,
|
* If the two m.key.verification.start messages do not specify the same verification method,
|
||||||
@ -96,7 +96,7 @@ export class SelectVerificationMethodStage extends BaseSASVerificationStage {
|
|||||||
* This will cause the Promise.race in completeStage() to resolve and we'll move
|
* This will cause the Promise.race in completeStage() to resolve and we'll move
|
||||||
* to the next stage (where we will send the key).
|
* to the next stage (where we will send the key).
|
||||||
*/
|
*/
|
||||||
await this.channel.send(VerificationEventTypes.Start, content, log);
|
await this.channel.send(VerificationEventType.Start, content, log);
|
||||||
this.hasSentStartMessage = true;
|
this.hasSentStartMessage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
import anotherjson from "another-json";
|
import anotherjson from "another-json";
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {HASHES_LIST, MAC_LIST, SAS_SET, KEY_AGREEMENT_LIST} from "./constants";
|
import {HASHES_LIST, MAC_LIST, SAS_SET, KEY_AGREEMENT_LIST} from "./constants";
|
||||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
import {CancelReason, VerificationEventType} from "../channel/types";
|
||||||
import {SendKeyStage} from "./SendKeyStage";
|
import {SendKeyStage} from "./SendKeyStage";
|
||||||
|
|
||||||
// from element-web
|
// from element-web
|
||||||
@ -45,8 +45,8 @@ export class SendAcceptVerificationStage extends BaseSASVerificationStage {
|
|||||||
short_authentication_string: sasMethod,
|
short_authentication_string: sasMethod,
|
||||||
commitment: this.olmUtil.sha256(commitmentStr),
|
commitment: this.olmUtil.sha256(commitmentStr),
|
||||||
};
|
};
|
||||||
await this.channel.send(VerificationEventTypes.Accept, content, log);
|
await this.channel.send(VerificationEventType.Accept, content, log);
|
||||||
await this.channel.waitForEvent(VerificationEventTypes.Key);
|
await this.channel.waitForEvent(VerificationEventType.Key);
|
||||||
this.setNextStage(new SendKeyStage(this.options));
|
this.setNextStage(new SendKeyStage(this.options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {VerificationEventTypes} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
|
|
||||||
export class SendDoneStage extends BaseSASVerificationStage {
|
export class SendDoneStage extends BaseSASVerificationStage {
|
||||||
async completeStage() {
|
async completeStage() {
|
||||||
await this.log.wrap("SendDoneStage.completeStage", async (log) => {
|
await this.log.wrap("SendDoneStage.completeStage", async (log) => {
|
||||||
await this.channel.send(VerificationEventTypes.Done, {}, log);
|
await this.channel.send(VerificationEventType.Done, {}, log);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,21 +14,21 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {VerificationEventTypes} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
import {CalculateSASStage} from "./CalculateSASStage";
|
import {CalculateSASStage} from "./CalculateSASStage";
|
||||||
|
|
||||||
export class SendKeyStage extends BaseSASVerificationStage {
|
export class SendKeyStage extends BaseSASVerificationStage {
|
||||||
async completeStage() {
|
async completeStage() {
|
||||||
await this.log.wrap("SendKeyStage.completeStage", async (log) => {
|
await this.log.wrap("SendKeyStage.completeStage", async (log) => {
|
||||||
const ourSasKey = this.olmSAS.get_pubkey();
|
const ourSasKey = this.olmSAS.get_pubkey();
|
||||||
await this.channel.send(VerificationEventTypes.Key, {key: ourSasKey}, log);
|
await this.channel.send(VerificationEventType.Key, {key: ourSasKey}, log);
|
||||||
/**
|
/**
|
||||||
* We may have already got the key in SendAcceptVerificationStage,
|
* We may have already got the key in SendAcceptVerificationStage,
|
||||||
* in which case waitForEvent will return a resolved promise with
|
* in which case waitForEvent will return a resolved promise with
|
||||||
* that content. Otherwise, waitForEvent will actually wait for the
|
* that content. Otherwise, waitForEvent will actually wait for the
|
||||||
* key message.
|
* key message.
|
||||||
*/
|
*/
|
||||||
await this.channel.waitForEvent(VerificationEventTypes.Key);
|
await this.channel.waitForEvent(VerificationEventType.Key);
|
||||||
this.setNextStage(new CalculateSASStage(this.options));
|
this.setNextStage(new CalculateSASStage(this.options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {ILogItem} from "../../../../logging/types";
|
import {ILogItem} from "../../../../logging/types";
|
||||||
import {VerificationEventTypes} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
import {createCalculateMAC} from "../mac";
|
import {createCalculateMAC} from "../mac";
|
||||||
import {VerifyMacStage} from "./VerifyMacStage";
|
import {VerifyMacStage} from "./VerifyMacStage";
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export class SendMacStage extends BaseSASVerificationStage {
|
|||||||
const macMethod = acceptMessage.message_authentication_code;
|
const macMethod = acceptMessage.message_authentication_code;
|
||||||
const calculateMAC = createCalculateMAC(this.olmSAS, macMethod);
|
const calculateMAC = createCalculateMAC(this.olmSAS, macMethod);
|
||||||
await this.sendMAC(calculateMAC, log);
|
await this.sendMAC(calculateMAC, log);
|
||||||
await this.channel.waitForEvent(VerificationEventTypes.Mac);
|
await this.channel.waitForEvent(VerificationEventType.Mac);
|
||||||
this.setNextStage(new VerifyMacStage(this.options));
|
this.setNextStage(new VerifyMacStage(this.options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ export class SendMacStage extends BaseSASVerificationStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const keys = calculateMAC(keyList.sort().join(","), baseInfo + "KEY_IDS");
|
const keys = calculateMAC(keyList.sort().join(","), baseInfo + "KEY_IDS");
|
||||||
await this.channel.send(VerificationEventTypes.Mac, { mac, keys }, log);
|
await this.channel.send(VerificationEventType.Mac, { mac, keys }, log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {VerificationEventTypes} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
import {SelectVerificationMethodStage} from "./SelectVerificationMethodStage";
|
import {SelectVerificationMethodStage} from "./SelectVerificationMethodStage";
|
||||||
|
|
||||||
export class SendReadyStage extends BaseSASVerificationStage {
|
export class SendReadyStage extends BaseSASVerificationStage {
|
||||||
@ -24,7 +24,7 @@ export class SendReadyStage extends BaseSASVerificationStage {
|
|||||||
"from_device": this.ourUserDeviceId,
|
"from_device": this.ourUserDeviceId,
|
||||||
"methods": ["m.sas.v1"],
|
"methods": ["m.sas.v1"],
|
||||||
};
|
};
|
||||||
await this.channel.send(VerificationEventTypes.Ready, content, log);
|
await this.channel.send(VerificationEventType.Ready, content, log);
|
||||||
this.setNextStage(new SelectVerificationMethodStage(this.options));
|
this.setNextStage(new SelectVerificationMethodStage(this.options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {SelectVerificationMethodStage} from "./SelectVerificationMethodStage";
|
import {SelectVerificationMethodStage} from "./SelectVerificationMethodStage";
|
||||||
import {VerificationEventTypes} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
|
|
||||||
export class SendRequestVerificationStage extends BaseSASVerificationStage {
|
export class SendRequestVerificationStage extends BaseSASVerificationStage {
|
||||||
async completeStage() {
|
async completeStage() {
|
||||||
@ -24,9 +24,9 @@ export class SendRequestVerificationStage extends BaseSASVerificationStage {
|
|||||||
"from_device": this.ourUserDeviceId,
|
"from_device": this.ourUserDeviceId,
|
||||||
"methods": ["m.sas.v1"],
|
"methods": ["m.sas.v1"],
|
||||||
};
|
};
|
||||||
await this.channel.send(VerificationEventTypes.Request, content, log);
|
await this.channel.send(VerificationEventType.Request, content, log);
|
||||||
this.setNextStage(new SelectVerificationMethodStage(this.options));
|
this.setNextStage(new SelectVerificationMethodStage(this.options));
|
||||||
await this.channel.waitForEvent(VerificationEventTypes.Ready);
|
await this.channel.waitForEvent(VerificationEventType.Ready);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||||
import {ILogItem} from "../../../../logging/types";
|
import {ILogItem} from "../../../../logging/types";
|
||||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
import {CancelReason, VerificationEventType} from "../channel/types";
|
||||||
import {createCalculateMAC} from "../mac";
|
import {createCalculateMAC} from "../mac";
|
||||||
import {SendDoneStage} from "./SendDoneStage";
|
import {SendDoneStage} from "./SendDoneStage";
|
||||||
|
|
||||||
@ -28,13 +28,13 @@ export class VerifyMacStage extends BaseSASVerificationStage {
|
|||||||
const macMethod = acceptMessage.message_authentication_code;
|
const macMethod = acceptMessage.message_authentication_code;
|
||||||
const calculateMAC = createCalculateMAC(this.olmSAS, macMethod);
|
const calculateMAC = createCalculateMAC(this.olmSAS, macMethod);
|
||||||
await this.checkMAC(calculateMAC, log);
|
await this.checkMAC(calculateMAC, log);
|
||||||
await this.channel.waitForEvent(VerificationEventTypes.Done);
|
await this.channel.waitForEvent(VerificationEventType.Done);
|
||||||
this.setNextStage(new SendDoneStage(this.options));
|
this.setNextStage(new SendDoneStage(this.options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkMAC(calculateMAC: (input: string, info: string) => string, log: ILogItem): Promise<void> {
|
private async checkMAC(calculateMAC: (input: string, info: string) => string, log: ILogItem): Promise<void> {
|
||||||
const {content} = this.channel.getReceivedMessage(VerificationEventTypes.Mac);
|
const {content} = this.channel.getReceivedMessage(VerificationEventType.Mac);
|
||||||
const baseInfo =
|
const baseInfo =
|
||||||
"MATRIX_KEY_VERIFICATION_MAC" +
|
"MATRIX_KEY_VERIFICATION_MAC" +
|
||||||
this.otherUserId +
|
this.otherUserId +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user