Skip to content

Commit 8284e78

Browse files
authored
Merge pull request #2826 from matrix-org/uhoreg/keys_withheld
add spec for reporting that keys are withheld
2 parents 4ee990e + 267eead commit 8284e78

File tree

5 files changed

+147
-8
lines changed

5 files changed

+147
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document how clients can advise recipients that it is withholding decryption keys as per `MSC2399 <https://github.com/matrix-org/matrix-doc/pull/2399>`_.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$ref": "core/event.json",
3+
"type": "m.room_key.withheld",
4+
"content": {
5+
"algorithm": "m.megolm.v1.aes-sha2",
6+
"room_id": "!Cuyf34gef24t:localhost",
7+
"session_id": "X3lUlvLELLYxeTx4yOVu6UDpasGEVO0Jbu+QFnm0cKQ",
8+
"sender_key": "RF3s+E7RkTQTGF2d8Deol0FkQvgII2aJDf3/Jp5mxVU",
9+
"code": "m.unverified",
10+
"reason": "Device not verified"
11+
}
12+
}

event-schemas/schema/m.forwarded_room_key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ properties:
4343
to the end of the list. For example, if the key is forwarded from A to B to
4444
C, this field is empty between A and B, and contains A's Curve25519 key between
4545
B and C.
46+
withheld:
47+
type: object
48+
description: |-
49+
Indicates that the key cannot be used to decrypt all the messages
50+
from the session because a portion of the session was withheld as
51+
described in `Reporting that decryption keys are withheld`_. This
52+
object must include the ``code`` and ``reason`` properties from the
53+
``m.room_key.withheld`` message that was received by the sender of
54+
this message.
4655
required:
4756
- algorithm
4857
- room_id
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
allOf:
3+
- $ref: core-event-schema/event.yaml
4+
5+
description: |-
6+
This event type is used to indicate that the sender is not sharing room keys
7+
with the recipient. It is sent as a to-device event.
8+
9+
Possible values for ``code`` include:
10+
11+
* ``m.blacklisted``: the user/device was blacklisted.
12+
* ``m.unverified``: the user/device was not verified, and the sender is only
13+
sharing keys with verified users/devices.
14+
* ``m.unauthorised``: the user/device is not allowed to have the key. For
15+
example, this could be sent in response to a key request if the user/device
16+
was not in the room when the original message was sent.
17+
* ``m.unavailable``: sent in reply to a key request if the device that the
18+
key is requested from does not have the requested key.
19+
* ``m.no_olm``: an olm session could not be established.
20+
21+
In most cases, this event refers to a specific room key. The one exception to
22+
this is when the sender is unable to establish an olm session with the
23+
recipient. When this happens, multiple sessions will be affected. In order
24+
to avoid filling the recipient\'s device mailbox, the sender should only send
25+
one ``m.room_key.withheld`` message with no ``room_id`` nor ``session_id``
26+
set. If the sender retries and fails to create an olm session again in the
27+
future, it should not send another ``m.room_key.withheld`` message with a
28+
``code`` of ``m.no_olm``, unless another olm session was previously
29+
established successfully. In response to receiving an
30+
``m.room_key.withheld`` message with a ``code`` of ``m.no_olm``, the
31+
recipient may start an olm session with the sender and send an ``m.dummy``
32+
message to notify the sender of the new olm session. The recipient may
33+
assume that this ``m.room_key.withheld`` message applies to all encrypted
34+
room messages sent before it receives the message.
35+
properties:
36+
content:
37+
properties:
38+
algorithm:
39+
type: string
40+
enum: ["m.megolm.v1.aes-sha2"]
41+
description: |-
42+
The encryption algorithm for the key that this event is about.
43+
room_id:
44+
type: string
45+
description: |-
46+
Required if ``code`` is not ``m.no_olm``. The room for the key that
47+
this event is about.
48+
session_id:
49+
type: string
50+
description: |-
51+
Required of ``code`` is not ``m.no_olm``. The session ID of the key
52+
that this event is aboutis for.
53+
sender_key:
54+
type: string
55+
description: |-
56+
The unpadded base64-encoded device curve25519 key of the event\'s
57+
sender.
58+
code:
59+
type: string
60+
enum:
61+
- m.blacklisted
62+
- m.unverified
63+
- m.unauthorised
64+
- m.unavailable
65+
- m.no_olm
66+
description: |-
67+
A machine-readable code for why the key was not sent. Codes beginning
68+
with `m.` are reserved for codes defined in the Matrix
69+
specification. Custom codes must use the Java package naming
70+
convention.
71+
reason:
72+
type: string
73+
description: |-
74+
A human-readable reason for why the key was not sent. The receiving
75+
client should only use this string if it does not understand the
76+
``code``.
77+
required:
78+
- algorithm
79+
- sender_key
80+
- code
81+
type: object
82+
type:
83+
enum:
84+
- m.room_key.withheld
85+
type: string
86+
type: object

