Skip to content

Commit 78b8133

Browse files
committed
use binary encoding of keys to reduce size of QR code
1 parent 7f93084 commit 78b8133

File tree

1 file changed

+64
-55
lines changed

1 file changed

+64
-55
lines changed

proposals/1543-qr_code_key_verification.md

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Key verification using QR codes
2-
===============================
1+
Bi-directional Key verification using QR codes
2+
==============================================
33

44
Problem/Background
55
------------------
@@ -28,25 +28,20 @@ who can then tell his device that the keys match.
2828
`m.key.verification.request` message (see
2929
[MSC2241](https://github.com/matrix-org/matrix-doc/pull/2241)), with
3030
`m.qr_code.show.v1`, `m.qr_code.scan.v1`, and `m.reciprocate.v1` listed in
31-
`methods`.
31+
`methods`, and Bob responds with a `m.key.verification.ready` message.
3232
3. Alice's client displays a QR code that Bob is able to scan, and an option to
3333
scan Bob's QR code.
3434
4. Bob's client prompts Bob to verify Alice's key. The prompt includes a QR
3535
code that Alice can scan (if the `m.key.verification.request` message listed
3636
`m.qr_code.scan.v1`), and an option to scan Alice's QR code (if the
3737
`m.key.verification.request` message listed `m.qr_code.show.v1`). The QR
3838
code encodes:
39-
- Bob's Matrix user ID,
40-
- Bob's keys that he wants Alice to verify (should contain at least his
41-
master cross-signing key),
42-
- what Bob thinks Alice's master cross-signing key is,
39+
- Bob's master cross-signing public key,
40+
- what Bob thinks Alice's master cross-signing public key is,
4341
- a random shared secret.
4442
5. Alice scans Bob's QR code.
4543
6. Alice's device ensures that:
46-
- the user ID in the QR code is the same as the expected user ID (which it
47-
knows because it is the recipient of her `m.key.verification.request`
48-
message),
49-
- Bob's keys encoded in the QR code match the keys that she already has for
44+
- Bob's key encoded in the QR code match the key that she already has for
5045
Bob, and
5146
- Alice's cross-signing key matches the cross-signing key encoded in the QR
5247
code.
@@ -111,9 +106,8 @@ In the first example, Osborne2 scans Dynabook:
111106
it via cross-signing, and to trust other devices via cross-signing.
112107
2. Dynabook retrieves Alice's public cross-signing key from the server, and
113108
displays a QR code that encodes:
114-
- Alice's user ID,
115109
- Dynabook's device key,
116-
- what it thinks Alice's master key is, as the `other_user_key` parameter, and
110+
- what it thinks Alice's master key is, and
117111
- a random shared secret.
118112

