This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 823
Add support for device dehydration v2 #12316
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6b12844
rehydrate/dehydrate device if configured in well-known
uhoreg d89e379
add handling for dehydrated devices
uhoreg bef714c
some fixes
uhoreg bdff188
schedule dehydration
uhoreg 1b79b6e
improve display of own dehydrated device
uhoreg 2f16e94
created dehydrated device when creating or resetting SSSS
uhoreg 685926d
some UI tweaks
uhoreg 91a8d81
reorder strings
uhoreg 861ab63
lint
uhoreg a325e3f
Merge branch 'develop' into dehydration_v2
uhoreg b0b0662
remove statement for testing
uhoreg aeac5c7
add playwright test
uhoreg 18da268
lint and fix broken test
uhoreg abe5057
Merge branch 'develop' into dehydration_v2
uhoreg 1269c76
update to new dehydration API
uhoreg 8ff1e8c
some fixes from review
uhoreg 93da280
try to fix test error
uhoreg b456185
remove unneeded debug line
uhoreg ac6bb3a
apply changes from review
uhoreg 3d51646
add Jest tests
uhoreg a974159
fix typo
uhoreg e1a19d9
don't need Object.assign
uhoreg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
Copyright 2024 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { Locator, type Page } from "@playwright/test"; | ||
|
||
import { test as base, expect } from "../../element-web-test"; | ||
import { viewRoomSummaryByName } from "../right-panel/utils"; | ||
import { isDendrite } from "../../plugins/homeserver/dendrite"; | ||
|
||
const test = base.extend({ | ||
// eslint-disable-next-line no-empty-pattern | ||
startHomeserverOpts: async ({}, use) => { | ||
await use("dehydration"); | ||
}, | ||
config: async ({ homeserver, context }, use) => { | ||
const wellKnown = { | ||
"m.homeserver": { | ||
base_url: homeserver.config.baseUrl, | ||
}, | ||
"org.matrix.msc3814": true, | ||
}; | ||
|
||
await context.route("https://localhost/.well-known/matrix/client", async (route) => { | ||
await route.fulfill({ json: wellKnown }); | ||
}); | ||
|
||
await use({ | ||
default_server_config: wellKnown, | ||
}); | ||
}, | ||
}); | ||
|
||
const ROOM_NAME = "Test room"; | ||
const NAME = "Alice"; | ||
|
||
function getMemberTileByName(page: Page, name: string): Locator { | ||
return page.locator(`.mx_EntityTile, [title="${name}"]`); | ||
} | ||
|
||
test.describe("Dehydration", () => { | ||
test.skip(isDendrite, "does not yet support dehydration v2"); | ||
|
||
test.use({ | ||
displayName: NAME, | ||
}); | ||
|
||
test("Create dehydrated device", async ({ page, user, app }, workerInfo) => { | ||
test.skip(workerInfo.project.name === "Legacy Crypto", "This test only works with Rust crypto."); | ||
|
||
// Create a backup (which will create SSSS, and dehydrated device) | ||
|
||
const securityTab = await app.settings.openUserSettings("Security & Privacy"); | ||
|
||
await expect(securityTab.getByRole("heading", { name: "Secure Backup" })).toBeVisible(); | ||
await expect(securityTab.getByText("Offline device enabled")).not.toBeVisible(); | ||
await securityTab.getByRole("button", { name: "Set up", exact: true }).click(); | ||
|
||
const currentDialogLocator = page.locator(".mx_Dialog"); | ||
|
||
// It's the first time and secure storage is not set up, so it will create one | ||
await expect(currentDialogLocator.getByRole("heading", { name: "Set up Secure Backup" })).toBeVisible(); | ||
await currentDialogLocator.getByRole("button", { name: "Continue", exact: true }).click(); | ||
await expect(currentDialogLocator.getByRole("heading", { name: "Save your Security Key" })).toBeVisible(); | ||
await currentDialogLocator.getByRole("button", { name: "Copy", exact: true }).click(); | ||
await currentDialogLocator.getByRole("button", { name: "Continue", exact: true }).click(); | ||
|
||
await expect(currentDialogLocator.getByRole("heading", { name: "Secure Backup successful" })).toBeVisible(); | ||
await currentDialogLocator.getByRole("button", { name: "Done", exact: true }).click(); | ||
|
||
// Open the settings again | ||
await app.settings.openUserSettings("Security & Privacy"); | ||
|
||
// The Security tab should indicate that there is a dehydrated device present | ||
await expect(securityTab.getByText("Offline device enabled")).toBeVisible(); | ||
|
||
await app.settings.closeDialog(); | ||
|
||
// the dehydrated device gets created with the name "Dehydrated | ||
// device". We want to make sure that it is not visible as a normal | ||
// device. | ||
const sessionsTab = await app.settings.openUserSettings("Sessions"); | ||
await expect(sessionsTab.getByText("Dehydrated device")).not.toBeVisible(); | ||
|
||
await app.settings.closeDialog(); | ||
|
||
// now check that the user info right-panel shows the dehydrated device | ||
// as a feature rather than as a normal device | ||
await app.client.createRoom({ name: ROOM_NAME }); | ||
|
||
await viewRoomSummaryByName(page, app, ROOM_NAME); | ||
|
||
await page.getByRole("menuitem", { name: "People" }).click(); | ||
await expect(page.locator(".mx_MemberList")).toBeVisible(); | ||
|
||
await getMemberTileByName(page, NAME).click(); | ||
await page.locator(".mx_UserInfo_devices .mx_UserInfo_expand").click(); | ||
|
||
await expect(page.locator(".mx_UserInfo_devices").getByText("Offline device enabled")).toBeVisible(); | ||
await expect(page.locator(".mx_UserInfo_devices").getByText("Dehydrated device")).not.toBeVisible(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
playwright/plugins/homeserver/synapse/templates/dehydration/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A synapse configured with device dehydration v2 enabled |
102 changes: 102 additions & 0 deletions
102
playwright/plugins/homeserver/synapse/templates/dehydration/homeserver.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
server_name: "localhost" | ||
pid_file: /data/homeserver.pid | ||
public_baseurl: "{{PUBLIC_BASEURL}}" | ||
listeners: | ||
- port: 8008 | ||
tls: false | ||
bind_addresses: ["::"] | ||
type: http | ||
x_forwarded: true | ||
|
||
resources: | ||
- names: [client] | ||
compress: false | ||
|
||
database: | ||
name: "sqlite3" | ||
args: | ||
database: ":memory:" | ||
|
||
log_config: "/data/log.config" | ||
|
||
rc_messages_per_second: 10000 | ||
rc_message_burst_count: 10000 | ||
rc_registration: | ||
per_second: 10000 | ||
burst_count: 10000 | ||
rc_joins: | ||
local: | ||
per_second: 9999 | ||
burst_count: 9999 | ||
remote: | ||
per_second: 9999 | ||
burst_count: 9999 | ||
rc_joins_per_room: | ||
per_second: 9999 | ||
burst_count: 9999 | ||
rc_3pid_validation: | ||
per_second: 1000 | ||
burst_count: 1000 | ||
|
||
rc_invites: | ||
per_room: | ||
per_second: 1000 | ||
burst_count: 1000 | ||
per_user: | ||
per_second: 1000 | ||
burst_count: 1000 | ||
|
||
rc_login: | ||
address: | ||
per_second: 10000 | ||
burst_count: 10000 | ||
account: | ||
per_second: 10000 | ||
burst_count: 10000 | ||
failed_attempts: | ||
per_second: 10000 | ||
burst_count: 10000 | ||
|
||
media_store_path: "/data/media_store" | ||
uploads_path: "/data/uploads" | ||
enable_registration: true | ||
enable_registration_without_verification: true | ||
disable_msisdn_registration: false | ||
registration_shared_secret: "{{REGISTRATION_SECRET}}" | ||
report_stats: false | ||
macaroon_secret_key: "{{MACAROON_SECRET_KEY}}" | ||
form_secret: "{{FORM_SECRET}}" | ||
signing_key_path: "/data/localhost.signing.key" | ||
|
||
trusted_key_servers: | ||
- server_name: "matrix.org" | ||
suppress_key_server_warning: true | ||
|
||
ui_auth: | ||
session_timeout: "300s" | ||
|
||
oidc_providers: | ||
- idp_id: test | ||
idp_name: "OAuth test" | ||
issuer: "http://localhost:{{OAUTH_SERVER_PORT}}/oauth" | ||
authorization_endpoint: "http://localhost:{{OAUTH_SERVER_PORT}}/oauth/auth.html" | ||
# the token endpoint receives requests from synapse, rather than the webapp, so needs to escape the docker container. | ||
token_endpoint: "http://host.containers.internal:{{OAUTH_SERVER_PORT}}/oauth/token" | ||
userinfo_endpoint: "http://host.containers.internal:{{OAUTH_SERVER_PORT}}/oauth/userinfo" | ||
client_id: "synapse" | ||
discover: false | ||
scopes: ["profile"] | ||
skip_verification: true | ||
client_auth_method: none | ||
user_mapping_provider: | ||
config: | ||
display_name_template: "{{ user.name }}" | ||
|
||
# Inhibit background updates as this Synapse isn't long-lived | ||
background_updates: | ||
min_batch_size: 100000 | ||
sleep_duration_ms: 100000 | ||
|
||
experimental_features: | ||
msc2697_enabled: false | ||
msc3814_enabled: true |
50 changes: 50 additions & 0 deletions
50
playwright/plugins/homeserver/synapse/templates/dehydration/log.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Log configuration for Synapse. | ||
# | ||
# This is a YAML file containing a standard Python logging configuration | ||
# dictionary. See [1] for details on the valid settings. | ||
# | ||
# Synapse also supports structured logging for machine readable logs which can | ||
# be ingested by ELK stacks. See [2] for details. | ||
# | ||
# [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema | ||
# [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html | ||
|
||
version: 1 | ||
|
||
formatters: | ||
precise: | ||
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' | ||
|
||
handlers: | ||
# A handler that writes logs to stderr. Unused by default, but can be used | ||
# instead of "buffer" and "file" in the logger handlers. | ||
console: | ||
class: logging.StreamHandler | ||
formatter: precise | ||
|
||
loggers: | ||
synapse.storage.SQL: | ||
# beware: increasing this to DEBUG will make synapse log sensitive | ||
# information such as access tokens. | ||
level: DEBUG | ||
|
||
twisted: | ||
# We send the twisted logging directly to the file handler, | ||
# to work around https://github.com/matrix-org/synapse/issues/3471 | ||
# when using "buffer" logger. Use "console" to log to stderr instead. | ||
handlers: [console] | ||
propagate: false | ||
|
||
root: | ||
level: DEBUG | ||
|
||
# Write logs to the `buffer` handler, which will buffer them together in memory, | ||
# then write them to a file. | ||
# | ||
# Replace "buffer" with "console" to log to stderr instead. (Note that you'll | ||
# also need to update the configuration for the `twisted` logger above, in | ||
# this case.) | ||
# | ||
handlers: [console] | ||
|
||
disable_existing_loggers: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ export enum OwnDevicesError { | |
} | ||
export type DevicesState = { | ||
devices: DevicesDictionary; | ||
dehydratedDeviceId?: string; | ||
pushers: IPusher[]; | ||
localNotificationSettings: Map<string, LocalNotificationSettings>; | ||
currentDeviceId: string; | ||
|
@@ -97,6 +98,7 @@ export const useOwnDevices = (): DevicesState => { | |
const userId = matrixClient.getSafeUserId(); | ||
|
||
const [devices, setDevices] = useState<DevicesState["devices"]>({}); | ||
const [dehydratedDeviceId, setDehydratedDeviceId] = useState<DevicesState["dehydratedDeviceId"]>(undefined); | ||
const [pushers, setPushers] = useState<DevicesState["pushers"]>([]); | ||
const [localNotificationSettings, setLocalNotificationSettings] = useState< | ||
DevicesState["localNotificationSettings"] | ||
|
@@ -131,6 +133,21 @@ export const useOwnDevices = (): DevicesState => { | |
}); | ||
setLocalNotificationSettings(notificationSettings); | ||
|
||
const ownUserId = matrixClient.getUserId()!; | ||
const userDevices = (await matrixClient.getCrypto()?.getUserDeviceInfo([ownUserId]))?.get(ownUserId); | ||
const dehydratedDeviceIds: string[] = []; | ||
for (const device of userDevices?.values() ?? []) { | ||
if (device.dehydrated) { | ||
dehydratedDeviceIds.push(device.deviceId); | ||
} | ||
} | ||
// If the user has exactly one device marked as dehydrated, we consider | ||
// that as the dehydrated device, and hide it as a normal device (but | ||
// indicate that the user is using a dehydrated device). If the user has | ||
// more than one, that is anomalous, and we show all the devices so that | ||
// nothing is hidden. | ||
setDehydratedDeviceId(dehydratedDeviceIds.length == 1 ? dehydratedDeviceIds[0] : undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, how should we handle >1 dehydrated devices? |
||
|
||
setIsLoadingDeviceList(false); | ||
} catch (error) { | ||
if ((error as MatrixError).httpStatus == 404) { | ||
|
@@ -228,6 +245,7 @@ export const useOwnDevices = (): DevicesState => { | |
|
||
return { | ||
devices, | ||
dehydratedDeviceId, | ||
pushers, | ||
localNotificationSettings, | ||
currentDeviceId, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.