Sign the actual device/user

This commit is contained in:
RMidhunSuresh 2023-06-09 16:06:31 +05:30
parent 960c701454
commit f56cfba906
2 changed files with 13 additions and 6 deletions

View File

@ -40,20 +40,20 @@ export class DeviceVerificationViewModel extends ErrorReportViewModel<SegmentTyp
constructor(options: Readonly<Options>) {
super(options);
this.init(options);
this.start(options);
}
private async init(options: Options): Promise<void> {
private async start(options: Options): Promise<void> {
const room = options.room;
let requestOrUserId: SASRequest | string;
requestOrUserId =
options.request ??
options.userId ??
this.getOption("session").userId;
await this.start(requestOrUserId, room);
await this.startVerification(requestOrUserId, room);
}
private async start(requestOrUserId: SASRequest | string, room?: Room) {
private async startVerification(requestOrUserId: SASRequest | string, room?: Room) {
await this.logAndCatch("DeviceVerificationViewModel.start", (log) => {
const crossSigning = this.getOption("session").crossSigning.get();
this.sas = crossSigning.startVerification(requestOrUserId, room, log);
@ -64,7 +64,12 @@ export class DeviceVerificationViewModel extends ErrorReportViewModel<SegmentTyp
if (typeof requestOrUserId === "string") {
this.updateCurrentStageViewModel(new WaitingForOtherUserViewModel(this.childOptions({ sas: this.sas })));
}
return this.sas.verify();
if (this.sas.isCrossSigningAnotherUser) {
return crossSigning.signUser(this.sas, log);
}
else {
return crossSigning.signDevice(this.sas, log);
}
});
}

View File

@ -84,6 +84,7 @@ enum MSKVerification {
export interface IVerificationMethod {
verify(): Promise<boolean>;
otherDeviceId: string;
otherUserId: string;
}
export class CrossSigning {
@ -295,8 +296,9 @@ export class CrossSigning {
}
/** @return the signed MSK for the given user id */
async signUser(userId: string, verification: IVerificationMethod, log: ILogItem): Promise<CrossSigningKey | undefined> {
async signUser(verification: IVerificationMethod, log: ILogItem): Promise<CrossSigningKey | undefined> {
return log.wrap("CrossSigning.signUser", async log => {
const userId = verification.otherUserId;
log.set("id", userId);
if (!this._isMasterKeyTrusted) {
log.set("mskNotTrusted", true);