mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-20 07:27:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9190219bd0 | ||
|
|
49207a42f8 | ||
|
|
62fc507798 | ||
|
|
8f10378bff | ||
|
|
52a6bf0003 | ||
|
|
fcddfb5f35 | ||
|
|
94ba3b2b83 | ||
|
|
4e7493604a | ||
|
|
cebeee6bae | ||
|
|
f3cbfed721 | ||
|
|
9bdbaf3300 | ||
|
|
06c63e8de3 | ||
|
|
8ffa3e5367 | ||
|
|
cec1f85f88 | ||
|
|
ad50b9a3b3 |
No files matched your search
Generated
+9
-2
@@ -624,6 +624,12 @@ dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cache_control"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bf2a5fb3207c12b5d208ebc145f967fea5cac41a021c37417ccc31ba40f39ee"
|
||||
|
||||
[[package]]
|
||||
name = "camino"
|
||||
version = "1.2.6"
|
||||
@@ -4898,10 +4904,11 @@ checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7"
|
||||
|
||||
[[package]]
|
||||
name = "resolvematrix"
|
||||
version = "1.4.2"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6e659fe17ed82acfac43641d00d1bbfd0a9d53ec4d2f901b01f792f0e2c9e3c"
|
||||
checksum = "39a1efc3c55274528f8b1a916eb0edf5c40a8364b4899fbc1283a57c8d0024db"
|
||||
dependencies = [
|
||||
"cache_control",
|
||||
"hickory-resolver",
|
||||
"num-traits",
|
||||
"parking_lot",
|
||||
|
||||
+1
-1
@@ -603,7 +603,7 @@ features = ["std"]
|
||||
version = "0.3.0"
|
||||
|
||||
[workspace.dependencies.resolvematrix]
|
||||
version = "1.4.2"
|
||||
version = "1.5.0"
|
||||
features = ["unstable-msc4188"]
|
||||
|
||||
[workspace.dependencies.serde_urlencoded]
|
||||
|
||||
+17
-3
@@ -52,8 +52,10 @@ else
|
||||
fi
|
||||
|
||||
# The base docker image to use for complement tests
|
||||
# You can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`. Only the debug binary is used.
|
||||
# On Linux, you can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`.
|
||||
# On non-Linux platforms (or to use a container build), build `docker/Dockerfile` with debuginfo and openreg `--build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg`
|
||||
# and then run `docker build -t continuwuity:complement --target container -f ./docker/complement.Dockerfile .`.
|
||||
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-continuwuity:complement}"
|
||||
|
||||
# Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
|
||||
@@ -83,6 +85,13 @@ for command in docker go jq; do
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${DOCKER_HOST:-}" ]; then
|
||||
DOCKER_HOST="$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || true)"
|
||||
if [ -n "$DOCKER_HOST" ]; then
|
||||
export DOCKER_HOST
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$IMAGE_ARCHIVE" ]; then
|
||||
if [ ! -f "$IMAGE_ARCHIVE" ]; then
|
||||
echo "Docker image archive not found: $IMAGE_ARCHIVE"
|
||||
@@ -99,7 +108,12 @@ fi
|
||||
|
||||
if ! docker image inspect "$COMPLEMENT_BASE_IMAGE" > /dev/null 2>&1; then
|
||||
echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE"
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
if [ "$(uname -s)" != "Linux" ]; then
|
||||
echo "Build it with: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
else
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
echo "Or from a container build: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Fix remote server key signature verification when extra fields exist. Contributed by @hexchen
|
||||
@@ -0,0 +1 @@
|
||||
Fixed the experiments implementation in #2517 not properly disabling some functionality when associated experiments weren't enabled.
|
||||
+38
-9
@@ -812,15 +812,6 @@
|
||||
# env: CONTINUWUITY_FORGET_FORCED_UPON_LEAVE
|
||||
#forget_forced_upon_leave = false
|
||||
|
||||
# Set this to true to require authentication on the normally
|
||||
# unauthenticated profile retrieval endpoints (GET)
|
||||
# "/_matrix/client/v3/profile/{userId}".
|
||||
#
|
||||
# This can prevent profile scraping.
|
||||
#
|
||||
# env: CONTINUWUITY_REQUIRE_AUTH_FOR_PROFILE_REQUESTS
|
||||
#require_auth_for_profile_requests = false
|
||||
|
||||
# Set this to true to allow your server's public room directory to be
|
||||
# federated. Set this to false to protect against /publicRooms spiders,
|
||||
# but will forbid external users from viewing your server's public room
|
||||
@@ -2669,6 +2660,26 @@
|
||||
# and consequently know why you should enable them.
|
||||
|
||||
|
||||
# MSC3814: Dehydrated devices with SSSS
|
||||
#
|
||||
# Enables server-side support for "dehydrated devices", which are
|
||||
# server-side devices (created by supporting clients) that can collect
|
||||
# encryption keys when there are no online devices, which supporting
|
||||
# clients can then "hydrate" to download any encryption keys that were
|
||||
# sent while they were offline.
|
||||
#
|
||||
# Important: this is NOT required to receive encrypted messages while you
|
||||
# are offline. Devices can still receive encrypted messages while they are
|
||||
# offline, but to share those keys with new devices, they have to be
|
||||
# online. Dehydrated devices work around this by providing a "shared"
|
||||
# device new sessions can bootstrap from, to receive keys from before they
|
||||
# logged in that haven't been uploaded to the server-side key backup yet.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/3814
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC3814
|
||||
#msc3814 = false
|
||||
|
||||
# MSC4155: Invite filtering
|
||||
#
|
||||
# Provides advanced invite filtering rules for users, allowing complex
|
||||
@@ -2693,6 +2704,24 @@
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4174
|
||||
#msc4174 = false
|
||||
|
||||
# MSC4406: `M_SENDER_IGNORED` error code
|
||||
#
|
||||
# Introduces a new error code that explicitly informs clients the reason
|
||||
# they cannot access an event if it is sent by an ignored user. Without
|
||||
# this proposal, clients will simply get a "not found" or "forbidden"
|
||||
# error when requesting events sent by users that have been ignored, which
|
||||
# leads to replies being shown as "this message could not be found".
|
||||
# The new error code allows clients to distinguish unknown/forbidden
|
||||
# events from ignored senders, allowing them to display an error message
|
||||
# like "you have blocked this sender" instead.
|
||||
#
|
||||
# Requires a supporting client to be useful.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4406
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4406
|
||||
#msc4406 = false
|
||||
|
||||
# MSC4484: Server Administration OAuth Scope
|
||||
#
|
||||
# Adds a new OAuth2 scope that explicitly grants a token temporary
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
FROM ubuntu:latest
|
||||
ARG CONTINUWUITY_IMAGE=continuwuity:latest-openreg
|
||||
ARG BINARY_SOURCE=host
|
||||
|
||||
FROM ${CONTINUWUITY_IMAGE} AS container-binary
|
||||
|
||||
FROM scratch AS host-binary
|
||||
ARG BINARY_PATH=target/debug/conduwuit
|
||||
COPY ${BINARY_PATH} /sbin/conduwuit
|
||||
|
||||
FROM ubuntu:latest AS base
|
||||
EXPOSE 8008
|
||||
EXPOSE 8448
|
||||
RUN apt-get update && apt-get install -y ca-certificates liburing2 && rm -rf /var/lib/apt/lists/*
|
||||
RUN mkdir -p /etc/continuwuity /var/lib/continuwuity /usr/local/bin/
|
||||
COPY complement/complement-entrypoint.sh /usr/local/bin/complement-entrypoint.sh
|
||||
COPY complement/complement.config.toml /etc/continuwuity/config.toml
|
||||
COPY target/debug/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit /usr/local/bin/complement-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/complement-entrypoint.sh
|
||||
#HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://localhost:8008/_continuwuity/server_version || exit 1
|
||||
ENTRYPOINT ["/usr/local/bin/complement-entrypoint.sh"]
|
||||
|
||||
FROM base AS container
|
||||
COPY --from=container-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM base AS host
|
||||
COPY --from=host-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM ${BINARY_SOURCE}
|
||||
@@ -20,6 +20,20 @@ docker build -t continuwuity:complement -f docker/complement.Dockerfile .
|
||||
The `openreg` feature is required: without it the server refuses the open
|
||||
registrations Complement uses to create test users, and almost every test fails.
|
||||
|
||||
On non-Linux (or to build inside a container instead of on the host), build the Continuwuity image with the `openreg` feature and `RUST_PROFILE=dev` first (open
|
||||
registration is only enabled when `debug_assertions` are active), then build
|
||||
the Complement image using the `container` target:
|
||||
|
||||
```bash
|
||||
docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile .
|
||||
docker build -t continuwuity:complement --target container -f docker/complement.Dockerfile .
|
||||
./bin/complement
|
||||
```
|
||||
|
||||
Pass `--build-arg CONTINUWUITY_IMAGE=your-image:tag` when building
|
||||
`docker/complement.Dockerfile` if your Continuwuity container image uses a
|
||||
different tag.
|
||||
|
||||
The run can take up to an hour. The runner writes the full Go test stream to
|
||||
`tests/test_results/complement/test_logs.jsonl` and a sorted pass/fail/skip
|
||||
summary to `tests/test_results/complement/test_results.jsonl`. It exits nonzero
|
||||
|
||||
@@ -142,11 +142,11 @@ impl crate::Context<'_> {
|
||||
.await?;
|
||||
self.write_str("| ------ | ---------- | --------------------------- |\n")
|
||||
.await?;
|
||||
for (key_id, key) in &response.verify_keys {
|
||||
for (key_id, key) in &response.parsed.verify_keys {
|
||||
self.write_str(&format!("| {key_id} | {} | |\n", key.key))
|
||||
.await?;
|
||||
}
|
||||
for (key_id, old_key) in &response.old_verify_keys {
|
||||
for (key_id, old_key) in &response.parsed.old_verify_keys {
|
||||
self.write_str(&format!(
|
||||
"| {key_id} | {} | {:0<13} |\n",
|
||||
old_key.key,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Result, Server};
|
||||
use conduwuit::{Result, Server, config::experiments::ToggledExperiment};
|
||||
use ruma::{
|
||||
RoomVersionId,
|
||||
api::{
|
||||
@@ -53,8 +53,11 @@ pub(crate) async fn get_capabilities_route(
|
||||
capabilities.account_moderation.lock = true;
|
||||
capabilities.account_moderation.suspend = true;
|
||||
|
||||
capabilities.admin =
|
||||
AdminCapability::new(BTreeSet::from_iter([OAuthClientScope::ServerAdministration]));
|
||||
if services.config.experiments.msc4484.is_enabled() {
|
||||
capabilities.admin = AdminCapability::new(BTreeSet::from_iter([
|
||||
OAuthClientScope::ServerAdministration,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
capabilities.profile_fields = Some(
|
||||
@@ -63,7 +66,10 @@ pub(crate) async fn get_capabilities_route(
|
||||
|
||||
capabilities.set(
|
||||
"org.matrix.msc4174.webpush",
|
||||
json!({ "enabled": true, "vapid": services.pusher.webpush_vapid_public_key() }),
|
||||
json!({
|
||||
"enabled": services.config.experiments.msc4174.is_enabled(),
|
||||
"vapid": services.pusher.webpush_vapid_public_key()
|
||||
}),
|
||||
)?;
|
||||
|
||||
Ok(get_capabilities::v3::Response::new(capabilities))
|
||||
|
||||
+21
-11
@@ -1,6 +1,8 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Error, Result, at, debug_warn,
|
||||
Err, Error, Result, at,
|
||||
config::experiments::ToggledExperiment,
|
||||
debug_warn,
|
||||
matrix::{
|
||||
event::{Event, Matches},
|
||||
pdu::PduCount,
|
||||
@@ -315,21 +317,29 @@ where
|
||||
|
||||
if server_ignored {
|
||||
// the sender's server is ignored, so ignore this event
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()),
|
||||
"The sender's server is ignored by this server.",
|
||||
));
|
||||
return if services.config.experiments.msc4406.is_enabled() {
|
||||
Err(Error::BadRequest(
|
||||
ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()),
|
||||
"The sender's server is ignored by this server.",
|
||||
))
|
||||
} else {
|
||||
Err!(Request(NotFound("This event's sender's homeserver is ignored by this server.")))
|
||||
};
|
||||
}
|
||||
|
||||
if user_ignored && !services.config.send_messages_from_ignored_users_to_client {
|
||||
// the recipient of this PDU has the sender ignored, and we're not
|
||||
// configured to send ignored messages to clients
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
|
||||
event.sender().to_owned(),
|
||||
)),
|
||||
"You have ignored this sender.",
|
||||
));
|
||||
return if services.config.experiments.msc4406.is_enabled() {
|
||||
Err(Error::BadRequest(
|
||||
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
|
||||
event.sender().to_owned(),
|
||||
)),
|
||||
"You have ignored this sender.",
|
||||
))
|
||||
} else {
|
||||
Err!(Request(NotFound("You have ignored the sender of this event.")))
|
||||
};
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
|
||||
@@ -29,7 +29,7 @@ pub(crate) async fn get_profile_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_profile::v3::Request>,
|
||||
) -> Result<get_profile::v3::Response> {
|
||||
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
|
||||
if body.identity.is_none() {
|
||||
return Err!(Request(Unauthorized(
|
||||
"This server requires authentication to access user profiles."
|
||||
)));
|
||||
@@ -46,7 +46,7 @@ pub(crate) async fn get_profile_field_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_profile_field::v3::Request>,
|
||||
) -> Result<get_profile_field::v3::Response> {
|
||||
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
|
||||
if body.identity.is_none() {
|
||||
return Err!(Request(Unauthorized(
|
||||
"This server requires authentication to access user profiles."
|
||||
)));
|
||||
|
||||
+14
-7
@@ -10,7 +10,7 @@ use axum::{
|
||||
response::{IntoResponse, Redirect},
|
||||
routing::{any, get},
|
||||
};
|
||||
use conduwuit::err;
|
||||
use conduwuit::{config::experiments::ToggledExperiment, err};
|
||||
pub(super) use conduwuit_service::state::State;
|
||||
use http::{Uri, uri};
|
||||
|
||||
@@ -162,10 +162,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::update_device_route)
|
||||
.ruma_route(&client::delete_device_route)
|
||||
.ruma_route(&client::delete_devices_route)
|
||||
.ruma_route(&client::put_dehydrated_device_route)
|
||||
.ruma_route(&client::delete_dehydrated_device_route)
|
||||
.ruma_route(&client::get_dehydrated_device_route)
|
||||
.ruma_route(&client::get_dehydrated_events_route)
|
||||
.ruma_route(&client::get_tags_route)
|
||||
.ruma_route(&client::update_tag_route)
|
||||
.ruma_route(&client::delete_tag_route)
|
||||
@@ -184,7 +180,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::get_mutual_rooms_unstable_route)
|
||||
.ruma_route(&client::get_mutual_rooms_route)
|
||||
.ruma_route(&client::get_room_summary)
|
||||
.ruma_route(&client::get_stripped_state_route)
|
||||
.ruma_route(&client::get_suspended_status)
|
||||
.ruma_route(&client::put_suspended_status)
|
||||
.ruma_route(&client::get_lock_status)
|
||||
@@ -199,6 +194,16 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.route("/_continuwuity/server_version", get(client::continuwuity_server_version))
|
||||
.ruma_route(&admin::rooms::ban::ban_room)
|
||||
.ruma_route(&admin::rooms::list::list_rooms);
|
||||
if config.experiments.msc3814.is_enabled() {
|
||||
router = router
|
||||
.ruma_route(&client::put_dehydrated_device_route)
|
||||
.ruma_route(&client::delete_dehydrated_device_route)
|
||||
.ruma_route(&client::get_dehydrated_device_route)
|
||||
.ruma_route(&client::get_dehydrated_events_route);
|
||||
}
|
||||
if config.experiments.msc4560.is_enabled() {
|
||||
router = router.ruma_route(&client::get_stripped_state_route);
|
||||
}
|
||||
|
||||
if config.allow_prometheus_metrics {
|
||||
router = router.route("/_continuwuity/metrics", get(client::continuwuity_metrics));
|
||||
@@ -230,11 +235,13 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&server::get_keys_route)
|
||||
.ruma_route(&server::claim_keys_route)
|
||||
.ruma_route(&server::get_hierarchy_route)
|
||||
.ruma_route(&server::get_stripped_state_route)
|
||||
.ruma_route(&server::well_known_server)
|
||||
.ruma_route(&server::get_content_route)
|
||||
.ruma_route(&server::get_content_thumbnail_route)
|
||||
.route("/_continuwuity/local_user_count", get(client::continuwuity_local_user_count));
|
||||
if config.experiments.msc4560.is_enabled() {
|
||||
router = router.ruma_route(&server::get_stripped_state_route);
|
||||
}
|
||||
} else {
|
||||
router = router
|
||||
.route("/_matrix/federation/{*path}", any(federation_disabled))
|
||||
|
||||
+13
-9
@@ -5,7 +5,9 @@ use std::{
|
||||
};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Error, Result, err,
|
||||
Err, Error, Result,
|
||||
config::experiments::ToggledExperiment,
|
||||
err,
|
||||
utils::{IterStream, millis_since_unix_epoch},
|
||||
};
|
||||
use http::StatusCode;
|
||||
@@ -338,17 +340,19 @@ async fn check_access_token(
|
||||
.map(Box::new);
|
||||
|
||||
// Make sure the user has the right scopes to use the route
|
||||
let user_scopes = if let Some(session_info) = &session_info {
|
||||
let mut user_scopes = if let Some(session_info) = &session_info {
|
||||
session_info.scopes()
|
||||
} else {
|
||||
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]);
|
||||
|
||||
if services.admin.user_is_admin(&sender_user).await {
|
||||
scopes.insert(OAuthClientScope::ServerAdministration);
|
||||
}
|
||||
|
||||
scopes
|
||||
BTreeSet::from_iter([OAuthClientScope::ApiFullAccess])
|
||||
};
|
||||
if (!services.config.experiments.msc4484.is_enabled() || session_info.is_none())
|
||||
&& services.admin.user_is_admin(&sender_user).await
|
||||
{
|
||||
// This is required to make sure admin APIs still work when msc4484
|
||||
// is disabled.
|
||||
// https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533#issuecomment-40042
|
||||
user_scopes.insert(OAuthClientScope::ServerAdministration);
|
||||
}
|
||||
|
||||
if !required_scopes
|
||||
.iter()
|
||||
|
||||
@@ -34,7 +34,7 @@ pub(crate) async fn get_server_keys_route(
|
||||
// We need to verify that this response is still trusted based on
|
||||
// the current configuration. It's possible we got this response
|
||||
// from a notary who we no longer trust.
|
||||
if resp.valid_until_ts > in_one_week() {
|
||||
if resp.parsed.valid_until_ts > in_one_week() {
|
||||
continue;
|
||||
}
|
||||
let trusted = services.config.trusted_servers.iter().any(|notary| {
|
||||
@@ -47,8 +47,8 @@ pub(crate) async fn get_server_keys_route(
|
||||
if !trusted {
|
||||
continue;
|
||||
}
|
||||
for (old_key_id, old_key) in resp.old_verify_keys {
|
||||
if old_key.expired_ts > resp.valid_until_ts {
|
||||
for (old_key_id, old_key) in resp.parsed.old_verify_keys {
|
||||
if old_key.expired_ts > resp.parsed.valid_until_ts {
|
||||
// This key expired in the future which is probably illegal
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,26 @@ pub struct Experiments {
|
||||
/// display: nested
|
||||
#[serde(default)]
|
||||
pub msc2815: Option<MSC2815>,
|
||||
/// MSC3814: Dehydrated devices with SSSS
|
||||
///
|
||||
/// Enables server-side support for "dehydrated devices", which are
|
||||
/// server-side devices (created by supporting clients) that can collect
|
||||
/// encryption keys when there are no online devices, which supporting
|
||||
/// clients can then "hydrate" to download any encryption keys that were
|
||||
/// sent while they were offline.
|
||||
///
|
||||
/// Important: this is NOT required to receive encrypted messages while you
|
||||
/// are offline. Devices can still receive encrypted messages while they are
|
||||
/// offline, but to share those keys with new devices, they have to be
|
||||
/// online. Dehydrated devices work around this by providing a "shared"
|
||||
/// device new sessions can bootstrap from, to receive keys from before they
|
||||
/// logged in that haven't been uploaded to the server-side key backup yet.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/3814
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc3814: SimpleExperiment,
|
||||
/// MSC4155: Invite filtering
|
||||
///
|
||||
/// Provides advanced invite filtering rules for users, allowing complex
|
||||
@@ -48,6 +68,24 @@ pub struct Experiments {
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4174: SimpleExperiment,
|
||||
/// MSC4406: `M_SENDER_IGNORED` error code
|
||||
///
|
||||
/// Introduces a new error code that explicitly informs clients the reason
|
||||
/// they cannot access an event if it is sent by an ignored user. Without
|
||||
/// this proposal, clients will simply get a "not found" or "forbidden"
|
||||
/// error when requesting events sent by users that have been ignored, which
|
||||
/// leads to replies being shown as "this message could not be found".
|
||||
/// The new error code allows clients to distinguish unknown/forbidden
|
||||
/// events from ignored senders, allowing them to display an error message
|
||||
/// like "you have blocked this sender" instead.
|
||||
///
|
||||
/// Requires a supporting client to be useful.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4406
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4406: SimpleExperiment,
|
||||
/// MSC4484: Server Administration OAuth Scope
|
||||
///
|
||||
/// Adds a new OAuth2 scope that explicitly grants a token temporary
|
||||
|
||||
@@ -919,14 +919,6 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub forget_forced_upon_leave: bool,
|
||||
|
||||
/// Set this to true to require authentication on the normally
|
||||
/// unauthenticated profile retrieval endpoints (GET)
|
||||
/// "/_matrix/client/v3/profile/{userId}".
|
||||
///
|
||||
/// This can prevent profile scraping.
|
||||
#[serde(default)]
|
||||
pub require_auth_for_profile_requests: bool,
|
||||
|
||||
/// Set this to true to allow your server's public room directory to be
|
||||
/// federated. Set this to false to protect against /publicRooms spiders,
|
||||
/// but will forbid external users from viewing your server's public room
|
||||
@@ -2977,6 +2969,7 @@ const DEPRECATED_KEYS: &[&str] = &[
|
||||
"conduit_cache_capacity_modifier",
|
||||
"max_concurrent_requests",
|
||||
"otlp_protocol",
|
||||
"require_auth_for_profile_requests",
|
||||
"roomid_spacehierarchy_cache_capacity",
|
||||
"well_known_client",
|
||||
"well_known_server",
|
||||
|
||||
@@ -6,7 +6,9 @@ use std::{
|
||||
|
||||
use base64::Engine;
|
||||
use conduwuit::{
|
||||
Result, SyncMutex, info,
|
||||
Result, SyncMutex,
|
||||
config::experiments::ToggledExperiment,
|
||||
info,
|
||||
utils::{self, hash::sha256},
|
||||
};
|
||||
use database::{Deserialized, Json, Map};
|
||||
@@ -762,6 +764,7 @@ impl Service {
|
||||
scopes: &BTreeSet<OAuthClientScope>,
|
||||
) -> Result<(), OAuthError> {
|
||||
if scopes.contains(&OAuthClientScope::ServerAdministration)
|
||||
&& self.services.config.experiments.msc4484.is_enabled()
|
||||
&& !self.services.admin.user_is_admin(authorizing_user).await
|
||||
{
|
||||
return Err(OAuthError::new(
|
||||
|
||||
@@ -3,7 +3,7 @@ mod webpush;
|
||||
use std::{fmt::Debug, mem, net::IpAddr, sync::Arc};
|
||||
|
||||
use bytes::BytesMut;
|
||||
use conduwuit::utils::response::LimitReadExt;
|
||||
use conduwuit::{config::experiments::ToggledExperiment, utils::response::LimitReadExt};
|
||||
use conduwuit_core::{
|
||||
Err, Event, Result, Server, debug_warn, err, trace,
|
||||
utils::{stream::TryIgnore, string_from_bytes},
|
||||
@@ -133,7 +133,9 @@ impl Service {
|
||||
self.validate_push_url(&http.url, PUSH_GATEWAY_SCHEMES)
|
||||
.await?;
|
||||
},
|
||||
| PusherKind::WebPush(data) => {
|
||||
| PusherKind::WebPush(data)
|
||||
if self.services.config.experiments.msc4174.is_enabled() =>
|
||||
{
|
||||
self.validate_push_url(&data.url, WEBPUSH_SCHEMES).await?;
|
||||
webpush::decode_pushkey(pushkey)?;
|
||||
webpush::decode_auth(&data.auth)?;
|
||||
@@ -147,7 +149,7 @@ impl Service {
|
||||
}
|
||||
}
|
||||
},
|
||||
| PusherKind::Email(_) | PusherKind::Custom { .. } => (),
|
||||
| _ => (),
|
||||
}
|
||||
|
||||
let key = (sender, pushkey);
|
||||
@@ -547,7 +549,9 @@ impl Service {
|
||||
|
||||
Ok(())
|
||||
},
|
||||
| PusherKind::WebPush(data) => {
|
||||
| PusherKind::WebPush(data)
|
||||
if self.services.config.experiments.msc4174.is_enabled() =>
|
||||
{
|
||||
let notify = self
|
||||
.build_notification(
|
||||
user,
|
||||
@@ -562,7 +566,7 @@ impl Service {
|
||||
|
||||
self.send_webpush_notice(user, pusher, data, notify).await
|
||||
},
|
||||
| PusherKind::Email(_) | PusherKind::Custom { .. } => Ok(()),
|
||||
| _ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ mod vapid;
|
||||
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use conduwuit::config::experiments::ToggledExperiment;
|
||||
use conduwuit_core::{
|
||||
Err, Result, debug, debug_warn, err,
|
||||
utils::{self, string::constant_time_eq},
|
||||
@@ -85,6 +86,9 @@ impl Service {
|
||||
/// Reports whether a Web Push pusher has completed its activation
|
||||
/// handshake.
|
||||
pub async fn is_webpush_activated(&self, sender: &UserId, pushkey: &str) -> bool {
|
||||
if !self.services.config.experiments.msc4174.is_enabled() {
|
||||
return false;
|
||||
}
|
||||
self.webpush_state(sender, pushkey).await.activated
|
||||
}
|
||||
|
||||
@@ -109,6 +113,9 @@ impl Service {
|
||||
pusher: &Pusher,
|
||||
previous: Option<&Pusher>,
|
||||
) -> bool {
|
||||
if !self.services.config.experiments.msc4174.is_enabled() {
|
||||
return false;
|
||||
}
|
||||
let Some(data) = pusher.kind.as_webpush() else {
|
||||
return false;
|
||||
};
|
||||
@@ -126,6 +133,13 @@ impl Service {
|
||||
}
|
||||
|
||||
pub(super) fn begin_webpush_activation(&self, sender: &UserId, pusher: &Pusher) {
|
||||
debug_assert!(
|
||||
self.services.config.experiments.msc4174.is_enabled(),
|
||||
"begin_webpush_activation should not be called with MSC4174 disabled"
|
||||
);
|
||||
if !self.services.config.experiments.msc4174.is_enabled() {
|
||||
return;
|
||||
}
|
||||
// Send a one-time encrypted token before allowing notification
|
||||
// delivery.
|
||||
let token = utils::rand::string(ACK_TOKEN_LENGTH);
|
||||
|
||||
@@ -241,9 +241,9 @@ impl super::Service {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
trace!(?origin_response, "Got signing key response from origin");
|
||||
trace!(?origin_response.raw, "Got signing key response from origin");
|
||||
self.add_signing_keys(&origin_response);
|
||||
Self::track_result(&mut result, &mut still_missing, &origin_response);
|
||||
Self::track_result(&mut result, &mut still_missing, &origin_response.parsed);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -262,9 +262,9 @@ impl super::Service {
|
||||
"Got signing keys response from a notary"
|
||||
);
|
||||
for server_keys in notary_response {
|
||||
trace!(?server_keys, "Adding response from notary");
|
||||
trace!(?server_keys.raw, "Adding response from notary");
|
||||
self.add_signing_keys(&server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -285,9 +285,9 @@ impl super::Service {
|
||||
continue;
|
||||
};
|
||||
for server_keys in res {
|
||||
trace!(?server_keys, "Adding response from notary");
|
||||
trace!(?server_keys.raw, "Adding response from notary");
|
||||
self.add_signing_keys(&server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
|
||||
}
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
@@ -300,9 +300,9 @@ impl super::Service {
|
||||
debug_warn!(err=?res.err(), "Got error response from origin");
|
||||
continue;
|
||||
};
|
||||
trace!(response=?res, "Got signing key response from origin");
|
||||
trace!(response=?res.raw, "Got signing key response from origin");
|
||||
self.add_signing_keys(&res);
|
||||
Self::track_result(&mut result, &mut still_missing, &res);
|
||||
Self::track_result(&mut result, &mut still_missing, &res.parsed);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ impl super::Service {
|
||||
.inspect_err(|e| info!("Could not acquire signing key from origin server: {e:?}"))
|
||||
.ok()?;
|
||||
|
||||
verify_key_from_response(key_id, &response, min_valid_ts)
|
||||
verify_key_from_response(key_id, &response.parsed, min_valid_ts)
|
||||
.inspect(|_| self.add_signing_keys(&response))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ use ruma::{
|
||||
ServerSigningKeyId,
|
||||
api::federation::discovery::{ServerSigningKeys, VerifyKey},
|
||||
room_version_rules::RoomVersionRules,
|
||||
serde::Raw,
|
||||
signatures::{Ed25519KeyPair, PublicKeyMap, PublicKeySet},
|
||||
};
|
||||
use verify::IncomingServerKeys;
|
||||
|
||||
use crate::{Dep, globals, sending, server_keys::util::required_keys};
|
||||
|
||||
@@ -83,19 +85,22 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Adds a signing key response to the database.
|
||||
fn add_signing_keys(&self, new_keys: &ServerSigningKeys) {
|
||||
fn add_signing_keys(&self, new_keys: &IncomingServerKeys) {
|
||||
// TODO(nex): this results in massive amounts of data duplication.
|
||||
// Perhaps a sliding approach would be better? where we just update the
|
||||
// last known response if the only thing that changed was the
|
||||
// valid_until_ts. This would require a more complex data structure
|
||||
// though. For now, just storing the duplicated data is fine.
|
||||
for key in new_keys
|
||||
.parsed
|
||||
.verify_keys
|
||||
.keys()
|
||||
.chain(new_keys.old_verify_keys.keys())
|
||||
.chain(new_keys.parsed.old_verify_keys.keys())
|
||||
{
|
||||
let db_key = (new_keys.server_name.as_str(), key.as_str());
|
||||
self.db.servernamekeyid_response.put(db_key, Json(new_keys));
|
||||
let db_key = (new_keys.parsed.server_name.as_str(), key.as_str());
|
||||
self.db
|
||||
.servernamekeyid_response
|
||||
.put(db_key, Json(&new_keys.raw));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +175,7 @@ impl Service {
|
||||
let mut keys = self
|
||||
.signing_keys_for(origin)
|
||||
.ready_fold(BTreeMap::new(), |mut base, keys| {
|
||||
base.extend(keys.verify_keys);
|
||||
base.extend(keys.parsed.verify_keys);
|
||||
base
|
||||
})
|
||||
.await;
|
||||
@@ -186,11 +191,12 @@ impl Service {
|
||||
pub fn signing_keys_for<'a>(
|
||||
&'a self,
|
||||
origin: &'a ServerName,
|
||||
) -> impl Stream<Item = ServerSigningKeys> + Send + 'a {
|
||||
) -> impl Stream<Item = IncomingServerKeys> + Send + 'a {
|
||||
self.db
|
||||
.servernamekeyid_response
|
||||
.stream_prefix(&(origin, Interfix))
|
||||
.ignore_err()
|
||||
.map(|(_, v): (Ignore, ServerSigningKeys)| v)
|
||||
.map(|(_, v): (Ignore, Raw<ServerSigningKeys>)| v.try_into().map_err(Into::into))
|
||||
.ignore_err()
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ use conduwuit::{Err, Result, trace, utils::millis_since_unix_epoch, warn};
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName, UInt,
|
||||
api::federation::discovery::{
|
||||
ServerSigningKeys,
|
||||
get_remote_server_keys_batch::{
|
||||
self,
|
||||
v2::{QueryCriteria, Response as NotaryResponse},
|
||||
@@ -15,6 +14,8 @@ use ruma::{
|
||||
uint,
|
||||
};
|
||||
|
||||
use crate::server_keys::verify::IncomingServerKeys;
|
||||
|
||||
pub(crate) type ServerKeysQuery = BTreeMap<OwnedServerName, ServerKeysQuerySet>;
|
||||
pub(crate) type ServerKeysQuerySet = BTreeMap<OwnedServerSigningKeyId, QueryCriteria>;
|
||||
|
||||
@@ -27,32 +28,33 @@ impl super::Service {
|
||||
&self,
|
||||
target: OwnedServerName,
|
||||
min_valid_ts: MilliSecondsSinceUnixEpoch,
|
||||
) -> Result<ServerSigningKeys> {
|
||||
) -> Result<IncomingServerKeys> {
|
||||
use get_server_keys::v2::Request;
|
||||
|
||||
let server_signing_key = self
|
||||
let raw_server_key = self
|
||||
.services
|
||||
.sending
|
||||
.send_unauthenticated_request(&target, Request::new())
|
||||
.await
|
||||
.map(|response| response.server_key)
|
||||
.and_then(|key| key.deserialize().map_err(Into::into))?;
|
||||
.map(|response| response.server_key)?;
|
||||
|
||||
if server_signing_key.server_name != target {
|
||||
let server_signing_key: IncomingServerKeys = raw_server_key.try_into()?;
|
||||
|
||||
if server_signing_key.parsed.server_name != target {
|
||||
return Err!(BadServerResponse(debug_warn!(
|
||||
requested = ?target,
|
||||
response = ?server_signing_key.server_name,
|
||||
response = ?server_signing_key.parsed.server_name,
|
||||
"Origin server responded with bogus server_name"
|
||||
)));
|
||||
}
|
||||
|
||||
if server_signing_key.valid_until_ts < min_valid_ts
|
||||
|| server_signing_key.valid_until_ts > in_one_week()
|
||||
if server_signing_key.parsed.valid_until_ts < min_valid_ts
|
||||
|| server_signing_key.parsed.valid_until_ts > in_one_week()
|
||||
{
|
||||
return Err!(BadServerResponse(debug_warn!(
|
||||
?target,
|
||||
?min_valid_ts,
|
||||
?server_signing_key.valid_until_ts,
|
||||
?server_signing_key.parsed.valid_until_ts,
|
||||
"Origin server responded with server keys that are not in-date"
|
||||
)));
|
||||
}
|
||||
@@ -83,7 +85,7 @@ impl super::Service {
|
||||
&self,
|
||||
notary: &ServerName,
|
||||
batch: ServerKeysQuery,
|
||||
) -> Result<Vec<ServerSigningKeys>> {
|
||||
) -> Result<Vec<IncomingServerKeys>> {
|
||||
use get_remote_server_keys_batch::v2::Request;
|
||||
|
||||
let is_empty = batch.is_empty() || batch.values().all(BTreeMap::is_empty);
|
||||
@@ -116,12 +118,12 @@ impl super::Service {
|
||||
}
|
||||
|
||||
/// Parses a notary response, returning a vec of server signing key
|
||||
/// responses. Drops any chunks that cannot be deserialized.
|
||||
fn parse_notary_response(raw: &NotaryResponse) -> Vec<ServerSigningKeys> {
|
||||
/// responses, each paired with its raw JSON (which is what the signatures
|
||||
/// were made over). Drops any chunks that cannot be deserialized.
|
||||
fn parse_notary_response(raw: &NotaryResponse) -> Vec<IncomingServerKeys> {
|
||||
raw.server_keys
|
||||
.iter()
|
||||
.map(ruma::serde::Raw::deserialize)
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|chunk| chunk.try_into().ok())
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -129,12 +131,15 @@ impl super::Service {
|
||||
/// if the response should be dropped, true if it should be kept.
|
||||
fn validate_notary_chunk(
|
||||
batch: &ServerKeysQuery,
|
||||
keys: &ServerSigningKeys,
|
||||
incoming: &IncomingServerKeys,
|
||||
notary_name: &ServerName,
|
||||
notary_keys: &[Base64],
|
||||
) -> bool {
|
||||
let Some(expected_keys) = batch.get(&keys.server_name) else {
|
||||
trace!("Dropping signing keys chunk for unrequested server: {}", keys.server_name);
|
||||
let Some(expected_keys) = batch.get(&incoming.parsed.server_name) else {
|
||||
trace!(
|
||||
"Dropping signing keys chunk for unrequested server: {}",
|
||||
incoming.parsed.server_name
|
||||
);
|
||||
return false;
|
||||
};
|
||||
let min_valid_ts = expected_keys
|
||||
@@ -148,13 +153,15 @@ impl super::Service {
|
||||
|
||||
// If this notary response is older than any of the min_valid_ts we
|
||||
// requested, then we should drop it.
|
||||
if keys.valid_until_ts < min_valid_ts || keys.valid_until_ts > in_one_week() {
|
||||
if incoming.parsed.valid_until_ts < min_valid_ts
|
||||
|| incoming.parsed.valid_until_ts > in_one_week()
|
||||
{
|
||||
trace!(
|
||||
?min_valid_ts,
|
||||
?keys.valid_until_ts,
|
||||
?incoming.parsed.valid_until_ts,
|
||||
"Dropping signing keys chunk for server {} because it is older than the minimum \
|
||||
valid timestamp we requested",
|
||||
keys.server_name
|
||||
incoming.parsed.server_name
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -162,38 +169,39 @@ impl super::Service {
|
||||
// Does this chunk even contain any keys we asked for?
|
||||
// Note that this enforces min_valid_ts per-key, instead of using the
|
||||
// lowest denominator.
|
||||
let all_key_ids = keys
|
||||
let all_key_ids = incoming
|
||||
.parsed
|
||||
.verify_keys
|
||||
.keys()
|
||||
.chain(keys.old_verify_keys.keys())
|
||||
.chain(incoming.parsed.old_verify_keys.keys())
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<_>>();
|
||||
let interesting = expected_keys.iter().any(|(k, q)| {
|
||||
all_key_ids.contains(k)
|
||||
&& q.minimum_valid_until_ts
|
||||
.is_none_or(|m| m <= keys.valid_until_ts)
|
||||
.is_none_or(|m| m <= incoming.parsed.valid_until_ts)
|
||||
});
|
||||
if !interesting {
|
||||
trace!(
|
||||
"Dropping signing keys chunk for server {} because it does not contain any keys \
|
||||
we requested",
|
||||
keys.server_name
|
||||
incoming.parsed.server_name
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Self::verify_server_keys_response(keys, Some((notary_name, notary_keys)))
|
||||
Self::verify_server_keys_response(incoming, Some((notary_name, notary_keys)))
|
||||
.inspect_err(|e| {
|
||||
trace!(
|
||||
?e,
|
||||
?keys,
|
||||
?incoming.raw,
|
||||
?notary_name,
|
||||
?notary_keys,
|
||||
"Dropping illegal server signing keys response chunk"
|
||||
);
|
||||
warn!(
|
||||
%notary_name,
|
||||
server_name=%keys.server_name,
|
||||
server_name=%incoming.parsed.server_name,
|
||||
"Dropping illegal server signing keys response chunk: {e:?}"
|
||||
);
|
||||
})
|
||||
|
||||
@@ -5,11 +5,36 @@ use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, ServerName, SigningKeyAlgorithm,
|
||||
api::federation::discovery::ServerSigningKeys,
|
||||
room_version_rules::RoomVersionRules,
|
||||
serde::{Base64, base64::Standard},
|
||||
serde::{Base64, Raw, base64::Standard},
|
||||
signatures::Verified,
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
pub struct IncomingServerKeys {
|
||||
pub raw: Raw<ServerSigningKeys>,
|
||||
pub parsed: ServerSigningKeys,
|
||||
}
|
||||
|
||||
impl TryFrom<Raw<ServerSigningKeys>> for IncomingServerKeys {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(value: Raw<ServerSigningKeys>) -> std::result::Result<Self, Self::Error> {
|
||||
value
|
||||
.deserialize()
|
||||
.map(|parsed| Self { raw: value, parsed })
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Raw<ServerSigningKeys>> for IncomingServerKeys {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(value: &Raw<ServerSigningKeys>) -> std::result::Result<Self, Self::Error> {
|
||||
value
|
||||
.deserialize()
|
||||
.map(|parsed| Self { raw: value.to_owned(), parsed })
|
||||
}
|
||||
}
|
||||
|
||||
impl super::Service {
|
||||
/// Validates the incoming event only using locally known verification keys.
|
||||
/// Inserts the calculated event ID into the event_id field upon success.
|
||||
@@ -58,34 +83,38 @@ impl super::Service {
|
||||
/// `notary` must either be empty or have ONE entry. Extraneous notaries
|
||||
/// will be ignored.
|
||||
pub fn verify_server_keys_response(
|
||||
server_keys: &ServerSigningKeys,
|
||||
incoming: &IncomingServerKeys,
|
||||
notary: Option<(&ServerName, &[Base64])>,
|
||||
) -> Result<()> {
|
||||
if let Some((notary_name, notary_keys)) = notary {
|
||||
if !notary_keys.is_empty() {
|
||||
Self::verify_notary_signature(server_keys, notary_name, notary_keys)?;
|
||||
Self::verify_notary_signature(incoming, notary_name, notary_keys)?;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: old_verify_keys aren't considered here because old keys can't
|
||||
// be used to sign key responses.
|
||||
let mut set = ruma::signatures::PublicKeySet::new();
|
||||
server_keys.verify_keys.iter().for_each(|(key_id, key)| {
|
||||
set.insert(key_id.to_string(), key.key.clone());
|
||||
});
|
||||
incoming
|
||||
.parsed
|
||||
.verify_keys
|
||||
.iter()
|
||||
.for_each(|(key_id, key)| {
|
||||
set.insert(key_id.to_string(), key.key.clone());
|
||||
});
|
||||
|
||||
let mut pubkey_map = ruma::signatures::PublicKeyMap::new();
|
||||
pubkey_map.insert(server_keys.server_name.to_string(), set);
|
||||
pubkey_map.insert(incoming.parsed.server_name.to_string(), set);
|
||||
|
||||
let mut canonical = to_canonical_object(server_keys)?;
|
||||
Self::strip_extraneous_signatures(&mut canonical, &server_keys.server_name, &[]);
|
||||
let mut canonical = to_canonical_object(&incoming.raw)?;
|
||||
Self::strip_extraneous_signatures(&mut canonical, &incoming.parsed.server_name, &[]);
|
||||
ruma::signatures::verify_json(&pubkey_map, &canonical).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Verifies that the notary has at least one valid signature present with
|
||||
/// the provided signing keys.
|
||||
fn verify_notary_signature(
|
||||
server_keys: &ServerSigningKeys,
|
||||
incoming: &IncomingServerKeys,
|
||||
notary_name: &ServerName,
|
||||
notary_keys: &[Base64],
|
||||
) -> Result<()> {
|
||||
@@ -94,19 +123,16 @@ impl super::Service {
|
||||
// certificate has been compromised, which would otherwise allow
|
||||
// them to produce attacker-controlled signing keys with valid
|
||||
// self-signatures.
|
||||
let Some(notary_signatures) = server_keys.signatures.get(notary_name) else {
|
||||
let Some(notary_signatures) = incoming.parsed.signatures.get(notary_name) else {
|
||||
return Err!(Request(Forbidden(
|
||||
"Missing notary server signature from {notary_name}"
|
||||
)));
|
||||
};
|
||||
let mut canonical_object = to_canonical_object(notary_signatures)?;
|
||||
Self::strip_extraneous_signatures(&mut canonical_object, &server_keys.server_name, &[
|
||||
notary_name,
|
||||
]);
|
||||
// The notary signed the response as the origin served it, so verify
|
||||
// over the raw JSON, not a re-serialised `ServerSigningKeys`.
|
||||
let for_verify = ruma::signatures::to_canonical_json_string_for_signing(
|
||||
&to_canonical_object(server_keys).expect("server keys object must be canonical json"),
|
||||
)
|
||||
.expect("canonical JSON must be stringable");
|
||||
&to_canonical_object(&incoming.raw)?,
|
||||
)?;
|
||||
|
||||
let raw_notary_keys = notary_keys.iter().map(Base64::as_bytes).collect::<Vec<_>>();
|
||||
let raw_notary_signatures = notary_signatures
|
||||
@@ -126,7 +152,7 @@ impl super::Service {
|
||||
trace!(
|
||||
"Valid signature from {notary_name} present on signing keys response \
|
||||
for {}",
|
||||
server_keys.server_name
|
||||
incoming.parsed.server_name
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
@@ -181,9 +207,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap();
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect("Self-signature of real key response is valid");
|
||||
}
|
||||
|
||||
@@ -208,9 +234,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap();
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect("Self-signature of real key response is valid");
|
||||
}
|
||||
|
||||
@@ -235,11 +261,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap();
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
let starstruck_pubkey =
|
||||
Base64::<Standard>::parse("Z4oHuEjdUbtC5W/z/gzc5B8raxNk+8gGwbNwgxHqW8Y").unwrap();
|
||||
Service::verify_server_keys_response(
|
||||
&response_data.deserialize().unwrap(),
|
||||
&response_data,
|
||||
Some((server_name!("starstruck.systems"), &[starstruck_pubkey])),
|
||||
)
|
||||
.expect("Server keys from notary are valid");
|
||||
@@ -265,8 +291,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap();
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect_err("Tampered response should fail self-signature check");
|
||||
}
|
||||
|
||||
@@ -303,8 +329,45 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap();
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect_err("Intercepted notary response should fail strict validation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_response_with_extra_fields() {
|
||||
let response_data = serde_json::from_value(serde_json::json!(
|
||||
{
|
||||
"old_verify_keys": {},
|
||||
"server_name": "origin.example",
|
||||
"signatures": {
|
||||
"notary.example": {
|
||||
"ed25519:a_RBdc": "ozlc2T5TlUa9XAsmeam+ESr20573vqFJvYHonj3nG8x+m6v7K5TSlEKTAlTRrJYiC6T/aWB+yxMae6FYR6nqCA"
|
||||
},
|
||||
"origin.example": {
|
||||
"ed25519:a_jUhC": "+8xKspAfqI8SfrioOVliQ/jCPRDZEuag6JfkN5dXx9gsCX2rSnbvVTJlTJXFiDYUSyIJZg8ilq1QaPsT85ltBA"
|
||||
}
|
||||
},
|
||||
"tls_fingerprints": [],
|
||||
"valid_until_ts": 1900000000000_i64,
|
||||
"verify_keys": {
|
||||
"ed25519:a_jUhC": {
|
||||
"key": "idcPtcSpRB5Chnlv1azhL3rMlcTawgQhoGNZWKaNFGI"
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
|
||||
let notary_pubkey =
|
||||
Base64::<Standard>::parse("0ocHGigwa/ap6gSZzzspDQhhOkVkloaf9apolOvwqo8").unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect("Self-signature must verify over the raw response");
|
||||
|
||||
Service::verify_server_keys_response(
|
||||
&response_data,
|
||||
Some((server_name!("notary.example"), &[notary_pubkey])),
|
||||
)
|
||||
.expect("Notary signature must verify over the raw response");
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ use std::{
|
||||
};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Result, debug, debug_error, debug_warn, err, error, info, trace,
|
||||
Err, Result,
|
||||
config::experiments::ToggledExperiment,
|
||||
debug, debug_error, debug_warn, err, error, info, trace,
|
||||
utils::{self, stream::TryIgnore},
|
||||
warn,
|
||||
};
|
||||
@@ -107,6 +109,27 @@ impl super::Service {
|
||||
if stable.is_err() && unstable.is_err() {
|
||||
return FilterLevel::Default;
|
||||
}
|
||||
let msc4494_enabled = self.services.config.experiments.msc4494.is_enabled();
|
||||
if !self.services.config.experiments.msc4155.is_enabled() {
|
||||
// Only MSC4380 should be checked here, since it's in spec.
|
||||
let Some(action) = stable.ok().and_then(|c| c.content.default_action) else {
|
||||
return FilterLevel::Default;
|
||||
};
|
||||
return match action {
|
||||
| InvitePermissionAction::Block => FilterLevel::Block,
|
||||
| InvitePermissionAction::DenyPublic if msc4494_enabled => {
|
||||
if !self
|
||||
.check_msc4494_mutual_room(sender_user, recipient_user)
|
||||
.await
|
||||
{
|
||||
FilterLevel::Block
|
||||
} else {
|
||||
FilterLevel::Default
|
||||
}
|
||||
},
|
||||
| _ => FilterLevel::Allow,
|
||||
};
|
||||
}
|
||||
let content = stable.unwrap_or_else(|_| unstable.unwrap()).content;
|
||||
let verdict = content.user_filter_level(sender_user);
|
||||
if verdict != FilterLevel::Default {
|
||||
@@ -114,7 +137,8 @@ impl super::Service {
|
||||
}
|
||||
// Apply other layers of invite blocking first, so that user/server
|
||||
// denies take priority over implicit allows.
|
||||
if content.default_action == Some(InvitePermissionAction::DenyPublic)
|
||||
if msc4494_enabled
|
||||
&& content.default_action == Some(InvitePermissionAction::DenyPublic)
|
||||
&& !self
|
||||
.check_msc4494_mutual_room(sender_user, recipient_user)
|
||||
.await
|
||||
|
||||
Reference in new issue
Block a user