matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.19k stars 232 forks source link

Store sender data for Megolm sessions as per Invisible crypto #3544

Closed andybalaam closed 3 days ago

andybalaam commented 2 months ago

Part of Invisible Crypto.

Currently when we store an Inbound group session, we associate some SessionCreatorInfo to it. Currently this info mainly contains the curve25519 identity key of the session creator.

We need now to add more info:

We are currently computing the "authenticity" of a megolm session but we are doing it at decryption time. The info we get at decryption time are sender: OwnedUserId and sender_device: OwnedDeviceId. Both related to a VerificationState. This owner info is untrusted (claimed), unless the VerificationState is Trusted.

The VerificationState variants are:

We are basically trying to get this same info but at reception time.

Three places we populate SenderData in an InboundGroupSession

  1. When we receive the room keys via a to-device message. (This is already done via SenderDataFinder.)

  2. When we get new or updated device info from /keys/query. To do this we need to be able to look up InboundGroupSessions that don't have SenderData by device curve key. This will require a new index on the inboundgroupsessions table. Question: if there are lots of sessions for a particular device, will we break everything by working through batches of them to update them?

  3. When we decrypt a message for a session. In this case we have the session and device already, so it's just a case of persisting (into inboundgroupsessions) the VerificationState that we already look up at this moment.

The plan

In order to complete this we need to do these tasks:

Old tasks that are no longer relevant (see old plan in a comment below):

Out of scope


[Moved from https://github.com/element-hq/crypto-internal/issues/310]

andybalaam commented 1 month ago

Old description for reference:

Part of Invisible Crypto.

Currently when we store an Inbound group session, we associate some SessionCreatorInfo to it. Currently this info mainly contains the curve25519 identity key of the session creator.

We need now to add more info:

We are currently computing the "authenticity" of a megolm session but we are doing it at decryption time. The info we get at decryption time are sender: OwnedUserId and sender_device: OwnedDeviceId. Both related to a VerificationState. This owner info is untrusted (claimed), unless the VerificationState is Trusted.

The VerificationState variants are:

We are basically trying to get this same info but at reception time.

Three speeds for handling a new session

When we receive a to-device message establishing a megolm session, we want to process it as quickly as possible, so there are 3 speeds:

"Quarantine"

(These ideas will be used by e.g. https://github.com/element-hq/crypto-internal/issues/308 - not really for this issue.)

In previous documents, we talked about "quarantine", but this is a difficult subject because different sessions will be acceptable to different clients at different times. We prefer to talk about what messages will be shown in what modes. These are some possible policies:

Importing session keys

If we import a session from backup or from an exported file, we mark it as legacy and let the background task handle it.

The plan

In order to complete this we need to do these tasks:

In addition, as a separate story, we need to this:


[Moved from https://github.com/element-hq/crypto-internal/issues/310]