feat: Support acting as a notary server #2314

Merged
Jade merged 37 commits from nex/feat/notary-server into main 2026-11-27 18:41:02 +00:00
Owner

This PR implements POST /_matrix/key/v2/query and GET /_matrix/key/v2/query/{server_name}, allowing continuwuity to act as a key notary server, and finally a trusted server..

Closes: #784, #1208

Pull request checklist:

  • This pull request targets the main branch, and the branch is named something other than
    main.
  • I have written an appropriate pull request title and my description is clear.
  • I understand I am responsible for the contents of this pull request.
  • I have followed the contributing guidelines:
This PR implements [`POST /_matrix/key/v2/query`](https://spec.matrix.org/v1.19/server-server-api/#post_matrixkeyv2query) and [`GET /_matrix/key/v2/query/{server_name}`](https://spec.matrix.org/v1.19/server-server-api/#get_matrixkeyv2queryservername), allowing continuwuity to act as a key notary server, and finally a trusted server.. <!-- Example: This pull request allows us to warp through time and space ten times faster than before by double-inverting the warp drive with hyperheated jump fluid, both making the drive faster and more efficient. This resolves the common issue where we have to wait more than 10 milliseconds to engage, use, and disengage the warp drive when travelling between galaxies. --> Closes: #784, #1208 <!-- Uncomment the above line(s) if your pull request fixes an issue or closes another pull request by superseding it. Replace `#...` with the issue/pr number, such as `#123`. --> **Pull request checklist:** <!-- You need to complete these before your PR can be considered. If you aren't sure about some, feel free to ask for clarification in #dev:continuwuity.org. --> - [x] This pull request targets the `main` branch, and the branch is named something other than `main`. - [x] I have written an appropriate pull request title and my description is clear. - [x] I understand I am responsible for the contents of this pull request. - I have followed the [contributing guidelines][c1]: - [x] My contribution follows the [code style][c2], if applicable. - [x] I ran [pre-commit checks][c1pc] before opening/drafting this pull request. - [x] I have [tested my contribution][c1t] (or proof-read it for documentation-only changes) myself, if applicable. This includes ensuring code compiles. - [x] My commit messages follow the [commit message format][c1cm] and are descriptive. <!-- Notes on these requirements: - While not required, we encourage you to sign your commits with GPG or SSH to attest the authenticity of your changes. - While we allow LLM-assisted contributions, we do not appreciate contributions that are low quality, which is typical of machine-generated contributions that have not had a lot of love and care from a human. Please do not open a PR if all you have done is asked ChatGPT to tidy up the codebase with a +-100,000 diff. - In the case of code style violations, reviewers may leave review comments/change requests indicating what the ideal change would look like. For example, a reviewer may suggest you lower a log level, or use `match` instead of `if/else` etc. - In the case of code style violations, pre-commit check failures, minor things like typos/spelling errors, and in some cases commit format violations, reviewers may modify your branch directly, typically by making changes and adding a commit. Particularly in the latter case, a reviewer may rebase your commits to squash "spammy" ones (like "fix", "fix", "actually fix"), and reword commit messages that don't satisfy the format. - Pull requests MUST pass the `Checks` CI workflows to be capable of being merged. This can only be bypassed in exceptional circumstances. If your CI flakes, let us know in matrix:r/dev:continuwuity.org. - Pull requests have to be based on the latest `main` commit before being merged. If the main branch changes while you're making your changes, you should make sure you rebase on main before opening a PR. Your branch will be rebased on main before it is merged if it has fallen behind. - We typically only do fast-forward merges, so your entire commit log will be included. Once in main, it's difficult to get out cleanly, so put on your best dress, smile for the cameras! --> [c1]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md [c2]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/docs/development/code_style.mdx [c1pc]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#pre-commit-checks [c1t]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#running-tests-locally [c1cm]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#commit-messages
nex self-assigned this 2026-10-02 20:54:41 +00:00
feat: Strip extraneous signatures to avoid leaking our own notaries
Some checks failed
Auto Labeler / Apply labels based on changed files (pull_request_target) Successful in 4s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Failing after 8s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m5s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m9s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m56s
dcf61d6487
ginger requested changes 2026-10-02 21:02:06 +00:00
Dismissed
@ -90,0 +103,4 @@
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys_batch::v2::Request>,
) -> Result<get_remote_server_keys_batch::v2::Response> {
let total_queried_keys = body
Owner

you're gonna lose your mind when you learn about BTreeMap::len()

you're gonna lose your mind when you learn about `BTreeMap::len()`
Author
Owner

Yeah I will because you made me realise I'm calculating bullshit lmao. It's supposed to sum the length of each value map but instead it's just counting the length of the top level map. I can't believe I reimplemented len()

Yeah I will because you made me realise I'm calculating bullshit lmao. It's supposed to sum the length of each value map but instead it's just counting the length of the top level map. I can't believe I reimplemented len()
nex marked this conversation as resolved
@ -90,0 +119,4 @@
let mut response = Vec::with_capacity(total_queried_keys);
for (server_name, queries) in &body.server_keys {
if queries.is_empty() {
Owner

there is a fair bit of logic duplicated between this if and the code after it

there is a fair bit of logic duplicated between this `if` and the code after it
nex marked this conversation as resolved
@ -90,0 +151,4 @@
else {
continue;
};
if ssk.valid_until_ts < minimum_valid_until_ts || ssk.valid_until_ts > in_one_week() {
Owner

you might as well fix !2312 while you're at it (maybe by having in_one_week() be "in one week and one hour")

you might as well fix !2312 while you're at it (maybe by having `in_one_week()` be "in one week and one hour")
Author
Owner

Didn't see that issue, that's actually deliberate because otherwise the range check will always return true if someone returns keys that last forever, which defeats the purpose of the 7-day limit

Didn't see that issue, that's actually deliberate because otherwise the range check will always return true if someone returns keys that last forever, which defeats the purpose of the 7-day limit
Owner

I'm not sure I follow your logic, why isn't that possible with the current seven-day limit as opposed to a seven-day-and-one-hour limit?

I'm not sure I follow your logic, why isn't that possible with the current seven-day limit as opposed to a seven-day-and-one-hour limit?
Author
Owner

If you query a key on 2026-01-01, and receive a response that expires at 2026-02-01, accepting that response will result in a cache hit against that response for every lookup until February. This means a request to the origin won't be made until Feb, meaning the origin can't revoke any keys that may have been maliciously injected, or leaked, etc. All that clamping would do is prevent someone then sending an event that was created on 2026-02-01, at 2026-01-02 (since the 1st of Feb is more than 7 days in the future as of the 2nd of Jan). Now imagine someone's web server was hacked and someone published a key response for a decade...

I don't know where this "plus one hour" is coming from, the spec very clearly states exactly 7 days

If you query a key on 2026-01-01, and receive a response that expires at 2026-02-01, accepting that response will result in a cache hit against that response for every lookup until February. This means a request to the origin won't be made until Feb, meaning the origin can't revoke any keys that may have been maliciously injected, or leaked, etc. All that clamping would do is prevent someone then sending an event that was created on 2026-02-01, at 2026-01-02 (since the 1st of Feb is more than 7 days in the future as of the 2nd of Jan). Now imagine someone's web server was hacked and someone published a key response for a decade... I don't know where this "plus one hour" is coming from, the spec very clearly states exactly 7 days
Owner

"plus one hour" allows for clock skew, basically. intentionally lightly imprecise definition of 7 days

"plus one hour" allows for clock skew, basically. intentionally lightly imprecise definition of 7 days
Author
Owner

But whose skew? That accounts for a +1 timezone offset, but there's more timezones with >+1. People should just have the right time?

But whose skew? That accounts for a +1 timezone offset, but there's more timezones with >+1. People should just have the right time?
Owner

A) the issue isn't timezones, that's not what clock skee is, but latency and clocks that are off by a second or two
B) that over-caching sounds like a bug to me, you can make it so that you only treat the key as valid for the clamped length and then recheck that it's still on the origin.

A) the issue isn't timezones, that's not what clock skee is, but latency and clocks that are off by a second or two B) that over-caching sounds like a bug to me, you can make it so that you only treat the key as valid for the clamped length and then recheck that it's still on the origin.
Author
Owner

