Skip to content

Commit 09d4ced

Browse files
uhoregrichvdh
authored andcommitted
spec verification in DMs and m.key.verification.ready/done
1 parent cf1e6e1 commit 09d4ced

13 files changed

+283
-93
lines changed

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

Lines changed: 131 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ out-of-band channel: there is no way to do it within Matrix without
357357
trusting the administrators of the homeservers.
358358

359359
In Matrix, verification works by Alice meeting Bob in person, or
360-
contacting him via some other trusted medium, and use [SAS
360+
contacting him via some other trusted medium, and using [SAS
361361
Verification](#SAS Verification) to interactively verify Bob's devices.
362362
Alice and Bob may also read aloud their unpadded base64 encoded Ed25519
363363
public key, as returned by `/keys/query`.
@@ -390,60 +390,68 @@ decrypted by such a device. For the Olm protocol, this is documented at
390390
Verifying keys manually by reading out the Ed25519 key is not very
391391
user-friendly, and can lead to errors. In order to help mitigate errors,
392392
and to make the process easier for users, some verification methods are
393-
supported by the specification. The methods all use a common framework
393+
supported by the specification and use messages exchanged by the user's devices
394+
to assist in the verification. The methods all use a common framework
394395
for negotiating the key verification.
395396

396-
To use this framework, Alice's client would send
397-
`m.key.verification.request` events to Bob's devices. All of the
398-
`to_device` messages sent to Bob MUST have the same `transaction_id` to
399-
indicate they are part of the same request. This allows Bob to reject
400-
the request on one device, and have it apply to all of his devices.
401-
Similarly, it allows Bob to process the verification on one device
402-
without having to involve all of his devices.
403-
404-
When Bob's device receives an `m.key.verification.request`, it should
405-
prompt Bob to verify keys with Alice using one of the supported methods
406-
in the request. If Bob's device does not understand any of the methods,
407-
it should not cancel the request as one of his other devices may support
408-
the request. Instead, Bob's device should tell Bob that an unsupported
409-
method was used for starting key verification. The prompt for Bob to
410-
accept/reject Alice's request (or the unsupported method prompt) should
411-
be automatically dismissed 10 minutes after the `timestamp` field or 2
412-
minutes after Bob's client receives the message, whichever comes first,
413-
if Bob does not interact with the prompt. The prompt should additionally
414-
be hidden if an appropriate `m.key.verification.cancel` message is
415-
received.
416-
417-
If Bob rejects the request, Bob's client must send an
418-
`m.key.verification.cancel` message to Alice's device. Upon receipt,
419-
Alice's device should tell her that Bob does not want to verify her
420-
device and send `m.key.verification.cancel` messages to all of Bob's
421-
devices to notify them that the request was rejected.
422-
423-
If Bob accepts the request, Bob's device starts the key verification
424-
process by sending an `m.key.verification.start` message to Alice's
425-
device. Upon receipt of this message, Alice's device should send an
426-
`m.key.verification.cancel` message to all of Bob's other devices to
427-
indicate the process has been started. The start message must use the
428-
same `transaction_id` from the original key verification request if it
429-
is in response to the request. The start message can be sent
430-
independently of any request.
431-
432-
Individual verification methods may add additional steps, events, and
433-
properties to the verification messages. Event types for methods defined
434-
in this specification must be under the `m.key.verification` namespace
435-
and any other event types must be namespaced according to the Java
436-
package naming convention.
437-
438-
Any of Alice's or Bob's devices can cancel the key verification request
439-
or process at any time with an `m.key.verification.cancel` message to
440-
all applicable devices.
441-
442-
This framework yields the following handshake, assuming both Alice and
443-
Bob each have 2 devices, Bob's first device accepts the key verification
444-
request, and Alice's second device initiates the request. Note how
445-
Alice's first device is not involved in the request or verification
446-
process.
397+
Verification messages can be sent either in a room shared by the two parties,
398+
which should be a [direct messaging](#direct-messaging) room between the two
399+
parties, or by using [to-device](#send-to-device-messaging) messages sent
400+
directly between the two devices involved. In both cases, the messages
401+
exchanged are similar, with minor differences as detailed below. Verifying
402+
between two different users should be performed using in-room messages, whereas
403+
verifying two devices belonging to the same user should be performed using
404+
to-device messages.
405+
406+
A key verification session is identified by an ID that is established by the
407+
first message sent in that session. For verifications using in-room messages,
408+
the ID is the event ID of the initial message, and for verifications using
409+
to-device messages, the first message contains a `transaction_id` field that is
410+
shared by the other messages of that session.
411+
412+
In general, verification operates as follows:
413+
414+
- Alice requests a key verification with Bob by sending an
415+
`m.key.verification.request` event. This event indicates the verification
416+
methods that Alice's client supports. (Note that "Alice" and "Bob" may in
417+
fact be the same user, in the case where a user is verifying their own
418+
devices.)
419+
- Bob's client prompts Bob to accepts the key verification. When Bob accepts
420+
the verification, Bob's client sends an `m.key.verification.ready` event.
421+
This event indicates the verification methods, corresponding to the
422+
verification methods supported by Alice's client, that Bob's client supports.
423+
- Alice's or Bob's devices allow their users to select one of the verification
424+
methods supported by both devices to use for verification. When Alice or Bob
425+
selects a verification method, their device begins the verification by
426+
sending an `m.key.verification.start` event, indicating the selected
427+
verification method.
428+
- Alice and Bob complete the verification as defined by the selected
429+
verification method. This could involve their clients exchanging messages,
430+
Alice and Bob exchanging information out-of-band, and/or Alice and Bob
431+
interacting with their devices.
432+
- Alice's and Bob's clients send `m.key.verification.done` events to indicate
433+
that the verification was successful.
434+
435+
Verifications can be cancelled by either device at any time by sending an
436+
`m.key.verification.cancel` event with a `code` field that indicates the reason
437+
it was cancelled.
438+
439+
When using to-device messages, Alice may not know which of Bob's devices to
440+
verify, or may not want to choose a specific device. In this case, Alice will
441+
send `m.key.verification.request` events to all of Bob's devices. All of these
442+
events will use the same transaction ID. When Bob accepts or declines the
443+
verification on one of his devices (sending either an
444+
`m.key.verification.ready` or `m.key.verification.cancel` event), Alice will
445+
send an `m.key.verification.cancel` event to Bob's other devices with a `code`
446+
of `m.accepted` in the case where Bob accepted the verification, or `m.user` in
447+
the case where Bob rejected the verification. This yields the following
448+
handshake when using to-device messages, assuming both Alice and Bob each have
449+
2 devices, Bob's first device accepts the key verification request, and Alice's
450+
second device initiates the request. Note how Alice's first device is not
451+
involved in the request or verification process. Also note that, although in
452+
this example, Bob's device sends the `m.key.verification.start`, Alice's device
453+
could also send that message. As well, the order of the
454+
`m.key.verification.done` messages could be reversed.
447455

448456
```
449457
+---------------+ +---------------+ +-------------+ +-------------+
@@ -456,20 +464,84 @@ process.
456464
| | m.key.verification.request | |
457465
| |-------------------------------------------------->|
458466
| | | |
459-
| | m.key.verification.start | |
467+
| | m.key.verification.ready | |
460468
| |<----------------------------------| |
461469
| | | |
462470
| | m.key.verification.cancel | |
463471
| |-------------------------------------------------->|
464472
| | | |
473+
| | m.key.verification.start | |
474+
| |<----------------------------------| |
475+
| | | |
476+
.
477+
. (verification messages)
478+
.
479+
| | | |
480+
| | m.key.verification.done | |
481+
| |<----------------------------------| |
482+
| | | |
483+
| | m.key.verification.done | |
484+
| |---------------------------------->| |
485+
| | | |
465486
```
466487

467-
After the handshake, the verification process begins.
488+
When using in-room messages and the room has encryption enabled, clients should
489+
ensure that encryption does not hinder the verification. For example, if the
490+
verification messages are encrypted, clients must ensure that all the
491+
recipient's unverified devices receive the keys necessary to decrypt the
492+
messages, even if they would normally not be given the keys to decrypt messages
493+
in the room. Alternatively, verification messages may be sent unencrypted.
494+
495+
Upon receipt of Alice's `m.key.verification.request` message, if Bob's device
496+
does not understand any of the methods, it should not cancel the request as one
497+
of his other devices may support the request. Instead, Bob's device should tell
498+
Bob that no supported method was found, and allow him to manually reject the
499+
request.
500+
501+
The prompt for Bob to accept/reject Alice's request (or the unsupported method
502+
prompt) should be automatically dismissed 10 minutes after the `timestamp` (in
503+
the case of to-device messages) or `origin_ts` (in the case of in-room
504+
messages) field or 2 minutes after Bob's client receives the message, whichever
505+
comes first, if Bob does not interact with the prompt. The prompt should
506+
additionally be hidden if an appropriate `m.key.verification.cancel` message is
507+
received.
508+
509+
If Bob rejects the request, Bob's client must send an
510+
`m.key.verification.cancel` event with `code` set to `m.user`. Upon receipt,
511+
Alice's device should tell her that Bob does not want to verify her device and,
512+
if the request was sent as a to-device message, send
513+
`m.key.verification.cancel` messages to all of Bob's devices to notify them
514+
that the request was rejected.
515+
516+
If Alice's and Bob's clients both send an `m.key.verification.start` message,
517+
and both specify the same verification method, then the
518+
`m.key.verification.start` message sent by the user whose ID is the
519+
lexicographically largest user ID should be ignored, and the situation should
520+
be treated the same as if only the user with the lexicographically smallest
521+
user ID had sent the `m.key.verification.start` message. In the case where the
522+
user IDs are the same (that is, when a user is verifying their own device),
523+
then the device IDs should be compared instead. If the two
524+
`m.key.verification.start` messages do not specify the same verification
525+
method, then the verification should be cancelled with a `code` of
526+
`m.unexpected_message`.
527+
528+
An `m.key.verification.start` message can also be sent independently of any
529+
request, specifying the verification method to use.
530+
531+
Individual verification methods may add additional steps, events, and
532+
properties to the verification messages. Event types for methods defined
533+
in this specification must be under the `m.key.verification` namespace
534+
and any other event types must be namespaced according to the Java
535+
package naming convention.
468536

469537
{{% event event="m.key.verification.request" %}}
470538

539+
{{% event event="m.key.verification.ready" %}}
540+
471541
{{% event event="m.key.verification.start" %}}
472542

543+
{{% event event="m.key.verification.done" %}}
544+
473545
{{% event event="m.key.verification.cancel" %}}
474546

475547
##### Short Authentication String (SAS) verification
@@ -493,6 +565,10 @@ example, if we verify 40 bits, then an attacker has a 1 in
493565
success. A failed attack would result in a mismatched Short
494566
Authentication String, alerting users to the attack.
495567

568+
To advertise support for this method, clients use the name `m.sas.v1` in the
569+
`methods` fields of the `m.key.verification.request` and
570+
`m.key.verification.ready` events.
571+
496572
The verification process takes place over [to-device](#send-to-device-messaging) messages in two
497573
phases:
498574

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "m.key.verification.done",
3+
"content": {
4+
"transaction_id": "S0meUniqueAndOpaqueString"
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "m.key.verification.ready",
3+
"content": {
4+
"from_device": "BobDevice1",
5+
"transaction_id": "S0meUniqueAndOpaqueString",
6+
"methods": [
7+
"m.sas.v1"
8+
]
9+
}
10+
}

data/event-schemas/schema/m.key.verification.accept.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ allOf:
33
- $ref: core-event-schema/event.yaml
44

55
description: |-
6-
Accepts a previously sent `m.key.verification.start` message. Typically sent as a
7-
[to-device](/client-server-api/#send-to-device-messaging) event.
6+
Accepts a previously sent `m.key.verification.start` message.
87
properties:
98
content:
109
properties:
1110
transaction_id:
1211
type: string
1312
description: |-
14-
An opaque identifier for the verification process. Must be the same as
15-
the one used for the `m.key.verification.start` message.
13+
Required when sent as a to-device message. An opaque identifier for
14+
the verification process. Must be the same as the one used for the
15+
`m.key.verification.start` message.
1616
key_agreement_protocol:
1717
type: string
1818
description: |-
@@ -43,8 +43,10 @@ properties:
4343
The hash (encoded as unpadded base64) of the concatenation of the device's
4444
ephemeral public key (encoded as unpadded base64) and the canonical JSON
4545
representation of the `m.key.verification.start` message.
46+
m.relates_to:
47+
allOf:
48+
- $ref: m.key.verification.m.relates_to.yaml
4649
required:
47-
- transaction_id
4850
- method
4951
- key_agreement_protocol
5052
- hash

data/event-schemas/schema/m.key.verification.cancel.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ allOf:
33
- $ref: core-event-schema/event.yaml
44

55
description: |-
6-
Cancels a key verification process/request. Typically sent as a [to-device](/client-server-api/#send-to-device-messaging) event.
6+
Cancels a key verification process/request.
77
properties:
88
content:
99
properties:
1010
transaction_id:
1111
type: string
1212
description: |-
13-
The opaque identifier for the verification process/request.
13+
Required when sent as a to-device message. The opaque identifier for
14+
the verification process/request.
1415
reason:
1516
type: string
1617
description: |-
@@ -56,8 +57,10 @@ properties:
5657
gets an unexpected response with `m.unexpected_message`, the client should not
5758
respond again with `m.unexpected_message` to avoid the other device potentially
5859
sending another error response.
60+
m.relates_to:
61+
allOf:
62+
- $ref: m.key.verification.m.relates_to.yaml
5963
required:
60-
- transaction_id
6164
- code
6265
- reason
6366
type: object
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
allOf:
3+
- $ref: core-event-schema/event.yaml
4+
5+
description: |-
6+
Indicates that a verification process/request has completed successfully.
7+
properties:
8+
content:
9+
properties:
10+
transaction_id:
11+
type: string
12+
description: |-
13+
Required when sent as a to-device message. The opaque identifier for
14+
the verification process/request.
15+
m.relates_to:
16+
allOf:
17+
- $ref: m.key.verification.m.relates_to.yaml
18+
type: object
19+
type:
20+
enum:
21+
- m.key.verification.done
22+
type: string
23+
type: object

data/event-schemas/schema/m.key.verification.key.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ allOf:
33
- $ref: core-event-schema/event.yaml
44

55
description: |-
6-
Sends the ephemeral public key for a device to the partner device. Typically sent as a
7-
[to-device](/client-server-api/#send-to-device-messaging) event.
6+
Sends the ephemeral public key for a device to the partner device.
87
properties:
98
content:
109
properties:
1110
transaction_id:
1211
type: string
1312
description: |-
14-
An opaque identifier for the verification process. Must be the same as
15-
the one used for the `m.key.verification.start` message.
13+
Required when sent as a to-device message. An opaque identifier for
14+
the verification process. Must be the same as the one used for the
15+
`m.key.verification.start` message.
1616
key:
1717
type: string
1818
description: |-
1919
The device's ephemeral public key, encoded as unpadded base64.
20+
m.relates_to:
21+
allOf:
22+
- $ref: m.key.verification.m.relates_to.yaml
2023
required:
21-
- transaction_id
2224
- key
2325
type: object
2426
type:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: |-
3+
Required when sent as an in-room message. Indicates the
4+
`m.key.verification.request` that this message is related to. Note that for
5+
encrypted messages, this property should be in the unencrypted portion of the
6+
event.
7+
properties:
8+
rel_type:
9+
type: string
10+
enum:
11+
- m.reference
12+
description: |-
13+
The relationship type.
14+
event_id:
15+
type: string
16+
description: |-
17+
The event ID of the `m.key.verification.request` that this message is
18+
related to.
19+
type: object
20+
type: object
21+
title: VerificationRelatesTo

0 commit comments

Comments
 (0)