Skip to content

Commit 224773d

Browse files
turt2liveuhoreg
andauthored
Specify fallback keys (#3615)
* Specify fallback keys MSC: #2732 * changelog * Appease spell check * Fine, let's appease the spellcheck this way * Apply suggestions from code review Co-authored-by: Hubert Chathi <[email protected]> * Fix intro * word wrap Co-authored-by: Hubert Chathi <[email protected]>
1 parent 26e0765 commit 224773d

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

.github/_typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ au1ba7o = "au1ba7o"
99

1010
[default.extend-words]
1111
Appy = "Appy"
12-
fo = "fo"
12+
fo = "fo"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for fallback keys (optional keys used once one-time keys run out), as per [MSC2732](https://github.com/matrix-org/matrix-doc/pull/2732).

content/client-server-api/modules/end_to_end_encryption.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ must include the public part of the device's Ed25519 key, and must be
117117
signed by that key, as described in [Signing
118118
JSON](/appendices/#signing-json).
119119

120-
One-time keys are also uploaded to the homeserver using the
120+
One-time and fallback keys are also uploaded to the homeserver using the
121121
[`/keys/upload`](/client-server-api/#post_matrixclientv3keysupload) API.
122122

123+
{{% added-in v="1.2" %}} Fallback keys are similar to one-time keys, but
124+
are not consumed once used. They are only used when the device has run out
125+
of one-time keys, and can be replaced by a new fallback key.
126+
123127
Devices must store the private part of each key they upload. They can
124128
discard the private part of a one-time key when they receive a message
125129
using that key. However it's possible that a one-time key given out by a
@@ -128,6 +132,24 @@ never know that it can discard the key. Therefore a device could end up
128132
trying to store too many private keys. A device that is trying to store
129133
too many private keys may discard keys starting with the oldest.
130134

135+
{{% boxes/warning %}}
136+
Fallback keys are used to prevent one-time key exhaustion when devices
137+
are offline/unable to upload additional keys, though sessions started using
138+
fallback keys could be vulnerable to replay attacks.
139+
{{% /boxes/warning %}}
140+
141+
{{% boxes/warning %}}
142+
Clients should not store the private half of fallback keys indefinitely
143+
to avoid situations where attackers can decrypt past messages sent using
144+
that fallback key.
145+
146+
Instead, clients should keep the private keys for at most 2 fallback keys:
147+
the current, unused, fallback key and the key immediately preceding it.
148+
Once the client is reasonably certain it has received all messages that
149+
used the old fallback key, such as after an hour since the first message,
150+
it should remove that fallback key.
151+
{{% /boxes/warning %}}
152+
131153
##### Tracking the device list for a user
132154

133155
Before Alice can send an encrypted message to Bob, she needs a list of
@@ -344,6 +366,11 @@ A homeserver should rate-limit the number of one-time keys that a given
344366
user or remote server can claim. A homeserver should discard the public
345367
part of a one time key once it has given that key to another user.
346368

369+
{{% added-in v="1.2" %}} If the device has run out of one-time keys which
370+
can be claimed, the homeserver will return the fallback key (if one was
371+
uploaded). Fallback keys are not deleted once used and should be replaced
372+
by the device when they are able to upload more one-time keys.
373+
347374
#### Device verification
348375

349376
Before Alice sends Bob encrypted data, or trusts data received from him,
@@ -1603,10 +1630,23 @@ It also adds a `one_time_keys_count` property. Note the spelling
16031630
difference with the `one_time_key_counts` property in the
16041631
[`/keys/upload`](/client-server-api/#post_matrixclientv3keysupload) response.
16051632

1606-
| Parameter | Type | Description |
1607-
|----------------------------|--------------------|------------------------------------------------------------------------------------------------------------------------|
1608-
| device_lists | DeviceLists | Optional. Information on e2e device updates. Note: only present on an incremental sync. |
1609-
| device_one_time_keys_count | {string: integer} | Optional. For each key algorithm, the number of unclaimed one-time keys currently held on the server for this device. |
1633+
1634+
{{% added-in v="1.2" %}} Finally, a `device_unused_fallback_key_types` property
1635+
is added to list the key algorithms where the device has a fallback key that
1636+
*has not* been used in a [`/keys/claim`](/client-server-api/#post_matrixclientv3keysclaim)
1637+
response. When a previously uploaded fallback key's algorithm is missing
1638+
from this list, the device should upload a replacement key alongside any
1639+
necessary one-time keys to avoid the fallback key's further usage. This
1640+
property is required for inclusion, though previous versions of the
1641+
specification did not have it. In addition to `/versions`, this can be
1642+
a way to identify the server's support for fallback keys.
1643+
1644+
1645+
| Parameter | Type | Description |
1646+
|----------------------------------|--------------------|------------------------------------------------------------------------------------------------------------------------|
1647+
| device_lists | DeviceLists | Optional. Information on e2e device updates. Note: only present on an incremental sync. |
1648+
| device_one_time_keys_count | {string: integer} | Optional. For each key algorithm, the number of unclaimed one-time keys currently held on the server for this device. |
1649+
| device_unused_fallback_key_types | [string] | **Required.** The unused fallback key algorithms. |
16101650

16111651
`DeviceLists`
16121652

data/api/client-server/keys.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ paths:
100100
}
101101
}
102102
}
103+
fallback_keys:
104+
type: object
105+
x-addedInMatrixVersion: "1.2"
106+
description: |-
107+
The public key which should be used if the device's one-time keys
108+
are exhausted. The fallback key is not deleted once used, but should
109+
be replaced when additional one-time keys are being uploaded. The
110+
server will notify the client of the fallback key being used through
111+
`/sync`.
112+
113+
There can only be at most one key per algorithm uploaded, and the server
114+
will only persist one key per algorithm.
115+
116+
When uploading a signed key, an additional `fallback: true` key should
117+
be included to denote that the key is a fallback key.
118+
119+
May be absent if a new fallback key is not required.
120+
additionalProperties:
121+
type:
122+
- string
123+
- object
124+
# XXX: We can't define an actual object here - see one_time_keys.
125+
example: {
126+
"curve25519:AAAAAG": "/qyvZvwjiTxGdGU0RCguDCLeR+nmsb3FfNG3/Ve4vU8",
127+
"signed_curve25519:AAAAGj": {
128+
"key": "zKbLg+NrIjpnagy+pIY6uPL4ZwEG2v+8F9lmgsnlZzs",
129+
"fallback": true,
130+
"signatures": {
131+
"@alice:example.com": {
132+
"ed25519:JLAFKJWSCS": "FLWxXqGbwrb8SM3Y795eB6OA8bwBcoMZFXBqnTn58AYWZSqiD45tlBVcDa2L7RwdKXebW/VzDlnfVJ+9jok1Bw"
133+
}
134+
}
135+
}
136+
}
103137
responses:
104138
200:
105139
description:
@@ -378,6 +412,9 @@ paths:
378412
379413
See the [key algorithms](/client-server-api/#key-algorithms) section for information
380414
on the Key Object format.
415+
416+
If necessary, the claimed key might be a fallback key. Fallback
417+
keys are re-used by the server until replaced by the device.
381418
additionalProperties:
382419
type: object
383420
additionalProperties:

0 commit comments

Comments
 (0)