Skip to content

Commit c55289e

Browse files
authored
Use server name instead of homeserver url to allow well-known lookups during QR OIDC reciprocation (#4233)
* Use server name instead of homeserver url to allow well-known lookups during QR OIDC reciprocation Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 987ec1e commit c55289e

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
],
5454
"dependencies": {
5555
"@babel/runtime": "^7.12.5",
56-
"@matrix-org/matrix-sdk-crypto-wasm": "^5.0.0",
56+
"@matrix-org/matrix-sdk-crypto-wasm": "^6.0.0",
5757
"another-json": "^0.2.0",
5858
"bs58": "^5.0.0",
5959
"content-type": "^1.0.4",

Diff for: spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ function makeMockClient(opts: { userId: string; deviceId: string; msc4108Enabled
5454
return opts.deviceId;
5555
},
5656
baseUrl,
57-
getHomeserverUrl() {
58-
return baseUrl;
59-
},
57+
getDomain: () => "example.com",
6058
getDevice: jest.fn(),
6159
getCrypto: jest.fn(() => crypto),
6260
getAuthIssuer: jest.fn().mockResolvedValue({ issuer: "https://issuer/" }),
@@ -157,19 +155,19 @@ describe("MSC4108SignInWithQR", () => {
157155
client = makeMockClient({ userId: "@alice:example.com", deviceId: "alice", msc4108Enabled: true });
158156

159157
const ourChannel = new MSC4108SecureChannel(ourMockSession);
160-
const qrCodeData = QrCodeData.from_bytes(
161-
await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getHomeserverUrl()),
158+
const qrCodeData = QrCodeData.fromBytes(
159+
await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getDomain()!),
162160
);
163-
const opponentChannel = new MSC4108SecureChannel(opponentMockSession, qrCodeData.public_key);
161+
const opponentChannel = new MSC4108SecureChannel(opponentMockSession, qrCodeData.publicKey);
164162

165163
ourLogin = new MSC4108SignInWithQR(ourChannel, true, client);
166164
opponentLogin = new MSC4108SignInWithQR(opponentChannel, false);
167165
});
168166

169-
it("should be able to connect with opponent and share homeserver url & check code", async () => {
167+
it("should be able to connect with opponent and share server name & check code", async () => {
170168
await Promise.all([
171169
expect(ourLogin.negotiateProtocols()).resolves.toEqual({}),
172-
expect(opponentLogin.negotiateProtocols()).resolves.toEqual({ homeserverBaseUrl: client.baseUrl }),
170+
expect(opponentLogin.negotiateProtocols()).resolves.toEqual({ serverName: client.getDomain() }),
173171
]);
174172

175173
expect(ourLogin.checkCode).toBe(opponentLogin.checkCode);

Diff for: spec/unit/rendezvous/channels/MSC4108SecureChannel.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ describe("MSC4108SecureChannel", () => {
4444
} as unknown as MSC4108RendezvousSession;
4545
const channel = new MSC4108SecureChannel(mockSession);
4646

47-
const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
47+
const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
4848
const { initial_message: ciphertext } = new Ecies().establish_outbound_channel(
49-
qrCodeData.public_key,
49+
qrCodeData.publicKey,
5050
"MATRIX_QR_CODE_LOGIN_INITIATE",
5151
);
5252
mocked(mockSession.receive).mockResolvedValue(ciphertext);
@@ -65,9 +65,9 @@ describe("MSC4108SecureChannel", () => {
6565
mocked(mockSession.receive).mockResolvedValue("");
6666
await expect(channel.connect()).rejects.toThrow("No response from other device");
6767

68-
const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
68+
const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
6969
const { initial_message: ciphertext } = new Ecies().establish_outbound_channel(
70-
qrCodeData.public_key,
70+
qrCodeData.publicKey,
7171
"NOT_REAL_MATRIX_QR_CODE_LOGIN_INITIATE",
7272
);
7373

@@ -88,9 +88,9 @@ describe("MSC4108SecureChannel", () => {
8888
} as unknown as MSC4108RendezvousSession;
8989
channel = new MSC4108SecureChannel(mockSession);
9090

91-
const qrCodeData = QrCodeData.from_bytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
91+
const qrCodeData = QrCodeData.fromBytes(await channel.generateCode(QrCodeMode.Reciprocate, baseUrl));
9292
const { channel: _opponentChannel, initial_message: ciphertext } = new Ecies().establish_outbound_channel(
93-
qrCodeData.public_key,
93+
qrCodeData.publicKey,
9494
"MATRIX_QR_CODE_LOGIN_INITIATE",
9595
);
9696
opponentChannel = _opponentChannel;

Diff for: src/@types/matrix-sdk-crypto-wasm.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ declare module "@matrix-org/matrix-sdk-crypto-wasm" {
3737
};
3838
}>;
3939
}
40+
41+
interface Device {
42+
requestVerification(methods?: any[]): [RustSdkCryptoJs.VerificationRequest, RustSdkCryptoJs.ToDeviceRequest];
43+
}
4044
}

Diff for: src/rendezvous/MSC4108SignInWithQR.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class MSC4108SignInWithQR {
145145
}
146146

147147
if (this.ourIntent === QrCodeMode.Reciprocate && this.client) {
148-
this._code = await this.channel.generateCode(this.ourIntent, this.client.getHomeserverUrl());
148+
this._code = await this.channel.generateCode(this.ourIntent, this.client.getDomain()!);
149149
} else if (this.ourIntent === QrCodeMode.Login) {
150150
this._code = await this.channel.generateCode(this.ourIntent);
151151
}
@@ -171,7 +171,7 @@ export class MSC4108SignInWithQR {
171171
* The scanning device has to discover the homeserver details, if they scanned the code then they already have it.
172172
* 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.
173173
*/
174-
public async negotiateProtocols(): Promise<{ homeserverBaseUrl?: string }> {
174+
public async negotiateProtocols(): Promise<{ serverName?: string }> {
175175
logger.info(`negotiateProtocols(isNewDevice=${this.isNewDevice} didScanCode=${this.didScanCode})`);
176176
await this.channel.connect();
177177

@@ -194,7 +194,7 @@ export class MSC4108SignInWithQR {
194194
await this.send<ProtocolsPayload>({
195195
type: PayloadType.Protocols,
196196
protocols: ["device_authorization_grant"],
197-
homeserver: this.client?.getHomeserverUrl() ?? "",
197+
homeserver: this.client!.getDomain()!,
198198
});
199199
} else {
200200
await this.send<FailurePayload>({
@@ -227,7 +227,7 @@ export class MSC4108SignInWithQR {
227227
);
228228
}
229229

230-
return { homeserverBaseUrl: payload.homeserver };
230+
return { serverName: payload.homeserver };
231231
} else {
232232
// MSC4108-Flow: NewScanned - nothing to do
233233
}

Diff for: src/rendezvous/channels/MSC4108SecureChannel.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export class MSC4108SecureChannel {
5454
/**
5555
* Generate a QR code for the current session.
5656
* @param mode the mode to generate the QR code in, either `Login` or `Reciprocate`.
57-
* @param homeserverBaseUrl the base URL of the homeserver to connect to, required for `Reciprocate` mode.
57+
* @param serverName the name of the homeserver to connect to, as defined by server discovery in the spec, required for `Reciprocate` mode.
5858
*/
5959
public async generateCode(mode: QrCodeMode.Login): Promise<Uint8Array>;
60-
public async generateCode(mode: QrCodeMode.Reciprocate, homeserverBaseUrl: string): Promise<Uint8Array>;
61-
public async generateCode(mode: QrCodeMode, homeserverBaseUrl?: string): Promise<Uint8Array> {
60+
public async generateCode(mode: QrCodeMode.Reciprocate, serverName: string): Promise<Uint8Array>;
61+
public async generateCode(mode: QrCodeMode, serverName?: string): Promise<Uint8Array> {
6262
const { url } = this.rendezvousSession;
6363

6464
if (!url) {
@@ -68,8 +68,8 @@ export class MSC4108SecureChannel {
6868
return new QrCodeData(
6969
this.secureChannel.public_key(),
7070
url,
71-
mode === QrCodeMode.Reciprocate ? homeserverBaseUrl : undefined,
72-
).to_bytes();
71+
mode === QrCodeMode.Reciprocate ? serverName : undefined,
72+
).toBytes();
7373
}
7474

7575
/**

Diff for: src/rust-crypto/rust-crypto.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
11001100
}
11011101

11021102
try {
1103-
const [request, outgoingRequest]: [RustSdkCryptoJs.VerificationRequest, RustSdkCryptoJs.ToDeviceRequest] =
1104-
await device.requestVerification(
1105-
this._supportedVerificationMethods.map(verificationMethodIdentifierToMethod),
1106-
);
1103+
const [request, outgoingRequest] = device.requestVerification(
1104+
this._supportedVerificationMethods.map(verificationMethodIdentifierToMethod),
1105+
);
11071106
await this.outgoingRequestProcessor.makeOutgoingRequest(outgoingRequest);
11081107
return new RustVerificationRequest(
11091108
this.olmMachine,

Diff for: yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1925,10 +1925,10 @@
19251925
"@jridgewell/resolve-uri" "^3.1.0"
19261926
"@jridgewell/sourcemap-codec" "^1.4.14"
19271927

1928-
"@matrix-org/matrix-sdk-crypto-wasm@^5.0.0":
1929-
version "5.0.0"
1930-
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-5.0.0.tgz#f45a7bccaad218c05bcf9e7c8ca783c9d9a07af4"
1931-
integrity sha512-37ASjCKSTU5ycGfkP+LUXG4Ok6OAf6vE+1qU6uwWhe6FwadCS3vVWzJYd/3d9BQFwsx4GhFTIAXrW4iLG85rmQ==
1928+
"@matrix-org/matrix-sdk-crypto-wasm@^6.0.0":
1929+
version "6.0.0"
1930+
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-6.0.0.tgz#5e62ff07ee85a2e1b766a116683b7715a5e70c03"
1931+
integrity sha512-VVXfkIX2qr5Lz8EEUqsv/RBs0hZYoD1TyvtnaaNHW+2WaBo+TXu6Kpz2cQBNvRQbR3GhxDa/ZyQUxZYotORLWg==
19321932

19331933
"@matrix-org/[email protected]":
19341934
version "3.2.15"

0 commit comments

Comments
 (0)