Compare commits

..
Author SHA1 Message Date
timedout 9aacbf2650 feat: Start on PDU builders
ran out of creative juices so this doesn't work but i'll find a way later
2026-07-12 03:51:28 +01:00
timedout b1a3bcfb88 fix: Skip serialization in null fields
feat: Add fallible conversions from common JSON types
2026-07-12 00:25:26 +01:00
timedout 3c2274b9e7 feat: Create versioned PDU types 2026-07-12 00:07:52 +01:00
Henry-Hiles 6858e1b893 fix: fallback rev to empty string
Fixes flake-compat support
2026-07-11 20:13:58 +00:00
Ginger 07e241f616 chore: News fragment 2026-07-11 19:40:25 +00:00
Ginger cfbe590f1c fix: Do not require an access token on 3pid token request route 2026-07-11 19:40:25 +00:00
Ginger d9c2f04d73 fix: Correctly handle preferred_username claim 2026-07-11 19:21:33 +00:00
Ginger ada0b3184b fix: Properly sync newly created rooms 2026-07-11 19:21:19 +00:00
Renovate Bot 1d6ad485f6 chore(deps): update ruma digest to 9b6a2e7 2026-07-11 16:29:54 +00:00
timedout 9d2ce72f73 style: Remove redundant length check for dag build 2026-07-11 17:27:42 +01:00
timedout 13bcb5af13 style: Accept event id reference in pdu_format_check_1 2026-07-11 17:27:42 +01:00
timedout 5868510df1 fix: Remove redundant "correct room ID" filter 2026-07-11 17:27:42 +01:00
timedout c34d1fe76e feat: Move PDU validation out of parsing and into check 1 2026-07-11 17:27:42 +01:00
timedout 838764b0ac style: Remove needless async def for parse_incoming_pdu_with_known_room 2026-07-11 17:27:42 +01:00
timedout b51a34c1c1 fix: Address review feedback 2026-07-11 17:27:42 +01:00
timedout 2fbb779d12 fix: Invert boolean returned by policy server check 2026-07-11 17:27:42 +01:00
timedout e16a62e1ed feat: Add more debug logging to PDU handle funcs
Tracking down weird soft-fails
2026-07-11 17:27:42 +01:00
timedout 64a08262ca perf: Change signature of build_local_dag to remove refmap hacks 2026-07-11 17:27:42 +01:00
timedout 70a3905761 style: Remove duplicate pdu check 1 call in handle_incoming_pdu 2026-07-11 17:27:42 +01:00
timedout cf9179e8f6 fix: Perform checks 1-3 on auth chain PDUs 2026-07-11 17:27:42 +01:00
timedout 6b899b7f80 refactor: Move PDU checks 1, 2, and 3 into pdu_checks.rs 2026-07-11 17:27:42 +01:00
timedout ad57fa06fc style: Unify and document state_before_incoming 2026-07-11 17:27:42 +01:00
timedout ec9efbada5 fix: Don't reject auth events when they're innocent in auth chain response 2026-07-11 17:27:42 +01:00
timedout 318d2b205a style: Move PDU check functions into their own module 2026-07-11 17:27:42 +01:00
timedout 99a5f2a9fb refactor: Reduce complexity of incoming PDU handling
* Ignores any events pushed without a room ID
* Removes needless clones for PDU size checking
* Removes incorrect ACL check in incoming handler
* Fast-path handling already handled outlier events
* Remove redundant same-room checks, replace with useful ones
* Combine event rejection and persistence in a single function
* Additional safety assertions in upgrade task
* Split upgrade task into multiple subroutines for reduced cognitive complexity
* Only mutate current state and forward extremities in tandem
* Improve code documentation to better explain the logic flow
2026-07-11 17:27:42 +01:00
Renovate Bot ace0d52074 chore(deps): Update rust crate termimad to 0.35.0 2026-07-11 15:35:53 +00:00
Ginger 0b1e24a9ad fix: Add admin command to ensure all appservice puppets are active 2026-07-11 14:55:43 +00:00
Ginger f55207d5c7 fix: Stop appservice users from being wrongly deactivated during migration 2026-07-11 14:55:43 +00:00
Renovate Bot 3f2fae4ca7 chore(deps): update dependency typescript to v7 2026-07-11 05:04:52 +00:00
theS1LV3R 081f865705 chore: Use CARGO_LOG=debug for cargo build 2026-07-11 01:31:07 +00:00
theS1LV3R 0d6608a2f8 fix: Ensure docker builds stop on failed compilation 2026-07-11 01:31:07 +00:00
renovate abf96140b2 chore(Nix): Updated flake hashes 2026-07-11 01:30:41 +00:00
Renovate Bot 35fb56aafd chore(deps): update rust to v1.97.0 2026-07-11 01:30:41 +00:00
33 changed files with 1179 additions and 119 deletions

No files matched your search

