mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-08 18:48:18 +01:00
Fix tests and code to use new data structure
This commit is contained in:
parent
3e7a4d95c3
commit
10c92c56f5
@ -145,16 +145,25 @@ export function tests() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const deviceTracker = {
|
const deviceTracker = {
|
||||||
getCrossSigningKeysForUser: (userId, _hsApi, _) => {
|
getCrossSigningKeyForUser: (userId, __, _hsApi, _) => {
|
||||||
let masterKey =
|
let masterKey =
|
||||||
userId === ourUserId
|
userId === ourUserId
|
||||||
? "5HIrEawRiiQioViNfezPDWfPWH2pdaw3pbQNHEVN2jM"
|
? "5HIrEawRiiQioViNfezPDWfPWH2pdaw3pbQNHEVN2jM"
|
||||||
: "Ot8Y58PueQ7hJVpYWAJkg2qaREJAY/UhGZYOrsd52oo";
|
: "Ot8Y58PueQ7hJVpYWAJkg2qaREJAY/UhGZYOrsd52oo";
|
||||||
return { masterKey };
|
|
||||||
},
|
|
||||||
deviceForId: (_userId, _deviceId, _hsApi, _log) => {
|
|
||||||
return {
|
return {
|
||||||
ed25519Key: "D8w9mrokGdEZPdPgrU0kQkYi4vZyzKEBfvGyZsGK7+Q",
|
user_id: userId,
|
||||||
|
usage: ["master"],
|
||||||
|
keys: {
|
||||||
|
[`ed25519:${masterKey}`]: masterKey,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
deviceForId: (_userId, deviceId, _hsApi, _log) => {
|
||||||
|
return {
|
||||||
|
device_id: deviceId,
|
||||||
|
keys: {
|
||||||
|
[`ed25519:${deviceId}`]: "D8w9mrokGdEZPdPgrU0kQkYi4vZyzKEBfvGyZsGK7+Q",
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -177,6 +186,7 @@ export function tests() {
|
|||||||
channel,
|
channel,
|
||||||
clock,
|
clock,
|
||||||
hsApi,
|
hsApi,
|
||||||
|
// @ts-ignore
|
||||||
deviceTracker,
|
deviceTracker,
|
||||||
e2eeAccount,
|
e2eeAccount,
|
||||||
olm,
|
olm,
|
||||||
|
@ -211,13 +211,13 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
this.otherUserDeviceId = fromDevice;
|
this.otherUserDeviceId = fromDevice;
|
||||||
// We need to send cancel messages to all other devices
|
// We need to send cancel messages to all other devices
|
||||||
const devices = await this.deviceTracker.devicesForUsers([this.otherUserId], this.hsApi, log);
|
const devices = await this.deviceTracker.devicesForUsers([this.otherUserId], this.hsApi, log);
|
||||||
const otherDevices = devices.filter(device => device.deviceId !== fromDevice && device.deviceId !== this.ourDeviceId);
|
const otherDevices = devices.filter(device => device.device_id !== fromDevice && device.device_id !== this.ourDeviceId);
|
||||||
const cancelMessage = {
|
const cancelMessage = {
|
||||||
code: CancelReason.OtherDeviceAccepted,
|
code: CancelReason.OtherDeviceAccepted,
|
||||||
reason: messageFromErrorType[CancelReason.OtherDeviceAccepted],
|
reason: messageFromErrorType[CancelReason.OtherDeviceAccepted],
|
||||||
transaction_id: this.id,
|
transaction_id: this.id,
|
||||||
};
|
};
|
||||||
const deviceMessages = otherDevices.reduce((acc, device) => { acc[device.deviceId] = cancelMessage; return acc; }, {});
|
const deviceMessages = otherDevices.reduce((acc, device) => { acc[device.device_id] = cancelMessage; return acc; }, {});
|
||||||
const payload = {
|
const payload = {
|
||||||
messages: {
|
messages: {
|
||||||
[this.otherUserId]: deviceMessages
|
[this.otherUserId]: deviceMessages
|
||||||
|
@ -3,6 +3,8 @@ import {createCalculateMAC} from "../mac";
|
|||||||
import {VerificationCancelledError} from "../VerificationCancelledError";
|
import {VerificationCancelledError} from "../VerificationCancelledError";
|
||||||
import {IChannel} from "./Channel";
|
import {IChannel} from "./Channel";
|
||||||
import {CancelReason, VerificationEventType} from "./types";
|
import {CancelReason, VerificationEventType} from "./types";
|
||||||
|
import {getKeyEd25519Key} from "../../CrossSigning";
|
||||||
|
import {getDeviceEd25519Key} from "../../../e2ee/common";
|
||||||
import anotherjson from "another-json";
|
import anotherjson from "another-json";
|
||||||
|
|
||||||
interface ITestChannel extends IChannel {
|
interface ITestChannel extends IChannel {
|
||||||
@ -96,10 +98,11 @@ export class MockChannel implements ITestChannel {
|
|||||||
const deviceId = keyId.split(":", 2)[1];
|
const deviceId = keyId.split(":", 2)[1];
|
||||||
const device = await this.deviceTracker.deviceForId(this.otherUserDeviceId, deviceId);
|
const device = await this.deviceTracker.deviceForId(this.otherUserDeviceId, deviceId);
|
||||||
if (device) {
|
if (device) {
|
||||||
macContent.mac[keyId] = calculateMac(device.ed25519Key, baseInfo + keyId);
|
macContent.mac[keyId] = calculateMac(getDeviceEd25519Key(device), baseInfo + keyId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const {masterKey} = await this.deviceTracker.getCrossSigningKeysForUser(this.otherUserId);
|
const key = await this.deviceTracker.getCrossSigningKeyForUser(this.otherUserId);
|
||||||
|
const masterKey = getKeyEd25519Key(key)!;
|
||||||
macContent.mac[keyId] = calculateMac(masterKey, baseInfo + keyId);
|
macContent.mac[keyId] = calculateMac(masterKey, baseInfo + keyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +115,6 @@ export class MockChannel implements ITestChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async cancelVerification(_: CancelReason): Promise<void> {
|
async cancelVerification(_: CancelReason): Promise<void> {
|
||||||
console.log("MockChannel.cancelVerification()");
|
|
||||||
this.isCancelled = true;
|
this.isCancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import {ILogItem} from "../../../../logging/types";
|
|||||||
import {VerificationEventType} from "../channel/types";
|
import {VerificationEventType} from "../channel/types";
|
||||||
import {createCalculateMAC} from "../mac";
|
import {createCalculateMAC} from "../mac";
|
||||||
import {VerifyMacStage} from "./VerifyMacStage";
|
import {VerifyMacStage} from "./VerifyMacStage";
|
||||||
|
import {getKeyEd25519Key, KeyUsage} from "../../CrossSigning";
|
||||||
|
|
||||||
export class SendMacStage extends BaseSASVerificationStage {
|
export class SendMacStage extends BaseSASVerificationStage {
|
||||||
async completeStage() {
|
async completeStage() {
|
||||||
@ -47,7 +48,12 @@ export class SendMacStage extends BaseSASVerificationStage {
|
|||||||
mac[deviceKeyId] = calculateMAC(deviceKeys.keys[deviceKeyId], baseInfo + deviceKeyId);
|
mac[deviceKeyId] = calculateMAC(deviceKeys.keys[deviceKeyId], baseInfo + deviceKeyId);
|
||||||
keyList.push(deviceKeyId);
|
keyList.push(deviceKeyId);
|
||||||
|
|
||||||
const {masterKey: crossSigningKey} = await this.deviceTracker.getCrossSigningKeysForUser(this.ourUserId, this.hsApi, log);
|
const key = await this.deviceTracker.getCrossSigningKeyForUser(this.ourUserId, KeyUsage.Master, this.hsApi, log);
|
||||||
|
if (!key) {
|
||||||
|
log.log({ l: "Fetching msk failed", userId: this.ourUserId });
|
||||||
|
throw new Error("Fetching MSK for user failed!");
|
||||||
|
}
|
||||||
|
const crossSigningKey = getKeyEd25519Key(key);
|
||||||
if (crossSigningKey) {
|
if (crossSigningKey) {
|
||||||
const crossSigningKeyId = `ed25519:${crossSigningKey}`;
|
const crossSigningKeyId = `ed25519:${crossSigningKey}`;
|
||||||
mac[crossSigningKeyId] = calculateMAC(crossSigningKey, baseInfo + crossSigningKeyId);
|
mac[crossSigningKeyId] = calculateMAC(crossSigningKey, baseInfo + crossSigningKeyId);
|
||||||
|
@ -18,6 +18,8 @@ import {ILogItem} from "../../../../logging/types";
|
|||||||
import {CancelReason, VerificationEventType} 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";
|
||||||
|
import {KeyUsage, getKeyEd25519Key} from "../../CrossSigning";
|
||||||
|
import {getDeviceEd25519Key} from "../../../e2ee/common";
|
||||||
|
|
||||||
export type KeyVerifier = (keyId: string, device: any, keyInfo: string) => void;
|
export type KeyVerifier = (keyId: string, device: any, keyInfo: string) => void;
|
||||||
|
|
||||||
@ -66,11 +68,16 @@ export class VerifyMacStage extends BaseSASVerificationStage {
|
|||||||
const deviceIdOrMSK = keyId.split(":", 2)[1];
|
const deviceIdOrMSK = keyId.split(":", 2)[1];
|
||||||
const device = await this.deviceTracker.deviceForId(userId, deviceIdOrMSK, this.hsApi, log);
|
const device = await this.deviceTracker.deviceForId(userId, deviceIdOrMSK, this.hsApi, log);
|
||||||
if (device) {
|
if (device) {
|
||||||
verifier(keyId, device.ed25519Key, keyInfo);
|
verifier(keyId, getDeviceEd25519Key(device), keyInfo);
|
||||||
// todo: mark device as verified here
|
// todo: mark device as verified here
|
||||||
} else {
|
} else {
|
||||||
// If we were not able to find the device, then deviceIdOrMSK is actually the MSK!
|
// If we were not able to find the device, then deviceIdOrMSK is actually the MSK!
|
||||||
const {masterKey} = await this.deviceTracker.getCrossSigningKeysForUser(userId, this.hsApi, log);
|
const key = await this.deviceTracker.getCrossSigningKeyForUser(userId, KeyUsage.Master, this.hsApi, log);
|
||||||
|
if (!key) {
|
||||||
|
log.log({ l: "Fetching msk failed", userId });
|
||||||
|
throw new Error("Fetching MSK for user failed!");
|
||||||
|
}
|
||||||
|
const masterKey = getKeyEd25519Key(key);
|
||||||
verifier(keyId, masterKey, keyInfo);
|
verifier(keyId, masterKey, keyInfo);
|
||||||
// todo: mark user as verified here
|
// todo: mark user as verified here
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user