specification/modules/end_to_end_encryption.rst

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,19 @@ Key requests
792792

793793
When a device is missing keys to decrypt messages, it can request the keys by
794794
sending `m.room_key_request`_ to-device messages to other devices with
795-
``action`` set to ``request``. If a device wishes to share the keys with that
796-
device, it can forward the keys to the first device by sending an encrypted
797-
`m.forwarded_room_key`_ to-device message. The first device should then send an
798-
`m.room_key_request`_ to-device message with ``action`` set to
799-
``request_cancellation`` to the other devices that it had originally sent the key
800-
request to; a device that receives a ``request_cancellation`` should disregard any
801-
previously-received ``request`` message with the same ``request_id`` and
802-
``requesting_device_id``.
795+
``action`` set to ``request``.
796+
797+
If a device wishes to share the keys with that device, it can forward the keys
798+
to the first device by sending an encrypted `m.forwarded_room_key`_ to-device
799+
message. The first device should then send an `m.room_key_request`_ to-device
800+
message with ``action`` set to ``request_cancellation`` to the other devices
801+
that it had originally sent the key request to; a device that receives a
802+
``request_cancellation`` should disregard any previously-received ``request``
803+
message with the same ``request_id`` and ``requesting_device_id``.
804+
805+
If a device does not wish to share keys with that device, it can indicate this
806+
by sending an `m.room_key.withheld`_ to-device message, as described in
807+
`Reporting that decryption keys are withheld`_.
803808

804809
.. NOTE::
805810

@@ -1333,6 +1338,32 @@ Example response:
13331338
}
13341339
}
13351340
1341+
Reporting that decryption keys are withheld
1342+
-------------------------------------------
1343+
1344+
When sending an encrypted event to a room, a client can optionally signal to
1345+
other devices in that room that it is not sending them the keys needed to
1346+
decrypt the event. In this way, the receiving client can indicate to the user
1347+
why it cannot decrypt the event, rather than just showing a generic error
1348+
message.
1349+
1350+
In the same way, when one device requests keys from another using `Key
1351+
requests`_, the device from which the key is being requested may want to tell
1352+
the requester that it is purposely not sharing the key.
1353+
1354+
If Alice withholds a megolm session from Bob for some messages in a room, and
1355+
then later on decides to allow Bob to decrypt later messages, she can send Bob
1356+
the megolm session, ratcheted up to the point at which she allows Bob to
1357+
decrypt the messages. If Bob logs into a new device and uses key sharing to
1358+
obtain the decryption keys, the new device will be sent the megolm sessions
1359+
that have been ratcheted up. Bob's old device can include the reason that the
1360+
session was initially not shared by including a ``withheld`` property in the
1361+
``m.forwarded_room_key`` message that is an object with the ``code`` and
1362+
``reason`` properties from the ``m.room_key.withheld`` message.
1363+
1364+
{{m_room_key_withheld_event}}
1365+
1366+
13361367
.. References
13371368
13381369
.. _ed25519: http://ed25519.cr.yp.to/

0 commit comments

Comments
 (0)