diff --git a/package.json b/package.json index d31db3600e9..360c4df7042 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ ], "dependencies": { "@babel/runtime": "^7.12.5", - "@matrix-org/matrix-sdk-crypto-wasm": "^5.0.0", + "@matrix-org/matrix-sdk-crypto-wasm": "^6.0.0", "another-json": "^0.2.0", "bs58": "^5.0.0", "content-type": "^1.0.4", diff --git a/spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts b/spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts index ef9ed201615..4910759ea4e 100644 --- a/spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts +++ b/spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts @@ -54,9 +54,7 @@ function makeMockClient(opts: { userId: string; deviceId: string; msc4108Enabled return opts.deviceId; }, baseUrl, - getHomeserverUrl() { - return baseUrl; - }, + getDomain: () => "example.com", getDevice: jest.fn(), getCrypto: jest.fn(() => crypto), getAuthIssuer: jest.fn().mockResolvedValue({ issuer: "https://issuer/" }), @@ -157,19 +155,19 @@ describe("MSC4108SignInWithQR", () => { client = makeMockClient({ userId: "@alice:example.com", deviceId: "alice", msc4108Enabled: true }); const ourChannel = new MSC4108SecureChannel(ourMockSession); - const qrCodeData = QrCodeData.from_bytes( - await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getHomeserverUrl()), + const qrCodeData = QrCodeData.fromBytes( + await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getDomain()!), ); - const opponentChannel = new MSC4108SecureChannel(opponentMockSession, qrCodeData.public_key); + const opponentChannel = new MSC4108SecureChannel(opponentMockSession, qrCodeData.publicKey); ourLogin = new MSC4108SignInWithQR(ourChannel, true, client); opponentLogin = new MSC4108SignInWithQR(opponentChannel, false); }); - it("should be able to connect with opponent and share homeserver url & check code", async () => { + it("should be able to connect with opponent and share server name & check code", async () => { await Promise.all([ expect(ourLogin.negotiateProtocols()).resolves.toEqual({}), - expect(opponentLogin.negotiateProtocols()).resolves.toEqual({ homeserverBaseUrl: client.baseUrl }), + expect(opponentLogin.negotiateProtocols()).resolves.toEqual({ serverName: client.getDomain() }), ]); expect(ourLogin.checkCode).toBe(opponentLogin.checkCode); diff --git a/spec/unit/rendezvous/channels/MSC4108SecureChannel.spec.ts b/spec/unit/rendezvous/channels/MSC4108SecureChannel.spec.ts index 6daae603491..bc357d9ac90 100644 --- a/spec/unit/rendezvous/channels/MSC4108SecureChannel.spec.ts +++ b/spec/unit/rendezvous/channels/MSC4108SecureChannel.spec.ts @@ -44,9 +44,9 @@ describe("MSC4108SecureChannel", () => { } as unknown as MSC4108RendezvousSession; const channel = new MSC4108SecureChannel(mockSession); - const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); + const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); const { initial_message: ciphertext } = new Ecies().establish_outbound_channel( - qrCodeData.public_key, + qrCodeData.publicKey, "MATRIX_QR_CODE_LOGIN_INITIATE", ); mocked(mockSession.receive).mockResolvedValue(ciphertext); @@ -65,9 +65,9 @@ describe("MSC4108SecureChannel", () => { mocked(mockSession.receive).mockResolvedValue(""); await expect(channel.connect()).rejects.toThrow("No response from other device"); - const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); + const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); const { initial_message: ciphertext } = new Ecies().establish_outbound_channel( - qrCodeData.public_key, + qrCodeData.publicKey, "NOT_REAL_MATRIX_QR_CODE_LOGIN_INITIATE", ); @@ -88,9 +88,9 @@ describe("MSC4108SecureChannel", () => { } as unknown as MSC4108RendezvousSession; channel = new MSC4108SecureChannel(mockSession); - const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); + const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl)); const { channel: _opponentChannel, initial_message: ciphertext } = new Ecies().establish_outbound_channel( - qrCodeData.public_key, + qrCodeData.publicKey, "MATRIX_QR_CODE_LOGIN_INITIATE", ); opponentChannel = _opponentChannel; diff --git a/src/@types/matrix-sdk-crypto-wasm.d.ts b/src/@types/matrix-sdk-crypto-wasm.d.ts index 591ecd6406d..c7504a3484d 100644 --- a/src/@types/matrix-sdk-crypto-wasm.d.ts +++ b/src/@types/matrix-sdk-crypto-wasm.d.ts @@ -37,4 +37,8 @@ declare module "@matrix-org/matrix-sdk-crypto-wasm" { }; }>; } + + interface Device { + requestVerification(methods?: any[]): [RustSdkCryptoJs.VerificationRequest, RustSdkCryptoJs.ToDeviceRequest]; + } } diff --git a/src/rendezvous/MSC4108SignInWithQR.ts b/src/rendezvous/MSC4108SignInWithQR.ts index 275d44bd8a4..827d5d08867 100644 --- a/src/rendezvous/MSC4108SignInWithQR.ts +++ b/src/rendezvous/MSC4108SignInWithQR.ts @@ -145,7 +145,7 @@ export class MSC4108SignInWithQR { } if (this.ourIntent === QrCodeMode.Reciprocate && this.client) { - this._code = await this.channel.generateCode(this.ourIntent, this.client.getHomeserverUrl()); + this._code = await this.channel.generateCode(this.ourIntent, this.client.getDomain()!); } else if (this.ourIntent === QrCodeMode.Login) { this._code = await this.channel.generateCode(this.ourIntent); } @@ -171,7 +171,7 @@ export class MSC4108SignInWithQR { * The scanning device has to discover the homeserver details, if they scanned the code then they already have it. * If the new device is the one rendering the QR code then it has to wait be sent the homeserver details via the rendezvous channel. */ - public async negotiateProtocols(): Promise<{ homeserverBaseUrl?: string }> { + public async negotiateProtocols(): Promise<{ serverName?: string }> { logger.info(`negotiateProtocols(isNewDevice=${this.isNewDevice} didScanCode=${this.didScanCode})`); await this.channel.connect(); @@ -194,7 +194,7 @@ export class MSC4108SignInWithQR { await this.send({ type: PayloadType.Protocols, protocols: ["device_authorization_grant"], - homeserver: this.client?.getHomeserverUrl() ?? "", + homeserver: this.client!.getDomain()!, }); } else { await this.send({ @@ -227,7 +227,7 @@ export class MSC4108SignInWithQR { ); } - return { homeserverBaseUrl: payload.homeserver }; + return { serverName: payload.homeserver }; } else { // MSC4108-Flow: NewScanned - nothing to do } diff --git a/src/rendezvous/channels/MSC4108SecureChannel.ts b/src/rendezvous/channels/MSC4108SecureChannel.ts index 8db12ebd2cd..717b5441705 100644 --- a/src/rendezvous/channels/MSC4108SecureChannel.ts +++ b/src/rendezvous/channels/MSC4108SecureChannel.ts @@ -54,11 +54,11 @@ export class MSC4108SecureChannel { /** * Generate a QR code for the current session. * @param mode the mode to generate the QR code in, either `Login` or `Reciprocate`. - * @param homeserverBaseUrl the base URL of the homeserver to connect to, required for `Reciprocate` mode. + * @param serverName the name of the homeserver to connect to, as defined by server discovery in the spec, required for `Reciprocate` mode. */ public async generateCode(mode: QrCodeMode.Login): Promise; - public async generateCode(mode: QrCodeMode.Reciprocate, homeserverBaseUrl: string): Promise; - public async generateCode(mode: QrCodeMode, homeserverBaseUrl?: string): Promise { + public async generateCode(mode: QrCodeMode.Reciprocate, serverName: string): Promise; + public async generateCode(mode: QrCodeMode, serverName?: string): Promise { const { url } = this.rendezvousSession; if (!url) { @@ -68,8 +68,8 @@ export class MSC4108SecureChannel { return new QrCodeData( this.secureChannel.public_key(), url, - mode === QrCodeMode.Reciprocate ? homeserverBaseUrl : undefined, - ).to_bytes(); + mode === QrCodeMode.Reciprocate ? serverName : undefined, + ).toBytes(); } /** diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index a0a7f8323d4..c5e9bd9044f 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -1100,10 +1100,9 @@ export class RustCrypto extends TypedEventEmitter