Skip to content

Commit 3639083

Browse files
committed
Support for MSC3906 v2
1 parent 585ce07 commit 3639083

8 files changed

+851
-56
lines changed

spec/unit/rendezvous/rendezvousv1.spec.ts

+652
Large diffs are not rendered by default.

spec/unit/rendezvous/rendezvous.spec.ts renamed to spec/unit/rendezvous/rendezvousv2.spec.ts

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Matrix.org Foundation C.I.C.
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -17,7 +17,13 @@ limitations under the License.
1717
import MockHttpBackend from "matrix-mock-request";
1818

1919
import "../../olm-loader";
20-
import { MSC3906Rendezvous, RendezvousCode, RendezvousFailureReason, RendezvousIntent } from "../../../src/rendezvous";
20+
import {
21+
MSC3906Rendezvous,
22+
RendezvousCode,
23+
RendezvousFailureReason,
24+
RendezvousIntent,
25+
SETUP_ADDITIONAL_DEVICE_FLOW_V2,
26+
} from "../../../src/rendezvous";
2127
import {
2228
ECDHv2RendezvousCode as ECDHRendezvousCode,
2329
MSC3903ECDHPayload,
@@ -86,7 +92,7 @@ function makeTransport(name: string, uri = "https://test.rz/123456") {
8692
return new DummyTransport<any, MSC3903ECDHPayload>(name, { type: "http.v1", uri });
8793
}
8894

89-
describe("Rendezvous", function () {
95+
describe("RendezvousV2", function () {
9096
beforeAll(async function () {
9197
await global.Olm.init();
9298
});
@@ -143,6 +149,7 @@ describe("Rendezvous", function () {
143149
const code = JSON.parse(aliceRz.code!) as RendezvousCode;
144150

145151
expect(code.intent).toEqual(RendezvousIntent.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE);
152+
expect(code.flow).toEqual(SETUP_ADDITIONAL_DEVICE_FLOW_V2.name);
146153
expect(code.rendezvous?.algorithm).toEqual("org.matrix.msc3903.rendezvous.v2.curve25519-aes-sha256");
147154
expect(code.rendezvous?.transport.type).toEqual("org.matrix.msc3886.http.v1");
148155
expect((code.rendezvous?.transport as MSC3886SimpleHttpRendezvousTransportDetails).uri).toEqual(
@@ -201,8 +208,7 @@ describe("Rendezvous", function () {
201208

202209
const bobStartPromise = (async () => {
203210
const bobChecksum = await bobEcdh.connect();
204-
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
205-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
211+
logger.info(`Bob checksums is ${bobChecksum}`);
206212

207213
// wait for protocols
208214
logger.info("Bob waiting for protocols");
@@ -211,16 +217,16 @@ describe("Rendezvous", function () {
211217
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
212218

213219
expect(protocols).toEqual({
214-
type: "m.login.finish",
215-
outcome: "unsupported",
220+
type: "m.login.failure",
221+
reason: "unsupported",
216222
});
217223
})();
218224

219225
await aliceStartProm;
220226
await bobStartPromise;
221227
});
222228

223-
it("new device declines protocol with outcome unsupported", async function () {
229+
it("new device declines protocol with reason unsupported", async function () {
224230
const aliceTransport = makeTransport("Alice", "https://test.rz/123456");
225231
const bobTransport = makeTransport("Bob", "https://test.rz/999999");
226232
transports.push(aliceTransport, bobTransport);
@@ -256,7 +262,6 @@ describe("Rendezvous", function () {
256262
const bobStartPromise = (async () => {
257263
const bobChecksum = await bobEcdh.connect();
258264
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
259-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
260265

261266
// wait for protocols
262267
logger.info("Bob waiting for protocols");
@@ -265,11 +270,11 @@ describe("Rendezvous", function () {
265270
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
266271

267272
expect(protocols).toEqual({
268-
type: "m.login.progress",
273+
type: "m.login.protocols",
269274
protocols: ["org.matrix.msc3906.login_token"],
270275
});
271276

272-
await bobEcdh.send({ type: "m.login.finish", outcome: "unsupported" });
277+
await bobEcdh.send({ type: "m.login.failure", reason: "unsupported" });
273278
})();
274279

275280
await aliceStartProm;
@@ -313,8 +318,7 @@ describe("Rendezvous", function () {
313318

314319
const bobStartPromise = (async () => {
315320
const bobChecksum = await bobEcdh.connect();
316-
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
317-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
321+
logger.info(`Bob checksums is ${bobChecksum}`);
318322

319323
// wait for protocols
320324
logger.info("Bob waiting for protocols");
@@ -323,11 +327,11 @@ describe("Rendezvous", function () {
323327
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
324328

325329
expect(protocols).toEqual({
326-
type: "m.login.progress",
330+
type: "m.login.protocols",
327331
protocols: ["org.matrix.msc3906.login_token"],
328332
});
329333

330-
await bobEcdh.send({ type: "m.login.progress", protocol: "bad protocol" });
334+
await bobEcdh.send({ type: "m.login.protocol", protocol: "bad protocol" });
331335
})();
332336

333337
await aliceStartProm;
@@ -371,8 +375,7 @@ describe("Rendezvous", function () {
371375

372376
const bobStartPromise = (async () => {
373377
const bobChecksum = await bobEcdh.connect();
374-
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
375-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
378+
logger.info(`Bob checksums is ${bobChecksum}`);
376379

377380
// wait for protocols
378381
logger.info("Bob waiting for protocols");
@@ -381,19 +384,19 @@ describe("Rendezvous", function () {
381384
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
382385

383386
expect(protocols).toEqual({
384-
type: "m.login.progress",
387+
type: "m.login.protocols",
385388
protocols: ["org.matrix.msc3906.login_token"],
386389
});
387390

388-
await bobEcdh.send({ type: "m.login.progress", protocol: "org.matrix.msc3906.login_token" });
391+
await bobEcdh.send({ type: "m.login.protocol", protocol: "org.matrix.msc3906.login_token" });
389392
})();
390393

391394
await aliceStartProm;
392395
await bobStartPromise;
393396

394397
await aliceRz.declineLoginOnExistingDevice();
395398
const loginToken = await bobEcdh.receive();
396-
expect(loginToken).toEqual({ type: "m.login.finish", outcome: "declined" });
399+
expect(loginToken).toEqual({ type: "m.login.declined" });
397400
});
398401

399402
it("approve on existing device + no verification", async function () {
@@ -431,8 +434,7 @@ describe("Rendezvous", function () {
431434

432435
const bobStartPromise = (async () => {
433436
const bobChecksum = await bobEcdh.connect();
434-
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
435-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
437+
logger.info(`Bob checksums is ${bobChecksum}`);
436438

437439
// wait for protocols
438440
logger.info("Bob waiting for protocols");
@@ -441,11 +443,11 @@ describe("Rendezvous", function () {
441443
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
442444

443445
expect(protocols).toEqual({
444-
type: "m.login.progress",
446+
type: "m.login.protocols",
445447
protocols: ["org.matrix.msc3906.login_token"],
446448
});
447449

448-
await bobEcdh.send({ type: "m.login.progress", protocol: "org.matrix.msc3906.login_token" });
450+
await bobEcdh.send({ type: "m.login.protocol", protocol: "org.matrix.msc3906.login_token" });
449451
})();
450452

451453
await aliceStartProm;
@@ -455,8 +457,8 @@ describe("Rendezvous", function () {
455457

456458
const bobCompleteProm = (async () => {
457459
const loginToken = await bobEcdh.receive();
458-
expect(loginToken).toEqual({ type: "m.login.progress", login_token: "token", homeserver: alice.baseUrl });
459-
await bobEcdh.send({ type: "m.login.finish", outcome: "success" });
460+
expect(loginToken).toEqual({ type: "m.login.approved", login_token: "token", homeserver: alice.baseUrl });
461+
await bobEcdh.send({ type: "m.login.success" });
460462
})();
461463

462464
await confirmProm;
@@ -505,8 +507,7 @@ describe("Rendezvous", function () {
505507

506508
const bobStartPromise = (async () => {
507509
const bobChecksum = await bobEcdh.connect();
508-
logger.info(`Bob checksums is ${bobChecksum} now sending intent`);
509-
// await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
510+
logger.info(`Bob checksums is ${bobChecksum}`);
510511

511512
// wait for protocols
512513
logger.info("Bob waiting for protocols");
@@ -515,11 +516,11 @@ describe("Rendezvous", function () {
515516
logger.info(`Bob protocols: ${JSON.stringify(protocols)}`);
516517

517518
expect(protocols).toEqual({
518-
type: "m.login.progress",
519+
type: "m.login.protocols",
519520
protocols: ["org.matrix.msc3906.login_token"],
520521
});
521522

522-
await bobEcdh.send({ type: "m.login.progress", protocol: "org.matrix.msc3906.login_token" });
523+
await bobEcdh.send({ type: "m.login.protocol", protocol: "org.matrix.msc3906.login_token" });
523524
})();
524525

525526
await aliceStartProm;
@@ -529,8 +530,8 @@ describe("Rendezvous", function () {
529530

530531
const bobLoginProm = (async () => {
531532
const loginToken = await bobEcdh.receive();
532-
expect(loginToken).toEqual({ type: "m.login.progress", login_token: "token", homeserver: alice.baseUrl });
533-
await bobEcdh.send({ type: "m.login.finish", outcome: "success", device_id: "BOB", device_key: "bbbb" });
533+
expect(loginToken).toEqual({ type: "m.login.approved", login_token: "token", homeserver: alice.baseUrl });
534+
await bobEcdh.send({ type: "m.login.success", device_id: "BOB", device_key: "bbbb" });
534535
})();
535536

536537
expect(await confirmProm).toEqual("BOB");
@@ -556,8 +557,7 @@ describe("Rendezvous", function () {
556557
const bobVerifyProm = (async () => {
557558
const verified = await bobEcdh.receive();
558559
expect(verified).toEqual({
559-
type: "m.login.finish",
560-
outcome: "verified",
560+
type: "m.login.verified",
561561
verifying_device_id: "ALICE",
562562
verifying_device_key: "aaaa",
563563
master_key: "mmmmm",

0 commit comments

Comments
 (0)