Skip to content

Commit 3aae60f

Browse files
authored
Enable cross-signing key upload without UIA (#17284)
Per MSC3967, which is now stable, we should not require UIA when uploading cross-signing keys for the first time. Fixes: #17227
1 parent 2c36a67 commit 3aae60f

File tree

7 files changed

+32
-123
lines changed

7 files changed

+32
-123
lines changed

changelog.d/17284.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not require user-interactive authentication for uploading cross-signing keys for the first time, per MSC3967.

synapse/config/experimental.py

-3
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
393393
# MSC3391: Removing account data.
394394
self.msc3391_enabled = experimental.get("msc3391_enabled", False)
395395

396-
# MSC3967: Do not require UIA when first uploading cross signing keys
397-
self.msc3967_enabled = experimental.get("msc3967_enabled", False)
398-
399396
# MSC3861: Matrix architecture change to delegate authentication via OIDC
400397
try:
401398
self.msc3861 = MSC3861(**experimental.get("msc3861", {}))

synapse/rest/admin/experimental_features.py

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class ExperimentalFeature(str, Enum):
4141

4242
MSC3026 = "msc3026"
4343
MSC3881 = "msc3881"
44-
MSC3967 = "msc3967"
4544

4645

4746
class ExperimentalFeaturesRestServlet(RestServlet):

synapse/rest/client/keys.py

+29-50
Original file line numberDiff line numberDiff line change
@@ -382,44 +382,35 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
382382
master_key_updatable_without_uia,
383383
) = await self.e2e_keys_handler.check_cross_signing_setup(user_id)
384384

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.
423414
await self.auth_handler.validate_user_via_ui_auth(
424415
requester,
425416
request,
@@ -428,18 +419,6 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
428419
# Do not allow skipping of UIA auth.
429420
can_skip_ui_auth=False,
430421
)
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-
)
443422

444423
result = await self.e2e_keys_handler.upload_signing_keys_for_user(user_id, body)
445424
return 200, result

tests/handlers/test_oauth_delegation.py

+2
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ def test_cross_signing(self) -> None:
541541

542542
self.assertEqual(channel.code, 200, channel.json_body)
543543

544+
# Try uploading *different* keys; it should cause a 501 error.
545+
keys_upload_body = self.make_device_keys(USER_ID, DEVICE)
544546
channel = self.make_request(
545547
"POST",
546548
"/_matrix/client/v3/keys/device_signing/upload",

tests/rest/admin/test_admin.py

-4
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,6 @@ def test_enable_and_disable(self) -> None:
435435
True,
436436
channel.json_body["features"]["msc3881"],
437437
)
438-
self.assertEqual(
439-
False,
440-
channel.json_body["features"]["msc3967"],
441-
)
442438

443439
# test nothing blows up if you try to disable a feature that isn't already enabled
444440
url = f"{self.url}/{self.other_user}"

tests/rest/client/test_keys.py

-65
Original file line numberDiff line numberDiff line change
@@ -155,71 +155,6 @@ def make_device_keys(self, user_id: str, device_id: str) -> JsonDict:
155155
}
156156

157157
def test_device_signing_with_uia(self) -> None:
158-
"""Device signing key upload requires UIA."""
159-
password = "wonderland"
160-
device_id = "ABCDEFGHI"
161-
alice_id = self.register_user("alice", password)
162-
alice_token = self.login("alice", password, device_id=device_id)
163-
164-
content = self.make_device_keys(alice_id, device_id)
165-
166-
channel = self.make_request(
167-
"POST",
168-
"/_matrix/client/v3/keys/device_signing/upload",
169-
content,
170-
alice_token,
171-
)
172-
173-
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
174-
# Grab the session
175-
session = channel.json_body["session"]
176-
# Ensure that flows are what is expected.
177-
self.assertIn({"stages": ["m.login.password"]}, channel.json_body["flows"])
178-
179-
# add UI auth
180-
content["auth"] = {
181-
"type": "m.login.password",
182-
"identifier": {"type": "m.id.user", "user": alice_id},
183-
"password": password,
184-
"session": session,
185-
}
186-
187-
channel = self.make_request(
188-
"POST",
189-
"/_matrix/client/v3/keys/device_signing/upload",
190-
content,
191-
alice_token,
192-
)
193-
194-
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
195-
196-
@override_config({"ui_auth": {"session_timeout": "15m"}})
197-
def test_device_signing_with_uia_session_timeout(self) -> None:
198-
"""Device signing key upload requires UIA buy passes with grace period."""
199-
password = "wonderland"
200-
device_id = "ABCDEFGHI"
201-
alice_id = self.register_user("alice", password)
202-
alice_token = self.login("alice", password, device_id=device_id)
203-
204-
content = self.make_device_keys(alice_id, device_id)
205-
206-
channel = self.make_request(
207-
"POST",
208-
"/_matrix/client/v3/keys/device_signing/upload",
209-
content,
210-
alice_token,
211-
)
212-
213-
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
214-
215-
@override_config(
216-
{
217-
"experimental_features": {"msc3967_enabled": True},
218-
"ui_auth": {"session_timeout": "15s"},
219-
}
220-
)
221-
def test_device_signing_with_msc3967(self) -> None:
222-
"""Device signing key follows MSC3967 behaviour when enabled."""
223158
password = "wonderland"
224159
device_id = "ABCDEFGHI"
225160
alice_id = self.register_user("alice", password)

0 commit comments

Comments
 (0)