Skip to content

Commit ec05d1a

Browse files
committed
Specify fallback keys
MSC: #2732
1 parent 592cbd5 commit ec05d1a

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

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

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

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

124+
{{% added-in v="1.2" %}} Fallback keys are simply one-time keys which get
125+
used when the device has run out of one-time keys. They are not consumed
126+
once used, but should be replaced when additional one-time keys are uploaded.
127+
124128
Devices must store the private part of each key they upload. They can
125129
discard the private part of a one-time key when they receive a message
126130
using that key. However it's possible that a one-time key given out by a
@@ -129,6 +133,24 @@ never know that it can discard the key. Therefore a device could end up
129133
trying to store too many private keys. A device that is trying to store
130134
too many private keys may discard keys starting with the oldest.
131135

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

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

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

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

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

16121652
`DeviceLists`
16131653

data/api/client-server/keys.yaml

+37
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 OTKs.
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)