119113
Note that in this case, the QR code does not include Alice's master key in a
@@ -138,11 +132,8 @@ In the second example, Dynabook scans Osborne2:
138132
it via cross-signing, and to trust other devices via cross-signing.
139133
2. Osborne2 notices that Dynabook is a new device. Osborne2 fetches Dynabook's
140134
identity key and displays a QR code that encodes:
141-
- Alice's user ID,
142-
- Osborne2's device key (optional),
143-
- what it thinks Dynabook's key is, as `other_device_key`,
144-
- Alice's master key as a `key_<key_id>` parameter and (optionally) a `other_user_key`
145-
parameter, and
135+
- what it thinks Dynabook's key is,
136+
- Alice's master key, and
146137
- a random shared secret.
147138
3. Dynabook scans the QR code shown by Osborne2. At this point, Dynabook knows
148139
Alice's cross-signing key, and so it can trust it to sign other devices. It
@@ -163,12 +154,12 @@ This proposal defines three verification methods that can be used in
163154
`m.key.verification.request` messages (see
164155
[MSC2241](https://github.com/matrix-org/matrix-doc/pull/2241)).
165156

166-
- `m.qr_code.show.v1`: means that the sender of the
157+
- `m.qr_code.show.v2`: means that the sender of the
167158
`m.key.verification.request` message can show a QR code that the recipient
168159
can scan. If the recipient can scan the QR code, it should allow the user to
169160
do so. This method is never sent as part of a `m.key.verification.start`
170161
message.
171-
- `m.qr_code.scan.v1`: means that the sender of the
162+
- `m.qr_code.scan.v2`: means that the sender of the
172163
`m.key.verification.request` message can scan a QR code displayed by the
173164
recipient. If the recipient can display a QR code, it should allow the user
174165
to display it so that the sender can scan it. This method is never sent as
@@ -179,34 +170,51 @@ This proposal defines three verification methods that can be used in
179170

180171
### QR code format
181172

182-
The QR codes to be displayed and scanned using this format will encode URLs of
183-
the form:
184-
`https://matrix.to/#/<user-id>?request=<event-id>&action=verify&key_<keyid>=<key-in-base64>...&secret=<shared-secret>&other_user_key=<master-key-in-base64>`
185-
(when `matrix:` URLs are specced, this will be used instead).
186-
187-
- `request`: is the event ID or `transaction_id` of the associated verification
188-
request event.
189-
- `key_<key_id>`: each key that the user wants verified will have an entry of
190-
this form, where the value is the key in unpadded base64. The QR code should
191-
contain at least the user's master cross-signing key. In the case where a
192-
device does not have a cross-signing key (as in the case where a user logs in
193-
to a new device, and is verifying against another device), thin the QR code
194-
should contain at least the device's key.
195-
- `secret`: is a random single-use shared secret in unpadded base64. It must be
196-
at least 256-bits long (43 characters when base64-encoded).
197-
- `other_user_key`: the other user's master cross-signing key, in unpadded
198-
base64. In other words, if Alice is displaying the QR code, this would be
199-
the copy of Bob's master cross-signing key that Alice has.
200-
- `other_device_key`: the other device's key, in unpadded base64. This is only
201-
needed when a user is verifying their own devices, where the other device has
202-
not yet been signed with the cross-signing key.
203-
204-
The QR codes to be displayed and scanned, which are not a part of an in-person
205-
verification (for example, for printing on business cards), will encode URLs of
206-
the form:
207-
`https://matrix.to/#/<user-id>?action=verify&key_<keyid>=<key-in-base64>...`
208-
In this case, only the user scanning the QR code will verify the key of the
209-
user whose QR code was scanned; bi-directional verification is not possible.
173+
The QR codes to be displayed and scanned using this format will encode binary
174+
strings in the general form:
175+
176+
- the ASCII string "MATRIX"
177+
- one byte indicating the QR code version (must be `0x02`)
178+
- one byte indicating the QR code verification mode. May be one of the
179+
following values:
180+
- `0x00` verifying another user with cross-signing
181+
- `0x01` self-verifying in which the current device does trust the master key
182+
- `0x02` self-verifying in which the current device does not yet trust the
183+
master key
184+
- the event ID or `transaction_id` of the associated verification
185+
request event, encoded as:
186+
- two bytes in network byte order (big-endian) indicating the length of the
187+
ID
188+
- the ID as an ASCII string
189+
- the first key, as 32 bytes. The key to use depends on the mode field:
190+
- if `0x00` or `0x01`, then the user's own master cross-signing public key
191+
- if `0x02`, then the current device's device key
192+
- the second key, as 32 bytes. The key to use depends on the mode field:
193+
- if `0x00`, then what the device thinks the other user's master
194+
cross-signing key is
195+
- if `0x01`, then what the device thinks the other device's device key is
196+
- if `0x02`, then what the device thinks the user's master cross-signing key
197+
is
198+
- a random shared secret, as a byte string. It is suggested to use a secret
199+
that is about 8 bytes long. Note: as we do not share the length of the
200+
secret, and it is not a fixed size, clients will just use the remainder of
201+
binary string as the shared secret.
202+
203+
For example, if Alice displays a QR code encoding the following binary string:
204+
205+
```
206+
"MATRIX" |ver|mode| len | event ID
207+
4D 41 54 52 49 58 02 00 00 2D 21 41 42 43 44 ...
208+
| user's cross-signing key | other user's cross-signing key | shared secret
209+
00 01 02 03 04 05 06 07 ... 10 11 12 13 14 15 16 17 ... 20 21 22 23 24 25 26 27
210+
```
211+
212+
this indicates that Alice is verifying another user (say Bob), in response to
213+
the request from event "!ABCD...", her cross-signing key is
214+
`0001020304050607...` (which is "AAECAwQFBg..." in base64), she thinks that
215+
Bob's cross-signing key is `1011121314151617...` (which is "EBESExQVFh..." in
216+
base64), and the shared secret is `2021222324252627` (which is "ICEiIyQlJic" in
217+
base64).
210218

211219
### Message types
212220

@@ -218,7 +226,7 @@ message contents:
218226

219227
- `method`: `m.reciprocate.v1`
220228
- `m.relates_to`: as per [key verification framework](https://github.com/matrix-org/matrix-doc/pull/2241)
221-
- `secret`: the shared secret from the QR code
229+
- `secret`: the shared secret from the QR code, encoded using unpadded base64
222230

223231
Example:
224232

@@ -257,7 +265,9 @@ Tradeoffs/Alternatives
257265

258266
Other methods of verifying keys, which do not require scanning QR codes, are
259267
needed for devices that are unable to scan QR codes. One such method is
260-
[MSC1267](https://github.com/matrix-org/matrix-doc/issues/1267).
268+
[MSC1267](https://github.com/matrix-org/matrix-doc/issues/1267). Since the key
269+
verification framework allows for multiple methods to be supported, clients can
270+
allow users to use different methods depending on their capability.
261271

262272
Rather than embedding the keys in the QR codes directly, the two clients could
263273
perform an exchange similar to
@@ -267,14 +277,13 @@ the clients must exchange several messages before they can verify each other,
267277
which would delay showing the QR codes. This proposal is also simpler to
268278
implement.
269279

280+
This proposal does not support the case of asynchronous verification, such as
281+
printing a QR code on a business card for others to scan. That may be address
282+
in a separate MSC.
283+
270284
Security Considerations
271285
-----------------------
272286

273-
The first check in Step 6 in the example flow is to ensure that Bob does not
274-
present a QR code claiming to be Carol's key. Without this check, Bob will be
275-
able to trick Alice into verifying a key under his control, and evesdropping on
276-
Alice's communications with Carol.
277-
278287
The security of verifying Alice's key depends on Bob not hitting the "Verified"
279288
button (step 10 in the example flow) until after Alice's device indicates
280289
success or failure. Users have a tendency to click on buttons without reading

0 commit comments

Comments
 (0)