@@ -9,11 +9,6 @@ Please see LICENSE files in the repository root for full details.
9
9
import React from "react" ;
10
10
import {
11
11
ClientRendezvousFailureReason ,
12
- LegacyRendezvousFailureReason ,
13
- MSC3886SimpleHttpRendezvousTransport ,
14
- MSC3903ECDHPayload ,
15
- MSC3903ECDHv2RendezvousChannel ,
16
- MSC3906Rendezvous ,
17
12
MSC4108FailureReason ,
18
13
MSC4108RendezvousSession ,
19
14
MSC4108SecureChannel ,
@@ -23,29 +18,21 @@ import {
23
18
RendezvousIntent ,
24
19
} from "matrix-js-sdk/src/rendezvous" ;
25
20
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" ;
27
22
28
23
import { Click , Mode , Phase } from "./LoginWithQR-types" ;
29
24
import LoginWithQRFlow from "./LoginWithQRFlow" ;
30
- import { wrapRequestWithDialog } from "../../../utils/UserInteractiveAuth" ;
31
- import { _t } from "../../../languageHandler" ;
32
25
33
26
interface IProps {
34
27
client : MatrixClient ;
35
28
mode : Mode ;
36
- legacy : boolean ;
37
29
onFinished ( ...args : any ) : void ;
38
30
}
39
31
40
32
interface IState {
41
33
phase : Phase ;
42
- rendezvous ?: MSC3906Rendezvous | MSC4108SignInWithQR ;
34
+ rendezvous ?: MSC4108SignInWithQR ;
43
35
mediaPermissionError ?: boolean ;
44
-
45
- // MSC3906
46
- confirmationDigits ?: string ;
47
-
48
- // MSC4108
49
36
verificationUri ?: string ;
50
37
userCode ?: string ;
51
38
checkCode ?: string ;
@@ -54,25 +41,18 @@ interface IState {
54
41
}
55
42
56
43
export enum LoginWithQRFailureReason {
57
- /**
58
- * @deprecated the MSC3906 implementation is deprecated in favour of MSC4108.
59
- */
60
44
RateLimited = "rate_limited" ,
61
45
CheckCodeMismatch = "check_code_mismatch" ,
62
46
}
63
47
64
48
export type FailureReason = RendezvousFailureReason | LoginWithQRFailureReason ;
65
49
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
-
70
50
/**
71
51
* A component that allows sign in and E2EE set up with a QR code.
72
52
*
73
53
* It implements `login.reciprocate` capabilities and showing QR codes.
74
54
*
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
76
56
*/
77
57
export default class LoginWithQR extends React . Component < IProps , IState > {
78
58
private finished = false ;
@@ -104,9 +84,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
104
84
if ( this . state . rendezvous ) {
105
85
const rendezvous = this . state . rendezvous ;
106
86
rendezvous . onFailure = undefined ;
107
- if ( rendezvous instanceof MSC3906Rendezvous ) {
108
- await rendezvous . cancel ( LegacyRendezvousFailureReason . UserCancelled ) ;
109
- }
110
87
this . setState ( { rendezvous : undefined } ) ;
111
88
}
112
89
if ( mode === Mode . Show ) {
@@ -119,60 +96,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
119
96
// eslint-disable-next-line react/no-direct-mutation-state
120
97
this . state . rendezvous . onFailure = undefined ;
121
98
// 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 ) ;
176
100
}
177
101
}
178
102
@@ -182,28 +106,18 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
182
106
}
183
107
184
108
private generateAndShowCode = async ( ) : Promise < void > => {
185
- let rendezvous : MSC4108SignInWithQR | MSC3906Rendezvous ;
109
+ let rendezvous : MSC4108SignInWithQR ;
186
110
try {
187
111
const fallbackRzServer = this . props . client ?. getClientWellKnown ( ) ?. [ "io.element.rendezvous" ] ?. server ;
188
112
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 ) ;
207
121
208
122
await rendezvous . generateCode ( ) ;
209
123
this . setState ( {
@@ -218,10 +132,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
218
132
}
219
133
220
134
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 ) {
225
136
// MSC4108-Flow: NewScanned
226
137
await rendezvous . negotiateProtocols ( ) ;
227
138
const { verificationUri } = await rendezvous . deviceAuthorizationGrant ( ) ;
@@ -234,18 +145,9 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
234
145
// we ask the user to confirm that the channel is secure
235
146
} catch ( e : RendezvousError | unknown ) {
236
147
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
+ ) ;
249
151
}
250
152
} ;
251
153
@@ -298,7 +200,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
298
200
public reset ( ) : void {
299
201
this . setState ( {
300
202
rendezvous : undefined ,
301
- confirmationDigits : undefined ,
302
203
verificationUri : undefined ,
303
204
failureReason : undefined ,
304
205
userCode : undefined ,
@@ -311,28 +212,20 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
311
212
private onClick = async ( type : Click , checkCode ?: string ) : Promise < void > => {
312
213
switch ( type ) {
313
214
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 ) ;
319
216
this . reset ( ) ;
320
217
this . onFinished ( false ) ;
321
218
break ;
322
219
case Click . Approve :
323
- await ( this . props . legacy ? this . legacyApproveLogin ( ) : this . approveLogin ( checkCode ) ) ;
220
+ await this . approveLogin ( checkCode ) ;
324
221
break ;
325
222
case Click . Decline :
326
223
await this . state . rendezvous ?. declineLoginOnExistingDevice ( ) ;
327
224
this . reset ( ) ;
328
225
this . onFinished ( false ) ;
329
226
break ;
330
227
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 ) ;
336
229
this . onFinished ( false ) ;
337
230
break ;
338
231
case Click . ShowQr :
@@ -342,20 +235,6 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
342
235
} ;
343
236
344
237
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
-
359
238
return (
360
239
< LoginWithQRFlow
361
240
onClick = { this . onClick }
0 commit comments