Generated
+15 -15
View File
@@ -3253,9 +3253,9 @@ dependencies = [
[[package]]
name = "minimad"
version = "0.14.0"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8b688969b16915f3ecadc7829d5b7779dee4977e503f767f34136803d5c06f"
checksum = "de632ee829aec3a874d18a4192eae64a0460b3a45c54ed556b334f6fe5a1d62f"
dependencies = [
"once_cell",
]
@@ -4601,7 +4601,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"assign",
"js_int",
@@ -4620,7 +4620,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"js_int",
"ruma-common",
@@ -4632,7 +4632,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.24.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"as_variant",
"assign",
@@ -4654,7 +4654,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.19.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"as_variant",
"base64 0.22.1",
@@ -4687,7 +4687,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.34.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"as_variant",
"indexmap 2.14.0",
@@ -4708,7 +4708,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.15.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"bytes",
"headers",
@@ -4731,7 +4731,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.12.1"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"js_int",
"thiserror 2.0.18",
@@ -4740,7 +4740,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.19.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"as_variant",
"cfg-if",
@@ -4756,7 +4756,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.15.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"js_int",
"ruma-common",
@@ -4768,7 +4768,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.21.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"base64 0.22.1",
"ed25519-dalek",
@@ -4785,7 +4785,7 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=fca1dbc060f730c1aaf84c9c2fb1e8a587455be8#fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
source = "git+https://github.com/ruma/ruma.git?rev=9b6a2e7323649af926e4b5363d87239ee4247f4a#9b6a2e7323649af926e4b5363d87239ee4247f4a"
dependencies = [
"js_int",
"ruma-common",
@@ -5722,9 +5722,9 @@ dependencies = [
[[package]]
name = "termimad"
version = "0.34.1"
version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "889a9370996b74cf46016ce35b96c248a9ac36d69aab1d112b3e09bc33affa49"
checksum = "903906afabf58273a7a90b47e0e60701cbd01731ca72ba88508b38b5539647f4"
dependencies = [
"coolor",
"crokey",
+2 -2
View File
@@ -350,7 +350,7 @@ version = "1.1.1"
[workspace.dependencies.ruma]
# version = "0.14.1"
git = "https://github.com/ruma/ruma.git"
rev = "fca1dbc060f730c1aaf84c9c2fb1e8a587455be8"
rev = "9b6a2e7323649af926e4b5363d87239ee4247f4a"
features = [
"appservice-api-c",
"client-api",
@@ -502,7 +502,7 @@ version = "0.4.9"
default-features = false
[workspace.dependencies.termimad]
version = "0.34.0"
version = "0.35.0"
default-features = false
[workspace.dependencies.checked_ops]
+34
View File
@@ -0,0 +1,34 @@
# Roadmap for PDU versioning
Currently, PDUs are one monolithic `PduEvent` struct which applies a one-size-fits-all approach to PDUs, however as we
support a wide range of room versions, this only just about currently works, and will cause more and more problems as
time progresses. This branch will split the `PduEvent` struct into multiple versioned structs that represent the proper
format for appropriate room versions, and will drop the `Event` trait in favour of Ruma's `ruma::state_res::Event`
trait.
This will require a lot of work, and since I forget everything the moment I look out the window, here be a list (waow):
- [x] Split `PduEvent` into multiple versioned structs, implementing `ruma::state_res::Event` for each of them.
- [ ] Refactor out all references to `PduEvent`.
- [ ] Refactor out all references to `conduwuit_core::event::Event` trait in favour of `ruma::state_res::Event`.
- [ ] Centralise PDU struct creation in a way that allows us to greater control the deserialization process.
- Developers can't be trusted to read documentation so we can't store the PDU metadata (things like event ID and
rejection status) in the PDU struct itself, as this may end up being leaked to consumers. Instead, PDU metadata
should be stored seprately from the PDU struct itself, but needs to be strongly associated with it (i.e. fetched
at the same time, always returned together, etc). This may take a form similar to
`StoredPdu<T: Event> { pdu: T, metadata: PduMetadata }`.
- [ ] Stop storing generated data in the `unsigned` field, but instead calculate it on demand(?).
- Storing generated data in the `unsigned` field results in:
- History visibility cannot be enforced on `prev_content` or `redacted_because`.
- `age` is manually calculated but only sometimes.
- `membership` is not provided at all.
- `prev_content` can leak redacted state event content ([#1103]).
- `prev_content` cannot easily be populated for backfilled events, leaving them contextless.
- It is easy to accidentally leak `transaction_id`.
Once `PduEvent` is gone, we can then do the following lovely things:
- Drop our local state resolution logic and event authorisation logic and instead use Ruma's, which naturally receives
more love and attention. Our current `Event` trait and `PduEvent` implementations are incompatible with what Ruma
needs, and do not store the appropriate information required.
- There's something else but I forgot just trust me
+1
View File
@@ -0,0 +1 @@
Fixed newly created rooms failing to sync properly in clients using legacy sync.
+1
View File
@@ -0,0 +1 @@
Stopped appservice users from being erroneously marked as deactivated during a 26.6 database migration.
+1
View File
@@ -0,0 +1 @@
Fixed existing accounts failing to link when logging in with OIDC if `prompt_for_localpart` was `false`.
+1
View File
@@ -0,0 +1 @@
Authentication is no longer required on the `/_matrix/client/v3/account/3pid/email/requestToken` endpoint.
+3 -1
View File
@@ -171,6 +171,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/app/target,id=continuwuity-cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-${RUST_PROFILE} \
bash <<'EOF'
set -euo pipefail
set -o allexport
set -o xtrace
. /etc/environment
@@ -191,7 +192,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
jq -r ".target_directory"))
mkdir /out/sbin
PACKAGE=conduwuit
xx-cargo build --locked --profile ${RUST_PROFILE} \
CARGO_LOG=debug xx-cargo build --locked --profile ${RUST_PROFILE} \
--no-default-features --features ${CARGO_FEATURES} \
-p $PACKAGE;
BINARIES=($(cargo metadata --no-deps --format-version 1 | \
@@ -207,6 +208,7 @@ EOF
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git/db \
bash <<'EOF'
set -euo pipefail
set -o xtrace
mkdir /out/sbom
typeset -A PACKAGES
+4
View File
@@ -27,3 +27,7 @@ You can find the ID using the `list-appservices` command.
## `!admin appservices list-registered`
List all the currently registered appservices
## `!admin appservices ensure-puppets-active`
Ensure no appservice puppets are marked as deactivated. This is a debug command to fix issues caused by a faulty database migration in Continuwuity 26.6.0
+4
View File
@@ -146,6 +146,10 @@ List database files
Send a test email to the invoking admin's email address
## `!admin debug rooms-by-extremity-count`
Lists room IDs by forward extremity count in descending order
## `!admin debug tester`
Developer test stubs
+1 -3
View File
@@ -106,9 +106,7 @@ resolver service
### `!admin query resolver cache`
Query the destinations or overrides cache
Shows entire cache by default, but can be narrowed to only show overrides with `-o/--overrides true`, or to exclude them with `false`
Query the destinations or overrides cache, depending on the value of the `overrides` flag (default false)
### `!admin query resolver flush-cache`
+2 -2
View File
@@ -43,8 +43,8 @@ let
env = {
CARGO_PROFILE = profile;
RUSTFLAGS = rustflags;
GIT_COMMIT_HASH = self.rev or self.dirtyRev;
GIT_COMMIT_HASH_SHORT = self.shortRev or self.dirtyShortRev;
GIT_COMMIT_HASH = self.rev or self.dirtyRev or "";
GIT_COMMIT_HASH_SHORT = self.shortRev or self.dirtyShortRev or "";
}
// (lib.optionalAttrs (rocksdb != null) {
ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
+1 -1
View File
@@ -12,7 +12,7 @@
target:
target.fromToolchainName {
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
sha256 = "sha256-h+t2xTBz5yt2YIO+1VMIIGlCU7gyp2LYOFvaV1nwOXU=";
sha256 = "sha256-OATSZm98Es5kIFuqaba+UvkQtFsVgJEBMmS+t6od5/U=";
};
in
{
+368 -7
View File
@@ -12,7 +12,7 @@
"@rspress/core": "^2.0.0",
"@rspress/plugin-client-redirects": "^2.0.0",
"@rspress/plugin-sitemap": "^2.0.0",
"typescript": "^6.0.0"
"typescript": "^7.0.0"
}
},
"node_modules/@emnapi/core": {
@@ -735,6 +735,346 @@
"dev": true,
"license": "MIT"
},
"node_modules/@typescript/typescript-aix-ppc64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz",
"integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"aix"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-darwin-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz",
"integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-darwin-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz",
"integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-freebsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz",
"integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-freebsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz",
"integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-arm": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz",
"integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==",
"cpu": [
"arm"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz",
"integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-loong64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz",
"integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==",
"cpu": [
"loong64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-mips64el": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz",
"integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==",
"cpu": [
"mips64el"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-ppc64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz",
"integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-riscv64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz",
"integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==",
"cpu": [
"riscv64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-s390x": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz",
"integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==",
"cpu": [
"s390x"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-linux-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz",
"integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-netbsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz",
"integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-netbsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz",
"integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"netbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-openbsd-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz",
"integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-openbsd-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz",
"integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"openbsd"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-sunos-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz",
"integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"sunos"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-win32-arm64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz",
"integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@typescript/typescript-win32-x64": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz",
"integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==",
"cpu": [
"x64"
],
"dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">=16.20.0"
}
},
"node_modules/@ungap/structured-clone": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.1.tgz",
@@ -3361,17 +3701,38 @@
"license": "0BSD"
},
"node_modules/typescript": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz",
"integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
"tsc": "bin/tsc"
},
"engines": {
"node": ">=14.17"
"node": ">=16.20.0"
},
"optionalDependencies": {
"@typescript/typescript-aix-ppc64": "7.0.2",
"@typescript/typescript-darwin-arm64": "7.0.2",
"@typescript/typescript-darwin-x64": "7.0.2",
"@typescript/typescript-freebsd-arm64": "7.0.2",
"@typescript/typescript-freebsd-x64": "7.0.2",
"@typescript/typescript-linux-arm": "7.0.2",
"@typescript/typescript-linux-arm64": "7.0.2",
"@typescript/typescript-linux-loong64": "7.0.2",
"@typescript/typescript-linux-mips64el": "7.0.2",
"@typescript/typescript-linux-ppc64": "7.0.2",
"@typescript/typescript-linux-riscv64": "7.0.2",
"@typescript/typescript-linux-s390x": "7.0.2",
"@typescript/typescript-linux-x64": "7.0.2",
"@typescript/typescript-netbsd-arm64": "7.0.2",
"@typescript/typescript-netbsd-x64": "7.0.2",
"@typescript/typescript-openbsd-arm64": "7.0.2",
"@typescript/typescript-openbsd-x64": "7.0.2",
"@typescript/typescript-sunos-x64": "7.0.2",
"@typescript/typescript-win32-arm64": "7.0.2",
"@typescript/typescript-win32-x64": "7.0.2"
}
},
"node_modules/unhead": {
+1 -1
View File
@@ -25,6 +25,6 @@
"@rspress/core": "^2.0.0",
"@rspress/plugin-client-redirects": "^2.0.0",
"@rspress/plugin-sitemap": "^2.0.0",
"typescript": "^6.0.0"
"typescript": "^7.0.0"
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
[toolchain]
profile = "minimal"
channel = "1.96.1"
channel = "1.97.0"
components = [
# For rust-analyzer
"rust-src",
+25
View File
@@ -73,4 +73,29 @@ impl crate::Context<'_> {
})
.await
}
pub(super) async fn ensure_puppets_active(&self) -> Result {
self.services
.users
.stream_local_users()
.filter_map(async |user_id| {
if self.services.appservice.is_user_id(&user_id).await {
Some(user_id)
} else {
None
}
})
.for_each(async |user_id| {
self.services
.users
.convert_to_shadow_account(&user_id)
.await
.expect("should be able to convert to shadow");
})
.await;
write!(self, "All appservice puppets have been marked as active.").await?;
Ok(())
}
}
+6
View File
@@ -37,4 +37,10 @@ pub enum AppserviceCommand {
/// List all the currently registered appservices
#[clap(alias("list"))]
ListRegistered,
/// Ensure no appservice puppets are marked as deactivated.
/// This is a debug command to fix issues caused by a faulty database
/// migration in Continuwuity 26.6.0.
#[clap(hide = true)]
EnsurePuppetsActive,
}
+2 -4
View File
@@ -57,13 +57,11 @@ pub(crate) async fn request_3pid_management_token_via_email_route(
State(services): State<crate::State>,
body: Ruma<request_3pid_management_token_via_email::v3::Request>,
) -> Result<request_3pid_management_token_via_email::v3::Response> {
// Authentication for this endpoint is technically optional,
// but we require the user to be logged in
let sender_user = body
.identity
.as_ref()
.map(ClientIdentity::expect_sender_user)
.ok_or_else(|| err!(Request(MissingToken("Missing access token."))))??;
.transpose()?;
if !services.threepid.email_requirement().may_change() {
return Err!(Request(Forbidden("You may not change your email address.")));
@@ -88,7 +86,7 @@ pub(crate) async fn request_3pid_management_token_via_email_route(
Mailbox::new(None, email),
|verification_link| messages::ChangeEmail {
server_name: services.config.server_name.as_str(),
user_id: Some(sender_user),
user_id: sender_user,
verification_link,
},
&body.client_secret,
+11 -4
View File
@@ -1,9 +1,11 @@
use std::collections::HashSet;
use assign::assign;
use axum::extract::State;
use conduwuit::{
Err, Pdu, Result, debug_info, debug_warn, err,
matrix::{event::gen_event_id, pdu::PartialPdu},
pdu::{AnyPDU, metadata::PduMetadata, new_pdu},
utils::{self, FutureBoolExt, future::ReadyEqExt},
warn,
};
@@ -216,7 +218,7 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
room_id: &RoomId,
reason: Option<String>,
mut servers: HashSet<OwnedServerName, S>,
) -> Result<Pdu> {
) -> Result<AnyPDU> {
let mut make_leave_response_and_server =
Err!(BadServerResponse("No remote server available to assist in leaving {room_id}."));
@@ -406,9 +408,14 @@ pub async fn remote_leave_room<S: ::std::hash::BuildHasher>(
.outlier
.add_pdu_outlier(&event_id, &leave_event);
let leave_pdu = Pdu::from_id_val(&event_id, leave_event).map_err(|e| {
err!(BadServerResponse("Invalid leave PDU received during federated leave: {e:?}"))
})?;
let leave_pdu = new_pdu(
room_version_rules.into(),
PduMetadata::new(event_id),
serde_json::to_value(leave_event)?,
)?;
// let leave_pdu = Pdu::from_id_val(&event_id, leave_event).map_err(|e| {
// err!(BadServerResponse("Invalid leave PDU received during federated leave:
// {e:?}")) })?;
Ok(leave_pdu)
}
+15 -10
View File
@@ -381,16 +381,21 @@ async fn fetch_shortstatehashes(
| Some((_, pdu_after_last_sync_end)) => {
trace!(?pdu_after_last_sync_end.event_id, "pdu at last sync end");
Some(
services
.rooms
.state_accessor
.pdu_shortstatehash(&pdu_after_last_sync_end.event_id)
.await
.map_err(|err| {
err!("Last sync end PDU has no shortstatehash: {err}")
}),
)
if pdu_after_last_sync_end.kind == RoomCreate {
// Room create events have no previous state
None
} else {
Some(
services
.rooms
.state_accessor
.pdu_shortstatehash(&pdu_after_last_sync_end.event_id)
.await
.map_err(|err| {
err!("Last sync end PDU has no shortstatehash: {err}")
}),
)
}
},
| None => {
// No events have been sent since the last sync, or we just joined this room
+1 -3
View File
@@ -143,8 +143,6 @@ pub trait Event: Clone + Debug {
fn into_pdu(self) -> Pdu;
fn is_owned(&self) -> bool;
//
// Canonical properties
//
@@ -182,12 +180,12 @@ pub trait Event: Clone + Debug {
fn state_key(&self) -> Option<&str>;
/// The event type.
// #[deprecated]
fn kind(&self) -> &TimelineEventType;
/// Metadata container; peer-trusted only.
fn unsigned(&self) -> Option<&RawJsonValue>;
//#[deprecated]
#[inline]
fn event_type(&self) -> &TimelineEventType { self.kind() }
}
+195 -12
View File
@@ -1,19 +1,25 @@
mod count;
pub mod hashes;
mod id;
pub mod metadata;
mod partial;
mod raw_id;
mod redact;
#[cfg(test)]
mod tests;
mod unsigned;
pub mod v2;
pub mod v3;
use std::cmp::Ordering;
use assign::assign;
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, UInt, UserId, events::TimelineEventType,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerSignatures, UInt, UserId, event_id,
events::TimelineEventType, room_version_rules::RoomVersionRules, state_res::Event,
};
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use serde_json::value::RawValue as RawJsonValue;
pub use self::{
@@ -23,10 +29,193 @@ pub use self::{
partial::PartialPdu,
raw_id::*,
};
use super::{Event, StateKey};
use crate::Result;
use super::StateKey;
use crate::{
Err, Result,
pdu::{hashes::Hashes, metadata::PduMetadata},
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EventFormatVersion {
/// V1 represents the PDU format for rooms v1 and v2.
V1,
/// V2 represents the PDU format for rooms v3-v11.
V2,
/// V3 represents the PDU format for rooms v12+.
V3,
}
impl From<RoomVersionRules> for EventFormatVersion {
fn from(rules: RoomVersionRules) -> Self {
// TODO: this is hacky because ruma doesn't actually define event versions in an
// enum, but does define consts with the appropriate rules.
if rules.event_format.require_event_id {
Self::V1
} else if rules.event_format.require_room_create_room_id {
Self::V2
} else {
Self::V3
}
}
}
/// Trait that allows conversion from a generic PDU to a concrete PDU type.
pub trait ConcretePDU: ruma::state_res::Event<Id = OwnedEventId> {
/// The concrete type for this PDU (`v2::PDU`, `v3::PDU`, etc)
type Concrete;
/// Get a reference to the concrete PDU type.
fn to_concrete(&self) -> &Self::Concrete;
/// Get the value of the concrete PDU type, consuming.
fn into_concrete(self) -> Self::Concrete;
}
pub fn new_pdu<E, C, P, JSON>(
format: EventFormatVersion,
metadata: PduMetadata,
json: serde_json::Value,
) -> Result<E>
where
E: ConcretePDU<Concrete = C>,
JSON: DeserializeOwned,
{
match format {
| EventFormatVersion::V2 =>
Ok(assign!(v2::PDU::try_from(json)?, {internal_metadata: metadata})),
| EventFormatVersion::V3 =>
Ok(assign!(v3::PDU::try_from(json)?, {internal_metadata: metadata})),
| _ => Err!("Unsupported event format: {format:?}"),
}
}
/// A builder type that specifies every field present on any PDU type, allowing
/// it to be used to create any PDU version with the appropriate function.
///
/// See `create_pdu`.
#[derive(Clone, Debug, Default)]
pub struct CommonPDUBuilder {
pub auth_events: Option<Vec<OwnedEventId>>,
pub content: Option<Box<RawJsonValue>>,
pub depth: Option<UInt>,
pub hashes: Option<Hashes>,
pub origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
pub prev_events: Option<Vec<OwnedEventId>>,
pub redacts: Option<OwnedEventId>,
pub room_id: Option<OwnedRoomId>,
pub sender: Option<OwnedUserId>,
pub signatures: Option<ServerSignatures>,
pub state_key: Option<String>,
pub event_type: Option<TimelineEventType>,
pub unsigned: Option<Box<RawJsonValue>>,
pub internal_metadata: Option<PduMetadata>,
}
/// Creates a new PDU based on the given version and builder.
///
/// ## Example
///
/// ```rust
/// use conduwuit_core::pdu::{CommonPDUBuilder, create_pdu}
///
/// let room_version_rules = RoomVersionRules::V10; // This usually comes dynamically.
/// let builder = CommonPDUBuilder {
/// auth_events: Some(vec![event_id!("$auth_event_id").to_owned()]),
/// content: Some(Box::new(serde_json::json!({"key": "value"}))),
/// depth: Some(1),
/// origin_server_ts: Some(MilliSecondsSinceUnixEpoch(123456789)),
/// prev_events: Some(vec![event_id!("$prev_event_id").to_owned()]),
/// room_id: Some(room_id!("!room_id").to_owned()),
/// sender: Some(user_id!("@sender:example.com").to_owned()),
/// event_type: Some(TimelineEventType::RoomMessage),
/// ..Default::default()
/// };
/// let pdu = create_pdu(
/// room_version_rules.into(),
/// builder,
/// ).expect("PDU creation must succeed");
/// ```
pub fn create_pdu<C>(version: EventFormatVersion, builder: CommonPDUBuilder) -> Result<C> {
match version {
| EventFormatVersion::V2 => Ok(create_v2_pdu(builder)),
| EventFormatVersion::V3 => Ok(create_v3_pdu(builder)),
| _ => Err!("Unsupported event format: {version:?}"),
}
}
fn create_v2_pdu<C>(builder: CommonPDUBuilder) -> v2::PDU {
v2::PDU {
auth_events: builder
.auth_events
.expect("auth_events must be provided for a V2 PDU"),
content: builder
.content
.expect("content must be provided for a V2 PDU"),
depth: builder.depth.expect("depth must be provided for a V2 PDU"),
hashes: builder.hashes.unwrap_or_default(), /* We allow default here since we might not
* have hashed yet */
origin_server_ts: builder
.origin_server_ts
.expect("origin_server_ts must be provided for a V2 PDU"),
prev_events: builder
.prev_events
.expect("prev_events must be provided for a V2 PDU"),
redacts: builder.redacts,
room_id: builder
.room_id
.expect("room_id must be provided for a V2 PDU"),
sender: builder
.sender
.expect("sender must be provided for a V2 PDU"),
signatures: builder.signatures.unwrap_or_default(), /* We allow default here since we
* might not have signed yet */
state_key: builder.state_key,
event_type: builder
.event_type
.expect("event_type must be provided for a V2 PDU"),
unsigned: builder.unsigned,
internal_metadata: builder
.internal_metadata
.unwrap_or_else(|| PduMetadata::new(event_id!("$unknown").to_owned())),
}
}
fn create_v3_pdu(builder: CommonPDUBuilder) -> v3::PDU {
v3::PDU {
auth_events: builder
.auth_events
.expect("auth_events must be provided for a V3 PDU"),
content: builder
.content
.expect("content must be provided for a V3 PDU"),
depth: builder.depth.expect("depth must be provided for a V3 PDU"),
hashes: builder.hashes.unwrap_or_default(), /* We allow default here since we might not
* have hashed yet */
origin_server_ts: builder
.origin_server_ts
.expect("origin_server_ts must be provided for a V3 PDU"),
prev_events: builder
.prev_events
.expect("prev_events must be provided for a V3 PDU"),
room_id: builder.room_id,
sender: builder
.sender
.expect("sender must be provided for a V3 PDU"),
signatures: builder.signatures.unwrap_or_default(), /* We allow default here since we
* might not have signed yet */
state_key: builder.state_key,
event_type: builder
.event_type
.expect("event_type must be provided for a V3 PDU"),
unsigned: builder.unsigned,
internal_metadata: builder
.internal_metadata
.unwrap_or_else(|| PduMetadata::new(event_id!("$unknown").to_owned())),
}
}
/// Persistent Data Unit (Event)
#[deprecated(note = "Use `v2::PDU` or `v3::PDU` or `ruma::state_res::Event` instead")]
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct Pdu {
pub event_id: OwnedEventId,
@@ -85,7 +274,7 @@ impl Pdu {
}
}
impl Event for Pdu {
impl crate::Event for Pdu {
#[inline]
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.auth_events.iter().map(AsRef::as_ref)
@@ -151,12 +340,9 @@ impl Event for Pdu {
#[inline]
fn into_pdu(self) -> Pdu { self }
#[inline]
fn is_owned(&self) -> bool { true }
}
impl Event for &Pdu {
impl crate::Event for &Pdu {
#[inline]
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.auth_events.iter().map(AsRef::as_ref)
@@ -219,9 +405,6 @@ impl Event for &Pdu {
#[inline]
fn into_pdu(self) -> Pdu { self.clone() }
#[inline]
fn is_owned(&self) -> bool { false }
}
/// Prevent derived equality which wouldn't limit itself to event_id
+15
View File
@@ -0,0 +1,15 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
/// The content hash map for a PDU.
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
pub struct Hashes {
/// The SHA256 content hash.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub sha256: String,
/// Any other hashes present, if any.
#[serde(flatten, default, skip_serializing_if = "HashMap::is_empty")]
pub other: HashMap<String, String>,
}
+16
View File
@@ -0,0 +1,16 @@
use ruma::{EventId, OwnedEventId};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PduMetadata {
/// This event's calculated event ID.
pub event_id: OwnedEventId,
/// Indicates whether the event has been rejected under auth rules.
pub rejected: bool,
}
impl PduMetadata {
/// Creates a new PduMetadata instance with the minimum required fields.
pub fn new(event_id: OwnedEventId) -> Self { Self { event_id, rejected: false } }
}
+174
View File
@@ -0,0 +1,174 @@
use ruma::{
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
OwnedUserId, RoomId, ServerSignatures, UInt, UserId, events::TimelineEventType,
};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue as RawJsonValue;
use crate::{
Pdu,
pdu::{hashes::Hashes, metadata::PduMetadata},
};
/// Represents a persistent data unit (PDU) version 2, introduced in room
/// version 3, up until room version 11.
///
/// Spec: https://spec.matrix.org/v1.19/rooms/v3/#event-format
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PDU {
/// The event IDs which authorise this event. Between 0 and 10 entries.
pub auth_events: Vec<OwnedEventId>,
/// This event's content.
pub content: Box<RawJsonValue>,
/// The depth of this event.
pub depth: UInt,
/// The content hashes for this event.
pub hashes: Hashes,
/// Timestamp in milliseconds on origin homeserver when this event was
/// created.
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The event IDs which immediately precede this event. Between 0 and 20
/// entries.
pub prev_events: Vec<OwnedEventId>,
/// For redaction events, the ID of the event being redacted.
///
/// Not used in v11.
#[serde(skip_serializing_if = "Option::is_none")]
pub redacts: Option<OwnedEventId>,
/// The room in which this event resides.
pub room_id: OwnedRoomId,
/// The user who sent this event.
pub sender: OwnedUserId,
/// The signatures on this event.
pub signatures: ServerSignatures,
/// The state key for this PDU, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>,
/// The type of this PDU.
#[serde(rename = "type")]
pub event_type: TimelineEventType,
/// Additional data added by the origin server but not covered by the
/// signatures.
///
/// This should be `None` when receiving from and transmitting over
/// federation.
#[serde(skip_serializing_if = "Option::is_none")]
pub unsigned: Option<Box<RawJsonValue>>,
/// Internal metadata that is important to the PDU but should not be
/// serialized into the final event.
///
/// This field MUST NOT be sent to clients or federation.
pub internal_metadata: PduMetadata,
}
impl PDU {
#[must_use]
pub fn internal_metadata(&self) -> &PduMetadata { &self.internal_metadata }
}
impl crate::pdu::ConcretePDU for PDU {
type Concrete = PDU;
fn to_concrete(&self) -> &Self::Concrete { &self }
fn into_concrete(self) -> Self::Concrete { self }
}
impl ruma::state_res::Event for PDU {
type Id = OwnedEventId;
fn event_id(&self) -> &Self::Id { &self.internal_metadata.event_id }
fn room_id(&self) -> Option<&RoomId> { Some(&self.room_id) }
fn sender(&self) -> &UserId { &self.sender }
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { self.origin_server_ts }
fn event_type(&self) -> &TimelineEventType { &self.event_type }
fn content(&self) -> &RawJsonValue { self.content.as_ref() }
fn state_key(&self) -> Option<&str> { self.state_key.as_deref() }
fn prev_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
Box::new(self.prev_events.iter())
}
fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
Box::new(self.auth_events.iter())
}
fn redacts(&self) -> Option<&Self::Id> { self.redacts.as_ref() }
fn rejected(&self) -> bool { self.internal_metadata().rejected }
}
impl crate::Event for PDU {
fn as_pdu(&self) -> &Pdu { todo!() }
fn into_pdu(self) -> Pdu { todo!() }
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.auth_events.iter().map(AsRef::as_ref)
}
fn content(&self) -> &RawJsonValue { self.content.as_ref() }
fn event_id(&self) -> &EventId { &self.internal_metadata.event_id }
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { self.origin_server_ts }
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.prev_events.iter().map(AsRef::as_ref)
}
fn redacts(&self) -> Option<&EventId> { self.redacts.as_deref() }
fn room_id(&self) -> Option<&RoomId> { Some(&self.room_id) }
fn room_id_or_hash(&self) -> OwnedRoomId { self.room_id.clone() }
fn sender(&self) -> &UserId { &self.sender }
fn state_key(&self) -> Option<&str> { self.state_key.as_deref() }
fn kind(&self) -> &TimelineEventType { self.event_type() }
fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() }
fn event_type(&self) -> &TimelineEventType { &self.event_type }
}
impl TryFrom<&RawJsonValue> for PDU {
type Error = crate::Error;
fn try_from(value: &RawJsonValue) -> Result<Self, Self::Error> {
serde_json::from_str(value.get()).map_err(Into::into)
}
}
impl TryFrom<Box<RawJsonValue>> for PDU {
type Error = crate::Error;
fn try_from(value: Box<RawJsonValue>) -> Result<Self, Self::Error> {
Self::try_from(value.as_ref())
}
}
impl TryFrom<serde_json::Value> for PDU {
type Error = crate::Error;
fn try_from(value: serde_json::Value) -> Result<Self, Self::Error> {
serde_json::from_value(value).map_err(Into::into)
}
}
impl TryFrom<CanonicalJsonObject> for PDU {
type Error = crate::Error;
fn try_from(value: CanonicalJsonObject) -> Result<Self, Self::Error> {
serde_json::from_value(serde_json::to_value(value)?).map_err(Into::into)
}
}
+187
View File
@@ -0,0 +1,187 @@
use ruma::{
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
OwnedUserId, RoomId, ServerSignatures, UInt, UserId,
events::{StateEventType, TimelineEventType},
};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue as RawJsonValue;
use crate::{
Pdu,
pdu::{hashes::Hashes, metadata::PduMetadata},
};
/// Represents a persistent data unit (PDU) version 3, introduced in room
/// version 12.
///
/// Spec: https://spec.matrix.org/v1.19/rooms/v12/#event-format
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PDU {
/// The event IDs which authorise this event. Between 0 and 10 entries.
pub auth_events: Vec<OwnedEventId>,
/// This event's content.
pub content: Box<RawJsonValue>,
/// The depth of this event.
pub depth: UInt,
/// The content hashes for this event.
pub hashes: Hashes,
/// Timestamp in milliseconds on origin homeserver when this event was
/// created.
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The event IDs which immediately precede this event. Between 0 and 20
/// entries.
pub prev_events: Vec<OwnedEventId>,
/// The room in which this event resides.
/// May be None if the event is a create event.
#[serde(skip_serializing_if = "Option::is_none")]
pub room_id: Option<OwnedRoomId>,
/// The user who sent this event.
pub sender: OwnedUserId,
/// The signatures on this event.
pub signatures: ServerSignatures,
/// The state key for this PDU, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>,
/// The type of this PDU.
#[serde(rename = "type")]
pub event_type: TimelineEventType,
/// Additional data added by the origin server but not covered by the
/// signatures.
///
/// This should be `None` when receiving from and transmitting over
/// federation.
#[serde(skip_serializing_if = "Option::is_none")]
pub unsigned: Option<Box<RawJsonValue>>,
/// Internal metadata that is important to the PDU but should not be
/// serialized into the final event.
///
/// This field MUST NOT be sent to clients or federation.
pub internal_metadata: PduMetadata,
}
impl PDU {
#[must_use]
pub fn internal_metadata(&self) -> &PduMetadata { &self.internal_metadata }
}
impl crate::pdu::ConcretePDU<PDU> for PDU {
fn to_concrete(&self) -> &PDU { &self }
fn into_concrete(self) -> PDU { self }
}
impl ruma::state_res::Event for PDU {
type Id = OwnedEventId;
fn event_id(&self) -> &Self::Id { &self.internal_metadata.event_id }
fn room_id(&self) -> Option<&RoomId> { self.room_id.as_deref() }
fn sender(&self) -> &UserId { &self.sender }
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { self.origin_server_ts }
fn event_type(&self) -> &TimelineEventType { &self.event_type }
fn content(&self) -> &RawJsonValue { self.content.as_ref() }
fn state_key(&self) -> Option<&str> { self.state_key.as_deref() }
fn prev_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
Box::new(self.prev_events.iter())
}
fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
Box::new(self.auth_events.iter())
}
fn redacts(&self) -> Option<&Self::Id> { None }
fn rejected(&self) -> bool { self.internal_metadata().rejected }
}
impl crate::Event for PDU {
fn as_pdu(&self) -> &Pdu { todo!() }
fn into_pdu(self) -> Pdu { todo!() }
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.auth_events.iter().map(AsRef::as_ref)
}
fn content(&self) -> &RawJsonValue { self.content.as_ref() }
fn event_id(&self) -> &EventId { &self.internal_metadata.event_id }
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { self.origin_server_ts }
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
self.prev_events.iter().map(AsRef::as_ref)
}
fn redacts(&self) -> Option<&EventId> { None }
fn room_id(&self) -> Option<&RoomId> { self.room_id.as_deref() }
fn room_id_or_hash(&self) -> OwnedRoomId {
if self.event_type == StateEventType::RoomCreate.into()
&& self.state_key().is_some_and(str::is_empty)
{
// Calculate the room ID for a create event.
RoomId::new_v2(
self.internal_metadata()
.event_id
.as_str()
.strip_prefix("$")
.expect("event ID must start with $ sigil"),
)
.expect("must be able to create a room ID from create event reference hash")
} else {
// Otherwise, all other events have a room ID field.
self.room_id.clone().unwrap()
}
}
fn sender(&self) -> &UserId { &self.sender }
fn state_key(&self) -> Option<&str> { self.state_key.as_deref() }
fn kind(&self) -> &TimelineEventType { self.event_type() }
fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() }
fn event_type(&self) -> &TimelineEventType { &self.event_type }
}
impl TryFrom<&RawJsonValue> for PDU {
type Error = crate::Error;
fn try_from(value: &RawJsonValue) -> Result<Self, Self::Error> {
serde_json::from_str(value.get()).map_err(Into::into)
}
}
impl TryFrom<Box<RawJsonValue>> for PDU {
type Error = crate::Error;
fn try_from(value: Box<RawJsonValue>) -> Result<Self, Self::Error> {
Self::try_from(value.as_ref())
}
}
impl TryFrom<serde_json::Value> for PDU {
type Error = crate::Error;
fn try_from(value: serde_json::Value) -> Result<Self, Self::Error> {
serde_json::from_value(value).map_err(Into::into)
}
}
impl TryFrom<CanonicalJsonObject> for PDU {
type Error = crate::Error;
fn try_from(value: CanonicalJsonObject) -> Result<Self, Self::Error> {
serde_json::from_value(serde_json::to_value(value)?).map_err(Into::into)
}
}
+2 -2
View File
@@ -219,7 +219,7 @@ fn configure_output_err(mut output: MadSkin) -> MadSkin {
use termimad::{Alignment, CompoundStyle, LineStyle, crossterm::style::Color};
let code_style = CompoundStyle::with_fgbg(Color::AnsiValue(196), Color::AnsiValue(234));
output.inline_code = code_style.clone();
output.inline_code = code_style;
output.code_block = LineStyle {
left_margin: 0,
right_margin: 0,
@@ -234,7 +234,7 @@ fn configure_output(mut output: MadSkin) -> MadSkin {
use termimad::{Alignment, CompoundStyle, LineStyle, crossterm::style::Color};
let code_style = CompoundStyle::with_fgbg(Color::AnsiValue(40), Color::AnsiValue(234));
output.inline_code = code_style.clone();
output.inline_code = code_style;
output.code_block = LineStyle {
left_margin: 0,
right_margin: 0,
+9
View File
@@ -224,6 +224,15 @@ impl Service {
.any(|info| info.is_exclusive_user_match(user_id))
}
/// Checks if a given user id matches any appservice regex, exclusive or
/// otherwise
pub async fn is_user_id(&self, user_id: &UserId) -> bool {
self.read()
.await
.values()
.any(|info| info.is_user_match(user_id))
}
/// Checks if a given room alias matches any exclusive appservice regex
pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
self.read()
+1 -1
View File
@@ -867,7 +867,7 @@ async fn split_userid_password(services: &Services) -> Result {
userid_password.remove(&user_id);
remote_users = remote_users.saturating_add(1);
} else if hash.is_empty() {
if !(services.appservice.is_exclusive_user_id(&user_id).await
if !(services.appservice.is_user_id(&user_id).await
|| user_id == services.globals.server_user)
{
info!("Marking {user_id} as deactivated");
+38 -6
View File
@@ -115,6 +115,21 @@ pub enum SessionCompletionStatus {
Complete(OwnedUserId),
}
pub enum ClaimedLocalUser {
/// The claim refers to an existing user.
Existing(OwnedUserId),
/// The claim refers to a new user ID which should be registered.
New(OwnedUserId),
}
impl ClaimedLocalUser {
fn into_user_id(self) -> OwnedUserId {
match self {
| Self::Existing(user_id) | Self::New(user_id) => user_id,
}
}
}
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
@@ -303,7 +318,7 @@ impl Service {
.expect("claims should be an object")
.to_owned();
debug!(?all_claims);
debug!(?all_claims, "Got claims from the identity provider");
let subject = claims.subject().as_str();
@@ -326,14 +341,13 @@ impl Service {
.get(&config.preferred_username_claim)
.and_then(|claim| claim.as_str())
{
self.services
.users
.determine_registration_user_id(Some(preferred_username.to_owned()), None, None)
self.identify_claimed_local_user(preferred_username)
.await
.map(ClaimedLocalUser::into_user_id)
.map_err(|err| {
error!("Preferred username claim is not a valid localpart: {err}");
"Your preferred username is not a valid Matrix user ID localpart. Contact \
your homeserver's administrator."
"Your preferred username could not be converted to a valid Matrix user ID. \
Contact your homeserver's administrator."
})?
} else {
error!("Preferred username claim was not present or was not a string");
@@ -482,4 +496,22 @@ impl Service {
}
pub fn unlink_user(&self, subject: &str) { self.db.openidsubject_localpart.remove(subject); }
/// Determine what user ID a localpart claim refers to.
pub async fn identify_claimed_local_user(&self, claim: &str) -> Result<ClaimedLocalUser> {
if let Ok(user_id) =
UserId::parse(format!("@{}:{}", claim, self.services.globals.server_name()))
&& self.services.users.status(&user_id).await.is_active()
{
Ok(ClaimedLocalUser::Existing(user_id))
} else {
let user_id = self
.services
.users
.determine_registration_user_id(Some(claim.to_owned()), None, None)
.await?;
Ok(ClaimedLocalUser::New(user_id))
}
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
use std::{cmp, collections::HashMap};
use conduwuit::{smallstr::SmallString, trace};
use conduwuit::{pdu::AnyPDU, smallstr::SmallString, trace};
use conduwuit_core::{
Err, Error, Result, err,
matrix::{
@@ -84,7 +84,7 @@ impl super::Service {
sender: &UserId,
room_id: Option<&RoomId>,
_mutex_lock: &RoomMutexGuard,
) -> Result<(PduEvent, RoomVersionRules)> {
) -> Result<AnyPDU> {
let PartialPdu {
event_type,
content,
@@ -282,7 +282,7 @@ impl super::Service {
sender: &UserId,
room_id: Option<&RoomId>,
mutex_lock: &RoomMutexGuard,
) -> Result<(PduEvent, CanonicalJsonObject)> {
) -> Result<AnyPDU> {
if !self.services.globals.user_is_local(sender) {
return Err!(Request(Forbidden("Sender must be a local user")));
}
+39 -41
View File
@@ -6,9 +6,12 @@ use axum::{
response::Redirect,
routing::on,
};
use conduwuit_service::{oauth::grant::AuthorizationCodeResponse, oidc::SessionCompletionStatus};
use conduwuit_service::{
oauth::grant::AuthorizationCodeResponse,
oidc::{ClaimedLocalUser, SessionCompletionStatus},
};
use futures::FutureExt;
use ruma::{OwnedServerName, UserId};
use ruma::OwnedServerName;
use serde::{Deserialize, de::IgnoredAny};
use tower_sessions::Session;
@@ -99,65 +102,60 @@ async fn route_complete(
state: OidcSessionState::Authorized { claims: Box::new(claims.clone()) },
})
.await
.expect("Should be able to serialize oidc session");
.expect("should be able to serialize oidc session");
services.oidc.complete_session(&claims, None).await
},
| OidcSessionState::Authorized { claims } => {
let supplied_user_id = if let Some(form) = form {
if let Ok(user_id) = UserId::parse(format!(
"@{}:{}",
&form.username,
services.globals.server_name()
)) && services.users.status(&user_id).await.is_active()
match services
.oidc
.identify_claimed_local_user(&form.username)
.await
{
let user_card = UserCard::for_local_user(&services, user_id.clone()).await;
| Ok(ClaimedLocalUser::Existing(user_id)) => {
let user_card =
UserCard::for_local_user(&services, user_id.clone()).await;
if let Some(password) = form.password {
if services
.users
.check_password(&user_id, &password)
.await
.is_ok()
{
Some(user_id)
if let Some(password) = form.password {
if services
.users
.check_password(&user_id, &password)
.await
.is_ok()
{
Some(user_id)
} else {
return response!(OidcComplete::new(
context,
OidcCompleteBody::PasswordPrompt {
username: form.username,
user_card,
password_error: true
}
));
}
} else {
return response!(OidcComplete::new(
context,
OidcCompleteBody::PasswordPrompt {
username: form.username,
user_card,
password_error: true
password_error: false,
}
));
}
} else {
},
| Ok(ClaimedLocalUser::New(user_id)) => Some(user_id),
| Err(err) => {
return response!(OidcComplete::new(
context,
OidcCompleteBody::PasswordPrompt {
username: form.username,
user_card,
password_error: false,
OidcCompleteBody::UsernamePrompt {
server_name: services.globals.server_name().to_owned(),
username_error: Some(err.message()),
}
));
}
} else {
match services
.users
.determine_registration_user_id(Some(form.username), None, None)
.await
{
| Ok(user_id) => Some(user_id),
| Err(err) => {
return response!(OidcComplete::new(
context,
OidcCompleteBody::UsernamePrompt {
server_name: services.globals.server_name().to_owned(),
username_error: Some(err.message()),
}
));
},
}
},
}
} else {
None