mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-02 07:31:38 +01:00
Rename CancelTypes -> CancelReason
This commit is contained in:
parent
e2ae5e716e
commit
321775b800
@ -21,7 +21,7 @@ import type {DeviceTracker} from "../../e2ee/DeviceTracker.js";
|
||||
import type * as OlmNamespace from "@matrix-org/olm";
|
||||
import {IChannel} from "./channel/Channel";
|
||||
import {HomeServerApi} from "../../net/HomeServerApi";
|
||||
import {CancelTypes, VerificationEventTypes} from "./channel/types";
|
||||
import {CancelReason, VerificationEventTypes} from "./channel/types";
|
||||
import {SendReadyStage} from "./stages/SendReadyStage";
|
||||
import {SelectVerificationMethodStage} from "./stages/SelectVerificationMethodStage";
|
||||
import {VerificationCancelledError} from "./VerificationCancelledError";
|
||||
@ -78,7 +78,7 @@ export class SASVerification {
|
||||
const tenMinutes = 10 * 60 * 1000;
|
||||
this.timeout = clock.createTimeout(tenMinutes);
|
||||
await this.timeout.elapsed();
|
||||
await this.channel.cancelVerification(CancelTypes.TimedOut);
|
||||
await this.channel.cancelVerification(CancelReason.TimedOut);
|
||||
}
|
||||
catch {
|
||||
// Ignore errors
|
||||
|
@ -20,22 +20,22 @@ import type {ILogItem} from "../../../../logging/types";
|
||||
import type {Clock} from "../../../../platform/web/dom/Clock.js";
|
||||
import type {DeviceMessageHandler} from "../../../DeviceMessageHandler.js";
|
||||
import {makeTxnId} from "../../../common.js";
|
||||
import {CancelTypes, VerificationEventTypes} from "./types";
|
||||
import {CancelReason, VerificationEventTypes} from "./types";
|
||||
import {Disposables} from "../../../../utils/Disposables";
|
||||
import {VerificationCancelledError} from "../VerificationCancelledError";
|
||||
|
||||
const messageFromErrorType = {
|
||||
[CancelTypes.UserCancelled]: "User declined",
|
||||
[CancelTypes.InvalidMessage]: "Invalid Message.",
|
||||
[CancelTypes.KeyMismatch]: "Key Mismatch.",
|
||||
[CancelTypes.OtherDeviceAccepted]: "Another device has accepted this request.",
|
||||
[CancelTypes.TimedOut]: "Timed Out",
|
||||
[CancelTypes.UnexpectedMessage]: "Unexpected Message.",
|
||||
[CancelTypes.UnknownMethod]: "Unknown method.",
|
||||
[CancelTypes.UnknownTransaction]: "Unknown Transaction.",
|
||||
[CancelTypes.UserMismatch]: "User Mismatch",
|
||||
[CancelTypes.MismatchedCommitment]: "Hash commitment does not match.",
|
||||
[CancelTypes.MismatchedSAS]: "Emoji/decimal does not match.",
|
||||
[CancelReason.UserCancelled]: "User declined",
|
||||
[CancelReason.InvalidMessage]: "Invalid Message.",
|
||||
[CancelReason.KeyMismatch]: "Key Mismatch.",
|
||||
[CancelReason.OtherDeviceAccepted]: "Another device has accepted this request.",
|
||||
[CancelReason.TimedOut]: "Timed Out",
|
||||
[CancelReason.UnexpectedMessage]: "Unexpected Message.",
|
||||
[CancelReason.UnknownMethod]: "Unknown method.",
|
||||
[CancelReason.UnknownTransaction]: "Unknown Transaction.",
|
||||
[CancelReason.UserMismatch]: "User Mismatch",
|
||||
[CancelReason.MismatchedCommitment]: "Hash commitment does not match.",
|
||||
[CancelReason.MismatchedSAS]: "Emoji/decimal does not match.",
|
||||
}
|
||||
|
||||
export interface IChannel {
|
||||
@ -45,7 +45,7 @@ export interface IChannel {
|
||||
getReceivedMessage(event: VerificationEventTypes): any;
|
||||
setStartMessage(content: any): void;
|
||||
setOurDeviceId(id: string): void;
|
||||
cancelVerification(cancellationType: CancelTypes): Promise<void>;
|
||||
cancelVerification(cancellationType: CancelReason): Promise<void>;
|
||||
acceptMessage: any;
|
||||
startMessage: any;
|
||||
initiatedByUs: boolean;
|
||||
@ -185,7 +185,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
||||
* This does not apply for inbound m.key.verification.start or m.key.verification.cancel messages.
|
||||
*/
|
||||
console.log("Received event with unknown transaction id: ", event);
|
||||
await this.cancelVerification(CancelTypes.UnknownTransaction);
|
||||
await this.cancelVerification(CancelReason.UnknownTransaction);
|
||||
return;
|
||||
}
|
||||
console.log("event", event);
|
||||
@ -211,8 +211,8 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
||||
const devices = await this.deviceTracker.devicesForUsers([this.otherUserId], this.hsApi, log);
|
||||
const otherDevices = devices.filter(device => device.deviceId !== fromDevice && device.deviceId !== this.ourDeviceId);
|
||||
const cancelMessage = {
|
||||
code: CancelTypes.OtherDeviceAccepted,
|
||||
reason: messageFromErrorType[CancelTypes.OtherDeviceAccepted],
|
||||
code: CancelReason.OtherDeviceAccepted,
|
||||
reason: messageFromErrorType[CancelReason.OtherDeviceAccepted],
|
||||
transaction_id: this.id,
|
||||
};
|
||||
const deviceMessages = otherDevices.reduce((acc, device) => { acc[device.deviceId] = cancelMessage; return acc; }, {});
|
||||
@ -224,7 +224,7 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
||||
await this.hsApi.sendToDevice(VerificationEventTypes.Cancel, payload, makeTxnId(), { log }).response();
|
||||
}
|
||||
|
||||
async cancelVerification(cancellationType: CancelTypes) {
|
||||
async cancelVerification(cancellationType: CancelReason) {
|
||||
await this.log.wrap("Channel.cancelVerification", async log => {
|
||||
if (this.isCancelled) {
|
||||
throw new VerificationCancelledError();
|
||||
|
@ -2,7 +2,7 @@ import type {ILogItem} from "../../../../lib";
|
||||
import {createCalculateMAC} from "../mac";
|
||||
import {VerificationCancelledError} from "../VerificationCancelledError";
|
||||
import {IChannel} from "./Channel";
|
||||
import {CancelTypes, VerificationEventTypes} from "./types";
|
||||
import {CancelReason, VerificationEventTypes} from "./types";
|
||||
import anotherjson from "another-json";
|
||||
|
||||
interface ITestChannel extends IChannel {
|
||||
@ -115,7 +115,7 @@ export class MockChannel implements ITestChannel {
|
||||
this.ourUserDeviceId = id;
|
||||
}
|
||||
|
||||
async cancelVerification(_: CancelTypes): Promise<void> {
|
||||
async cancelVerification(_: CancelReason): Promise<void> {
|
||||
console.log("MockChannel.cancelVerification()");
|
||||
this.isCancelled = true;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export const enum VerificationEventTypes {
|
||||
Done = "m.key.verification.done",
|
||||
}
|
||||
|
||||
export const enum CancelTypes {
|
||||
export const enum CancelReason {
|
||||
UserCancelled = "m.user",
|
||||
TimedOut = "m.timeout",
|
||||
UnknownTransaction = "m.unknown_transaction",
|
||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
import anotherjson from "another-json";
|
||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||
import {CancelTypes, VerificationEventTypes} from "../channel/types";
|
||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
||||
import {generateEmojiSas} from "../generator";
|
||||
import {ILogItem} from "../../../../logging/types";
|
||||
import {SendMacStage} from "./SendMacStage";
|
||||
@ -89,7 +89,7 @@ export class CalculateSASStage extends BaseSASVerificationStage {
|
||||
const hash = this.olmUtil.sha256(commitmentStr);
|
||||
if (hash !== receivedCommitment) {
|
||||
log.log({l: "Commitment mismatched!", received: receivedCommitment, calculated: hash});
|
||||
await this.channel.cancelVerification(CancelTypes.MismatchedCommitment);
|
||||
await this.channel.cancelVerification(CancelReason.MismatchedCommitment);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -130,7 +130,7 @@ export class CalculateSASStage extends BaseSASVerificationStage {
|
||||
this.resolve();
|
||||
}
|
||||
else {
|
||||
await this.channel.cancelVerification(CancelTypes.MismatchedSAS);
|
||||
await this.channel.cancelVerification(CancelReason.MismatchedSAS);
|
||||
this.reject(new VerificationCancelledError());
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||
import {CancelTypes, VerificationEventTypes} from "../channel/types";
|
||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
||||
import {KEY_AGREEMENT_LIST, HASHES_LIST, MAC_LIST, SAS_LIST} from "./constants";
|
||||
import {SendAcceptVerificationStage} from "./SendAcceptVerificationStage";
|
||||
import {SendKeyStage} from "./SendKeyStage";
|
||||
@ -69,7 +69,7 @@ export class SelectVerificationMethodStage extends BaseSASVerificationStage {
|
||||
received: receivedStartMessage.content.method,
|
||||
sent: sentStartMessage.content.method,
|
||||
});
|
||||
await this.channel.cancelVerification(CancelTypes.UnexpectedMessage);
|
||||
await this.channel.cancelVerification(CancelReason.UnexpectedMessage);
|
||||
return;
|
||||
}
|
||||
// In the case of conflict, the lexicographically smaller id wins
|
||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
import anotherjson from "another-json";
|
||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||
import {HASHES_LIST, MAC_LIST, SAS_SET, KEY_AGREEMENT_LIST} from "./constants";
|
||||
import {CancelTypes, VerificationEventTypes} from "../channel/types";
|
||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
||||
import {SendKeyStage} from "./SendKeyStage";
|
||||
|
||||
// from element-web
|
||||
@ -33,7 +33,7 @@ export class SendAcceptVerificationStage extends BaseSASVerificationStage {
|
||||
const macMethod = intersection(MAC_LIST, new Set(startMessage.message_authentication_codes))[0];
|
||||
const sasMethod = intersection(startMessage.short_authentication_string, SAS_SET);
|
||||
if (!keyAgreement || !hashMethod || !macMethod || !sasMethod.length) {
|
||||
await this.channel.cancelVerification(CancelTypes.UnknownMethod);
|
||||
await this.channel.cancelVerification(CancelReason.UnknownMethod);
|
||||
return;
|
||||
}
|
||||
const ourPubKey = this.olmSAS.get_pubkey();
|
||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
import {BaseSASVerificationStage} from "./BaseSASVerificationStage";
|
||||
import {ILogItem} from "../../../../logging/types";
|
||||
import {CancelTypes, VerificationEventTypes} from "../channel/types";
|
||||
import {CancelReason, VerificationEventTypes} from "../channel/types";
|
||||
import {createCalculateMAC} from "../mac";
|
||||
import {SendDoneStage} from "./SendDoneStage";
|
||||
|
||||
@ -46,7 +46,7 @@ export class VerifyMacStage extends BaseSASVerificationStage {
|
||||
const calculatedMAC = calculateMAC(Object.keys(content.mac).sort().join(","), baseInfo + "KEY_IDS");
|
||||
if (content.keys !== calculatedMAC) {
|
||||
log.log({ l: "MAC verification failed for keys field", keys: content.keys, calculated: calculatedMAC });
|
||||
this.channel.cancelVerification(CancelTypes.KeyMismatch);
|
||||
this.channel.cancelVerification(CancelReason.KeyMismatch);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ export class VerifyMacStage extends BaseSASVerificationStage {
|
||||
const calculatedMAC = calculateMAC(key, baseInfo + keyId);
|
||||
if (keyInfo !== calculatedMAC) {
|
||||
log.log({ l: "Mac verification failed for key", keyMac: keyInfo, calculatedMAC, keyId, key });
|
||||
this.channel.cancelVerification(CancelTypes.KeyMismatch);
|
||||
this.channel.cancelVerification(CancelReason.KeyMismatch);
|
||||
return;
|
||||
}
|
||||
}, log);
|
||||
|
Loading…
x
Reference in New Issue
Block a user