Skip to content

Sliding Sync: Notify and sync when one-time keys or fallback keys are claimed/uploaded #17820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Oct 10, 2024

Notify and sync when one-time keys or fallback keys are claimed/uploaded

Applies to Sync v2 and Sliding Sync although Sync v2 is untested in this area.

Fix #17474

Dev notes

Devices will generate one-time keys and upload them to the server; these will later be claimed by other users. Servers must ensure that each one-time key is only claimed once: a homeserver should discard the one time key once it has been given to another user.

Devices will be informed, via /sync, about the number of one-time keys remaining that can be claimed, as well as whether the fallback keys have been used. The device can thus ensure that, while it is online, there is a sufficient supply of one-time keys available, and that the fallback keys get replaced if they have been used.

https://spec.matrix.org/v1.11/client-server-api/#one-time-and-fallback-keys

Claiming one-time keys

POST /_matrix/client/v3/keys/claim

e2e_keys_handler.claim_one_time_keys
e2e_keys_handler.claim_local_one_time_keys

store.claim_e2e_one_time_keys
store.claim_e2e_fallback_keys

Uploading one-time keys

POST /_matrix/client/v3/keys/upload

e2e_keys_handler.upload_keys_for_user
e2e_keys_handler._upload_one_time_keys_for_user
e2e_keys_handler.set_e2e_fallback_keys

Todo

  • Handle workers/replication (keys are uploaded/claimed on one worker and we are notifier.wait_for_events() on a another worker like a syncotron)

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

Comment on lines +939 to +940
# FIXME: How can we poke the replication so that other workers also see the
# one-time key change
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the way to actually fix this is to introduce a new stream like StreamKeyType.E2EE_KEYS/E2eeKeysStream for changes to one-time or fallback keys changing?

Just want to sanity check before I go that route.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

notifier.wait_for_events(user_id) should notify when device_one_time_keys_count changes
1 participant