1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Don't require .done event for finishing self-verification

Instead, call onVerifierFinished from the verifier on the request
so we can internally mark it as done. This flag is not persisted,
but we don't have historical (persisted) to-device requests anyway.
This commit is contained in:
Bruno Windels
2020-02-28 14:56:38 +01:00
parent ce6dd8688c
commit ecaf21ceb0
3 changed files with 30 additions and 14 deletions

View File

@@ -186,10 +186,7 @@ export class VerificationBase extends EventEmitter {
done() { done() {
this._endTimer(); // always kill the activity timer this._endTimer(); // always kill the activity timer
if (!this._done) { if (!this._done) {
if (this._channel.needsDoneMessage) { this.request.onVerifierFinished();
// verification in DM requires a done message
this._send("m.key.verification.done", {});
}
this._resolve(); this._resolve();
} }
} }

View File

@@ -62,7 +62,7 @@ export class ToDeviceChannel {
} }
get needsDoneMessage() { get needsDoneMessage() {
return true; return false;
} }
static getEventType(event) { static getEventType(event) {

View File

@@ -73,6 +73,7 @@ export class VerificationRequest extends EventEmitter {
this._sharedSecret = null; // used for QR codes this._sharedSecret = null; // used for QR codes
this._accepting = false; this._accepting = false;
this._declining = false; this._declining = false;
this._verifierHasFinished = false;
} }
/** /**
@@ -505,7 +506,7 @@ export class VerificationRequest extends EventEmitter {
} }
const ourDoneEvent = this._eventsByUs.get(DONE_TYPE); const ourDoneEvent = this._eventsByUs.get(DONE_TYPE);
if (ourDoneEvent && phase() === PHASE_STARTED) { if (this._verifierHasFinished || (ourDoneEvent && phase() === PHASE_STARTED)) {
transitions.push({phase: PHASE_DONE}); transitions.push({phase: PHASE_DONE});
} }
@@ -553,6 +554,18 @@ export class VerificationRequest extends EventEmitter {
} }
} }
_applyPhaseTransitions() {
const transitions = this._calculatePhaseTransitions();
const existingIdx = transitions.findIndex(t => t.phase === this.phase);
// trim off phases we already went through, if any
const newTransitions = transitions.slice(existingIdx + 1);
// transition to all new phases
for (const transition of newTransitions) {
this._transitionToPhase(transition);
}
return newTransitions;
}
/** /**
* Changes the state of the request and verifier in response to a key verification event. * Changes the state of the request and verifier in response to a key verification event.
* @param {string} type the "symbolic" event type, as returned by the `getEventType` function on the channel. * @param {string} type the "symbolic" event type, as returned by the `getEventType` function on the channel.
@@ -581,14 +594,8 @@ export class VerificationRequest extends EventEmitter {
const oldPhase = this.phase; const oldPhase = this.phase;
this._addEvent(type, event, isSentByUs); this._addEvent(type, event, isSentByUs);
const transitions = this._calculatePhaseTransitions(); // this will create if needed the verifier so needs to happen before calling it
const existingIdx = transitions.findIndex(t => t.phase === this.phase); const newTransitions = this._applyPhaseTransitions();
// trim off phases we already went through, if any
const newTransitions = transitions.slice(existingIdx + 1);
// transition to all new phases
for (const transition of newTransitions) {
this._transitionToPhase(transition);
}
try { try {
// only pass events from the other side to the verifier, // only pass events from the other side to the verifier,
// no remote echos of our own events // no remote echos of our own events
@@ -752,4 +759,16 @@ export class VerificationRequest extends EventEmitter {
} }
return true; return true;
} }
onVerifierFinished() {
if (this.channel.needsDoneMessage) {
// verification in DM requires a done message
this.channel.send("m.key.verification.done", {});
}
this._verifierHasFinished = true;
const newTransitions = this._applyPhaseTransitions();
if (newTransitions.length) {
this._setPhase(newTransitions[newTransitions.length - 1].phase);
}
}
} }