Skip to content

Use server name instead of homeserver url to allow well-known lookups during QR OIDC reciprocation #4233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/" }),
Expand Down Expand Up @@ -158,18 +156,18 @@ describe("MSC4108SignInWithQR", () => {

const ourChannel = new MSC4108SecureChannel(ourMockSession);
const qrCodeData = QrCodeData.from_bytes(
await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getHomeserverUrl()),
await ourChannel.generateCode(QrCodeMode.Reciprocate, client.getDomain()!),
);
const opponentChannel = new MSC4108SecureChannel(opponentMockSession, qrCodeData.public_key);

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({ homeserverBaseUrl: client.getDomain() }),
]);

expect(ourLogin.checkCode).toBe(opponentLogin.checkCode);
Expand Down
4 changes: 2 additions & 2 deletions src/rendezvous/MSC4108SignInWithQR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ export class MSC4108SignInWithQR {
await this.send<ProtocolsPayload>({
type: PayloadType.Protocols,
protocols: ["device_authorization_grant"],
homeserver: this.client?.getHomeserverUrl() ?? "",
homeserver: this.client?.getDomain() ?? "",
});
} else {
await this.send<FailurePayload>({
Expand Down
8 changes: 4 additions & 4 deletions src/rendezvous/channels/MSC4108SecureChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array>;
public async generateCode(mode: QrCodeMode.Reciprocate, homeserverBaseUrl: string): Promise<Uint8Array>;
public async generateCode(mode: QrCodeMode, homeserverBaseUrl?: string): Promise<Uint8Array> {
public async generateCode(mode: QrCodeMode.Reciprocate, serverName: string): Promise<Uint8Array>;
public async generateCode(mode: QrCodeMode, serverName?: string): Promise<Uint8Array> {
const { url } = this.rendezvousSession;

if (!url) {
Expand All @@ -68,7 +68,7 @@ export class MSC4108SecureChannel {
return new QrCodeData(
this.secureChannel.public_key(),
url,
mode === QrCodeMode.Reciprocate ? homeserverBaseUrl : undefined,
mode === QrCodeMode.Reciprocate ? serverName : undefined,
).to_bytes();
}

Expand Down
Loading