Skip to content

Commit 5b5348e

Browse files
authored
Remove abandoned MSC3886, MSC3903, MSC3906 implementations (#28274)
* Remove abandoned MSC3886, MSC3903, MSC3906 implementations Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Remove stale snapshots * Improve coverage Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 6d0d237 commit 5b5348e

File tree

13 files changed

+60
-1373
lines changed

13 files changed

+60
-1373
lines changed

src/components/views/auth/LoginWithQR-types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export enum Phase {
2424
WaitingForDevice,
2525
Verifying,
2626
Error,
27-
/**
28-
* @deprecated the MSC3906 implementation is deprecated in favour of MSC4108.
29-
*/
30-
LegacyConnected,
3127
}
3228

3329
export enum Click {

src/components/views/auth/LoginWithQR.tsx

Lines changed: 20 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ Please see LICENSE files in the repository root for full details.
99
import React from "react";
1010
import {
1111
ClientRendezvousFailureReason,
12-
LegacyRendezvousFailureReason,
13-
MSC3886SimpleHttpRendezvousTransport,
14-
MSC3903ECDHPayload,
15-
MSC3903ECDHv2RendezvousChannel,
16-
MSC3906Rendezvous,
1712
MSC4108FailureReason,
1813
MSC4108RendezvousSession,
1914
MSC4108SecureChannel,
@@ -23,29 +18,21 @@ import {
2318
RendezvousIntent,
2419
} from "matrix-js-sdk/src/rendezvous";
2520
import { logger } from "matrix-js-sdk/src/logger";
26-
import { HTTPError, MatrixClient } from "matrix-js-sdk/src/matrix";
21+
import { MatrixClient } from "matrix-js-sdk/src/matrix";
2722

2823
import { Click, Mode, Phase } from "./LoginWithQR-types";
2924
import LoginWithQRFlow from "./LoginWithQRFlow";
30-
import { wrapRequestWithDialog } from "../../../utils/UserInteractiveAuth";
31-
import { _t } from "../../../languageHandler";
3225

3326
interface IProps {
3427
client: MatrixClient;
3528
mode: Mode;
36-
legacy: boolean;
3729
onFinished(...args: any): void;
3830
}
3931

4032
interface IState {
4133
phase: Phase;
42-
rendezvous?: MSC3906Rendezvous | MSC4108SignInWithQR;
34+
rendezvous?: MSC4108SignInWithQR;
4335
mediaPermissionError?: boolean;
44-
45-
// MSC3906
46-
confirmationDigits?: string;
47-
48-
// MSC4108
4936
verificationUri?: string;
5037
userCode?: string;
5138
checkCode?: string;
@@ -54,25 +41,18 @@ interface IState {
5441
}
5542

5643
export enum LoginWithQRFailureReason {
57-
/**
58-
* @deprecated the MSC3906 implementation is deprecated in favour of MSC4108.
59-
*/
6044
RateLimited = "rate_limited",
6145
CheckCodeMismatch = "check_code_mismatch",
6246
}
6347

6448
export type FailureReason = RendezvousFailureReason | LoginWithQRFailureReason;
6549

66-
// n.b MSC3886/MSC3903/MSC3906 that this is based on are now closed.
67-
// However, we want to keep this implementation around for some time.
68-
// TODO: define an end-of-life date for this implementation.
69-
7050
/**
7151
* A component that allows sign in and E2EE set up with a QR code.
7252
*
7353
* It implements `login.reciprocate` capabilities and showing QR codes.
7454
*
75-
* This uses the unstable feature of MSC3906: https://github.com/matrix-org/matrix-spec-proposals/pull/3906
55+
* This uses the unstable feature of MSC4108: https://github.com/matrix-org/matrix-spec-proposals/pull/4108
7656
*/
7757
export default class LoginWithQR extends React.Component<IProps, IState> {
7858
private finished = false;
@@ -104,9 +84,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
10484
if (this.state.rendezvous) {
10585
const rendezvous = this.state.rendezvous;
10686
rendezvous.onFailure = undefined;
107-
if (rendezvous instanceof MSC3906Rendezvous) {
108-
await rendezvous.cancel(LegacyRendezvousFailureReason.UserCancelled);
109-
}
11087
this.setState({ rendezvous: undefined });
11188
}
11289
if (mode === Mode.Show) {
@@ -119,60 +96,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
11996
// eslint-disable-next-line react/no-direct-mutation-state
12097
this.state.rendezvous.onFailure = undefined;
12198
// calling cancel will call close() as well to clean up the resources
122-
if (this.state.rendezvous instanceof MSC3906Rendezvous) {
123-
this.state.rendezvous.cancel(LegacyRendezvousFailureReason.UserCancelled);
124-
} else {
125-
this.state.rendezvous.cancel(MSC4108FailureReason.UserCancelled);
126-
}
127-
}
128-
}
129-
130-
private async legacyApproveLogin(): Promise<void> {
131-
if (!(this.state.rendezvous instanceof MSC3906Rendezvous)) {
132-
throw new Error("Rendezvous not found");
133-
}
134-
if (!this.props.client) {
135-
throw new Error("No client to approve login with");
136-
}
137-
this.setState({ phase: Phase.Loading });
138-
139-
try {
140-
logger.info("Requesting login token");
141-
142-
const { login_token: loginToken } = await wrapRequestWithDialog(this.props.client.requestLoginToken, {
143-
matrixClient: this.props.client,
144-
title: _t("auth|qr_code_login|sign_in_new_device"),
145-
})();
146-
147-
this.setState({ phase: Phase.WaitingForDevice });
148-
149-
const newDeviceId = await this.state.rendezvous.approveLoginOnExistingDevice(loginToken);
150-
if (!newDeviceId) {
151-
// user denied
152-
return;
153-
}
154-
if (!this.props.client.getCrypto()) {
155-
// no E2EE to set up
156-
this.onFinished(true);
157-
return;
158-
}
159-
this.setState({ phase: Phase.Verifying });
160-
await this.state.rendezvous.verifyNewDeviceOnExistingDevice();
161-
// clean up our state:
162-
try {
163-
await this.state.rendezvous.close();
164-
} finally {
165-
this.setState({ rendezvous: undefined });
166-
}
167-
this.onFinished(true);
168-
} catch (e) {
169-
logger.error("Error whilst approving sign in", e);
170-
if (e instanceof HTTPError && e.httpStatus === 429) {
171-
// 429: rate limit
172-
this.setState({ phase: Phase.Error, failureReason: LoginWithQRFailureReason.RateLimited });
173-
return;
174-
}
175-
this.setState({ phase: Phase.Error, failureReason: ClientRendezvousFailureReason.Unknown });
99+
this.state.rendezvous.cancel(MSC4108FailureReason.UserCancelled);
176100
}
177101
}
178102

@@ -182,28 +106,18 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
182106
}
183107

184108
private generateAndShowCode = async (): Promise<void> => {
185-
let rendezvous: MSC4108SignInWithQR | MSC3906Rendezvous;
109+
let rendezvous: MSC4108SignInWithQR;
186110
try {
187111
const fallbackRzServer = this.props.client?.getClientWellKnown()?.["io.element.rendezvous"]?.server;
188112

189-
if (this.props.legacy) {
190-
const transport = new MSC3886SimpleHttpRendezvousTransport<MSC3903ECDHPayload>({
191-
onFailure: this.onFailure,
192-
client: this.props.client,
193-
fallbackRzServer,
194-
});
195-
const channel = new MSC3903ECDHv2RendezvousChannel(transport, undefined, this.onFailure);
196-
rendezvous = new MSC3906Rendezvous(channel, this.props.client, this.onFailure);
197-
} else {
198-
const transport = new MSC4108RendezvousSession({
199-
onFailure: this.onFailure,
200-
client: this.props.client,
201-
fallbackRzServer,
202-
});
203-
await transport.send("");
204-
const channel = new MSC4108SecureChannel(transport, undefined, this.onFailure);
205-
rendezvous = new MSC4108SignInWithQR(channel, false, this.props.client, this.onFailure);
206-
}
113+
const transport = new MSC4108RendezvousSession({
114+
onFailure: this.onFailure,
115+
client: this.props.client,
116+
fallbackRzServer,
117+
});
118+
await transport.send("");
119+
const channel = new MSC4108SecureChannel(transport, undefined, this.onFailure);
120+
rendezvous = new MSC4108SignInWithQR(channel, false, this.props.client, this.onFailure);
207121

208122
await rendezvous.generateCode();
209123
this.setState({
@@ -218,10 +132,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
218132
}
219133

220134
try {
221-
if (rendezvous instanceof MSC3906Rendezvous) {
222-
const confirmationDigits = await rendezvous.startAfterShowingCode();
223-
this.setState({ phase: Phase.LegacyConnected, confirmationDigits });
224-
} else if (this.ourIntent === RendezvousIntent.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE) {
135+
if (this.ourIntent === RendezvousIntent.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE) {
225136
// MSC4108-Flow: NewScanned
226137
await rendezvous.negotiateProtocols();
227138
const { verificationUri } = await rendezvous.deviceAuthorizationGrant();
@@ -234,18 +145,9 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
234145
// we ask the user to confirm that the channel is secure
235146
} catch (e: RendezvousError | unknown) {
236147
logger.error("Error whilst approving login", e);
237-
if (rendezvous instanceof MSC3906Rendezvous) {
238-
// only set to error phase if it hasn't already been set by onFailure or similar
239-
if (this.state.phase !== Phase.Error) {
240-
this.setState({ phase: Phase.Error, failureReason: LegacyRendezvousFailureReason.Unknown });
241-
}
242-
} else {
243-
await rendezvous?.cancel(
244-
e instanceof RendezvousError
245-
? (e.code as MSC4108FailureReason)
246-
: ClientRendezvousFailureReason.Unknown,
247-
);
248-
}
148+
await rendezvous?.cancel(
149+
e instanceof RendezvousError ? (e.code as MSC4108FailureReason) : ClientRendezvousFailureReason.Unknown,
150+
);
249151
}
250152
};
251153

@@ -298,7 +200,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
298200
public reset(): void {
299201
this.setState({
300202
rendezvous: undefined,
301-
confirmationDigits: undefined,
302203
verificationUri: undefined,
303204
failureReason: undefined,
304205
userCode: undefined,
@@ -311,28 +212,20 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
311212
private onClick = async (type: Click, checkCode?: string): Promise<void> => {
312213
switch (type) {
313214
case Click.Cancel:
314-
if (this.state.rendezvous instanceof MSC3906Rendezvous) {
315-
await this.state.rendezvous?.cancel(LegacyRendezvousFailureReason.UserCancelled);
316-
} else {
317-
await this.state.rendezvous?.cancel(MSC4108FailureReason.UserCancelled);
318-
}
215+
await this.state.rendezvous?.cancel(MSC4108FailureReason.UserCancelled);
319216
this.reset();
320217
this.onFinished(false);
321218
break;
322219
case Click.Approve:
323-
await (this.props.legacy ? this.legacyApproveLogin() : this.approveLogin(checkCode));
220+
await this.approveLogin(checkCode);
324221
break;
325222
case Click.Decline:
326223
await this.state.rendezvous?.declineLoginOnExistingDevice();
327224
this.reset();
328225
this.onFinished(false);
329226
break;
330227
case Click.Back:
331-
if (this.state.rendezvous instanceof MSC3906Rendezvous) {
332-
await this.state.rendezvous?.cancel(LegacyRendezvousFailureReason.UserCancelled);
333-
} else {
334-
await this.state.rendezvous?.cancel(MSC4108FailureReason.UserCancelled);
335-
}
228+
await this.state.rendezvous?.cancel(MSC4108FailureReason.UserCancelled);
336229
this.onFinished(false);
337230
break;
338231
case Click.ShowQr:
@@ -342,20 +235,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
342235
};
343236

344237
public render(): React.ReactNode {
345-
if (this.state.rendezvous instanceof MSC3906Rendezvous) {
346-
return (
347-
<LoginWithQRFlow
348-
onClick={this.onClick}
349-
phase={this.state.phase}
350-
code={this.state.phase === Phase.ShowingQR ? this.state.rendezvous?.code : undefined}
351-
confirmationDigits={
352-
this.state.phase === Phase.LegacyConnected ? this.state.confirmationDigits : undefined
353-
}
354-
failureReason={this.state.failureReason}
355-
/>
356-
);
357-
}
358-
359238
return (
360239
<LoginWithQRFlow
361240
onClick={this.onClick}

0 commit comments

Comments
 (0)