I can, but I'm not going to. It's not over-caching, it's working as intended: if there's a locally stored key that is in-date and valid, use that. I don't see why you'd do anything less?

I can, but I'm not going to. It's not over-caching, it's working as intended: if there's a locally stored key that is in-date and valid, use that. I don't see why you'd do anything less?
Author
Owner

(discussion out-of-band decided this is out of scope for this PR but Jade wants to tackle 2312 herself, so the issue was re-opened and assigned)

(discussion out-of-band decided this is out of scope for this PR but Jade wants to tackle 2312 herself, so the issue was re-opened and assigned)
nex marked this conversation as resolved
Owner

also you need a news fragment :3

also you need a news fragment :3
style: Condense repeated code into a reusable function
Some checks failed
Checks / Prek / Check changed files (pull_request) Successful in 5s
Checks / Changelog / Check changelog is added (pull_request_target) Failing after 8s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m14s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m13s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 7m30s
6d3d24169a
nex changed title from feat: Support acting as a notary server to WIP: feat: Support acting as a notary server 2026-10-03 01:47:24 +00:00
chore: Add newsfrag
All checks were successful
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m10s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m41s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m19s
e712759419
chore: Rebuild example config
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m2s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m53s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 9m32s
a6656c6c33
fix: Don't short circuit if all requested servers have no query criteria
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 12s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m35s
Checks / Prek / Check changed files (pull_request) Successful in 9s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m6s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m27s
1543c31889
Also adds some traces
fix: Deduplicate signing key responses if we already satisfied them
Some checks failed
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m13s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m14s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 4m10s
09a7fba83b
fix: Refuse to process >4096 servers and/or >8192 keys
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m3s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 2m2s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 6m4s
80dd7d5071
pending msc
Jade force-pushed nex/feat/notary-server from 80dd7d5071
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m3s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 2m2s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 6m4s
to 69b4d6ffa4
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 8s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m6s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 1m51s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 4m32s
2026-10-04 22:28:59 +00:00
Compare
fix: Enforce specific notary limits per MSC4556
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m3s
Checks / Prek / Check changed files (pull_request) Successful in 14s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 1m15s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
bf251d0cde
nex changed title from WIP: feat: Support acting as a notary server to feat: Support acting as a notary server 2026-10-04 22:35:59 +00:00
fix: Don't serve expired responses in the criterialess path
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Has been cancelled
Documentation / Build and Deploy Documentation (pull_request) Has been cancelled
Checks / Prek / Pre-commit & Formatting (pull_request) Has been cancelled
Checks / Prek / Check changed files (pull_request) Has been cancelled
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
dec881457a
chore: Update trusted_servers docs
Some checks failed
Checks / Prek / Pre-commit & Formatting (pull_request) Has been cancelled
Checks / Prek / Check changed files (pull_request) Has been cancelled
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
Documentation / Build and Deploy Documentation (pull_request) Has been cancelled
Checks / Changelog / Check changelog is added (pull_request_target) Has been cancelled
912880fb6a
Jade force-pushed nex/feat/notary-server from 912880fb6a
Some checks failed
Checks / Prek / Pre-commit & Formatting (pull_request) Has been cancelled
Checks / Prek / Check changed files (pull_request) Has been cancelled
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
Documentation / Build and Deploy Documentation (pull_request) Has been cancelled
Checks / Changelog / Check changelog is added (pull_request_target) Has been cancelled
to 8cb173ad08
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m6s
Checks / Prek / Check changed files (pull_request) Successful in 36s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m0s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m18s
2026-10-04 23:29:06 +00:00
Compare
Jade requested changes 2026-10-05 13:23:18 +00:00
Dismissed
@ -90,0 +137,4 @@
// )));
}
if total_queried_keys > MAX_KEYS_PER_QUERY {
// We shouldn't really enforce this before MSC4456 either, but not doing
Owner

Typo (MSC4556)

Typo (MSC4556)
nex marked this conversation as resolved
@ -90,0 +203,4 @@
// First contact the origin (if we're allowed to)
if server_keys.notary_may_contact_origin(&remote) {
debug_info!("Asking remote directly for verify keys");
if let Ok(res) = server_keys.origin_request(remote.clone(), start).await
Owner

Same here, i don't think this persists the keys

Same here, i don't think this persists the keys
Owner

No check to avoid self-federation in these too I don't think

No check to avoid self-federation in these too I don't think
Author
Owner

That check is in the federation execute layer*

*or it should be, ginger told me a few hours ago that it's suspiciously absent now

That check is in the federation execute layer* \*or it should be, ginger told me a few hours ago that it's suspiciously absent now
nex marked this conversation as resolved
@ -90,0 +209,4 @@
let index = results.len();
results.push(ssk);
for key_id in res.verify_keys.keys().chain(res.old_verify_keys.keys()) {
if queries.is_empty()
Owner

This changes during iteration, so the condition may change and cause additional keys to be returned

This changes during iteration, so the condition may change and cause additional keys to be returned
nex marked this conversation as resolved
@ -90,0 +213,4 @@
|| queries
.get(key_id)
.and_then(|c| c.minimum_valid_until_ts)
.is_none_or(|m| res.valid_until_ts >= m)
Owner

Did you mean something like .and_then(|c| c.minimum_valid_until_ts.is_none_or(|m| res.valid_until_ts >= m))? Otherwise this will return keys that weren't queried for

Did you mean something like `.and_then(|c| c.minimum_valid_until_ts.is_none_or(|m| res.valid_until_ts >= m))`? Otherwise this will return keys that weren't queried for
Author
Owner

Uhh probably? I think clippy complained when I did that though 🤔

Uhh probably? I think clippy complained when I did that though 🤔
nex marked this conversation as resolved
@ -90,0 +322,4 @@
.notary_may_contact_origin(&body.server_name)
&& let Ok(response) = services
.server_keys
.origin_request(body.server_name.clone(), min_valid_ts)
Owner

This doesn't persist the keys, right? Might that be an issue?

This doesn't persist the keys, right? Might that be an issue?
Author
Owner

uhhh I guess storing the keys could be an optimisation, but it's not an issue otherwise afaik

uhhh I guess storing the keys could be an optimisation, but it's not an issue otherwise afaik
nex marked this conversation as resolved
@ -90,0 +242,4 @@
}
})
.ready_for_each(|signed_ssk| {
let ssk = signed_ssk.deserialize().unwrap();
Owner

Can't you just yield the ssk in the broad_filter_map above in a tuple to avoid pointless work here?

Can't you just yield the ssk in the broad_filter_map above in a tuple to avoid pointless work here?
Author
Owner

I didn't want to because sign_ssk moves ssk, but I suppose deserializing is probably more expensive than cloning

I didn't want to because `sign_ssk` moves ssk, but I suppose deserializing is probably more expensive than cloning
nex marked this conversation as resolved
@ -90,0 +332,4 @@
services.globals.server_name(),
)
.await
.map(|r| Ok(get_remote_server_keys::v2::Response::new(vec![r])))?;
Owner

.map(|r| get_remote_server_keys::v2::Response::new(vec![r]))?

`.map(|r| get_remote_server_keys::v2::Response::new(vec![r]))`?
Author
Owner

Has to return a Result<get_remote_server_keys::v2::Response> so the wrap is necessary. I'll just rid of the map

Has to return a `Result<get_remote_server_keys::v2::Response>` so the wrap is necessary. I'll just rid of the map
Author
Owner

Hmm, actually that's visually worse

		return Ok(get_remote_server_keys::v2::Response::new(vec![
			sign_ssk(
				&services.server_keys,
				response,
				&body.server_name,
				services.globals.server_name(),
			)
			.await?,
		]));

I'll keep the current chain

Hmm, actually that's visually worse ```rs return Ok(get_remote_server_keys::v2::Response::new(vec![ sign_ssk( &services.server_keys, response, &body.server_name, services.globals.server_name(), ) .await?, ])); ``` I'll keep the current chain
nex marked this conversation as resolved
@ -90,0 +271,4 @@
continue;
};
if ssk.valid_until_ts < minimum_valid_until_ts || ssk.valid_until_ts > in_one_week() {
Owner

do you need to check expired_ts too? (and in other checks)

do you need to check `expired_ts` too? (and in other checks)
nex marked this conversation as resolved
@ -29,6 +34,7 @@ pub struct Service {
verify_keys: VerifyKeys,
services: Services,
db: Data,
last_lookup: SyncRwLock<HashMap<OwnedServerName, Instant>>,
Owner

Woo! Unbounded growth! Not really a huge issue tho lol

Woo! Unbounded growth! Not really a huge issue tho lol
Author
Owner

Yeahh I'm not too sure how to get around that without a cleanup task (which just defines a time window for the unbounded growth). I think the map will hold small enough data that it won't really matter

Yeahh I'm not too sure how to get around that without a cleanup task (which just defines a time window for the unbounded growth). I think the map will hold small enough data that it won't really matter
nex marked this conversation as resolved
@ -101,3 +101,3 @@
};
let mut canonical_object = to_canonical_object(notary_signatures)?;
Self::strip_extraneous_signatures(&mut canonical_object, &server_keys.server_name, &[
strip_extraneous_signatures(&mut canonical_object, &server_keys.server_name, &[
Owner

This seems like dead code anyway

This seems like dead code anyway
Author
Owner

This is very much live code? what do you mean?

This is very much live code? what do you mean?
Owner

You're making and stripping a canonical object but then not using it for anything as far as I can read?

You're making and stripping a canonical object but then not using it for anything as far as I can read?
Author
Owner

Oh yeah, you're right, it was meant to be passed to to_canonical_json_string_for_signing below

Oh yeah, you're right, it was meant to be passed to `to_canonical_json_string_for_signing` below
nex marked this conversation as resolved
ginger approved these changes 2026-10-05 13:24:10 +00:00
Dismissed
Owner

look at jade's comments 👍she said most of the stuff I would've said

look at jade's comments 👍she said most of the stuff I would've said
@ -90,0 +119,4 @@
}
let total_queried_servers = body.server_keys.len();
let total_queried_keys = body
Owner

Hmm actually is this counting right? Might be overcounting

Hmm actually is this counting right? Might be overcounting
Author
Owner

Deliberately so, if a request is {"server_keys": {"servername.example": {}}}, we'll count zero total keys, but it's more likely that we'll end up fetching at least 1 key response, so I figured counting each server name in the total query count makes sense

Deliberately so, if a request is `{"server_keys": {"servername.example": {}}}`, we'll count zero total keys, but it's more likely that we'll end up fetching at least 1 key response, so I figured counting each server name in the total query count makes sense
nex marked this conversation as resolved
nex force-pushed nex/feat/notary-server from 8cb173ad08
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m6s
Checks / Prek / Check changed files (pull_request) Successful in 36s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m0s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m18s
to ad9ca737b2
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m20s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m30s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 2m1s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 9m42s
2026-10-07 10:49:05 +00:00
Compare
nex requested review from Jade 2026-10-08 21:54:19 +00:00
nex force-pushed nex/feat/notary-server from ad9ca737b2
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m20s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m30s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 2m1s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 9m42s
to adc0e5d3b8
Some checks failed
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 11s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m36s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m52s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 7m59s
2026-10-09 17:21:57 +00:00
Compare
feat: Update MSC4456 implementation, new route
Some checks failed
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m12s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m22s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 7m23s
58c5875013
Jade force-pushed nex/feat/notary-server from 58c5875013
Some checks failed
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m12s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m22s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 7m23s
to 298113c0a6
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m8s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m20s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 20m55s
Checks / Prek / Clippy and Cargo Tests (pull_request) Failing after 40m59s
2026-10-14 09:35:53 +00:00
Compare
Jade requested changes 2026-10-14 10:36:55 +00:00
Dismissed
Jade left a comment

You have the wrong MSC in one of your commit messages I think. And tests are failing.

failures:

---- server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature stdout ----

thread 'server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature' (6147872) panicked at src/service/server_keys/verify.rs:244:10:
Server keys from notary are valid: No valid signature from starstruck.systems present on signing keys response
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature
You have the wrong MSC in one of your commit messages I think. And tests are failing. ``` failures: ---- server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature stdout ---- thread 'server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature' (6147872) panicked at src/service/server_keys/verify.rs:244:10: Server keys from notary are valid: No valid signature from starstruck.systems present on signing keys response note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: server_keys::verify::tests::verify_notary_response_checks_valid_notary_signature ```
@ -28,0 +59,4 @@
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys_batch::v2::Request>,
) -> Result<get_remote_server_keys_batch::v2::Response> {
query_inner(&services, &body.server_keys, false)
Owner

false -> true?

`false` -> `true`?
nex marked this conversation as resolved
Lines 102-105
@ -28,0 +99,7 @@
// Count how many keys are being requested.
// Each server incurs a cost of at least one, and then the count of each key
// being queried per-server.
let total_queried_servers = body.len();
let total_queried_keys = body
.values()
.fold(body.len(), |acc, q| acc.saturating_add(q.len()));
Owner

Maybe

let total_queried_keys = body
    .values()
    .fold(0_usize, |acc, q| acc.saturating_add(q.len().max(1)));

would be better? It'll be less of an overcount.

Maybe ``` let total_queried_keys = body .values() .fold(0_usize, |acc, q| acc.saturating_add(q.len().max(1))); ``` would be better? It'll be less of an overcount.
nex marked this conversation as resolved
@ -28,0 +122,4 @@
total_queried_servers > MAX_SERVERS_PER_QUERY || total_queried_keys > MAX_KEYS_PER_QUERY;
debug_info!("Fetching {total_queried_keys} keys across {} servers", body.len());
let mut futs: FuturesUnordered<_> = FuturesUnordered::new();
Owner

Probably want something to limit concurrency here

Probably want something to limit concurrency here
Owner

futuresunordered is evil anyway, this really ought to be a Vec of tokio tasks

futuresunordered is evil anyway, this really ought to be a `Vec` of tokio tasks
nex marked this conversation as resolved
@ -83,0 +273,4 @@
let minimum_valid_until_ts = criteria
.clone()
.minimum_valid_until_ts
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(uint!(0)));
Owner

Doesn't this mean that the default could provide expired keys? But spec wants current time by default.
Perhaps:

let minimum_valid_until_ts = criteria.minimum_valid_until_ts.unwrap_or(start);
Doesn't this mean that the default could provide expired keys? But spec wants current time by default. Perhaps: ``` let minimum_valid_until_ts = criteria.minimum_valid_until_ts.unwrap_or(start); ```
nex marked this conversation as resolved
@ -0,0 +23,4 @@
rate_limited: true,
authentication: ServerSignatures,
history: {
unstable("org.continuwuity.msc4553") => "/_matrix/key/unstable/org.continuwuity.msc4556/query",
Owner

4556?

`4556`?
nex marked this conversation as resolved
@ -196,0 +260,4 @@
// 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() || resp.valid_until_ts < now {
Owner

Remind me to come back to this condition later.

Remind me to come back to this condition later.
Owner

@Jade this is your reminder 🗿

@Jade this is your reminder 🗿
Jade marked this conversation as resolved
@ -100,13 +100,12 @@ impl super::Service {
)));
};
let mut canonical_object = to_canonical_object(notary_signatures)?;
Owner

Did you mean
let mut canonical_object = to_canonical_object(server_keys)?;
(this is probably the cause of the test fail)

Did you mean `let mut canonical_object = to_canonical_object(server_keys)?;` (this is probably the cause of the test fail)
nex marked this conversation as resolved
ginger added this to the 26.11.0 milestone 2026-10-26 23:02:20 +00:00
ginger requested changes 2026-11-05 15:34:51 +00:00
Dismissed
@ -0,0 +1,58 @@
//! `POST /_matrix/key/*/query`
Owner

I would endorse putting this in ruma, but it's fine here for now

I would endorse putting this in ruma, but it's fine here for now
Author
Owner

I don't have time to upstream it unfortunately, it'd be a drive-by contribution if it were to be done at all, which wouldn't be nice :(

I don't have time to upstream it unfortunately, it'd be a drive-by contribution if it were to be done at all, which wouldn't be nice :(
@ -0,0 +22,4 @@
method: POST,
rate_limited: true,
authentication: ServerSignatures,
history: {
Owner

this should just be path, federation API endpoints don't use history

this should just be `path`, federation API endpoints don't use `history`
nex marked this conversation as resolved
@ -196,0 +237,4 @@
| None => self.discover_old_signing_keys().await,
};
let valid_until_ts = timepoint_from_now(VALID_UNTIL_TS_DURATION)
.map(|tp| {
Owner

this could be timepoint_from_now(...).ok().and_then(|tp| ...).expect(...)

this could be `timepoint_from_now(...).ok().and_then(|tp| ...).expect(...)`
nex marked this conversation as resolved
@ -150,3 +141,1 @@
origin == server_name || notaries.iter().any(|ns| *ns == server_name)
});
Some(s)
pub fn strip_extraneous_signatures(
Owner

this could do with a docstring

this could do with a docstring
nex marked this conversation as resolved
# Conflicts:
#	src/api/server/key.rs
#	src/service/server_keys/mod.rs
#	src/service/server_keys/request.rs
#	src/service/server_keys/verify.rs
Main changed the way we handle server signing keys to carry both the deserialised and serialised copy, so the notary code needs updating to use the right copy in several places (some places need to use the raw value, some need to use the serialised value).
fix: Add an experiment for MSC4556
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 8s
Checks / Prek / Check changed files (pull_request) Successful in 9s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m16s
Update flake hashes / update-flake-hashes (pull_request) Successful in 3m41s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 12m23s
a267a94b55
nex requested reviews from ginger, Jade 2026-11-23 15:14:21 +00:00
ginger requested changes 2026-11-23 15:44:17 +00:00
Dismissed
@ -54,0 +210,4 @@
};
let fetch_all = queries.is_empty();
let mut results = Vec::with_capacity(queries.len().max(1));
let mut keymap = HashMap::with_capacity(queries.len().max(1));
Owner

as far as I can tell, keymap is used for two purposes:

  • to deduplicate key IDs in the query
  • to let one key ID map to multiple signing key responses

I think you could clean this code up by:

  • removing keymap
  • adjusting the if fetch_all && keymap.is_empty() block to remove key IDs from query as it gets them, like the "ask remote directly" logic already does. see also my other comment further down
  • appending key responses to results multiple times if necessary, instead of adding their indexes to keymap multiple times and then reading from those indexes at the end
as far as I can tell, `keymap` is used for two purposes: - to deduplicate key IDs in the query - to let one key ID map to multiple signing key responses I think you could clean this code up by: - removing `keymap` - adjusting the `if fetch_all && keymap.is_empty()` block to remove key IDs from `query` as it gets them, like the "ask remote directly" logic already does. see also my other comment further down - appending key responses to `results` multiple times if necessary, instead of adding their indexes to `keymap` multiple times and then reading from those indexes at the end
ginger marked this conversation as resolved
@ -77,2 +280,2 @@
.map(|mut response| take(response.body_mut()))
.and_then(|body| serde_json::from_slice(&body).map_err(Into::into))?;
// If we're still missing some keys, fetch them from the local cache
for (key_id, criteria) in queries {
Owner

could this be in an else block of the if above it? as far as I can tell this code won't do anything if that if runs, since signing_keys_for and get_signing_key access the same database table.

could this be in an `else` block of the `if` above it? as far as I can tell this code won't do anything if that `if` runs, since `signing_keys_for` and `get_signing_key` access the same database table.
Author
Owner

If it doesn't do anything after the if block finishes execution then I don't think it needs to be in an else block 🤔

If it doesn't do anything after the `if` block finishes execution then I don't think it needs to be in an else block 🤔
ginger marked this conversation as resolved
refactor: Move semaphore logic out of acquire_keys_as_notary
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 32s
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Check changed files (pull_request) Successful in 39s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m40s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 10m3s
522065db6a
Lines 282-284
@ -223,0 +279,6 @@
{
key.expired_ts < minimum_valid_until_ts
} else {
// If the querying server didn't explicitly set a
// minimum timestamp for an old verify key,
// we should treat it as valid.
Author
Owner

mm no im pretty sure the spec says no min timestamp should default to the timestamp of the request

mm no im pretty sure the spec says no min timestamp should default to the timestamp of the request
Owner

I'm copying the behavior from your own code, boss!

I'm copying the behavior from your own code, boss!
Author
Owner

Yeah didn't I change that because Jade highlighted it to me?

Yeah didn't I change that because Jade highlighted it to me?
Owner

not in the version you had me review

not in the version you had me review
Owner

also like. think about that for a moment. if we check that the expiry timestamp of an old key is after the current time, we're going to reject every expired key. keys don't expire in the future!

also like. think about that for a moment. if we check that the _expiry timestamp of an old key_ is after the current time, we're going to reject _every_ expired key. keys don't expire in the future!
Author
Owner

keys don't expire in the future!

hahahaha. seriously though you're right, fair enough

> keys don't expire in the future! [hahahaha](https://github.com/matrix-org/matrix-spec/issues/2453). seriously though you're right, fair enough
nex marked this conversation as resolved
refactor: Clarify variable name a bit
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Check changed files (pull_request) Successful in 7s
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 9s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m18s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 10m52s
1d50422e30
The comparison was inverted when extracting discover_old_signing_keys.
Candidate filtering previously checked unrequested old keys and tracked
all response keys as satisfied even when criteria failed. Passing the
lowest requested minimum_valid_until_ts to origin_request also avoids
rejecting valid historical queries.
refactor: Pass notary query map by value
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Check changed files (pull_request) Successful in 13s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m13s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 12m28s
473d456d8b
Both callers own the request body, so passing the map by value avoids
cloning every server name and query criteria entry.
ginger requested changes 2026-11-23 19:23:24 +00:00
Dismissed
@ -285,3 +275,1 @@
// minimum timestamp for an old verify key,
// we should treat it as valid.
false
.filter_map(|(key_id, criterion)| {
Owner

I don't think this properly applies queries to the keys they're supposed to apply to. it seems to allow any key that matches any query, and also never marks keys as seen that aren't listed in a query but still appear in a key response.

I don't think this properly applies queries to the keys they're supposed to apply to. it seems to allow any key that matches any query, and also never marks keys as seen that aren't listed in a query but still appear in a key response.
Owner

actually I think this change is just incorrect. the original purpose of the signed_remote_key_ids map was as an optimization, to let us skip including 100% redundant key chunks. since we either do or don't include every key in a chunk, the correct behavior is to always add every key to signed_remote_key_ids if we decide to include a chunk, even ones that don't individually meet the criteria.

actually I think this change is just incorrect. the original purpose of the `signed_remote_key_ids` map was as an optimization, to let us skip including 100% redundant key chunks. since we either do or don't include every key in a chunk, the correct behavior _is_ to always add every key to `signed_remote_key_ids` if we decide to include a chunk, even ones that don't individually meet the criteria.
Owner

I swear this code is cursed

I swear this code is cursed
Owner

Anyway the other big in the original code was it rejecting some historical keys it wasn't supposed to iirc.

Anyway the other big in the original code was it rejecting some historical keys it wasn't supposed to iirc.
Owner

yeah, that fix was fine. it's just this change that I think is wrong

yeah, that fix was fine. it's just this change that I think is wrong
Owner

I think you might be wrong? it only allows a key included in a chunk that newly satisfies a query criteria. I don't think it actually needs to mark keys that aren't listed, either, because they aren't... requested.

It's annoyingly hard to explain

I think you might be wrong? it only allows a key included in a chunk that newly satisfies a query criteria. I don't think it actually needs to mark keys that aren't listed, either, because they aren't... requested. It's annoyingly hard to explain
Owner
<matrix:roomid/c10y-8Hm3mAW99j9KEKoWPQH2M_FxGwG-EVHK06iLKg/e/vNEq0gDkcvc3FWLcAuEES72Md4MOMc0oLZROMN3XdXk?via=ellis.link&via=continuwuity.org&via=matrix.org>
Owner

we hashed this out in a vc and decided that it's fine

we hashed this out in a vc and decided that it's fine
ginger marked this conversation as resolved
Jade approved these changes 2026-11-27 18:09:27 +00:00
ginger approved these changes 2026-11-27 18:10:13 +00:00
Jade force-pushed nex/feat/notary-server from 473d456d8b
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 7s
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Check changed files (pull_request) Successful in 13s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m13s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 12m28s
to 6b0eebc553
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Checks / Prek / Check changed files (pull_request) Successful in 8s
Update flake hashes / update-flake-hashes (pull_request) Successful in 1m22s
Checks / Prek / Pre-commit & Formatting (pull_request) Failing after 1m51s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m52s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 6m46s
Checks / Prek / Check changed files (push) Successful in 8s
Documentation / Build and Deploy Documentation (push) Has been cancelled
Checks / Prek / Pre-commit & Formatting (push) Has been cancelled
Checks / Prek / Clippy and Cargo Tests (push) Has been cancelled
Release Docker Image / Build linux-amd64 (release) (push) Has been cancelled
Release Docker Image / Build linux-arm64 (release) (push) Has been cancelled
Release Docker Image / Create Multi-arch Release Manifest (push) Has been cancelled
Release Docker Image / Build linux-amd64 (max-perf) (push) Has been cancelled
Release Docker Image / Build linux-arm64 (max-perf) (push) Has been cancelled
Release Docker Image / Create Max-Perf Manifest (push) Has been cancelled
Release Docker Image / Release Binaries (push) Has been cancelled
Release Docker Image / Mirror Images (push) Has been cancelled
2026-11-27 18:18:32 +00:00
Compare
Jade merged commit 6b0eebc553 into main 2026-11-27 18:41:02 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
continuwuation/continuwuity!2314
No description provided.