From 6e42f10bccddd19901fe859dd4b95c7fda04967a Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 22 Feb 2024 09:38:21 +0000 Subject: [PATCH 01/32] Placeholder --- proposals/xxxx-oidc-qr-login.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 proposals/xxxx-oidc-qr-login.md diff --git a/proposals/xxxx-oidc-qr-login.md b/proposals/xxxx-oidc-qr-login.md new file mode 100644 index 00000000000..d9fdc93543c --- /dev/null +++ b/proposals/xxxx-oidc-qr-login.md @@ -0,0 +1,13 @@ +# MSC0000: Mechanism to allow OIDC sign in and E2EE set up via QR code + +## Proposal + +## Potential issues + +## Alternatives + +## Security considerations + +## Unstable prefix + +## Dependencies From d90eda1529c867b0acc6ef7adda02d9e0267a807 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 22 Feb 2024 09:40:21 +0000 Subject: [PATCH 02/32] MSC4108 --- proposals/{xxxx-oidc-qr-login.md => 4108-oidc-qr-login.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename proposals/{xxxx-oidc-qr-login.md => 4108-oidc-qr-login.md} (65%) diff --git a/proposals/xxxx-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md similarity index 65% rename from proposals/xxxx-oidc-qr-login.md rename to proposals/4108-oidc-qr-login.md index d9fdc93543c..c32c61a6696 100644 --- a/proposals/xxxx-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1,4 +1,4 @@ -# MSC0000: Mechanism to allow OIDC sign in and E2EE set up via QR code +# MSC4108: Mechanism to allow OIDC sign in and E2EE set up via QR code ## Proposal From f7bbba399123cf537358d1a6e01e63b00064d647 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 3 Apr 2024 16:55:44 +0100 Subject: [PATCH 03/32] WIP of MSC4108 --- proposals/4108-oidc-qr-login.md | 1166 +++++++++++++++++++++++++++++++ 1 file changed, 1166 insertions(+) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index c32c61a6696..f72eb8cf3a4 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1,13 +1,1179 @@ # MSC4108: Mechanism to allow OIDC sign in and E2EE set up via QR code +We propose a method to allow an existing authenticated Matrix client to sign in a new client by scanning a QR code. The +new client will be a fully bootstrapped Matrix cryptographic device, possessing all the necessary secrets, namely the +cryptographic user identity ("cross-signing") and the server-side key backup decryption key (if used). + +This MSC supersedes [MSC3906](https://github.com/matrix-org/matrix-spec-proposals/pull/3906), +[MSC3903](https://github.com/matrix-org/matrix-spec-proposals/pull/3903) and +[MSC3886](https://github.com/matrix-org/matrix-spec-proposals/pull/3886) which achieved a similar feature but did not +work with a homeserver using the delegated OIDC mechanism proposed by [MSC3861](https://github.com/matrix-org/matrix-spec-proposals/pull/3861). + ## Proposal +Depending on the pair of devices used, it may be preferable to scan the QR code on either the new or existing device, +based on the availability of a camera. As such, this proposal allows for the generation of the QR on either device. + +In order for the new device to be fully set up, it needs to exchange information with an existing device such that: + +- The new device knows which homeserver to use +- The existing device can facilitate the new device in getting an access token +- The existing device shares the secrets necessary to set up end-to-end encryption + +### Insecure rendezvous session + +It is proposed that an HTTP-based protocol be used to establish an ephemeral bi-directional communication session over +which the two devices can exchange the necessary data. This session is described as "insecure" as it provides no +end-to-end confidentiality nor authenticity by itself—these are layered on top of it. + +#### High-level description + +TODO + +#### The send mechanism + +Every send request MUST include an `ETag` header, whose value is supplied by the `ETag` header in the last `GET` +response seen by the requester. (The initiating device may also use the `ETag` supplied in the initial `POST` response +to immediately update the payload.) Updates will succeed only if the supplied `ETag` matches the server's current +revision of the payload. This prevents concurrent writes to the payload. + +The `ETag` header is standard, described by [RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-etag). In this +proposal we only accept strong, single-valued `ETag` values; anything else constitutes a malformed request. + +n.b. Once a new payload has been sent there is no mechanism to retrieve previous payloads. + +#### Expiry + +The rendezvous session (i.e. the payload) SHOULD expire after a period of time communicated to clients via the `Expires` +header. After this point, any further attempts to query or update the payload MUST fail. The expiry time SHOULD be +extended every time the payload is updated. The rendezvous session can be manually expired with a `DELETE` call to the +rendezvous session. + +#### Threat analysis + +##### Denial of Service attack surface + +Because the rendezvous session protocol allows for the creation of arbitrary channels and storage of arbitrary data, it +is possible to use it as a denial of service attack surface. + +As such, the following standard mitigations such as the following may be deemed appropriate by homeserver +implementations and administrators: + +- rate limiting of requests +- imposing a low maximum payload size (e.g. kilobytes not megabytes) +- limiting the number of concurrent sessions + +##### Data exfiltration + +Because the rendezvous session protocol allows for the storage of arbitrary data, it +is possible to use it to circumvent firewalls and other network security measures. + +Implementation may want to block their production IP addresses from being able to make requests to the rendezvous +endpoints in order to avoid attackers using it as a dead-drop for exfiltrating data. + +#### API + +TODO + +### Secure channel + +The above rendezvous session is insecure, providing no confidentiality nor authenticity against the rendezvous server or +even arbitrary network participants which possess the rendezvous session server and ID. To provide a secure channel on +top of this insecure rendezvous session transport, we propose the following scheme. + +This scheme is essentially[ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme#Formal_description_of_ECIES) +instantiated with X25519, HKDF-SHA256 for the KDF and ChaCha20-Poly1305 (as specified by +[RFC8439](https://datatracker.ietf.org/doc/html/rfc8439#section-2.8)) for the authenticated encryption. Therefore, +existing security analyses of ECIES are applicable in this setting too. Nevertheless we include below a short +description of our instantiation of ECIES and discuss some potential pitfalls and attacks. + +The primary limitation of ECIES is that there is no authentication for the initiating party (the one to send the first +message; Device S in the text below). Thus the recipient party (the one to receive the first message; Device G in the +text below) has no assurance as to who actually sent the message. In QR code login, we work around this problem by +exploiting the fact that both of these devices are physically present during the exchange and offloading the check that +they are both in the correct state to the user performing the QR code login process. + +#### Establishment + +Participants: + +- Device G (the device generating the QR code) +- Device S (the device scanning the QR code) + +Regardless of which device generates the QR code, either device can be the existing (already signed in) device. The +other device is then the new device (one seeking to be signed in). + +Symmetric encryption uses deterministic nonces, incrementing by `2` with each message. Device S starts with `0`, using only +even nonces. Device A starts with `1`, using only odd nonces. + +1. **Ephemeral key pair generation** + + Both devices generate an _ephemeral_ Curve25519 key pair: + +- Device G generates **(Gp, Gs)**, where **Gp** is its public key and **Gs** the private (secret) key. +- Device S generates **(Sp, Ss)**, where **Sp** is its public key and **Ss** the private (secret) key. + +1. **Create rendezvous session** + +Device G creates a rendezvous session by making a `POST` request (as described previously) to the nominated homeserver +with an empty payload. It parses the **id** and **server** received. + +1. **Initial key exchange** + +Device G displays a QR code containing: + +- its public key **Gp** +- the insecure rendezvous session **URL** +- An indicator (the **intent**) to say if this is a new device which wishes to "initiate" a login, or an existing device +that wishes to "reciprocate" a login +- If the intent is to reciprocate a login, then the **homeserver base URL** + +To get a good trade-off between visual compactness and high level of error correction we use a binary mode QR with a +similar structure to that of the existing Device Verification QR code encoding described in [Client-Server API](https://spec.matrix.org/v1.9/client-server-api/#qr-code-format). + +This is defined in detail in a separate section of this proposal. + +Device S scans and parses the QR code to obtain **Gp**, the rendezvous session **URL**, **intent** and optionally the +**homeserver base URL**. + +At this point Device S should check that the received intent matches what the user has asked to do on the device. + +1. **Device S sends the initial message** + +Device S computes a shared secret **SH** using ECDH between **Ss** and **Gp**, thereby establishing a secure channel +with Device G which can be layered on top of the insecure rendezvous session transport. It then discards **Ss** and +derives a symmetric encryption **EncKey** from **SH** using HKDF_SHA256, each 32 bytes in length. + +Device S derives a confirmation message that Device G can use to confirm that the channel is secure. It contains: + +- The string `MATRIX_QR_CODE_LOGIN_INITIATE`, encrypted and authenticated with ChaCha20-Poly1305. +- Its public ephemeral key **Sp**. + +``` +Nonce := 0 +SH := ECDH(Ss, Gp) +EncKey := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN|" || Gp || "|" || Sp, salt=0, size=32) +NonceBytes := ToLowEndianBytes(Nonce)[..12] +TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey, NonceBytes, "MATRIX_QR_CODE_LOGIN_INITIATE") +Nonce := Nonce + 2 +LoginInitiateMessage := UnpaddedBase64(TaggedCiphertext) || "|" || UnpaddedBase64(Sp) +``` + +Device S then sends the **LoginInitiateMessage** as the payload to the rendezvous session using a `PUT` request with +`Content-Type` header set to `text/plain`. + +1. **Device G confirms** + +Device G receives **LoginInitiateMessage** (potentially coming from Device S) from the insecure rendezvous session by +polling with `GET` requests. + +It then does the reverse of the previous step, obtaining **Sp**, deriving the shared secret using **Gs** and **Sp**, +discarding **Gs** and decrypting (and authenticating) the **TaggedCiphertext**, obtaining a plaintext. + +It checks that the plaintext matches the string `MATRIX_QR_CODE_LOGIN_INITIATE`, failing and aborting if not. + +It then responds with a dummy message containing the string `MATRIX_QR_CODE_LOGIN_OK` encrypted with **SH** calculated +as follows: + +``` +Nonce := 1 +NonceBytes := ToLowEndianBytes(Nonce)[..12] +TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey, NonceBytes, "MATRIX_QR_CODE_LOGIN_OK") +Nonce := Nonce + 2 +LoginOkMessage := UnpaddedBase64Encode(TaggedCiphertext) +``` + +Device G sends **LoginOkMessage** as the payload via `PUT` request with `Content-Type` header set to `text/plain` to the +insecure rendezvous session. + +1. **Verification by Device S** + +Device S receives a response over the insecure rendezvous session by polling with `GET` requests, potentially from +Device G. + +It decrypts (and authenticates) it using the previously computed encryption key, which will succeed provided the message +was indeed sent by Device G. It then verifies the plaintext matches `MATRIX_QR_CODE_LOGIN_OK`, failing otherwise. + +``` +Nonce_G := 1 +(TaggedCiphertext, Sp) := Unpack(Message) +NonceBytes := ToLowEndianBytes(Nonce)[..12] +Plaintext := ChaCha20Poly1305_Decrypt(EncKey, NonceBytes, TaggedCiphertext) +Nonce_G := Nonce_G + 2 + +unless Plaintext == "MATRIX_QR_CODE_LOGIN_OK": + FAIL +``` + +If the above was successful, Device S then calculates a two digit **CheckCode** code derived from **SH**, **Gp** and **Sp**: + +``` +CheckBytes := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_CHECKCODE|" || Gp "|" || Sp , salt=0, size=2) +CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) +``` + +Device S then displays an indication to the user that the secure channel has been established and that the **CheckCode** +should be entered on the other device when prompted. e.g. wording to say "secure connection established"; enter the code +XY on your other device; + +1. **Out-of-band confirmation** + +**Warning**: *This step is crucial for the security of the scheme since it overcomes the aforementioned limitation of ECIES.* + +Device G asks the user to enter the **CheckCode** that is being displayed on Device S. + +The purpose of the code being entered is to ensure that the user has actually checked their other device rather than +just pressing "continue", and that the Device S has been able to determine that the channel is secure. + +Device G compares the code that the user has entered with the **CheckCode** that it calculates using the same mechanism +as before: + +``` +CheckBytes := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_CHECKCODE|" || Gp "|" || Sp , salt=0, size=2) +CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) +``` + +If the code that the user enters matches then the secure channel is established. + +Subsequent messages can be sent encrypted with **EncKey** with the nonces incremented as described above. + +#### Sequence diagram + +The sequence diagram for the above is as follows: + +```mermaid +sequenceDiagram + participant G as Device G + participant Z as Rendezvous server + participant S as Device S + + note over G,S: 1) Devices G and S each generate an ephemeral Curve25519 key pair + + activate G + note over G: 2) Device G creates a rendezvous session as follows + G->>+Z: POST /_matrix/client/rendezvous + Z->>-G: 201 Created
Location: /_matrix/client/rendezvous/abc-def
ETag: 1 + + note over G: 3) Device G generates and displays a QR code containing
its ephemeral public key and the rendezvous session URL + + G-->>S: Device S scans the QR code shown by Device G + deactivate G + + activate S + note over S: Device S validates QR scanned and the rendezvous session URL + + S->>+Z: GET /_matrix/client/rendezvous/abc-def + Z->>-S: 200 OK
ETag: 1 + + note over S: 4) Device S computes SH, EncKey and LoginInitiateMessage.
It sends LoginInitiateMessage via the rendezvous session + S->>+Z: PUT /_matrix/client/rendezvous/abc-def
If-Match: 1
Body: LoginInitiateMessage + Z->>-S: 202 Accepted
ETag: 2 + deactivate S + + G->>+Z: GET /_matrix/client/rendezvous/abc-def
If-None-Match: 1 + activate G + Z->>-G: 200 OK
ETag: 2
Body: Data + + note over G: 5) Device G attempts to parse Data as LoginInitiateMessage after calculating SH and EncKey + note over G: Device G checks that the plaintext matches MATRIX_QR_CODE_LOGIN_INITIATE + + note over G: Device G computes LoginOkMessage and sends to the rendezvous session + + G->>+Z: PUT /_matrix/client/rendezvous/abc-def
If-Match: 2
Body: LoginOkMessage + Z->>-G: 202 Accepted
ETag: 3 + deactivate G + + activate S + S->>+Z: GET /_matrix/client/rendezvous/abc-def
If-None-Match: 2 + Z->>-S: 200 OK
ETag: 3
Body: Data + + note over S: 6) Device S attempts to parse Data as LoginOkMessage + note over S: Device S checks that the plaintext matches MATRIX_QR_CODE_LOGIN_OK + + note over S: If okay, Device S calculates the CheckCode to be displayed + note over S: Device S displays a green checkmark, "secure connection established" and the CheckCode + note over S: Device S knows that the channel is secure + deactivate S + + note over G: 7) Device G asks the user to confirm that the other device is showing a green checkmark and enter the CheckCode + note over G: If the user enters the correct CheckCode and confirms that a green checkmark is shown then Device G knows that the channel is secure +``` + +#### Secure operations + +Conceptually, once established, the secure channel offers two operations, `SecureSend` and `SecureReceive`, which wrap +the `Send` and `Receive` operations offered by the rendezvous session API to securely send and receive data between two devices. + +At the end of the establishment phase, the next nonce for Device G should be `3` and the next nonce for Device S should +be `2`. + +Device G sets: + +``` +Nonce := 3 +NonceOther = 2 +``` + +Device S sets: + +``` +Nonce := 2 +NonceOther := 3 +``` + +#### Threat analysis + +In an attack scenario, we add a participant called Specter with the following capabilities: + +- Specter is present for QR code generation/scanning ("shoulder-surfing") and can scan the code themselves. +- Specter has full control over the network (in a Dolev-Yao sense), being able to observe and modify all traffic. +- Specter controls both the homeserver and the rendezvous server. + +##### Replay protection + +Due to use of ephemeral key pairs which are immediately discarded after use, each QR code login session derives a unique +secret so messages from earlier sessions cannot be replayed. Each message in the session is unique and expected only +once. Finally, the use of deterministic nonces prevents any possibility of replay. + +##### Pure Dolev-Yao attacker + +An attacker with control over the network but _not_ present for the QR code scanning cannot thwart the process since +they are unable to obtain the ephemeral key **Gp** of Device G. + +##### Shoulder-surfing attacker (Specter) + +Since Device G has no way of authenticating Device S, an attacker present for the QR code scanning can learn **Gp** and +attempt to mimic Device S in order to get their Device S signed in instead. + +- In step 3, Specter can shoulder surf the QR code scanning to obtain **Gp**. +- In step 4, Specter can intercept S’s message and replace it with a message of their own, replacing **Sp** with its +own key. +- The attack is only thwarted in step 7, because Device S won’t ever display the indicator of success to the user. The +user then must cancel the process on Device G, preventing it from sharing any sensitive material. + +### The OIDC login part and set up of E2EE + +Once the secure channel has been established, the two devices can then communicate securely. + +#### Login via OIDC Device Authorization Grant + +In this section the sequence of steps depends on whether the new device generated or scanned the QR code. + +For example, in the case that the new device scanned the QR code it is the first to do a `SecureSend` whereas if the new +device generated the QR then the existing device is the first to do a `SecureSend`. + +This can make it hard to read what is going on. + +1. **Homeserver discovery** + +The new device needs to know which homeserver it will be authenticating with. + +In the case that the new device scanned the QR code then the homeserver base URL can be taken from the QR code and the +new device proceeds to step 2 immediately. + +Otherwise the new device waits to be informed by receiving an `m.login.protocols` message from the existing device. + +The existing device would need to determine which "protocols" are available for the new device to use. + +Currently this could only be device_authorization_grant meaning the OIDC Provider supports the +`urn:ietf:params:oauth:grant-type:device_code` grant type. + +If it is available then the existing device informs the new device by sending the `m.login.protocols` message with the +homeserver specified: + +*Existing device => New device via secure channel* + +```json +{ + "type": "m.login.protocols", + "protocols": ["device_authorization_grant"], + "homeserver": "https://synapse-oidc.lab.element.dev" +} +``` + +1. **New device checks if it can use an available protocol** + +Once the existing device knows which homeserver it is to use it then: + +- checks that the homeserver is using delegated OIDC by calling `GET /_matrix/client/v1/auth_issuer` from [MSC2965](https://github.com/matrix-org/matrix-spec-proposals/pull/2965): + +*New device => Homeserver via HTTP* + +```http +GET /_matrix/client/v1/auth_issuer HTTP/1.1 +Host: synapse-oidc.lab.element.dev +Accept: application/json +``` + +With response like: + +```http +200 OK +Content-Type: application/json + +{ + "issuer": "https://auth-oidc.lab.element.dev/" +} +``` + +- parses the OIDC Provider (`issuer`) from the response +- fetches the OIDC Provider metadata as per [MSC2965](https://github.com/matrix-org/matrix-spec-proposals/pull/2965): + +*New device => OIDC Provider via HTTP* + +```http +GET /.well-known/openid-configuration HTTP/1.1 +Host: auth-oidc.lab.element.dev +Accept: application/json +``` + +With response like: + +```http +200 OK +Content-Type: application/json + +{ + "issuer": "https://auth-oidc.lab.element.dev/", + "authorization_endpoint": "https://auth-oidc.lab.element.dev/authorize", + "token_endpoint": "https://auth-oidc.lab.element.dev/oauth2/token", + "jwks_uri": "https://auth-oidc.lab.element.dev/oauth2/keys.json", + "registration_endpoint": "https://auth-oidc.lab.element.dev/oauth2/registration", + "scopes_supported": ["openid", "email"], + "response_types_supported": [...], + "response_modes_supported": [...], + "grant_types_supported": [ + "authorization_code", + "refresh_token", + "client_credentials", + "urn:ietf:params:oauth:grant-type:device_code" + ], + ... + "device_authorization_endpoint": "https://auth-oidc.lab.element.dev/oauth2/device" +} +``` + +- either does Dynamic Client Registration as per [MSC2966](https://github.com/matrix-org/matrix-spec-proposals/pull/2966) +or uses a static OIDC client_id. We will use `my_client_id` as an example `client_id`. + +- sends a [RFC8628 Device Authorization Request](https://datatracker.ietf.org/doc/html/rfc8628#section-3.1) to the OIDC +Provider using the `device_authorization_endpoint`: + +*New device => OIDC Provider via HTTP* + +```http +POST /oauth2/device HTTP/1.1 +Host: auth-oidc.lab.element.dev +Content-Type: application/x-www-form-urlencoded + +client_id=my_client_id&scope=openid%20urn%3Amatrix%3Aclient%3Aapi%3A%2A%20urn%3Amatrix%3Aclient%3Adevice%3AABCDEGH +``` + +With response like: + +```http +200 OK +Content-Type: application/json + +{ + "device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS", + "user_code": "123456", + "verification_uri": "https://auth-oidc.lab.element.dev/link", + "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456", + "expires_in": 1800, + "interval": 5 +} +``` + +- parses the [Device Authorization Response](https://datatracker.ietf.org/doc/html/rfc8628#section-3.2) above + +At this point the new device knows that, subject to the user consenting, it should be able to complete the login + +1. **New device informs existing device that it wants to use the device_authorization_grant** + +The new device send the `verification_uri` and, if present, the `verification_uri_complete` over to the existing device and +indicates that want to use protocol `device_authorization_grant` along with the `device_id` that will be used: + +*New device => Existing device via secure channel* + +```json +{ + "type": "m.login.protocol", + "protocol": "device_authorization_grant", + "device_authorization_grant": { + "verification_uri": "https://auth-oidc.lab.element.dev/link", + "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456" + }, + "device_id": "ABCDEFGH" +} +``` + +The sequence for steps 1 to 3 is as follows: (the sequence depending on which device has scanned the code varies for readability) + +_New device scanned QR code:_ + +```mermaid +sequenceDiagram + title: Variant: New device scanned QR code + participant E as Existing device
already signed in + participant Z as Rendezvous server + participant N as New device
wanting to sign in + participant OP as OIDC Provider + participant HS as Homeserver + + + rect rgba(255,0,0, 0.1) + #alt if New device scanned QR code + note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel + note over N: 1) New device got Homeserver base URL from QR code + + #else if Existing device scanned QR code + # note over E: Existing device completes step 6 + # note over E: Existing device displays checkmark and CheckCode + # note over E: 1) Existing device sends m.login.protocols message + # E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"}) + # note over N: New device waits for user to confirm secure channel from step 7 + # Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"} + # note over N: If user enters the correct CheckCode and confirms checkmark
then new device now trusts the channel, and uses the homeserver provided + end + + + rect rgba(0,255,0, 0.1) + note over N: 2) New device checks if it can use an available protocol: + + N->>+HS: GET /_matrix/client/v1/auth_issuer + activate N + HS-->>-N: 200 OK {"issuer": "https://id.matrix.org"} + Note over N: New device checks that it can communicate
with the issuer (OIDC Provider). Completing dynamic registration if needed + N->>+OP: GET /.well-known/openid-configuration + OP->>-N: 200 OK {..., "device_authorization_endpoint":
"https://id.matrix.org/auth/device", ...} + Note over N: Device now knows the OP and what the endpoint is, so then attempts to start the login + N->>+OP: POST /auth/device client_id=xyz&scope=openid+urn:matrix:api:*+urn:matrix:device:ABCDEFGH... + OP->>-N: 200 OK {"user_code": "123456",
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"expires_in_ms": 120000, "device_code": "XYZ", "interval": 1} + note over N: 3) New device informs existing device of choice of protocol: + N->>Z: SecureSend({"type": "m.login.protocol", "protocol": "device_authorization_grant",
"device_authorization_grant":{
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"verification_uri": ...}, "device_id": "ABCDEFGH"}) + + deactivate N + end + + rect rgba(255,0,0, 0.1) + # alt if New device scanned QR code + note over N: New device displays checkmark and CheckCode + note over E: Existing device waits for user to enter CheckCode
and confirm secure channel from step 7 + end + + rect rgba(0,255,0, 0.1) + Z->>E: SecureReceive() => {"type": "m.login.protocol", "protocol": "device_authorization_grant",
"device_authorization_grant":{
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"verification_uri": ...}, "device_id": "ABCDEFGH"} + end + + rect rgba(255,0,0, 0.1) + # alt if New device scanned QR code + note over E: If user entered correct CheckCode
and confirms checkmark then existing device now trusts the channel + end + + + rect rgba(0,255,0, 0.1) + note over E: Existing device checks that requested protocol is supported + + alt if requested protocol is not valid + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported",
"homeserver": "https://matrix-client.matrix.org}) + end + end +``` + +_Existing device scanned QR code:_ + +```mermaid +sequenceDiagram + title: Variant: Existing device scanned QR code + participant E as Existing device
already signed in + participant Z as Rendezvous server + participant N as New device
wanting to sign in + participant OP as OIDC Provider + participant HS as Homeserver + + + #alt if New device scanned QR code + # note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel + # note over N: 1) New device got Homeserver base URL from QR code + + rect rgba(0,0,255, 0.1) + #else if Existing device scanned QR code + note over E: Existing device completes step 6 + note over E: Existing device displays checkmark and CheckCode + note over E: 1) Existing device sends m.login.protocols message + E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"}) + note over N: New device waits for user to confirm secure channel from step 7 + Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"} + note over N: If user enters the correct CheckCode and confirms checkmark
then new device now trusts the channel, and uses the homeserver provided + end + + + rect rgba(0,255,0, 0.1) + note over N: 2) New device checks if it can use an available protocol: + N->>+HS: GET /_matrix/client/v1/auth_issuer + activate N + HS-->>-N: 200 OK {"issuer": "https://id.matrix.org"} + Note over N: New device checks that it can communicate
with the issuer (OIDC Provider). Completing dynamic registration if needed + N->>+OP: GET /.well-known/openid-configuration + OP->>-N: 200 OK {..., "device_authorization_endpoint":
"https://id.matrix.org/auth/device", ...} + Note over N: Device now knows the OP and what the endpoint is, so then attempts to start the login + N->>+OP: POST /auth/device client_id=xyz&scope=openid+urn:matrix:api:*+urn:matrix:device:ABCDEFGH... + OP->>-N: 200 OK {"user_code": "123456",
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"expires_in_ms": 120000, "device_code": "XYZ", "interval": 1} + note over N: 3) New device informs existing device of choice of protocol: + N->>Z: SecureSend({"type": "m.login.protocol", "protocol": "device_authorization_grant",
"device_authorization_grant":{
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"verification_uri": ...}, "device_id": "ABCDEFGH"}) + + deactivate N + end + + # alt if New device scanned QR code + # note over N: New device displays checkmark and CheckCode + # note over E: Existing device waits for user to enter CheckCode
and confirm secure channel from step 7 + #end + + rect rgba(0,255,0, 0.1) + Z->>E: SecureReceive() => {"type": "m.login.protocol", "protocol": "device_authorization_grant",
"device_authorization_grant":{
"verification_uri_complete": "https://id.matrix.org/device/abcde",
"verification_uri": ...}, "device_id": "ABCDEFGH"} + end + + # alt if New device scanned QR code + # note over E: If user entered correct CheckCode
and confirms checkmark then existing device now trusts the channel + #end + + + rect rgba(0,255,0, 0.1) + note over E: Existing device checks that requested protocol is supported + + alt if requested protocol is not valid + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported",
"homeserver": "https://matrix-client.matrix.org}) + end + end +``` + +Then we continue with the actual login: + +1. **New device waits for approval from OIDC Provider** + +On receipt of the `m.login.protocol_accepted` message: + +- In accordance with [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628#section-3.3.1) the new device must display +the user_code in order that the user can confirm it on the OIDC Provider if required. +- The new device then starts to poll the OIDC Provider by making +[Device Access Token Requests](https://datatracker.ietf.org/doc/html/rfc8628#section-3.4) using the interval and bounded +by expires_in. + +*New device => OIDC Provider via HTTP* + +```http +POST /oauth2/token HTTP/1.1 +Host: auth-oidc.lab.element.dev +Content-Type: application/x-www-form-urlencoded + +grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code + &device_code=GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS + &client_id=my_client_id +``` + +- It then parses the [Device Access Token Response](https://datatracker.ietf.org/doc/html/rfc8628#section-3.5) and +handles the different responses +- If the user consents in the next step then the new device will receive an `access_token` and `refresh_token` etc. as +normal for OIDC with MSC3861. + +1. **User is asked by OIDC Provider to consent on existing device** + +On receipt of the `m.login.protocol` message above, and having completed step 7 of the secure channel establishment, the +existing device then asserts that there is no existing device corresponding to the `device_id` from the +`m.login.protocol` message. + +It does so by calling [GET /_matrix/client/v3/devices/](https://spec.matrix.org/v1.9/client-server-api/#get_matrixclientv3devicesdeviceid) +and expecting to receive an HTTP 404 response. + +If the device already exists then the login request should be rejected with an `m.login.failure`. + +If no existing device was found then the existing device opens the `verification_uri_complete` - falling back to the +`verification_uri`, if `verification_uri_complete` isn’t present - in a system browser. + +Ideally this is in a trusted/secure environment where the cookie jar and password manager features are available. e.g. +on iOS this could be a `ASWebAuthenticationSession` + +The existing device then sends an acknowledgement message to let the other device know that the consent process is in progress: + +*Existing device => New device via secure channel* + +```json +{ + "type": "m.login.protocol_accepted" +} +``` + +The user is then prompted to consent by the OIDC Provider. They may be prompted to undertake additional actions by the +OIDC Provider such as 2FA, but this is all handled within the browser. + +Note that the existing device does not see the new access token. This is one of the benefits of the OIDC architecture. + +The sequence diagram for steps 4 and 5 is as follows: + +```mermaid +sequenceDiagram + participant E as Existing device
already signed in + participant UA as Web Browser + participant N as New device
wanting to sign in + participant OP as OIDC Provider + participant HS as Homeserver + + rect rgba(0,255,0, 0.1) + + par + E->>N: SecureSend({"type":"m.login.protocol_accepted"}) + note over N: 4) New device polls the OIDC Provider awaiting the outcome as per RFC8628 OIDC + loop Poll for result at interval seconds + N->>OP: POST /token client_id=xyz
&grant_type=urn:ietf:params:oauth:grant-type:device_code
&device_code=XYZ + alt pending + OP-->>N: 400 Bad Request {"error": "authorization_pending"} + else granted + OP-->>N: 200 OK {"access_token": "...", "token_type": "Bearer", ...} + else denied + OP-->>N: 400 Bad Request {"error": "authorization_declined"} + else expired + OP-->>N: 400 Bad Request {"error": "expired_token"} + end + end + and + E->>UA: 5) Existing device opens
verification_uri_complete (with fallback to verification_uri)
in the system web browser/ASWebAuthenticationSession: + Note over E: n.b. in the case of a Web Browser the user needs to have
clicked a button in order for the navigation to happen + rect rgba(240,240,240,0.5) + UA->>OP: GET https://id.matrix.org/device/abcde + OP->>UA: consent screen showing the user_code + UA->>OP: POST /allow or /deny + end + Note over UA: User closes browser + end + + alt declined + Note over E: or can the OP tell the existing device the outcome? + N->>E: SecureSend({"type":"m.login.declined"}) + else approved + Note over N: Device now has an access_token and can start to talk to the homeserver + N->>E: SecureSend({ "type": "m.login.success" }) + end + end +``` + +#### Secret sharing and device verification + +Once the new device has logged in and obtained an access token it will want to obtain the secrets necessary to set up +end-to-end encryption on the device and make itself cross-signed. + +Before sharing the end-to-end encryption secrets the existing device should validate that the new device has +successfully obtained an access token from the OIDC Provider. The purpose of this is so that, if the user or OIDC +Provider has disallowed the login, the secrets are not leaked. + +If checked successfully then the existing device sends the following secrets to the new device: + +- The private cross-signing key triplet: MSK, SSK, USK +- The backup recovery key and the currently used backup version. + +This is achieved as following: + +1. **Existing device confirms that the new device has indeed logged in successfully** + +On receipt of an m.login.success message the existing device queries the homeserver to check that the is a device online +with the corresponding device_id (from the `m.login.protocol` message). + +It does so by calling [GET /_matrix/client/v3/devices/](https://spec.matrix.org/v1.9/client-server-api/#get_matrixclientv3devicesdeviceid) +and expecting to receive an HTTP 200 response. + +If the device isn’t immediately visible it can repeat the `GET` request for up to, say, 10 seconds to allow for any latency. + +If no device is found then the process should be stopped. + +1. **Existing device shares secrets with new device** + +The existing device sends a `m.login.secrets` message via the secure channel: + +```json +{ + "type": "m.login.secrets", + "cross_signing": { + "master_key": "$base64_of_the_key", + "self_signing_key": "$base64_of_the_key", + "user_signing_key": "$base64_of_the_key" + }, + "backup": { + "algorithm": "foobar", + "key": "base64_of_the_backup_recovery_key", + "backup_version": "version_string" + } +} +``` + +1. **New device cross-signs itself and uploads device keys** + +On receipt of the m.login.secrets message the new device can store the secrets locally + +The new device can then generate the cross-signing signature for itself. + +It can then use a single request to upload the device keys and cross signing signature. This removes the chance of other +devices seeing the new device as unverified, incorrectly prompting the user to verify the already verified device. + +The request would look just like any other `/keys/upload` request, it would just include one additional signature, the +one from the self-signing key. The request would look like follows: + +```http +POST /_matrix/client/v3/keys/upload HTTP/1.1 +Host: synapse-oidc.lab.element.dev +Content-Type: application/json + +{ + "device_keys": { + "algorithms": [ + "m.olm.v1.curve25519-aes-sha2", + "m.megolm.v1.aes-sha2" + ], + "device_id": "SGKMSRAGBF", + "keys": { + "curve25519:SGKMSRAGBF": "I11VOe5quKuH/YjdOqn5VcW06fvPIJQ9JX8ryj6ario", + "ed25519:SGKMSRAGBF": "b8gROFh+UIHLD/obY0+IlxoWiGtYVhKdqixvw4QHcN8" + }, + "signatures": { + "@testing_35:morpheus.localhost": { + "ed25519:SGKMSRAGBF": "ziHEUIsHnrYBH4CqYpN1JC/ex3t4VG3zvo16D8ORqN6yAErpsKsnd/5LDdZERIOB1MGffKGfCL6ny5V7rT9FCQ", + "ed25519:bkYgAVUNqvuyy8b1w09utJNJxBvK3hZB65xxoLPVzFo": "p257k0tfPF98OIDuXnFSJS2DmVlxO4sgTHdF41DTdZBCpTZfPwok6iASo3xMRKdyy3WMEgkQ6lzhEyRKKZBGBQ" + } + }, + "user_id": "@testing_35:morpheus.localhost" + } +} +``` + +The sequence diagram for this would look as follows: + +```mermaid +sequenceDiagram + participant E as Existing device
already signed in + participant N as New device
wanting to sign in + participant OP as OIDC Provider + participant HS as Homeserver + + rect rgba(0,255,0, 0.1) + + rect rgb(191, 223, 255) +note over N,E: This step is duplicated from the previous section for readability + N-->>+E: { "type": "m.login.success" } + end + + Note over E: 1) Existing device checks that the device is actually online: + + E->>HS: GET /_matrix/client/v3/devices/{device_id} +activate HS + + alt is device not found + HS->>E: 404 Not Found + E->>N: { "type": "m.login.failed", "reason": "TODO" } + else is device found + HS->>E: 200 OK +deactivate HS + +Note over E: TODO: how do we check that this is actually the newly signed in device? + + E->>-N: 2) { "type": "m.login.secrets", "cross_signing": {...}, "backup": {...} } + + activate N + note over N: 3) New device stores the secrets locally + +alt is cross_signing present in m.login.secrets? +note over N: New device signs itself + note over N: New device uploads device keys and cross-signing signature: + N->>+HS: POST /_matrix/client/v3/keys/upload + HS->>-N: 200 OK + +else + note over N: New device uploads device keys only: + N->>+HS: POST /_matrix/client/v3/keys/upload + HS->>-N: 200 OK +end + +alt is backup present in m.login.secrets? + note over N: New device connects to room-key backup +end + +note over N: All done! + deactivate N + end + end +``` + +#### Message reference + +These are the messages that are exchanged between the devices to negotiate the sign in and set up of E2EE. + +##### `m.login.protocols` + +Sent by: existing device + +Purpose: to state the available protocols for signing in. At the moment only "`device_authorization_grant` is supported + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.protocols`| +|`protocols`|required `string[]`|Array of: one of: `device_authorization_grant` | +|`homeserver`|required `string`|The base URL of the homeserver| + +```json +{ + "type": "m.login.protocols", + "protocols": ["device_authorization_grant"], + "homeserver": "https://matrix-client.matrix.org" +} +``` + +##### `m.login.protocol` + +Sent by: new device + +Purpose: the new device sends this to indicate which protocol it intends to use + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.protocol`| +|`protocol`|required `string`|One of: `device_authorization_grant`| +|`device_authorization_grant`|Required `object` where `protocol` is `device_authorization_grant`|These values are taken from the RFC8628 Device Authorization Response that the new device received from the OIDC Provider:
Field Type
verification_uri required string
verification_uri_complete string
| +|`device_id`|required `string`|The device ID that the new device will use| + +Example: + +```json +{ + "type": "m.login.protocol", + "protocol": "device_authorization_grant", + "device_authorization_grant": { + "verification_uri_complete": "https://id.matrix.org/device/abcde", + "verification_uri": "..." + }, + "device_id": "ABCDEFGH" +} +``` + +##### `m.login.protocol_accepted` + +Sent by: existing device + +Purpose: Indicates that the existing device has accepted the protocol request and will open the `verification_uri` (or +`verification_uri_complete`) for the user to grant consent + +Example: + +```json +{ + "type":"m.login.protocol_accepted" +} +``` + +##### `m.login.failure` + +Sent by: either device + +Purpose: used to indicate a failure + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.failure`| +|`reason`|required `string`| One of: `TODO`| +|`homeserver`|`string`| When the existing device is sending this it can include the Base URL of the homeserver so that the new device can at least save the user the hassle of typing it in| + +Example: + +```json +{ + "type":"m.login.failure", +"reason": "unsupported", + "homeserver": "https://matrix-client.matrix.org" +} +``` + +##### `m.login.declined` + +Sent by: existing device + +Purpose: Indicates that the user declined the request + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.declined`| + + +Example: + +```json +{ + "type":"m.login.declined" +} +``` + +##### `m.login.success` + +Sent by: new device + +Purpose: to inform the existing device that it has successfully obtained an access token. + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.success`| + +Example: + +```json +{ + "type": "m.login.success" +} +``` + +##### `m.login.secrets` + +Sent by: existing device + +Purpose: Shares the secrets used for cross-signing and room key backups + +Fields: + +|Field|Type|| +|--- |--- |--- | +|`type`|required `string`|`m.login.secrets`| +|`cross_signing`|`object`|
Field Type
master_key required string Unpadded base64 encoded private key
self_signing_key required string Unpadded base64 encoded private key
user_signing_key required string Unpadded base64 encoded private key
| +|`backup`|`object`|
Field Type
algorithm required string One of the algorithms listed at https://spec.matrix.org/v1.9/client-server-api/#server-side-key-backups
key required string TODO
backup_version required string TODO
| + +Example: + +```json +{ + "type": "m.login.secrets", + "cross_signing": { + "master_key": "$base64_of_the_key", + "self_signing_key": "$base64_of_the_key", + "user_signing_key": "$base64_of_the_key" + }, + "backup": { + "algorithm": "foobar", + "key": "base64_of_the_backup_recovery_key", + "backup_version": "version_string" + } +} +``` + +### QR code format + +TODO + +### Discoverability of the capability + +Before offering this capability it would make sense that the device can check the availability of the feature. + +Where the homeserver is known: + +1. Check if the homeserver has a rendezvous session API available (/versions) from this MSC +1. Check that the homeserver is using the OIDC architecture (/auth_issuer) from MSC2965 +1. Check that the Device Authorization Grant is available on the OIDC Provider from MSC2965 + +For a new device it would need to know the homeserver ahead of time in order to do these checks. + +Additionally the new device needs to either have an existing (i.e. static) OIDC client registered with the OIDC Provider +already, or the OIDC Provider must support and allow dynamic client registration as described in [MSC2966](https://github.com/matrix-org/matrix-spec-proposals/pull/2966). + ## Potential issues +Because this is an entirely new set of functionality it should not cause issue with any existing Matrix functions or capabilities. + +The proposed protocol requires the devices to have IP connectivity to the server which might not be the case in P2P scenarios. + ## Alternatives +### Alternative to the rendezvous session protocol + +#### Send-to-Device messaging + +If you squint then this proposal looks similar in some regards to the existing +[Send-to-device messaging](https://spec.matrix.org/v1.9/client-server-api/#send-to-device-messaging) capability. + +Whilst to-device messaging already provides a mechanism for secure communication between two Matrix clients/devices, a +key consideration for the anticipated login with QR capability is that one of the clients is not yet authenticated with +a homeserver. + +Furthermore the client might not know which homeserver the user wishes to connect to. + +Conceptually, one could create a new type of "guest" login that would allow the unauthenticated client to connect to a +homeserver for the purposes of communicating with an existing authenticated client via to-device messages. + +Some considerations for this: + +Where the "actual" homeserver is not known then the "guest" homeserver nominated by the new client would need to be +federated with the "actual" homeserver. + +The "guest" homeserver would probably want to automatically clean up the "guest" accounts after a short period of time. + +The "actual" homeserver operator might not want to open up full "guest" access so a second type of "guest" account might +be required. + +Does the new device/client need to accept the T&Cs of the "guest" homeserver? + +#### Other existing protocols + +One could try and do something with STUN or TURN or [COAP](http://coap.technology/). + +#### Implementation details + +Rather than requiring the devices to poll for updates, "long-polling" could be used instead similar to `/sync`. Or WebSockets. + +### Alternative method of secret sharing + +Instead of the existing device sharing the secrets bundle instead the existing device could cross-sign the new device +and then use to-device messaging for sharing the secrets. + +For: + +- You re-use existing secret sharing + +Against: + +- The existing device needs to wait for the new device to upload the device keys for it to sign the new device. +- Takes several round-trips for the secrets to be be shared which will add latency to the overall flow +- The backup cannot be immediately enabled since we received the backup version as well, something the `m.secret.send` +mechanism does not offer. +- The new device cannot upload the cross-signing signature with the device keys in a single request. This introduces a +chance of other devices seeing the new device as unverified, incorrectly prompting the user to verify the device that +will soon be verified. + ## Security considerations +See individual threat analysis sections above. + ## Unstable prefix +While this feature is in development the new `POST` endpoint should be exposed using the following unstable prefix: + +- `/_matrix/client/unstable/org.matrix.msc4108/rendezvous` + +Additionally, the feature is to be advertised as unstable feature in the GET /_matrix/client/versions response, with the +key org.matrix.msc4108 set to true. So, the response could look then as following: + +```json +{ + "versions": ["..."], + "unstable_features": { + "org.matrix.msc4108": true + } +} +``` + ## Dependencies + +This MSC builds on [MSC3861](https://github.com/matrix-org/matrix-spec-proposals/pull/3861) (and its dependencies) which +proposes the adoption of OIDC for authentication in Matrix. From 177a2db95a97e64d0b244a8c14f46c1d16254d7d Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 3 Apr 2024 16:58:36 +0100 Subject: [PATCH 04/32] Auto numbers don't work on non-sequential items --- proposals/4108-oidc-qr-login.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index f72eb8cf3a4..22be50d10de 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -113,12 +113,12 @@ even nonces. Device A starts with `1`, using only odd nonces. - Device G generates **(Gp, Gs)**, where **Gp** is its public key and **Gs** the private (secret) key. - Device S generates **(Sp, Ss)**, where **Sp** is its public key and **Ss** the private (secret) key. -1. **Create rendezvous session** +2. **Create rendezvous session** Device G creates a rendezvous session by making a `POST` request (as described previously) to the nominated homeserver with an empty payload. It parses the **id** and **server** received. -1. **Initial key exchange** +3. **Initial key exchange** Device G displays a QR code containing: @@ -138,7 +138,7 @@ Device S scans and parses the QR code to obtain **Gp**, the rendezvous session * At this point Device S should check that the received intent matches what the user has asked to do on the device. -1. **Device S sends the initial message** +4. **Device S sends the initial message** Device S computes a shared secret **SH** using ECDH between **Ss** and **Gp**, thereby establishing a secure channel with Device G which can be layered on top of the insecure rendezvous session transport. It then discards **Ss** and @@ -162,7 +162,7 @@ LoginInitiateMessage := UnpaddedBase64(TaggedCiphertext) || "|" || UnpaddedBase6 Device S then sends the **LoginInitiateMessage** as the payload to the rendezvous session using a `PUT` request with `Content-Type` header set to `text/plain`. -1. **Device G confirms** +5. **Device G confirms** Device G receives **LoginInitiateMessage** (potentially coming from Device S) from the insecure rendezvous session by polling with `GET` requests. @@ -186,7 +186,7 @@ LoginOkMessage := UnpaddedBase64Encode(TaggedCiphertext) Device G sends **LoginOkMessage** as the payload via `PUT` request with `Content-Type` header set to `text/plain` to the insecure rendezvous session. -1. **Verification by Device S** +6. **Verification by Device S** Device S receives a response over the insecure rendezvous session by polling with `GET` requests, potentially from Device G. @@ -216,7 +216,7 @@ Device S then displays an indication to the user that the secure channel has bee should be entered on the other device when prompted. e.g. wording to say "secure connection established"; enter the code XY on your other device; -1. **Out-of-band confirmation** +7. **Out-of-band confirmation** **Warning**: *This step is crucial for the security of the scheme since it overcomes the aforementioned limitation of ECIES.* @@ -391,7 +391,7 @@ homeserver specified: } ``` -1. **New device checks if it can use an available protocol** +2. **New device checks if it can use an available protocol** Once the existing device knows which homeserver it is to use it then: @@ -489,7 +489,7 @@ Content-Type: application/json At this point the new device knows that, subject to the user consenting, it should be able to complete the login -1. **New device informs existing device that it wants to use the device_authorization_grant** +3. **New device informs existing device that it wants to use the `device_authorization_grant`** The new device send the `verification_uri` and, if present, the `verification_uri_complete` over to the existing device and indicates that want to use protocol `device_authorization_grant` along with the `device_id` that will be used: @@ -651,7 +651,7 @@ sequenceDiagram Then we continue with the actual login: -1. **New device waits for approval from OIDC Provider** +4. **New device waits for approval from OIDC Provider** On receipt of the `m.login.protocol_accepted` message: @@ -678,7 +678,7 @@ handles the different responses - If the user consents in the next step then the new device will receive an `access_token` and `refresh_token` etc. as normal for OIDC with MSC3861. -1. **User is asked by OIDC Provider to consent on existing device** +5. **User is asked by OIDC Provider to consent on existing device** On receipt of the `m.login.protocol` message above, and having completed step 7 of the secure channel establishment, the existing device then asserts that there is no existing device corresponding to the `device_id` from the @@ -786,7 +786,7 @@ If the device isn’t immediately visible it can repeat the `GET` request for up If no device is found then the process should be stopped. -1. **Existing device shares secrets with new device** +2. **Existing device shares secrets with new device** The existing device sends a `m.login.secrets` message via the secure channel: @@ -806,7 +806,7 @@ The existing device sends a `m.login.secrets` message via the secure channel: } ``` -1. **New device cross-signs itself and uploads device keys** +3. **New device cross-signs itself and uploads device keys** On receipt of the m.login.secrets message the new device can store the secrets locally From f54e194584a638ad4225628178fe4adcf27083fb Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 11:57:48 +0100 Subject: [PATCH 05/32] High level description of rendezvous protocol and consistency in payload vs message --- proposals/4108-oidc-qr-login.md | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 22be50d10de..27cb35d5a4a 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -28,7 +28,19 @@ end-to-end confidentiality nor authenticity by itself—these are layered on top #### High-level description -TODO +Suppose that Device A wants to establish communications with Device B. Device A can do so by creating a +_rendezvous session_ via a `POST /_matrix/client/v1/rendezvous` call to an appropriate homeserver. Its response includes +an HTTP _rendezvous URL_ which should be shared out-of-band with Device B. (This URL may be located on a different +domain to the initial `POST`.) + +The rendezvous URL points to an arbitrary data resource (the "payload"), which is initially populated using data from +A's initial `POST` request. There are no restrictions on the payload itself, but the rendezvous server SHOULD impose a +maximum size limit. + +Anyone who is able to reach the rendezvous URL - including: Device A; Device B; or a third party; - can then "receive" +the payload by polling via a `GET` request, and "send" a new a new payload by making a `PUT` request. + +In this way, Device A and Device B can communicate by repeatedly inspecting and updating the payload at the rendezvous URL. #### The send mechanism @@ -88,8 +100,8 @@ existing security analyses of ECIES are applicable in this setting too. Neverthe description of our instantiation of ECIES and discuss some potential pitfalls and attacks. The primary limitation of ECIES is that there is no authentication for the initiating party (the one to send the first -message; Device S in the text below). Thus the recipient party (the one to receive the first message; Device G in the -text below) has no assurance as to who actually sent the message. In QR code login, we work around this problem by +payload; Device S in the text below). Thus the recipient party (the one to receive the first payload; Device G in the +text below) has no assurance as to who actually sent the payload. In QR code login, we work around this problem by exploiting the fact that both of these devices are physically present during the exchange and offloading the check that they are both in the correct state to the user performing the QR code login process. @@ -103,7 +115,7 @@ Participants: Regardless of which device generates the QR code, either device can be the existing (already signed in) device. The other device is then the new device (one seeking to be signed in). -Symmetric encryption uses deterministic nonces, incrementing by `2` with each message. Device S starts with `0`, using only +Symmetric encryption uses deterministic nonces, incrementing by `2` with each payload. Device S starts with `0`, using only even nonces. Device A starts with `1`, using only odd nonces. 1. **Ephemeral key pair generation** @@ -138,13 +150,13 @@ Device S scans and parses the QR code to obtain **Gp**, the rendezvous session * At this point Device S should check that the received intent matches what the user has asked to do on the device. -4. **Device S sends the initial message** +4. **Device S sends the initial payload** Device S computes a shared secret **SH** using ECDH between **Ss** and **Gp**, thereby establishing a secure channel with Device G which can be layered on top of the insecure rendezvous session transport. It then discards **Ss** and derives a symmetric encryption **EncKey** from **SH** using HKDF_SHA256, each 32 bytes in length. -Device S derives a confirmation message that Device G can use to confirm that the channel is secure. It contains: +Device S derives a confirmation payload that Device G can use to confirm that the channel is secure. It contains: - The string `MATRIX_QR_CODE_LOGIN_INITIATE`, encrypted and authenticated with ChaCha20-Poly1305. - Its public ephemeral key **Sp**. @@ -172,7 +184,7 @@ discarding **Gs** and decrypting (and authenticating) the **TaggedCiphertext**, It checks that the plaintext matches the string `MATRIX_QR_CODE_LOGIN_INITIATE`, failing and aborting if not. -It then responds with a dummy message containing the string `MATRIX_QR_CODE_LOGIN_OK` encrypted with **SH** calculated +It then responds with a dummy payload containing the string `MATRIX_QR_CODE_LOGIN_OK` encrypted with **SH** calculated as follows: ``` @@ -191,7 +203,7 @@ insecure rendezvous session. Device S receives a response over the insecure rendezvous session by polling with `GET` requests, potentially from Device G. -It decrypts (and authenticates) it using the previously computed encryption key, which will succeed provided the message +It decrypts (and authenticates) it using the previously computed encryption key, which will succeed provided the payload was indeed sent by Device G. It then verifies the plaintext matches `MATRIX_QR_CODE_LOGIN_OK`, failing otherwise. ``` @@ -235,7 +247,7 @@ CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) If the code that the user enters matches then the secure channel is established. -Subsequent messages can be sent encrypted with **EncKey** with the nonces incremented as described above. +Subsequent payloads can be sent encrypted with **EncKey** with the nonces incremented as described above. #### Sequence diagram @@ -332,7 +344,7 @@ In an attack scenario, we add a participant called Specter with the following ca ##### Replay protection Due to use of ephemeral key pairs which are immediately discarded after use, each QR code login session derives a unique -secret so messages from earlier sessions cannot be replayed. Each message in the session is unique and expected only +secret so payloads from earlier sessions cannot be replayed. Each payload in the session is unique and expected only once. Finally, the use of deterministic nonces prevents any possibility of replay. ##### Pure Dolev-Yao attacker @@ -346,7 +358,7 @@ Since Device G has no way of authenticating Device S, an attacker present for th attempt to mimic Device S in order to get their Device S signed in instead. - In step 3, Specter can shoulder surf the QR code scanning to obtain **Gp**. -- In step 4, Specter can intercept S’s message and replace it with a message of their own, replacing **Sp** with its +- In step 4, Specter can intercept S’s payload and replace it with a payload of their own, replacing **Sp** with its own key. - The attack is only thwarted in step 7, because Device S won’t ever display the indicator of success to the user. The user then must cancel the process on Device G, preventing it from sharing any sensitive material. @@ -904,7 +916,8 @@ note over N: All done! #### Message reference -These are the messages that are exchanged between the devices to negotiate the sign in and set up of E2EE. +These are the messages that are exchanged between the devices via the secure channel to negotiate the sign in and set up +of E2EE. ##### `m.login.protocols` From f34bec334a8fa5fa5de9fe4f1f5570d87cd785f2 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 12:45:02 +0100 Subject: [PATCH 06/32] Cheat spell checker --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 27cb35d5a4a..2b092d95d56 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -849,7 +849,7 @@ Content-Type: application/json "signatures": { "@testing_35:morpheus.localhost": { "ed25519:SGKMSRAGBF": "ziHEUIsHnrYBH4CqYpN1JC/ex3t4VG3zvo16D8ORqN6yAErpsKsnd/5LDdZERIOB1MGffKGfCL6ny5V7rT9FCQ", - "ed25519:bkYgAVUNqvuyy8b1w09utJNJxBvK3hZB65xxoLPVzFo": "p257k0tfPF98OIDuXnFSJS2DmVlxO4sgTHdF41DTdZBCpTZfPwok6iASo3xMRKdyy3WMEgkQ6lzhEyRKKZBGBQ" + "ed25519:bkYgAVUNqvuyy8b1w09utJNJxBvK3hZB65xxoLPVzFol": "p257k0tfPF98OIDuXnFSJS2DmVlxO4sgTHdF41DTdZBCpTZfPwok6iASo3xMRKdyy3WMEgkQ6lzhEyRKKZBGBQ" } }, "user_id": "@testing_35:morpheus.localhost" From 2830e88bfc5d2893cf8f9de61a2771d93befed30 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 13:55:55 +0100 Subject: [PATCH 07/32] Description of rendezvous session API --- proposals/4108-oidc-qr-login.md | 219 +++++++++++++++++++++++++++++++- 1 file changed, 216 insertions(+), 3 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 2b092d95d56..c7b23eb362b 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -61,6 +61,220 @@ header. After this point, any further attempts to query or update the payload MU extended every time the payload is updated. The rendezvous session can be manually expired with a `DELETE` call to the rendezvous session. +####  API + +A new endpoint for the Client-Server API: + +##### Create a rendezvous session and send initial payload: `POST /_matrix/client/v1/rendezvous` + +HTTP request headers: + +- `Content-Length` - required +- `Content-Type` - required + +HTTP request body: + +- any data up to maximum size allowed by the server + +HTTP response codes, and Matrix error codes: + +- `201 Created` - rendezvous session created +- `400 Bad Request` (``M_MISSING_PARAM``) - no `Content-Length` was provided. +- `403 Forbidden` (``M_FORBIDDEN``) - forbidden by server policy +- `413 Payload Too Large` (``M_TOO_LARGE``) - the supplied payload is too large +- `429 Too Many Requests` (``M_UNKNOWN``) - the request has been rate limited +- `307 Temporary Redirect` - if the request should be served from somewhere else specified in the `Location` response header + +n.b. the [`307 Temporary Redirect`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307) response code has been chosen explicitly for the behaviour of ensuring that the method and body will not change whilst the user-agent follows the redirect. For this reason, no other `30x` response codes are allowed. + +HTTP response headers for `201 Created`: + +- `Content-Type`- required, application/json +- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) +- `Expires` - required, the expiry time of the rendezvous as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.expires) +- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) + +Example response: + +``` +HTTP 201 Created +ETag: VmbxF13QDusTgOCt8aoa0d2PQcnBOXeIxEqhw5aQ03o= +Expires: Wed, 07 Sep 2022 14:28:51 GMT +Last-Modified: Wed, 07 Sep 2022 14:27:51 GMT +Content-Type: application/json + +{ + "url": "http://example.org/abcdEFG12345" +} +``` + +##### Send a payload to the rendezvous session: `PUT ` + +HTTP request headers: + +- `Content-Length` - required +- `Content-Type` - required +- `If-Match` - required. The ETag of the last payload seen by the requesting device. + +HTTP request body: + +- any data up to maximum size allowed by the server + +HTTP response codes, and Matrix error codes: + +- `202 Accepted` - payload updated +- `400 Bad Request` (`M_MISSING_PARAM`) - a required header was not provided. +- `400 Bad Request` (`M_INVALID_PARAM`) - a malformed [`ETag`](https://github.com/matrix-org/matrix-spec-proposals/blob/hughns/simple-rendezvous-capability/proposals/3886-simple-rendezvous-capability.md#the-update-mechanism) header was provided. +- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session ID is not valid (it could have expired) +- `412 Precondition Failed` (`M_CONCURRENT_WRITE`, a new error code) - when the ETag does not match +- `413 Payload Too Large` (`M_TOO_LARGE`) - the supplied payload is too large +- `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited + +HTTP response headers for `202 Accepted` and `412 Precondition Failed`: + +- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) +- `Expires` - required, the expiry time of the rendezvous session as per [RFC7233](https://httpwg.org/specs/rfc7234.html#header.expires) +- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) + +##### Receive a payload from the rendezvous session: `GET ` + +HTTP request headers: + +- `If-None-Match` - optional, as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.if-none-match) server will only return data if given ETag does not match + +HTTP response codes, and Matrix error codes: + +- `200 OK` - payload returned +- `304 Not Modified` - when `If-None-Match` is supplied and the ETag does not match +- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) +- `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited + +HTTP response headers for `200 OK` and `304 Not Modified`: + +- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) +- `Expires` - required, the expiry time of the rendezvous session as per [RFC7233](https://httpwg.org/specs/rfc7234.html#header.expires) +- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) +- `Content-Type` - required for `200 OK` + +HTTP response body: + +- The payload last set for this rendezvous session, either via the creation POST request or a subsequent PUT request, up to the maximum size allowed by the server. + +##### Cancel a rendezvous session: `DELETE ` + +HTTP response codes: + +- `204 No Content` - rendezvous session cancelled +- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session ID is not valid (it could have expired) +- `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited + +##### Authentication + +These API endpoints do not require authentication because trust is established at the secure channel layer which is described later. + +##### Maximum payload size + +The server should allow a minimum payload size of 10KB and enforce a maximum payload size which is recommended to be 100KB. + +###### Maximum duration of a rendezvous + +The rendezvous session only needs to persist for the duration of the handshake. So a timeout such as 30 seconds is adequate. + +Clients should handle the case of the rendezvous session being cancelled or timed out by the server. + +###### ETags + +The ETag generated should be unique to the rendezvous session and the last modified time so that two clients can distinguish between identical payloads sent by either client. + +###### CORS + +For the POST /_matrix/client/rendezvous API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) headers, the ETag response header should also be allowed by exposing the following CORS header: + +```http +Access-Control-Expose-Headers: ETag +``` + +To support usage from web browsers the rendezvous URLs should allow CORS requests from any origin and expose the headers which aren’t on the CORS [request header safelist](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header) and [response header safelist](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header): + +```http +Access-Control-Allow-Headers: If-Match,If-None-Match +Access-Control-Allow-Methods: GET, PUT, DELETE +Access-Control-Allow-Origin: * +Access-Control-Expose-Headers: ETag +``` + +##### Choice of server + +Ultimately it will be up to the Matrix client implementation to decide which rendezvous server to use. + +However, it is suggested that the following logic is used by the device/client to choose the rendezvous server in order of preference: + +1. If the client is already logged in: try and use the current homeserver. +1. If the client is not logged in and it is known which homeserver the user wants to connect to: try and use that homeserver. +1. Otherwise use a default server. + +#### Example API usage + +```mermaid +sequenceDiagram + participant A as Device A + participant HS as Homeserver + participant R as Rendezvous Server
https://rz.example.com + participant B as Device B + Note over A: Device A determines which rendezvous server to use + + A->>+HS: POST /_matrix/client/rendezvous
Content-Type: text/plain
"Hello from A" + HS->>-A: 307 https://rz.example.com/foo + A->>+R: POST /foo
Content-Type: text/plain
"Hello from A" + R->>-A: 201 Created
ETag: 1
{"url":"https://rz.example.com/abc-def-123-456"} + + A-->>B: Rendezvous URL shared out of band as QR code: e.g. https://rz.example.com/abc-def-123-456 + + Note over A: Device A starts polling for new payloads at the
rendezvous session using the returned ETag + activate A + + B->>+R: GET /abc-def-123-456 + R->>-B: 200 OK
ETag: 1
Content-Type: text/plain
"Hello from A" + + loop Device A polls the rendezvous session for a new payload + A->>+R: GET /abc-def-123-456
If-None-Match: 1 + alt is not modified + R->>-A: 304 Not Modified + end + end + + note over B: Device B sends a new payload + B->>+R: PUT /abc-def-123-456
If-Match: 1
Content-Type: text/plain
"Hello from B" + R->>-B: 202 Accepted
ETag: 2 + + Note over B: Device B starts polling for new payloads at the
rendezvous session using the new ETag + activate B + + loop Device B polls the rendezvous session for a new payload + B->>+R: GET /abc-def-123-456
If-None-Match: 2 + alt is not modified + R->>-B: 304 Not Modified + end + end + + note over A: Device A then receives the new payload + opt modified + R->>A: 200 OK
ETag: 2
Content-Type: text/plain
"Hello from B" + end + deactivate A + + note over A: Device A sends a new payload + A->>+R: PUT /abc-def-123-456
If-None-Match: 2
Content-Type: text/plain
"Hello again from A" + R->>-A: 202 Accepted
ETag: 3 + + note over B: Device B then receives the new payload + opt modified + R->>B: 200 OK
ETag: 3
Content-Type: text/plain
... + end + + deactivate B +``` + #### Threat analysis ##### Denial of Service attack surface @@ -90,7 +304,7 @@ TODO ### Secure channel The above rendezvous session is insecure, providing no confidentiality nor authenticity against the rendezvous server or -even arbitrary network participants which possess the rendezvous session server and ID. To provide a secure channel on +even arbitrary network participants which possess the rendezvous session URL. To provide a secure channel on top of this insecure rendezvous session transport, we propose the following scheme. This scheme is essentially[ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme#Formal_description_of_ECIES) @@ -145,7 +359,7 @@ similar structure to that of the existing Device Verification QR code encoding d This is defined in detail in a separate section of this proposal. -Device S scans and parses the QR code to obtain **Gp**, the rendezvous session **URL**, **intent** and optionally the +Device S scans and parses the QR code to obtain **Gp**, the rendezvous session **URL**, **intent** and optionally the **homeserver base URL**. At this point Device S should check that the received intent matches what the user has asked to do on the device. @@ -1021,7 +1235,6 @@ Fields: |--- |--- |--- | |`type`|required `string`|`m.login.declined`| - Example: ```json From 24e2242f8d1e790df641b084d5541b8752ea9b16 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 15:53:03 +0100 Subject: [PATCH 08/32] Add description of QR format --- proposals/4108-oidc-qr-login.md | 63 +++++++++++++++++++++++++++- proposals/images/4108-qr-mode03.png | Bin 0 -> 921 bytes proposals/images/4108-qr-mode04.png | Bin 0 -> 1019 bytes 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 proposals/images/4108-qr-mode03.png create mode 100644 proposals/images/4108-qr-mode04.png diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index c7b23eb362b..7a9a605f3e4 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1297,7 +1297,68 @@ Example: ### QR code format -TODO +The proposed format of the QR code intends to be similar to that which is already described in the Client-Server API for +[device verification](https://spec.matrix.org/v1.9/client-server-api/#qr-code-format). + +Additional modes are added to the byte used for "QR code verification mode" to allow for the two login intents: initiate +on a new device; reciprocate on an existing device; + +The QR codes to be displayed and scanned using this format will encode binary strings in the general form: + +- the ASCII string `MATRIX` +- one byte indicating the QR code version (must be `0x02`) +- one byte indicating the QR code intent/mode. Should be one of the following values: + - `0x03` a new device wishing to initiate a login and self-verify + - `0x04` an existing device wishing to reciprocate the login of a new device and self-verify that other device +- the ephemeral Curve25519 public key, as 32 bytes +- the rendezvous session URL encoded as: + - two bytes in network byte order (big-endian) indicating the length in bytes of the rendezvous session URL as a UTF-8 + string + - the rendezvous session URL as a UTF-8 string +- If the QR code intent/mode is `0x04` then the homeserver base URL encode as: + - two bytes in network byte order (big-endian) indicating the length in bytes of the homeserver base URL as a UTF-8 string + - the homeserver base URL as a UTF-8 string + +For example, if Alice displays a QR code encoding the following binary string: + +This indicates that Alice is a new device that wishes to initiate a login using her ephemeral public key of +`0001020304050607...` (which is `AAECAwQFBg…` in base64), via the rendezvous session at URL `https:/…`. + +#### Example for QR code generated on new device + +A full example for a new device using ephemeral public key `2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws` (base64 +encoded) at rendezvous session `https://rendezvous.lab.element.dev/e8da6355-550b-4a32-a193-1619d9830668` is as follows: +(Whitespace is for readability only) + +``` +4D 41 54 52 49 58 02 03 +d8 86 68 6a b2 19 7b 78 0e 30 0a 9d 4a 21 47 48 07 00 d7 92 9f 39 ab 31 b9 e5 14 37 02 48 ed 6b +00 47 +68 74 74 70 73 3a 2f 2f 72 65 6e 64 65 7a 76 6f 75 73 2e 6c 61 62 2e 65 6c 65 6d 65 6e 74 2e 64 65 76 2f 65 38 64 61 36 33 35 35 2d 35 35 30 62 2d 34 61 33 32 2d 61 31 39 33 2d 31 36 31 39 64 39 38 33 30 36 36 38 +``` + +Which looks as follows as a QR with error correction level Q: + +![Example QR for mode 0x03](images/4108-qr-mode03.png) + +#### Example for QR code generated on existing device + +A full example for an existing device using ephemeral public key `2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws` (base64 +encoded), at rendezvous session `https://rendezvous.lab.element.dev/e8da6355-550b-4a32-a193-1619d9830668` on homeserver +`https://matrix-client.matrix.org` is as follows: (Whitespace is for readability only) + +``` +4D 41 54 52 49 58 02 04 +d8 86 68 6a b2 19 7b 78 0e 30 0a 9d 4a 21 47 48 07 00 d7 92 9f 39 ab 31 b9 e5 14 37 02 48 ed 6b +00 47 +68 74 74 70 73 3a 2f 2f 72 65 6e 64 65 7a 76 6f 75 73 2e 6c 61 62 2e 65 6c 65 6d 65 6e 74 2e 64 65 76 2f 65 38 64 61 36 33 35 35 2d 35 35 30 62 2d 34 61 33 32 2d 61 31 39 33 2d 31 36 31 39 64 39 38 33 30 36 36 38 +00 20 +68 74 74 70 73 3a 2f 2f 6d 61 74 72 69 78 2d 63 6c 69 65 6e 74 2e 6d 61 74 72 69 78 2e 6f 72 67 +``` + +Which looks as follows as a QR with error correction level Q: + +![Example QR for mode 0x04](images/4108-qr-mode04.png) ### Discoverability of the capability diff --git a/proposals/images/4108-qr-mode03.png b/proposals/images/4108-qr-mode03.png new file mode 100644 index 0000000000000000000000000000000000000000..4e1a629f17d2a711eb724b615c60a25e2ff2390c GIT binary patch literal 921 zcmV;K17`e*P)-o(5S${5q66 zbxOYQwZ-wx=j_HIj%q%2d=y>@@y*^GC6oE=y-jo-QNt6}A)N0r_Rb#h zc@7$$Ba+3Rw3I6cyL)py`L^;zIKfIDw}$%e*>=!yB)dsZn%$jCxYq7Mk16==&K|Ym zaVR)PwCFc}D^J*4xVY5bGlH+4xo9}z6VVVPcu)2wvpw~1<;h=LvDoMA$GNk2$J^(< zjXX2Lqsc2o00Q;GMfMt=JW{T`JKyn2&L)2jtl_zwL!sGUIM9UC?C>@XPaf@!u7JLo z9SRWfH4V?Pk`rxQyNadT@$RjHBgfT0H`kf1h}Pja6#RBX9$6dcEmpBb>U12DuZ;Yd9mm&Ek(VLoGext9X$HSUXs@*&@`5$Z0sEVscX+ zM|1Y}CVhOQm2-uxZPBb9ERs21pZn6vF*e*JbI1_jAZUj1yZ=U>Jj51Dv_$wU`rKsJ za3r`pc=R|hif=g5^yJ&hbEq>m8K1<-X1Rl`;Ver_G`l~^!5q&wYdAKB;cAJJH5VM{ z_|cPQUM`rm1Sgpvl603lc(q~R<_ zm$}h?{koMiW-8PTrZ4%f-tOPIv5hC_8{rvK1Vjn0jb3F1hav8r;ez2owD<1Ns8+!r z$H$n5HZTX~^GL6t;tYR8rZ5qhBjUr|G+gH4zz5?f%_dU~Mq*a*XFi9RRLtk(Wynt- zziZ_|^glg)zLWU%Ctn4ZhQzHAvBhyn8Fd^LgSWyWk3yLGe(6jjN4_5A!oUyp#$_?T v=BqZ2`Y)nvk}vLWPmmN1|5N`j|DF6Fc-by`AI33y00000NkvXXu0mjfFv!BI literal 0 HcmV?d00001 diff --git a/proposals/images/4108-qr-mode04.png b/proposals/images/4108-qr-mode04.png new file mode 100644 index 0000000000000000000000000000000000000000..68dc9c93b337ca6361f5a6ff9c74ca2389568f7e GIT binary patch literal 1019 zcmVCx^6yHZ!DU#pYmCk>|l zy!RO5|N77$^1tLHnk#cG7dNs*ArFx{Ey0C3-&$+ zeM<1T@$_tt)cQbEkjtzkcW51>sNf_=uDl1{wB(ZeU=nEw%qf$_9OXevaGxRZZP8~r z{>tb)>4`Nrj#(X9j8B`aTVtN}q)i@oaFfSGn=QJ5$3sg_UryOtv*Eneb%3?4T5=Qm zgYhvZxgq5#j2C8HOHOYNmbvZ&23&fDN~~IP)lB%?$>DA!V_5D`SW9jiPtUu>qdQ38 z5&0EHHQ`EYLc`reWvk;+F*v!?k}H-Ml`DxbZ>XqueQ>LmFpHd=)*Kbruq&uRQxmCy z9dA!vl%1Pn?$Wqv3DkX-^FoYWZ_%ID)6bS@2tzd!T9onVL&Y^fTD9c#Q1rY&u@cn% z5m79PmT)pxg=6H2(ByK;5VcuLt|Ya*WCmg2Z3>yl99nV`Rs_}!CBP~}m7j&ylB;5( z8=?eRM;@!po9v&GFq#v_JB+*dt!UoGr6y zFD*Ge_O;y5X2Px%t};G@mf(r6WM08Q?2%UBy2w6MaVHCn-St z^=%EgDy-F*AR%xR%xOq`+MG^#DPvrm|KUpu4rB)HF#dde)^*$ z5>If_Enz>LI2-@o=X3H%yV#BhgQO>e%(!Zayw9B@$|rYj>iB1002ovPDHLkV1m3z<&ppZ literal 0 HcmV?d00001 From 21ae2cac8a7bc58aa109146810a9eb3f110ca742 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 15:55:31 +0100 Subject: [PATCH 09/32] Lint --- proposals/4108-oidc-qr-login.md | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 7a9a605f3e4..23a022bac5c 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -85,7 +85,9 @@ HTTP response codes, and Matrix error codes: - `429 Too Many Requests` (``M_UNKNOWN``) - the request has been rate limited - `307 Temporary Redirect` - if the request should be served from somewhere else specified in the `Location` response header -n.b. the [`307 Temporary Redirect`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307) response code has been chosen explicitly for the behaviour of ensuring that the method and body will not change whilst the user-agent follows the redirect. For this reason, no other `30x` response codes are allowed. +n.b. the [`307 Temporary Redirect`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307) response code has been +chosen explicitly for the behaviour of ensuring that the method and body will not change whilst the user-agent follows +the redirect. For this reason, no other `30x` response codes are allowed. HTTP response headers for `201 Created`: @@ -124,7 +126,9 @@ HTTP response codes, and Matrix error codes: - `202 Accepted` - payload updated - `400 Bad Request` (`M_MISSING_PARAM`) - a required header was not provided. -- `400 Bad Request` (`M_INVALID_PARAM`) - a malformed [`ETag`](https://github.com/matrix-org/matrix-spec-proposals/blob/hughns/simple-rendezvous-capability/proposals/3886-simple-rendezvous-capability.md#the-update-mechanism) header was provided. +- `400 Bad Request` (`M_INVALID_PARAM`) - a malformed +[`ETag`](https://github.com/matrix-org/matrix-spec-proposals/blob/hughns/simple-rendezvous-capability/proposals/3886-simple-rendezvous-capability.md#the-update-mechanism) +header was provided. - `404 Not Found` (`M_NOT_FOUND`) - rendezvous session ID is not valid (it could have expired) - `412 Precondition Failed` (`M_CONCURRENT_WRITE`, a new error code) - when the ETag does not match - `413 Payload Too Large` (`M_TOO_LARGE`) - the supplied payload is too large @@ -140,7 +144,8 @@ HTTP response headers for `202 Accepted` and `412 Precondition Failed`: HTTP request headers: -- `If-None-Match` - optional, as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.if-none-match) server will only return data if given ETag does not match +- `If-None-Match` - optional, as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.if-none-match) server will +only return data if given ETag does not match HTTP response codes, and Matrix error codes: @@ -158,7 +163,8 @@ HTTP response headers for `200 OK` and `304 Not Modified`: HTTP response body: -- The payload last set for this rendezvous session, either via the creation POST request or a subsequent PUT request, up to the maximum size allowed by the server. +- The payload last set for this rendezvous session, either via the creation POST request or a subsequent PUT request, up +to the maximum size allowed by the server. ##### Cancel a rendezvous session: `DELETE ` @@ -170,7 +176,8 @@ HTTP response codes: ##### Authentication -These API endpoints do not require authentication because trust is established at the secure channel layer which is described later. +These API endpoints do not require authentication because trust is established at the secure channel layer which is +described later. ##### Maximum payload size @@ -188,13 +195,16 @@ The ETag generated should be unique to the rendezvous session and the last modif ###### CORS -For the POST /_matrix/client/rendezvous API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) headers, the ETag response header should also be allowed by exposing the following CORS header: +For the POST /_matrix/client/rendezvous API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) +headers, the ETag response header should also be allowed by exposing the following CORS header: ```http Access-Control-Expose-Headers: ETag ``` -To support usage from web browsers the rendezvous URLs should allow CORS requests from any origin and expose the headers which aren’t on the CORS [request header safelist](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header) and [response header safelist](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header): +To support usage from web browsers the rendezvous URLs should allow CORS requests from any origin and expose the headers +which aren’t on the CORS [request header](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header) and +[response header](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header) safelists: ```http Access-Control-Allow-Headers: If-Match,If-None-Match @@ -207,7 +217,8 @@ Access-Control-Expose-Headers: ETag Ultimately it will be up to the Matrix client implementation to decide which rendezvous server to use. -However, it is suggested that the following logic is used by the device/client to choose the rendezvous server in order of preference: +However, it is suggested that the following logic is used by the device/client to choose the rendezvous server in order +of preference: 1. If the client is already logged in: try and use the current homeserver. 1. If the client is not logged in and it is known which homeserver the user wants to connect to: try and use that homeserver. @@ -297,10 +308,6 @@ is possible to use it to circumvent firewalls and other network security measure Implementation may want to block their production IP addresses from being able to make requests to the rendezvous endpoints in order to avoid attackers using it as a dead-drop for exfiltrating data. -#### API - -TODO - ### Secure channel The above rendezvous session is insecure, providing no confidentiality nor authenticity against the rendezvous server or From 38eb66151ee558d2615fbda429954455b80e5eee Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 16:55:58 +0100 Subject: [PATCH 10/32] Notes on threat model --- proposals/4108-oidc-qr-login.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 23a022bac5c..f8ded79a1ed 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1447,7 +1447,17 @@ will soon be verified. ## Security considerations -See individual threat analysis sections above. +This proposed mechanism has been designed to protects users and their devices from the following threats: + +- A malicious actor who is able to scan the QR code generated by the legitimate user. +- A malicious actor who can intercept and modify traffic on the application layer, even if protected by encryption like TLS. +- Both of the above at the same time. + +Additionally, the OIDC Provider is able to define and enforce policies that can prevent a sign in on a new device. +Such policies depend on the OIDC Provider in use and could include, but are not limited to, time of day, day of the week, +source IP address and geolocation. + +A threat analysis has been done within each of the key layers in the proposal above. ## Unstable prefix From 9cd724f5008fc9a6f7960447d56400c0bd959ae9 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 17:05:53 +0100 Subject: [PATCH 11/32] Fix broken link --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index f8ded79a1ed..4a8ccc0897c 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1420,7 +1420,7 @@ Does the new device/client need to accept the T&Cs of the "guest" homeserver? #### Other existing protocols -One could try and do something with STUN or TURN or [COAP](http://coap.technology/). +One could try and do something with STUN or TURN or [COAP](https://datatracker.ietf.org/doc/html/rfc7252). #### Implementation details From db759eacce2c54cdedcf609f701ec361bb7fb59c Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 4 Apr 2024 17:32:39 +0100 Subject: [PATCH 12/32] Resolve some more TODOs --- proposals/4108-oidc-qr-login.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index f8ded79a1ed..6443611db84 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1088,26 +1088,23 @@ sequenceDiagram participant HS as Homeserver rect rgba(0,255,0, 0.1) - rect rgb(191, 223, 255) note over N,E: This step is duplicated from the previous section for readability N-->>+E: { "type": "m.login.success" } end - Note over E: 1) Existing device checks that the device is actually online: - + Note over E: 1) Existing device checks that the device is actually online E->>HS: GET /_matrix/client/v3/devices/{device_id} activate HS alt is device not found + note over E: We should wait and retry for 10 seconds HS->>E: 404 Not Found E->>N: { "type": "m.login.failed", "reason": "TODO" } else is device found HS->>E: 200 OK deactivate HS -Note over E: TODO: how do we check that this is actually the newly signed in device? - E->>-N: 2) { "type": "m.login.secrets", "cross_signing": {...}, "backup": {...} } activate N @@ -1282,7 +1279,7 @@ Fields: |--- |--- |--- | |`type`|required `string`|`m.login.secrets`| |`cross_signing`|`object`|
Field Type
master_key required string Unpadded base64 encoded private key
self_signing_key required string Unpadded base64 encoded private key
user_signing_key required string Unpadded base64 encoded private key
| -|`backup`|`object`|
Field Type
algorithm required string One of the algorithms listed at https://spec.matrix.org/v1.9/client-server-api/#server-side-key-backups
key required string TODO
backup_version required string TODO
| +|`backup`|`object`|
Field Type
algorithm required string One of the algorithms listed at https://spec.matrix.org/v1.9/client-server-api/#server-side-key-backups
key required string Unpadded base64 encoded private/secret key
backup_version required string The backup version as returned by [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.10/client-server-api/#post_matrixclientv3room_keysversion)
| Example: From 4e425afe49a34298f878fa7b71470569327e2179 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 5 Apr 2024 15:41:13 +0100 Subject: [PATCH 13/32] Define POST response body explicitly --- proposals/4108-oidc-qr-login.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index f44bdd2de43..738579a7fc3 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -96,9 +96,13 @@ HTTP response headers for `201 Created`: - `Expires` - required, the expiry time of the rendezvous as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.expires) - `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) +HTTP response body for `201 Created`: + +- a JSON object with a single key `url` whose value is the absolute URL of the rendezvous session + Example response: -``` +```http HTTP 201 Created ETag: VmbxF13QDusTgOCt8aoa0d2PQcnBOXeIxEqhw5aQ03o= Expires: Wed, 07 Sep 2022 14:28:51 GMT From a302c39faf81d36d75acc1f6e089ef8fb13c1794 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 9 Apr 2024 11:38:04 +0100 Subject: [PATCH 14/32] Add Cache-Control and Pragma HTTP response headers --- proposals/4108-oidc-qr-login.md | 67 +++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 738579a7fc3..ecb196dd72e 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -63,10 +63,18 @@ rendezvous session. ####  API -A new endpoint for the Client-Server API: +##### Common HTTP response headers + +- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) +- `Expires` - required, the expiry time of the rendezvous as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.expires) +- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) +- `Cache-Control` - required, `no-store` as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.cache-control) +- `Pragma` - required, `no-cache` as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.pragma) ##### Create a rendezvous session and send initial payload: `POST /_matrix/client/v1/rendezvous` +This would be part of the Client-Server API. + HTTP request headers: - `Content-Length` - required @@ -92,9 +100,7 @@ the redirect. For this reason, no other `30x` response codes are allowed. HTTP response headers for `201 Created`: - `Content-Type`- required, application/json -- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) -- `Expires` - required, the expiry time of the rendezvous as per [RFC7234](https://httpwg.org/specs/rfc7234.html#header.expires) -- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) +- common headers as defined above HTTP response body for `201 Created`: @@ -104,10 +110,12 @@ Example response: ```http HTTP 201 Created +Content-Type: application/json ETag: VmbxF13QDusTgOCt8aoa0d2PQcnBOXeIxEqhw5aQ03o= Expires: Wed, 07 Sep 2022 14:28:51 GMT Last-Modified: Wed, 07 Sep 2022 14:27:51 GMT -Content-Type: application/json +Cache-Control: no-store +Pragma: no-cache { "url": "http://example.org/abcdEFG12345" @@ -140,9 +148,7 @@ header was provided. HTTP response headers for `202 Accepted` and `412 Precondition Failed`: -- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) -- `Expires` - required, the expiry time of the rendezvous session as per [RFC7233](https://httpwg.org/specs/rfc7234.html#header.expires) -- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) +- common headers as defined above ##### Receive a payload from the rendezvous session: `GET ` @@ -158,18 +164,43 @@ HTTP response codes, and Matrix error codes: - `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) - `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited -HTTP response headers for `200 OK` and `304 Not Modified`: +HTTP response headers for `200 OK`: -- `ETag` - required, ETag for the current payload at the rendezvous session as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.etag) -- `Expires` - required, the expiry time of the rendezvous session as per [RFC7233](https://httpwg.org/specs/rfc7234.html#header.expires) -- `Last-Modified` - required, the last modified date of the payload as per [RFC7232](https://httpwg.org/specs/rfc7232.html#header.last-modified) -- `Content-Type` - required for `200 OK` +- `Content-Type` - required +- common headers as defined above + +HTTP response headers for `304 Not Modified`: -HTTP response body: +- common headers as defined above + +HTTP response body for `200 OK`:: - The payload last set for this rendezvous session, either via the creation POST request or a subsequent PUT request, up to the maximum size allowed by the server. +Example responses: + +```http +HTTP 200 OK +Content-Type: text/plain +ETag: VmbxF13QDusTgOCt8aoa0d2PQcnBOXeIxEqhw5aQ03o= +Expires: Wed, 07 Sep 2022 14:28:51 GMT +Last-Modified: Wed, 07 Sep 2022 14:27:51 GMT +Cache-Control: no-store +Pragma: no-cache + +foo +``` + +```http +HTTP 304 Not Modified +ETag: VmbxF13QDusTgOCt8aoa0d2PQcnBOXeIxEqhw5aQ03o= +Expires: Wed, 07 Sep 2022 14:28:51 GMT +Last-Modified: Wed, 07 Sep 2022 14:27:51 GMT +Cache-Control: no-store +Pragma: no-cache +``` + ##### Cancel a rendezvous session: `DELETE ` HTTP response codes: @@ -195,11 +226,15 @@ Clients should handle the case of the rendezvous session being cancelled or time ###### ETags -The ETag generated should be unique to the rendezvous session and the last modified time so that two clients can distinguish between identical payloads sent by either client. +The ETag generated should be unique to the rendezvous session and the last modified time so that two clients can +distinguish between identical payloads sent by either client. + +In order to make sure that no intermediate caches manipulate the ETags, the rendezvous server MUST include the HTTP +`Cache-Control` response header with a value of `no-store` and `Pragma` response header with a value of `no-cache`. ###### CORS -For the POST /_matrix/client/rendezvous API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) +For the `POST /_matrix/client/rendezvous` API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) headers, the ETag response header should also be allowed by exposing the following CORS header: ```http From a81491ca2b7143402ef15870d49ac3254615203c Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 10 Apr 2024 16:23:26 +0100 Subject: [PATCH 15/32] Add error codes --- proposals/4108-oidc-qr-login.md | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index ecb196dd72e..962ddcf392a 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -848,7 +848,7 @@ sequenceDiagram note over E: Existing device checks that requested protocol is supported alt if requested protocol is not valid - E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported",
"homeserver": "https://matrix-client.matrix.org}) + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "https://matrix-client.matrix.org}) end end ``` @@ -916,7 +916,7 @@ sequenceDiagram note over E: Existing device checks that requested protocol is supported alt if requested protocol is not valid - E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported",
"homeserver": "https://matrix-client.matrix.org}) + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "https://matrix-client.matrix.org}) end end ``` @@ -959,7 +959,7 @@ existing device then asserts that there is no existing device corresponding to t It does so by calling [GET /_matrix/client/v3/devices/](https://spec.matrix.org/v1.9/client-server-api/#get_matrixclientv3devicesdeviceid) and expecting to receive an HTTP 404 response. -If the device already exists then the login request should be rejected with an `m.login.failure`. +If the device already exists then the login request should be rejected with an `m.login.failure` and reason `device_already_exists`. If no existing device was found then the existing device opens the `verification_uri_complete` - falling back to the `verification_uri`, if `verification_uri_complete` isn’t present - in a system browser. @@ -1003,10 +1003,14 @@ sequenceDiagram OP-->>N: 400 Bad Request {"error": "authorization_pending"} else granted OP-->>N: 200 OK {"access_token": "...", "token_type": "Bearer", ...} + N->>E: SecureSend({ "type": "m.login.success" }) + Note over N: Device now has an access_token and can start to talk to the homeserver else denied OP-->>N: 400 Bad Request {"error": "authorization_declined"} + N->>E: SecureSend({"type":"m.login.declined"}) else expired OP-->>N: 400 Bad Request {"error": "expired_token"} + N->>E: SecureSend({"type":"m.login.failure", "reason": "authorization_expired"}) end end and @@ -1019,14 +1023,6 @@ sequenceDiagram end Note over UA: User closes browser end - - alt declined - Note over E: or can the OP tell the existing device the outcome? - N->>E: SecureSend({"type":"m.login.declined"}) - else approved - Note over N: Device now has an access_token and can start to talk to the homeserver - N->>E: SecureSend({ "type": "m.login.success" }) - end end ``` @@ -1048,7 +1044,7 @@ This is achieved as following: 1. **Existing device confirms that the new device has indeed logged in successfully** -On receipt of an m.login.success message the existing device queries the homeserver to check that the is a device online +On receipt of an `m.login.success` message the existing device queries the homeserver to check that the is a device online with the corresponding device_id (from the `m.login.protocol` message). It does so by calling [GET /_matrix/client/v3/devices/](https://spec.matrix.org/v1.9/client-server-api/#get_matrixclientv3devicesdeviceid) @@ -1080,7 +1076,7 @@ The existing device sends a `m.login.secrets` message via the secure channel: 3. **New device cross-signs itself and uploads device keys** -On receipt of the m.login.secrets message the new device can store the secrets locally +On receipt of the `m.login.secrets` message the new device can store the secrets locally The new device can then generate the cross-signing signature for itself. @@ -1139,7 +1135,7 @@ activate HS alt is device not found note over E: We should wait and retry for 10 seconds HS->>E: 404 Not Found - E->>N: { "type": "m.login.failed", "reason": "TODO" } + E->>N: { "type": "m.login.failure", "reason": "device_not_found" } else is device found HS->>E: 200 OK deactivate HS @@ -1253,9 +1249,9 @@ Fields: |Field|Type|| |--- |--- |--- | |`type`|required `string`|`m.login.failure`| -|`reason`|required `string`| One of: `TODO`| +|`reason`|required `string`| One of:
Value Description
authorization_expired The Device Authorization Grant expired
device_already_exists The device ID specified by the new client already exists in the Homeserver provided device list
device_not_foundThe new device is not present in the device list as returned by the Homeserver
unexpected_message_receivedSent by either device to indicate that they received a message of a type that they weren't expecting
unsupported_protocolSent by a device where no suitable protocol is available or the requested protocol requested is not supported
user_cancelledSent by either new or existing device to indicate that the user has cancelled the login
| |`homeserver`|`string`| When the existing device is sending this it can include the Base URL of the homeserver so that the new device can at least save the user the hassle of typing it in| - + Example: ```json From e1f7367b55a916cc1cf27b97aa2c0e12ccd998fa Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 15 Apr 2024 09:59:17 +0100 Subject: [PATCH 16/32] Formatting --- proposals/4108-oidc-qr-login.md | 168 ++++++++++++++++---------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 962ddcf392a..cee6057b0e0 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -24,7 +24,7 @@ In order for the new device to be fully set up, it needs to exchange information It is proposed that an HTTP-based protocol be used to establish an ephemeral bi-directional communication session over which the two devices can exchange the necessary data. This session is described as "insecure" as it provides no -end-to-end confidentiality nor authenticity by itself—these are layered on top of it. +end-to-end confidentiality nor authenticity by itself---these are layered on top of it. #### High-level description @@ -242,7 +242,7 @@ Access-Control-Expose-Headers: ETag ``` To support usage from web browsers the rendezvous URLs should allow CORS requests from any origin and expose the headers -which aren’t on the CORS [request header](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header) and +which aren't on the CORS [request header](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header) and [response header](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header) safelists: ```http @@ -394,8 +394,8 @@ with an empty payload. It parses the **id** and **server** received. Device G displays a QR code containing: -- its public key **Gp** -- the insecure rendezvous session **URL** +- Its public key **Gp** +- The insecure rendezvous session **URL** - An indicator (the **intent**) to say if this is a new device which wishes to "initiate" a login, or an existing device that wishes to "reciprocate" a login - If the intent is to reciprocate a login, then the **homeserver base URL** @@ -618,9 +618,9 @@ Since Device G has no way of authenticating Device S, an attacker present for th attempt to mimic Device S in order to get their Device S signed in instead. - In step 3, Specter can shoulder surf the QR code scanning to obtain **Gp**. -- In step 4, Specter can intercept S’s payload and replace it with a payload of their own, replacing **Sp** with its +- In step 4, Specter can intercept S's payload and replace it with a payload of their own, replacing **Sp** with its own key. -- The attack is only thwarted in step 7, because Device S won’t ever display the indicator of success to the user. The +- The attack is only thwarted in step 7, because Device S won't ever display the indicator of success to the user. The user then must cancel the process on Device G, preventing it from sharing any sensitive material. ### The OIDC login part and set up of E2EE @@ -657,9 +657,9 @@ homeserver specified: ```json { - "type": "m.login.protocols", - "protocols": ["device_authorization_grant"], - "homeserver": "https://synapse-oidc.lab.element.dev" + "type": "m.login.protocols", + "protocols": ["device_authorization_grant"], + "homeserver": "https://synapse-oidc.lab.element.dev" } ``` @@ -684,7 +684,7 @@ With response like: Content-Type: application/json { - "issuer": "https://auth-oidc.lab.element.dev/" + "issuer": "https://auth-oidc.lab.element.dev/" } ``` @@ -706,22 +706,22 @@ With response like: Content-Type: application/json { - "issuer": "https://auth-oidc.lab.element.dev/", - "authorization_endpoint": "https://auth-oidc.lab.element.dev/authorize", - "token_endpoint": "https://auth-oidc.lab.element.dev/oauth2/token", - "jwks_uri": "https://auth-oidc.lab.element.dev/oauth2/keys.json", - "registration_endpoint": "https://auth-oidc.lab.element.dev/oauth2/registration", - "scopes_supported": ["openid", "email"], - "response_types_supported": [...], - "response_modes_supported": [...], - "grant_types_supported": [ - "authorization_code", - "refresh_token", - "client_credentials", - "urn:ietf:params:oauth:grant-type:device_code" - ], - ... - "device_authorization_endpoint": "https://auth-oidc.lab.element.dev/oauth2/device" + "issuer": "https://auth-oidc.lab.element.dev/", + "authorization_endpoint": "https://auth-oidc.lab.element.dev/authorize", + "token_endpoint": "https://auth-oidc.lab.element.dev/oauth2/token", + "jwks_uri": "https://auth-oidc.lab.element.dev/oauth2/keys.json", + "registration_endpoint": "https://auth-oidc.lab.element.dev/oauth2/registration", + "scopes_supported": ["openid", "email"], + "response_types_supported": [...], + "response_modes_supported": [...], + "grant_types_supported": [ + "authorization_code", + "refresh_token", + "client_credentials", + "urn:ietf:params:oauth:grant-type:device_code" + ], + ... + "device_authorization_endpoint": "https://auth-oidc.lab.element.dev/oauth2/device" } ``` @@ -748,12 +748,12 @@ With response like: Content-Type: application/json { - "device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS", - "user_code": "123456", - "verification_uri": "https://auth-oidc.lab.element.dev/link", - "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456", - "expires_in": 1800, - "interval": 5 + "device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS", + "user_code": "123456", + "verification_uri": "https://auth-oidc.lab.element.dev/link", + "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456", + "expires_in": 1800, + "interval": 5 } ``` @@ -770,13 +770,13 @@ indicates that want to use protocol `device_authorization_grant` along with the ```json { - "type": "m.login.protocol", - "protocol": "device_authorization_grant", - "device_authorization_grant": { - "verification_uri": "https://auth-oidc.lab.element.dev/link", - "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456" - }, - "device_id": "ABCDEFGH" + "type": "m.login.protocol", + "protocol": "device_authorization_grant", + "device_authorization_grant": { + "verification_uri": "https://auth-oidc.lab.element.dev/link", + "verification_uri_complete": "https://auth-oidc.lab.element.dev/link?code=123456" + }, + "device_id": "ABCDEFGH" } ``` @@ -928,10 +928,10 @@ Then we continue with the actual login: On receipt of the `m.login.protocol_accepted` message: - In accordance with [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628#section-3.3.1) the new device must display -the user_code in order that the user can confirm it on the OIDC Provider if required. +the `user_code` in order that the user can confirm it on the OIDC Provider if required. - The new device then starts to poll the OIDC Provider by making [Device Access Token Requests](https://datatracker.ietf.org/doc/html/rfc8628#section-3.4) using the interval and bounded -by expires_in. +by `expires_in`. *New device => OIDC Provider via HTTP* @@ -962,7 +962,7 @@ and expecting to receive an HTTP 404 response. If the device already exists then the login request should be rejected with an `m.login.failure` and reason `device_already_exists`. If no existing device was found then the existing device opens the `verification_uri_complete` - falling back to the -`verification_uri`, if `verification_uri_complete` isn’t present - in a system browser. +`verification_uri`, if `verification_uri_complete` isn't present - in a system browser. Ideally this is in a trusted/secure environment where the cookie jar and password manager features are available. e.g. on iOS this could be a `ASWebAuthenticationSession` @@ -973,7 +973,7 @@ The existing device then sends an acknowledgement message to let the other devic ```json { - "type": "m.login.protocol_accepted" + "type": "m.login.protocol_accepted" } ``` @@ -1050,7 +1050,7 @@ with the corresponding device_id (from the `m.login.protocol` message). It does so by calling [GET /_matrix/client/v3/devices/](https://spec.matrix.org/v1.9/client-server-api/#get_matrixclientv3devicesdeviceid) and expecting to receive an HTTP 200 response. -If the device isn’t immediately visible it can repeat the `GET` request for up to, say, 10 seconds to allow for any latency. +If the device isn't immediately visible it can repeat the `GET` request for up to, say, 10 seconds to allow for any latency. If no device is found then the process should be stopped. @@ -1060,17 +1060,17 @@ The existing device sends a `m.login.secrets` message via the secure channel: ```json { - "type": "m.login.secrets", - "cross_signing": { - "master_key": "$base64_of_the_key", - "self_signing_key": "$base64_of_the_key", - "user_signing_key": "$base64_of_the_key" - }, - "backup": { - "algorithm": "foobar", - "key": "base64_of_the_backup_recovery_key", - "backup_version": "version_string" - } + "type": "m.login.secrets", + "cross_signing": { + "master_key": "$base64_of_the_key", + "self_signing_key": "$base64_of_the_key", + "user_signing_key": "$base64_of_the_key" + }, + "backup": { + "algorithm": "foobar", + "key": "base64_of_the_backup_recovery_key", + "backup_version": "version_string" + } } ``` @@ -1144,7 +1144,7 @@ deactivate HS activate N note over N: 3) New device stores the secrets locally - + alt is cross_signing present in m.login.secrets? note over N: New device signs itself note over N: New device uploads device keys and cross-signing signature: @@ -1188,9 +1188,9 @@ Fields: ```json { - "type": "m.login.protocols", - "protocols": ["device_authorization_grant"], - "homeserver": "https://matrix-client.matrix.org" + "type": "m.login.protocols", + "protocols": ["device_authorization_grant"], + "homeserver": "https://matrix-client.matrix.org" } ``` @@ -1213,13 +1213,13 @@ Example: ```json { - "type": "m.login.protocol", - "protocol": "device_authorization_grant", - "device_authorization_grant": { - "verification_uri_complete": "https://id.matrix.org/device/abcde", - "verification_uri": "..." - }, - "device_id": "ABCDEFGH" + "type": "m.login.protocol", + "protocol": "device_authorization_grant", + "device_authorization_grant": { + "verification_uri_complete": "https://id.matrix.org/device/abcde", + "verification_uri": "..." + }, + "device_id": "ABCDEFGH" } ``` @@ -1234,7 +1234,7 @@ Example: ```json { - "type":"m.login.protocol_accepted" + "type":"m.login.protocol_accepted" } ``` @@ -1251,14 +1251,14 @@ Fields: |`type`|required `string`|`m.login.failure`| |`reason`|required `string`| One of:
Value Description
authorization_expired The Device Authorization Grant expired
device_already_exists The device ID specified by the new client already exists in the Homeserver provided device list
device_not_foundThe new device is not present in the device list as returned by the Homeserver
unexpected_message_receivedSent by either device to indicate that they received a message of a type that they weren't expecting
unsupported_protocolSent by a device where no suitable protocol is available or the requested protocol requested is not supported
user_cancelledSent by either new or existing device to indicate that the user has cancelled the login
| |`homeserver`|`string`| When the existing device is sending this it can include the Base URL of the homeserver so that the new device can at least save the user the hassle of typing it in| - + Example: ```json { - "type":"m.login.failure", -"reason": "unsupported", - "homeserver": "https://matrix-client.matrix.org" + "type":"m.login.failure", + "reason": "unsupported", + "homeserver": "https://matrix-client.matrix.org" } ``` @@ -1278,7 +1278,7 @@ Example: ```json { - "type":"m.login.declined" + "type":"m.login.declined" } ``` @@ -1298,7 +1298,7 @@ Example: ```json { - "type": "m.login.success" + "type": "m.login.success" } ``` @@ -1320,17 +1320,17 @@ Example: ```json { - "type": "m.login.secrets", - "cross_signing": { - "master_key": "$base64_of_the_key", - "self_signing_key": "$base64_of_the_key", - "user_signing_key": "$base64_of_the_key" - }, - "backup": { - "algorithm": "foobar", - "key": "base64_of_the_backup_recovery_key", - "backup_version": "version_string" - } + "type": "m.login.secrets", + "cross_signing": { + "master_key": "$base64_of_the_key", + "self_signing_key": "$base64_of_the_key", + "user_signing_key": "$base64_of_the_key" + }, + "backup": { + "algorithm": "foobar", + "key": "base64_of_the_backup_recovery_key", + "backup_version": "version_string" + } } ``` From d8c62ed866c394bc582f10b17d8c2ae217e77403 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 15 Apr 2024 09:59:59 +0100 Subject: [PATCH 17/32] Whitespace --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index cee6057b0e0..0ab65c6e82e 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -353,7 +353,7 @@ The above rendezvous session is insecure, providing no confidentiality nor authe even arbitrary network participants which possess the rendezvous session URL. To provide a secure channel on top of this insecure rendezvous session transport, we propose the following scheme. -This scheme is essentially[ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme#Formal_description_of_ECIES) +This scheme is essentially [ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme#Formal_description_of_ECIES) instantiated with X25519, HKDF-SHA256 for the KDF and ChaCha20-Poly1305 (as specified by [RFC8439](https://datatracker.ietf.org/doc/html/rfc8439#section-2.8)) for the authenticated encryption. Therefore, existing security analyses of ECIES are applicable in this setting too. Nevertheless we include below a short From ad31acf891f29095231da1a6f8e711c60c23c907 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 15 Apr 2024 10:04:28 +0100 Subject: [PATCH 18/32] More formatting --- proposals/4108-oidc-qr-login.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 0ab65c6e82e..92425ba676a 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1068,7 +1068,7 @@ The existing device sends a `m.login.secrets` message via the secure channel: }, "backup": { "algorithm": "foobar", - "key": "base64_of_the_backup_recovery_key", + "key": "$base64_of_the_backup_recovery_key", "backup_version": "version_string" } } @@ -1093,7 +1093,7 @@ Content-Type: application/json { "device_keys": { - "algorithms": [ + "algorithms": [ "m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2" ], @@ -1328,7 +1328,7 @@ Example: }, "backup": { "algorithm": "foobar", - "key": "base64_of_the_backup_recovery_key", + "key": "$base64_of_the_backup_recovery_key", "backup_version": "version_string" } } From aa37af9b38ed9426655de07795a74b459b25ba4a Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Tue, 16 Apr 2024 12:23:23 +0000 Subject: [PATCH 19/32] Tweaks to the QR code login crypto (#4129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Derive separate encryption keys and nonces for the two sides of the secure channel - Spell out HKDF parameters in text too - Misc style fixes --------- Co-authored-by: Damir Jelić Co-authored-by: Hugh Nimmo-Smith --- proposals/4108-oidc-qr-login.md | 92 +++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 92425ba676a..fcb9c95e8db 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -375,8 +375,9 @@ Participants: Regardless of which device generates the QR code, either device can be the existing (already signed in) device. The other device is then the new device (one seeking to be signed in). -Symmetric encryption uses deterministic nonces, incrementing by `2` with each payload. Device S starts with `0`, using only -even nonces. Device A starts with `1`, using only odd nonces. +Symmetric encryption uses a separate encryption key for each sender, both derived from a shared secret using HKDF. A +separate deterministic, monotonically-incrementing nonce is used for each sender. Devices initially set both nonces to +`0` and increment the corresponding nonce by `1` for each message sent and received. 1. **Ephemeral key pair generation** @@ -401,7 +402,8 @@ that wishes to "reciprocate" a login - If the intent is to reciprocate a login, then the **homeserver base URL** To get a good trade-off between visual compactness and high level of error correction we use a binary mode QR with a -similar structure to that of the existing Device Verification QR code encoding described in [Client-Server API](https://spec.matrix.org/v1.9/client-server-api/#qr-code-format). +similar structure to that of the existing Device Verification QR code encoding described in [Client-Server +API](https://spec.matrix.org/v1.9/client-server-api/#qr-code-format). This is defined in detail in a separate section of this proposal. @@ -412,22 +414,41 @@ At this point Device S should check that the received intent matches what the us 4. **Device S sends the initial payload** -Device S computes a shared secret **SH** using ECDH between **Ss** and **Gp**, thereby establishing a secure channel -with Device G which can be layered on top of the insecure rendezvous session transport. It then discards **Ss** and -derives a symmetric encryption **EncKey** from **SH** using HKDF_SHA256, each 32 bytes in length. +Device S computes a shared secret **SH** by performing ECDH between **Ss** and **Gp**. It then discards **Ss** and +derives two 32-byte symmetric encryption keys from **SH** using HKDF-SHA256. One of those keys, **EncKey_S** is +used for messages encrypted by device S, while the other, **EncKey_G** is used for encryption by device G. -Device S derives a confirmation payload that Device G can use to confirm that the channel is secure. It contains: +The keys are generated with the following HKDF parameters: -- The string `MATRIX_QR_CODE_LOGIN_INITIATE`, encrypted and authenticated with ChaCha20-Poly1305. +**EncKey_S** + +- `MATRIX_QR_CODE_LOGIN_ENCKEY_S|Gp|Sp` as the info, where **Gp** and **Sp** stand for the generating + device's and the scanning device's ephemeral public keys, encoded as unpadded base64. +- An all-zero salt. + +**EncKey_G** + +- `MATRIX_QR_CODE_LOGIN_ENCKEY_G|Gp|Sp` as the info, where **Gp** and **Sp** stand for the generating + device's and the scanning device's ephemeral public keys, encoded as unpadded base64. +- An all-zero salt. + +With this, Device S has established its side of the secure channel. Device S then derives a confirmation payload that +Device G can use to confirm that the channel is secure. It contains: + +- The string `MATRIX_QR_CODE_LOGIN_ENCKEY_S`, encrypted and authenticated with ChaCha20-Poly1305. - Its public ephemeral key **Sp**. ``` -Nonce := 0 +Nonce_S := 0 SH := ECDH(Ss, Gp) -EncKey := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN|" || Gp || "|" || Sp, salt=0, size=32) -NonceBytes := ToLowEndianBytes(Nonce)[..12] -TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey, NonceBytes, "MATRIX_QR_CODE_LOGIN_INITIATE") -Nonce := Nonce + 2 +EncKey_S := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_ENCKEY_S|" || Gp || "|" || Sp, salt=0, size=32) + +// Stored, but not yet used +EncKey_G := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_ENCKEY_G|" || Gp || "|" || Sp, salt=0, size=32) + +NonceBytes_S := ToLowEndianBytes(Nonce_S)[..12] +TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey_S, NonceBytes_S, "MATRIX_QR_CODE_LOGIN_INITIATE") +Nonce_S := Nonce_S + 1 LoginInitiateMessage := UnpaddedBase64(TaggedCiphertext) || "|" || UnpaddedBase64(Sp) ``` @@ -440,7 +461,8 @@ Device G receives **LoginInitiateMessage** (potentially coming from Device S) fr polling with `GET` requests. It then does the reverse of the previous step, obtaining **Sp**, deriving the shared secret using **Gs** and **Sp**, -discarding **Gs** and decrypting (and authenticating) the **TaggedCiphertext**, obtaining a plaintext. +discarding **Gs**, deriving the two symmetric encryption keys **EncKey_S** and **EncKey_G**, then finally +decrypting (and authenticating) the **TaggedCiphertext** using **EncKey_S**, obtaining a plaintext. It checks that the plaintext matches the string `MATRIX_QR_CODE_LOGIN_INITIATE`, failing and aborting if not. @@ -448,10 +470,10 @@ It then responds with a dummy payload containing the string `MATRIX_QR_CODE_LOGI as follows: ``` -Nonce := 1 -NonceBytes := ToLowEndianBytes(Nonce)[..12] -TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey, NonceBytes, "MATRIX_QR_CODE_LOGIN_OK") -Nonce := Nonce + 2 +Nonce_G := 1 +NonceBytes_G := ToLowEndianBytes(Nonce_G)[..12] +TaggedCiphertext := ChaCha20Poly1305_Encrypt(EncKey_G, NonceBytes_G, "MATRIX_QR_CODE_LOGIN_OK") +Nonce_G := Nonce_G + 1 LoginOkMessage := UnpaddedBase64Encode(TaggedCiphertext) ``` @@ -470,27 +492,29 @@ was indeed sent by Device G. It then verifies the plaintext matches `MATRIX_QR_C Nonce_G := 1 (TaggedCiphertext, Sp) := Unpack(Message) NonceBytes := ToLowEndianBytes(Nonce)[..12] -Plaintext := ChaCha20Poly1305_Decrypt(EncKey, NonceBytes, TaggedCiphertext) -Nonce_G := Nonce_G + 2 +Plaintext := ChaCha20Poly1305_Decrypt(EncKey_G, NonceBytes, TaggedCiphertext) +Nonce_G := Nonce_G + 1 unless Plaintext == "MATRIX_QR_CODE_LOGIN_OK": FAIL ``` -If the above was successful, Device S then calculates a two digit **CheckCode** code derived from **SH**, **Gp** and **Sp**: +If the above was successful, Device S then calculates a two digit **CheckCode** code derived from **SH**, **Gp** and +**Sp**: ``` CheckBytes := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_CHECKCODE|" || Gp "|" || Sp , salt=0, size=2) CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) ``` -Device S then displays an indication to the user that the secure channel has been established and that the **CheckCode** -should be entered on the other device when prompted. e.g. wording to say "secure connection established"; enter the code -XY on your other device; +Device S then displays an indicator to the user that the secure channel has been established and that the **CheckCode** +should be entered on the other device when prompted. Example wording could say "Secure connection established. Enter the +code XY on your other device." 7. **Out-of-band confirmation** -**Warning**: *This step is crucial for the security of the scheme since it overcomes the aforementioned limitation of ECIES.* +**Warning**: *This step is crucial for the security of the scheme since it overcomes the aforementioned limitation of +ECIES.* Device G asks the user to enter the **CheckCode** that is being displayed on Device S. @@ -507,7 +531,8 @@ CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) If the code that the user enters matches then the secure channel is established. -Subsequent payloads can be sent encrypted with **EncKey** with the nonces incremented as described above. +Subsequent payloads sent from G should be encrypted using **EncKey_G**, while payloads sent from S should be +encrypted with **EncKey_S**, incrementing the corresponding nonce for each message sent/received. #### Sequence diagram @@ -537,7 +562,7 @@ sequenceDiagram S->>+Z: GET /_matrix/client/rendezvous/abc-def Z->>-S: 200 OK
ETag: 1 - note over S: 4) Device S computes SH, EncKey and LoginInitiateMessage.
It sends LoginInitiateMessage via the rendezvous session + note over S: 4) Device S computes SH, EncKey_S, EncKey_G and LoginInitiateMessage.
It sends LoginInitiateMessage via the rendezvous session S->>+Z: PUT /_matrix/client/rendezvous/abc-def
If-Match: 1
Body: LoginInitiateMessage Z->>-S: 202 Accepted
ETag: 2 deactivate S @@ -546,7 +571,7 @@ sequenceDiagram activate G Z->>-G: 200 OK
ETag: 2
Body: Data - note over G: 5) Device G attempts to parse Data as LoginInitiateMessage after calculating SH and EncKey + note over G: 5) Device G attempts to parse Data as LoginInitiateMessage after calculating SH, EncKey_S and EncKey_G note over G: Device G checks that the plaintext matches MATRIX_QR_CODE_LOGIN_INITIATE note over G: Device G computes LoginOkMessage and sends to the rendezvous session @@ -576,21 +601,20 @@ sequenceDiagram Conceptually, once established, the secure channel offers two operations, `SecureSend` and `SecureReceive`, which wrap the `Send` and `Receive` operations offered by the rendezvous session API to securely send and receive data between two devices. -At the end of the establishment phase, the next nonce for Device G should be `3` and the next nonce for Device S should -be `2`. +At the end of the establishment phase, the next nonce for each device should be `1`. Device G sets: ``` -Nonce := 3 -NonceOther = 2 +Nonce_G := 1 +Nonce_S := 1 ``` Device S sets: ``` -Nonce := 2 -NonceOther := 3 +Nonce_G := 1 +Nonce_S := 1 ``` #### Threat analysis From 289a810f605c51b03d6405879a460b3b9b3c277b Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 16 Apr 2024 16:06:07 +0100 Subject: [PATCH 20/32] Add missing device id check step to sequence diagram --- proposals/4108-oidc-qr-login.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index fcb9c95e8db..49fddffb066 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1018,6 +1018,13 @@ sequenceDiagram rect rgba(0,255,0, 0.1) + E->>HS: GET /_matrix/client/v3/devices/{device_id} + alt device already exists + HS->>E: 200 OK + E->>N: SecureSend({ "type": "m.login.failure", "reason": "device_already_exists" }) + else device not found + HS->>E: 404 Not Found + end par E->>N: SecureSend({"type":"m.login.protocol_accepted"}) note over N: 4) New device polls the OIDC Provider awaiting the outcome as per RFC8628 OIDC From 25e8fcb2c34089efd707a98917d24a57d26d23b9 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 18 Apr 2024 18:29:00 +0100 Subject: [PATCH 21/32] Remove references to rendezvous session ID --- proposals/4108-oidc-qr-login.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 49fddffb066..7b5b6015acc 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -141,7 +141,7 @@ HTTP response codes, and Matrix error codes: - `400 Bad Request` (`M_INVALID_PARAM`) - a malformed [`ETag`](https://github.com/matrix-org/matrix-spec-proposals/blob/hughns/simple-rendezvous-capability/proposals/3886-simple-rendezvous-capability.md#the-update-mechanism) header was provided. -- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session ID is not valid (it could have expired) +- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) - `412 Precondition Failed` (`M_CONCURRENT_WRITE`, a new error code) - when the ETag does not match - `413 Payload Too Large` (`M_TOO_LARGE`) - the supplied payload is too large - `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited @@ -206,7 +206,7 @@ Pragma: no-cache HTTP response codes: - `204 No Content` - rendezvous session cancelled -- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session ID is not valid (it could have expired) +- `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) - `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited ##### Authentication @@ -389,7 +389,7 @@ separate deterministic, monotonically-incrementing nonce is used for each sender 2. **Create rendezvous session** Device G creates a rendezvous session by making a `POST` request (as described previously) to the nominated homeserver -with an empty payload. It parses the **id** and **server** received. +with an empty payload. It parses the **url** received. 3. **Initial key exchange** From e12945c5fdb9b831edc4f702862cdb433a96961b Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 18 Apr 2024 18:43:34 +0100 Subject: [PATCH 22/32] Fix POST endpoint and Location references --- proposals/4108-oidc-qr-login.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 7b5b6015acc..4012a598426 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -234,7 +234,7 @@ In order to make sure that no intermediate caches manipulate the ETags, the rend ###### CORS -For the `POST /_matrix/client/rendezvous` API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) +For the `POST /_matrix/client/v1/rendezvous` API endpoint, in addition to the standard Client-Server API [CORS](https://spec.matrix.org/v1.4/client-server-api/#web-browser-clients) headers, the ETag response header should also be allowed by exposing the following CORS header: ```http @@ -265,6 +265,8 @@ of preference: #### Example API usage +n.b. This example demonstrates how the 307 response can be used to delegate the rendezvous session to a different server. + ```mermaid sequenceDiagram participant A as Device A @@ -273,8 +275,8 @@ sequenceDiagram participant B as Device B Note over A: Device A determines which rendezvous server to use - A->>+HS: POST /_matrix/client/rendezvous
Content-Type: text/plain
"Hello from A" - HS->>-A: 307 https://rz.example.com/foo + A->>+HS: POST /_matrix/client/v1/rendezvous
Content-Type: text/plain
"Hello from A" + HS->>-A: 307 Temporary Redirect
Location: https://rz.example.com/foo A->>+R: POST /foo
Content-Type: text/plain
"Hello from A" R->>-A: 201 Created
ETag: 1
{"url":"https://rz.example.com/abc-def-123-456"} @@ -541,15 +543,15 @@ The sequence diagram for the above is as follows: ```mermaid sequenceDiagram participant G as Device G - participant Z as Rendezvous server + participant Z as Homeserver with embedded Rendezvous Server
matrix.example.com participant S as Device S note over G,S: 1) Devices G and S each generate an ephemeral Curve25519 key pair activate G note over G: 2) Device G creates a rendezvous session as follows - G->>+Z: POST /_matrix/client/rendezvous - Z->>-G: 201 Created
Location: /_matrix/client/rendezvous/abc-def
ETag: 1 + G->>+Z: POST /_matrix/client/v1/rendezvous + Z->>-G: 201 Created
ETag: 1
{"url": "https://matrix.example.com/_synapse/client/rendezvous/abc-def"} note over G: 3) Device G generates and displays a QR code containing
its ephemeral public key and the rendezvous session URL @@ -559,15 +561,15 @@ sequenceDiagram activate S note over S: Device S validates QR scanned and the rendezvous session URL - S->>+Z: GET /_matrix/client/rendezvous/abc-def + S->>+Z: GET /_synapse/client/rendezvous/abc-def Z->>-S: 200 OK
ETag: 1 note over S: 4) Device S computes SH, EncKey_S, EncKey_G and LoginInitiateMessage.
It sends LoginInitiateMessage via the rendezvous session - S->>+Z: PUT /_matrix/client/rendezvous/abc-def
If-Match: 1
Body: LoginInitiateMessage + S->>+Z: PUT /_synapse/client/rendezvous/abc-def
If-Match: 1
Body: LoginInitiateMessage Z->>-S: 202 Accepted
ETag: 2 deactivate S - G->>+Z: GET /_matrix/client/rendezvous/abc-def
If-None-Match: 1 + G->>+Z: GET /_synapse/client/rendezvous/abc-def
If-None-Match: 1 activate G Z->>-G: 200 OK
ETag: 2
Body: Data @@ -576,12 +578,12 @@ sequenceDiagram note over G: Device G computes LoginOkMessage and sends to the rendezvous session - G->>+Z: PUT /_matrix/client/rendezvous/abc-def
If-Match: 2
Body: LoginOkMessage + G->>+Z: PUT /_synapse/client/rendezvous/abc-def
If-Match: 2
Body: LoginOkMessage Z->>-G: 202 Accepted
ETag: 3 deactivate G activate S - S->>+Z: GET /_matrix/client/rendezvous/abc-def
If-None-Match: 2 + S->>+Z: GET /_synapse/client/rendezvous/abc-def
If-None-Match: 2 Z->>-S: 200 OK
ETag: 3
Body: Data note over S: 6) Device S attempts to parse Data as LoginOkMessage From 4f9a4a42e6ba442989bee06a037eaedecc1cc846 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Fri, 19 Apr 2024 17:54:11 +0100 Subject: [PATCH 23/32] Rendezvous sessions should have a fixed lifetime and allow enough time to complete login --- proposals/4108-oidc-qr-login.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 4012a598426..ff71531f7af 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -57,9 +57,8 @@ n.b. Once a new payload has been sent there is no mechanism to retrieve previous #### Expiry The rendezvous session (i.e. the payload) SHOULD expire after a period of time communicated to clients via the `Expires` -header. After this point, any further attempts to query or update the payload MUST fail. The expiry time SHOULD be -extended every time the payload is updated. The rendezvous session can be manually expired with a `DELETE` call to the -rendezvous session. +header. After this point, any further attempts to query or update the payload MUST fail. The rendezvous session can be +manually expired with a `DELETE` call to the rendezvous session. ####  API @@ -220,7 +219,10 @@ The server should allow a minimum payload size of 10KB and enforce a maximum pay ###### Maximum duration of a rendezvous -The rendezvous session only needs to persist for the duration of the handshake. So a timeout such as 30 seconds is adequate. +The rendezvous session needs to persist for the duration of the login. So a timeout such as 60 seconds should be adequate. + +It does need to allow the user another time to confirm that the secure channel has been established and complete any extra +OIDC Provider mandated login steps such as MFA. Clients should handle the case of the rendezvous session being cancelled or timed out by the server. From fbb30ec812b5ad5d05c6988d6cb4dd1c10802658 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 22 Apr 2024 11:03:39 +0100 Subject: [PATCH 24/32] Set max payload size to 4KB and fix content-type as text/plain (#4134) * Set max payload size and fix content-type as text/plain * Set max payload size to 4KB --- proposals/4108-oidc-qr-login.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index ff71531f7af..824da5c202b 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -77,7 +77,7 @@ This would be part of the Client-Server API. HTTP request headers: - `Content-Length` - required -- `Content-Type` - required +- `Content-Type` - required, must be `text/plain` HTTP request body: @@ -86,7 +86,8 @@ HTTP request body: HTTP response codes, and Matrix error codes: - `201 Created` - rendezvous session created -- `400 Bad Request` (``M_MISSING_PARAM``) - no `Content-Length` was provided. +- `400 Bad Request` (``M_MISSING_PARAM``) - either `Content-Length` and/or `Content-Type` was not provided. +- `400 Bad Request` (`M_INVALID_PARAM`) - an invalid `Content-Type` was given. - `403 Forbidden` (``M_FORBIDDEN``) - forbidden by server policy - `413 Payload Too Large` (``M_TOO_LARGE``) - the supplied payload is too large - `429 Too Many Requests` (``M_UNKNOWN``) - the request has been rate limited @@ -126,7 +127,7 @@ Pragma: no-cache HTTP request headers: - `Content-Length` - required -- `Content-Type` - required +- `Content-Type` - required, must be `text/plain` - `If-Match` - required. The ETag of the last payload seen by the requesting device. HTTP request body: @@ -139,7 +140,7 @@ HTTP response codes, and Matrix error codes: - `400 Bad Request` (`M_MISSING_PARAM`) - a required header was not provided. - `400 Bad Request` (`M_INVALID_PARAM`) - a malformed [`ETag`](https://github.com/matrix-org/matrix-spec-proposals/blob/hughns/simple-rendezvous-capability/proposals/3886-simple-rendezvous-capability.md#the-update-mechanism) -header was provided. +header was provided or invalid `Content-Type`. - `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) - `412 Precondition Failed` (`M_CONCURRENT_WRITE`, a new error code) - when the ETag does not match - `413 Payload Too Large` (`M_TOO_LARGE`) - the supplied payload is too large @@ -165,7 +166,7 @@ HTTP response codes, and Matrix error codes: HTTP response headers for `200 OK`: -- `Content-Type` - required +- `Content-Type` - required, `text/plain` - common headers as defined above HTTP response headers for `304 Not Modified`: @@ -215,7 +216,7 @@ described later. ##### Maximum payload size -The server should allow a minimum payload size of 10KB and enforce a maximum payload size which is recommended to be 100KB. +The server enforce a maximum payload size of 4KB. ###### Maximum duration of a rendezvous @@ -351,6 +352,21 @@ is possible to use it to circumvent firewalls and other network security measure Implementation may want to block their production IP addresses from being able to make requests to the rendezvous endpoints in order to avoid attackers using it as a dead-drop for exfiltrating data. +##### Unsafe content + +Because the rendezvous session is not authenticated, it is possible for an attacker to use it to distribute malicious +content. + +This could lead to a reputational problem for the homeserver domain or IPs, as well as potentially causing harm to users. + +Mitigations that are included in this proposal: + +- the low maximum payload size +- restricted allowed content type +- the rendezvous session should be short-lived +- the ability for the rendezvous session to be hosted on a different domain to the homeserver (via +the `307 Temporary Redirect` response behaviour) + ### Secure channel The above rendezvous session is insecure, providing no confidentiality nor authenticity against the rendezvous server or From fe939bed89d9b043984aa483593b986c1f105e01 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 22 Apr 2024 16:41:00 +0100 Subject: [PATCH 25/32] Cross signing is mandatory The user must having cross signing set up and the private keys available on the existing device for the process to complete. --- proposals/4108-oidc-qr-login.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 824da5c202b..e099b9291ad 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -20,6 +20,12 @@ In order for the new device to be fully set up, it needs to exchange information - The existing device can facilitate the new device in getting an access token - The existing device shares the secrets necessary to set up end-to-end encryption +This proposal is split into three parts: + +1. An insecure rendezvous session API to allow the two devices to exchange the necessary data +2. A secure channel to protect the data exchanged over the rendezvous session +3. The OIDC login part and set up of E2EE + ### Insecure rendezvous session It is proposed that an HTTP-based protocol be used to establish an ephemeral bi-directional communication session over @@ -1196,18 +1202,11 @@ deactivate HS activate N note over N: 3) New device stores the secrets locally -alt is cross_signing present in m.login.secrets? note over N: New device signs itself note over N: New device uploads device keys and cross-signing signature: N->>+HS: POST /_matrix/client/v3/keys/upload HS->>-N: 200 OK -else - note over N: New device uploads device keys only: - N->>+HS: POST /_matrix/client/v3/keys/upload - HS->>-N: 200 OK -end - alt is backup present in m.login.secrets? note over N: New device connects to room-key backup end @@ -1364,7 +1363,7 @@ Fields: |Field|Type|| |--- |--- |--- | |`type`|required `string`|`m.login.secrets`| -|`cross_signing`|`object`|
Field Type
master_key required string Unpadded base64 encoded private key
self_signing_key required string Unpadded base64 encoded private key
user_signing_key required string Unpadded base64 encoded private key
| +|`cross_signing`|required `object`|
Field Type
master_key required string Unpadded base64 encoded private key
self_signing_key required string Unpadded base64 encoded private key
user_signing_key required string Unpadded base64 encoded private key
| |`backup`|`object`|
Field Type
algorithm required string One of the algorithms listed at https://spec.matrix.org/v1.9/client-server-api/#server-side-key-backups
key required string Unpadded base64 encoded private/secret key
backup_version required string The backup version as returned by [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.10/client-server-api/#post_matrixclientv3room_keysversion)
| Example: @@ -1465,6 +1464,9 @@ For a new device it would need to know the homeserver ahead of time in order to Additionally the new device needs to either have an existing (i.e. static) OIDC client registered with the OIDC Provider already, or the OIDC Provider must support and allow dynamic client registration as described in [MSC2966](https://github.com/matrix-org/matrix-spec-proposals/pull/2966). +The feature is also only available where a user has cross-signing set up and the existing device to be used has the +Master Signing Key, Self Signing Key and User Signing Key stored locally so that they can be shared with the new device. + ## Potential issues Because this is an entirely new set of functionality it should not cause issue with any existing Matrix functions or capabilities. From 76f175b0110dbda4deb33c33c692a1a7202a42ba Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 22 Apr 2024 16:57:32 +0100 Subject: [PATCH 26/32] Use unstable prefix for errcode --- proposals/4108-oidc-qr-login.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index e099b9291ad..da5d535682e 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1562,6 +1562,26 @@ key org.matrix.msc4108 set to true. So, the response could look then as followin } ``` +Furthermore, where a new `errcode` is being introduced the existing `M_UNKNOWN` code should be used instead, with the new +code placed in a `org.matrix.msc4108.errcode` field instead. For example, instead of: + +```json +{ + "errcode": "M_CONCURRENT_WRITE", + "error": "Data was modified" +} +``` + +The server should send: + +```json +{ + "errcode": "M_UNKNOWN", + "org.matrix.msc4108.errcode": "M_CONCURRENT_WRITE", + "error": "Data was modified" +} +``` + ## Dependencies This MSC builds on [MSC3861](https://github.com/matrix-org/matrix-spec-proposals/pull/3861) (and its dependencies) which From 0ca3dea0bd9422011f440da79b32df189dcdf479 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 23 Apr 2024 17:26:39 +0100 Subject: [PATCH 27/32] The If-Match header on PUT requests contains the ETag --- proposals/4108-oidc-qr-login.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index da5d535682e..ac85b678781 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -50,9 +50,9 @@ In this way, Device A and Device B can communicate by repeatedly inspecting and #### The send mechanism -Every send request MUST include an `ETag` header, whose value is supplied by the `ETag` header in the last `GET` +Every send request MUST include an `If-Match` header whose value is the `ETag` header in the last `GET` response seen by the requester. (The initiating device may also use the `ETag` supplied in the initial `POST` response -to immediately update the payload.) Updates will succeed only if the supplied `ETag` matches the server's current +to immediately update the payload.) Sends will succeed only if the supplied `ETag` matches the server's current revision of the payload. This prevents concurrent writes to the payload. The `ETag` header is standard, described by [RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#name-etag). In this From 02f18e1a303cd669e5f22e407f4e310776a4c48e Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 8 May 2024 11:15:29 +0100 Subject: [PATCH 28/32] Fix description of 304 GET response --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index ac85b678781..ea3bfce078c 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -166,7 +166,7 @@ only return data if given ETag does not match HTTP response codes, and Matrix error codes: - `200 OK` - payload returned -- `304 Not Modified` - when `If-None-Match` is supplied and the ETag does not match +- `304 Not Modified` - when `If-None-Match` is supplied and the ETag matched the existing payload - `404 Not Found` (`M_NOT_FOUND`) - rendezvous session URL is not valid (it could have expired) - `429 Too Many Requests` (`M_UNKNOWN`) - the request has been rate limited From f49fd7f5827b3be9a3d9d62f95c71620a8029104 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Tue, 28 May 2024 10:12:48 +0100 Subject: [PATCH 29/32] Fix m.login.failure reason typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Damir Jelić --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index ea3bfce078c..a4ed9e88141 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1307,7 +1307,7 @@ Example: ```json { "type":"m.login.failure", - "reason": "unsupported", + "reason": "unsupported_protocol", "homeserver": "https://matrix-client.matrix.org" } ``` From 73da95a970733f625340cb7bd928268b95a76aa9 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Thu, 30 May 2024 13:39:39 +0100 Subject: [PATCH 30/32] Fix originator of m.login.declined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Damir Jelić --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index a4ed9e88141..56e4cbf4327 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -1314,7 +1314,7 @@ Example: ##### `m.login.declined` -Sent by: existing device +Sent by: new device Purpose: Indicates that the user declined the request From 87f8317a902cd7bc5c2d2d225f71021b3a509e2d Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 12 Jun 2024 13:32:34 +0100 Subject: [PATCH 31/32] Use server name rather than base URL and clarify well-known discovery --- proposals/4108-oidc-qr-login.md | 54 +++++++++++++++------------- proposals/images/4108-qr-mode04.png | Bin 1019 -> 917 bytes 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 56e4cbf4327..9d26cc56b32 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -425,7 +425,7 @@ Device G displays a QR code containing: - The insecure rendezvous session **URL** - An indicator (the **intent**) to say if this is a new device which wishes to "initiate" a login, or an existing device that wishes to "reciprocate" a login -- If the intent is to reciprocate a login, then the **homeserver base URL** +- If the intent is to reciprocate a login, then the Matrix homeserver **[server name](https://spec.matrix.org/v1.10/appendices/#server-name)** To get a good trade-off between visual compactness and high level of error correction we use a binary mode QR with a similar structure to that of the existing Device Verification QR code encoding described in [Client-Server @@ -433,8 +433,8 @@ API](https://spec.matrix.org/v1.9/client-server-api/#qr-code-format). This is defined in detail in a separate section of this proposal. -Device S scans and parses the QR code to obtain **Gp**, the rendezvous session **URL**, **intent** and optionally the -**homeserver base URL**. +Device S scans and parses the QR code to obtain **Gp**, the rendezvous session **URL**, **intent** and optionally the Matrix homeserver +**[server name](https://spec.matrix.org/v1.10/appendices/#server-name)**. At this point Device S should check that the received intent matches what the user has asked to do on the device. @@ -690,7 +690,7 @@ This can make it hard to read what is going on. The new device needs to know which homeserver it will be authenticating with. -In the case that the new device scanned the QR code then the homeserver base URL can be taken from the QR code and the +In the case that the new device scanned the QR code then the [server name](https://spec.matrix.org/v1.10/appendices/#server-name) of the Matrix homeserver can be taken from the QR code and the new device proceeds to step 2 immediately. Otherwise the new device waits to be informed by receiving an `m.login.protocols` message from the existing device. @@ -709,14 +709,17 @@ homeserver specified: { "type": "m.login.protocols", "protocols": ["device_authorization_grant"], - "homeserver": "https://synapse-oidc.lab.element.dev" + "homeserver": "synapse-oidc.lab.element.dev" } ``` 2. **New device checks if it can use an available protocol** -Once the existing device knows which homeserver it is to use it then: +Once the existing device has determined the server name it then undertakes steps to determine if it is able to work with the homeserver. +The steps are as follows: + +- use [Server Discovery](https://spec.matrix.org/v1.10/client-server-api/#server-discovery) to determine the `base_url` from the well-known URI - checks that the homeserver is using delegated OIDC by calling `GET /_matrix/client/v1/auth_issuer` from [MSC2965](https://github.com/matrix-org/matrix-spec-proposals/pull/2965): *New device => Homeserver via HTTP* @@ -847,22 +850,22 @@ sequenceDiagram rect rgba(255,0,0, 0.1) #alt if New device scanned QR code note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel - note over N: 1) New device got Homeserver base URL from QR code + note over N: 1) New device got server name from the QR code #else if Existing device scanned QR code # note over E: Existing device completes step 6 # note over E: Existing device displays checkmark and CheckCode # note over E: 1) Existing device sends m.login.protocols message - # E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"}) + # E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "matrix.org"}) # note over N: New device waits for user to confirm secure channel from step 7 - # Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"} + # Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "matrix.org"} # note over N: If user enters the correct CheckCode and confirms checkmark
then new device now trusts the channel, and uses the homeserver provided end rect rgba(0,255,0, 0.1) note over N: 2) New device checks if it can use an available protocol: - + note over N: Use well-known discovery to get the homeserver base URL N->>+HS: GET /_matrix/client/v1/auth_issuer activate N HS-->>-N: 200 OK {"issuer": "https://id.matrix.org"} @@ -898,7 +901,7 @@ sequenceDiagram note over E: Existing device checks that requested protocol is supported alt if requested protocol is not valid - E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "https://matrix-client.matrix.org}) + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "matrix.org}) end end ``` @@ -917,22 +920,23 @@ sequenceDiagram #alt if New device scanned QR code # note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel - # note over N: 1) New device got Homeserver base URL from QR code + # note over N: 1) New device got server name from the QR code rect rgba(0,0,255, 0.1) #else if Existing device scanned QR code note over E: Existing device completes step 6 note over E: Existing device displays checkmark and CheckCode note over E: 1) Existing device sends m.login.protocols message - E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"}) + E->>Z: SecureSend({"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "matrix.org"}) note over N: New device waits for user to confirm secure channel from step 7 - Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "https://matrix-client.matrix.org"} + Z->>N: SecureReceive() => {"type":"m.login.protocols", "protocols":["device_authorization_grant],
"homeserver": "matrix.org"} note over N: If user enters the correct CheckCode and confirms checkmark
then new device now trusts the channel, and uses the homeserver provided end rect rgba(0,255,0, 0.1) note over N: 2) New device checks if it can use an available protocol: + note over N: Use well-known discovery to get the homeserver base URL N->>+HS: GET /_matrix/client/v1/auth_issuer activate N HS-->>-N: 200 OK {"issuer": "https://id.matrix.org"} @@ -966,7 +970,7 @@ sequenceDiagram note over E: Existing device checks that requested protocol is supported alt if requested protocol is not valid - E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "https://matrix-client.matrix.org}) + E->>N: SecureSend({"type":"m.login.failure", "reason":"unsupported_protocol",
"homeserver": "matrix.org}) end end ``` @@ -1234,13 +1238,13 @@ Fields: |--- |--- |--- | |`type`|required `string`|`m.login.protocols`| |`protocols`|required `string[]`|Array of: one of: `device_authorization_grant` | -|`homeserver`|required `string`|The base URL of the homeserver| +|`homeserver`|required `string`|The [server name](https://spec.matrix.org/v1.10/appendices/#server-name) of the Matrix homeserver| ```json { "type": "m.login.protocols", "protocols": ["device_authorization_grant"], - "homeserver": "https://matrix-client.matrix.org" + "homeserver": "matrix.org" } ``` @@ -1300,7 +1304,7 @@ Fields: |--- |--- |--- | |`type`|required `string`|`m.login.failure`| |`reason`|required `string`| One of:
Value Description
authorization_expired The Device Authorization Grant expired
device_already_exists The device ID specified by the new client already exists in the Homeserver provided device list
device_not_foundThe new device is not present in the device list as returned by the Homeserver
unexpected_message_receivedSent by either device to indicate that they received a message of a type that they weren't expecting
unsupported_protocolSent by a device where no suitable protocol is available or the requested protocol requested is not supported
user_cancelledSent by either new or existing device to indicate that the user has cancelled the login
| -|`homeserver`|`string`| When the existing device is sending this it can include the Base URL of the homeserver so that the new device can at least save the user the hassle of typing it in| +|`homeserver`|`string`| When the existing device is sending this it can include the [server name](https://spec.matrix.org/v1.10/appendices/#server-name) of the Matrix homeserver so that the new device can at least save the user the hassle of typing it in| Example: @@ -1308,7 +1312,7 @@ Example: { "type":"m.login.failure", "reason": "unsupported_protocol", - "homeserver": "https://matrix-client.matrix.org" + "homeserver": "matrix.org" } ``` @@ -1404,9 +1408,9 @@ The QR codes to be displayed and scanned using this format will encode binary st - two bytes in network byte order (big-endian) indicating the length in bytes of the rendezvous session URL as a UTF-8 string - the rendezvous session URL as a UTF-8 string -- If the QR code intent/mode is `0x04` then the homeserver base URL encode as: - - two bytes in network byte order (big-endian) indicating the length in bytes of the homeserver base URL as a UTF-8 string - - the homeserver base URL as a UTF-8 string +- If the QR code intent/mode is `0x04` then the [server name](https://spec.matrix.org/v1.10/appendices/#server-name) of the homeserver encoded as: + - two bytes in network byte order (big-endian) indicating the length in bytes of the server name as a UTF-8 string + - the server name as a UTF-8 string For example, if Alice displays a QR code encoding the following binary string: @@ -1434,15 +1438,15 @@ Which looks as follows as a QR with error correction level Q: A full example for an existing device using ephemeral public key `2IZoarIZe3gOMAqdSiFHSAcA15KfOasxueUUNwJI7Ws` (base64 encoded), at rendezvous session `https://rendezvous.lab.element.dev/e8da6355-550b-4a32-a193-1619d9830668` on homeserver -`https://matrix-client.matrix.org` is as follows: (Whitespace is for readability only) +`matrix.org` is as follows: (Whitespace is for readability only) ``` 4D 41 54 52 49 58 02 04 d8 86 68 6a b2 19 7b 78 0e 30 0a 9d 4a 21 47 48 07 00 d7 92 9f 39 ab 31 b9 e5 14 37 02 48 ed 6b 00 47 68 74 74 70 73 3a 2f 2f 72 65 6e 64 65 7a 76 6f 75 73 2e 6c 61 62 2e 65 6c 65 6d 65 6e 74 2e 64 65 76 2f 65 38 64 61 36 33 35 35 2d 35 35 30 62 2d 34 61 33 32 2d 61 31 39 33 2d 31 36 31 39 64 39 38 33 30 36 36 38 -00 20 -68 74 74 70 73 3a 2f 2f 6d 61 74 72 69 78 2d 63 6c 69 65 6e 74 2e 6d 61 74 72 69 78 2e 6f 72 67 +00 0A +6d 61 74 72 69 78 2e 6f 72 67 ``` Which looks as follows as a QR with error correction level Q: diff --git a/proposals/images/4108-qr-mode04.png b/proposals/images/4108-qr-mode04.png index 68dc9c93b337ca6361f5a6ff9c74ca2389568f7e..b01ee1e3672f4a71d14c35a58647679c87c3b632 100644 GIT binary patch delta 876 zcmV-y1C#vw2bBjQiBL{Q4GJ0x0000DNk~Le0002D0002D0RsR40BWFJ+>s$Te9VC^0}O0{*;2Y}BT_a1U5W_bQ2*$oPuB6o+&SJylQzxx5xHm6_0ieG|MBq z)Hc`lFiQU9!pSb2S8wNJ)%;=jfAG8!)*lbkl$_gx_?7a&v=R;JPae8B^1on{|M>kr zmoAR$_T@A*u-iNWcfaeTi{FGwV33pSGrFtt{@!OV=UA@fBx#(d;0`LUq~RCmIp$}z zQ$Y6GGommw{0`+dZHOb+az(d=@%4$flb@6qwiMhMXfiww zSL1HO`{%u#{9?lT12>2O1Zt=(TkYp(;0wX}yrhDoe1tr+hF>*LL~D?0NB2zzuX751 zBG|;2=-Y^9;gsiZ9{Tu|e;Rp$ra}3aN~;&GQ}ENHN2GH%Kkiku?t3ns{PskWx)D-< zr$9tH?oQtzwy5x#?Eq;?PQkA#4Faj$MQpL{Z@+YNcJKRw0$Y8Nzd^+-0)$6H_QyTF ztt4tVBVz&WRyH`AN572c$47cOH^|x^M+n09md#JU^m2&FP4+<$e>XS?ioufC@G~@m zbVDR1SjTC+Si|oy9v&WzVnF|noajML!LQg>%CJZYoKRHgAl7hxKQiSonLNx9wxZ!2 zWw?5>M9mdaX+Qna%@aHb6_p2(Zn!`0orXsgCm+FzO=D28FwIdc zfPxJ9c#DSPdx4+;8K-a%z8AjnYB&lT#|N5(Bge~n2* zK~z|U?U+A~v^WsO3psEG7qG-NocT&{0cb7&S90cSSn>rRb6`>Xis{kr2D?&Mr(dg+ z<|hrN{=D}X;{W>4AM(HCB$_L8EEhMjL?I86IxWG4IpsOEHMPZ4Pkba?)RO2HKc1A= zXs(E#c}O&WLDrhPIKC*)mF8HEfA7d*TUX10N3Z3!{1xGb^KzsiwJzn}=k@REd`zT2 z$^Gm5kIsEc@VW8yY>w3WKvR&*tR;779iyn=BuB2i2i~;glKWs1X$j0Jlf@k6K}&F- zA@Oa|XF2}L=sf9(H8+k~9a)S|o2*-7p7o?n9(Qn)$3&Ygx`D?-OHN--f7x2I;k?y# zfVHh!aufQ4@i8a4A>}EI7iL^bPHzsDx$Xl7TzZ8{tXgu_O!(W$;cg^jSng0*OKuuZ z&%4E=J4oOW`4vVr;Yw>l!`(z>tK(5IIJwi3E0!0PD~T{~sHk^+aI2Oui=3R+92M8F zE2u$J6RCk6Z%yl99nV`Rs_}!CBP~} zm7j&ylB;5(8=?eRM;@!po9v&GFq#v_JB+*dt!UoGck>dQh=*Wm6L}FN?u}|2$rlAc4QS^EqKz zU+OIinI|bg`}J)Nf4M5G)tpum(;3`CZFt{DLvGX{VRmS!2(utK`)}I#oM2@UdAOFB zWlZ92F^q4YQ;<{MMa(WC5e|v(h@xIv0)gMbv2Ark-b79z?*=WwT$61JB)Jl<^>S)H zv;=wpMPaBNVys2vX%o3wOD@S@;P^F)UBEQLPg>Uyh{{%Jf1)S*d)}hNflf=9TZgx< zXkH{WcwWVR`lBNfPjJ#LVLzNW8~@(tbMi>L*p3K;q$h*SxN3>K&#{{VRG}dYEFKH@ z1&N|nD-tn1YZnmoe%wq;62fNLEsN6Q3EB@$|rYj>iB1002ovPDHLkV1gaB B*)0G7 From 0b315f54398222b5ec114f7ae1aaf6801e341aab Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Sat, 21 Sep 2024 16:11:45 +0100 Subject: [PATCH 32/32] Update 4108-oidc-qr-login.md Co-authored-by: Denis Kasak --- proposals/4108-oidc-qr-login.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/4108-oidc-qr-login.md b/proposals/4108-oidc-qr-login.md index 9d26cc56b32..cd9b7272b2e 100644 --- a/proposals/4108-oidc-qr-login.md +++ b/proposals/4108-oidc-qr-login.md @@ -529,7 +529,7 @@ If the above was successful, Device S then calculates a two digit **CheckCode** **Sp**: ``` -CheckBytes := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_CHECKCODE|" || Gp "|" || Sp , salt=0, size=2) +CheckBytes := HKDF_SHA256(SH, "MATRIX_QR_CODE_LOGIN_CHECKCODE|" || Gp || "|" || Sp , salt=0, size=2) CheckCode := NumToString(CheckBytes[0] % 10) || NumToString(CheckBytes[1] % 10) ```