@@ -382,44 +382,35 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
382
382
master_key_updatable_without_uia ,
383
383
) = await self .e2e_keys_handler .check_cross_signing_setup (user_id )
384
384
385
- # Before MSC3967 we required UIA both when setting up cross signing for the
386
- # first time and when resetting the device signing key. With MSC3967 we only
387
- # require UIA when resetting cross-signing, and not when setting up the first
388
- # time. Because there is no UIA in MSC3861, for now we throw an error if the
389
- # user tries to reset the device signing key when MSC3861 is enabled, but allow
390
- # first-time setup.
391
- if self .hs .config .experimental .msc3861 .enabled :
392
- # The auth service has to explicitly mark the master key as replaceable
393
- # without UIA to reset the device signing key with MSC3861.
394
- if is_cross_signing_setup and not master_key_updatable_without_uia :
395
- config = self .hs .config .experimental .msc3861
396
- if config .account_management_url is not None :
397
- url = f"{ config .account_management_url } ?action=org.matrix.cross_signing_reset"
398
- else :
399
- url = config .issuer
400
-
401
- raise SynapseError (
402
- HTTPStatus .NOT_IMPLEMENTED ,
403
- "To reset your end-to-end encryption cross-signing identity, "
404
- f"you first need to approve it at { url } and then try again." ,
405
- Codes .UNRECOGNIZED ,
406
- )
407
- # But first-time setup is fine
408
-
409
- elif self .hs .config .experimental .msc3967_enabled :
410
- # MSC3967 allows this endpoint to 200 OK for idempotency. Resending exactly the same
411
- # keys should just 200 OK without doing a UIA prompt.
412
- keys_are_different = await self .e2e_keys_handler .has_different_keys (
413
- user_id , body
414
- )
415
- if not keys_are_different :
416
- # FIXME: we do not fallthrough to upload_signing_keys_for_user because confusingly
417
- # if we do, we 500 as it looks like it tries to INSERT the same key twice, causing a
418
- # unique key constraint violation. This sounds like a bug?
419
- return 200 , {}
420
- # the keys are different, is x-signing set up? If no, then the keys don't exist which is
421
- # why they are different. If yes, then we need to UIA to change them.
422
- if is_cross_signing_setup :
385
+ # Resending exactly the same keys should just 200 OK without doing a UIA prompt.
386
+ keys_are_different = await self .e2e_keys_handler .has_different_keys (
387
+ user_id , body
388
+ )
389
+ if not keys_are_different :
390
+ return 200 , {}
391
+
392
+ # The keys are different; is x-signing set up? If no, then this is first-time
393
+ # setup, and that is allowed without UIA, per MSC3967.
394
+ # If yes, then we need to authenticate the change.
395
+ if is_cross_signing_setup :
396
+ # With MSC3861, UIA is not possible. Instead, the auth service has to
397
+ # explicitly mark the master key as replaceable.
398
+ if self .hs .config .experimental .msc3861 .enabled :
399
+ if not master_key_updatable_without_uia :
400
+ config = self .hs .config .experimental .msc3861
401
+ if config .account_management_url is not None :
402
+ url = f"{ config .account_management_url } ?action=org.matrix.cross_signing_reset"
403
+ else :
404
+ url = config .issuer
405
+
406
+ raise SynapseError (
407
+ HTTPStatus .NOT_IMPLEMENTED ,
408
+ "To reset your end-to-end encryption cross-signing identity, "
409
+ f"you first need to approve it at { url } and then try again." ,
410
+ Codes .UNRECOGNIZED ,
411
+ )
412
+ else :
413
+ # Without MSC3861, we require UIA.
423
414
await self .auth_handler .validate_user_via_ui_auth (
424
415
requester ,
425
416
request ,
@@ -428,18 +419,6 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
428
419
# Do not allow skipping of UIA auth.
429
420
can_skip_ui_auth = False ,
430
421
)
431
- # Otherwise we don't require UIA since we are setting up cross signing for first time
432
- else :
433
- # Previous behaviour is to always require UIA but allow it to be skipped
434
- await self .auth_handler .validate_user_via_ui_auth (
435
- requester ,
436
- request ,
437
- body ,
438
- "add a device signing key to your account" ,
439
- # Allow skipping of UI auth since this is frequently called directly
440
- # after login and it is silly to ask users to re-auth immediately.
441
- can_skip_ui_auth = True ,
442
- )
443
422
444
423
result = await self .e2e_keys_handler .upload_signing_keys_for_user (user_id , body )
445
424
return 200 , result
0 commit comments