mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-12-04 06:11:47 +00:00
fix: Enforce notary query criteria per requested key
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.
This commit is contained in:
1 file changed
+48
-41
+48
-41
@@ -201,7 +201,16 @@ async fn acquire_keys_as_notary(
|
|||||||
// to update our caches, and we might as well use its response as a
|
// to update our caches, and we might as well use its response as a
|
||||||
// candidate.
|
// candidate.
|
||||||
if server_keys.origin_not_contacted_recently(&remote) {
|
if server_keys.origin_not_contacted_recently(&remote) {
|
||||||
if let Ok(remote_keys) = server_keys.origin_request(remote.clone(), start).await {
|
let min_valid_ts = queries
|
||||||
|
.values()
|
||||||
|
.map(|criterion| criterion.minimum_valid_until_ts.unwrap_or(start))
|
||||||
|
.min()
|
||||||
|
.unwrap_or(start);
|
||||||
|
|
||||||
|
if let Ok(remote_keys) = server_keys
|
||||||
|
.origin_request(remote.clone(), min_valid_ts)
|
||||||
|
.await
|
||||||
|
{
|
||||||
debug_info!("Considering keys from origin response");
|
debug_info!("Considering keys from origin response");
|
||||||
candidate_remote_keys.push(remote_keys);
|
candidate_remote_keys.push(remote_keys);
|
||||||
}
|
}
|
||||||
@@ -243,52 +252,53 @@ async fn acquire_keys_as_notary(
|
|||||||
let mut signed_remote_key_ids = HashSet::with_capacity(queries.len().max(1));
|
let mut signed_remote_key_ids = HashSet::with_capacity(queries.len().max(1));
|
||||||
|
|
||||||
for remote_keys in candidate_remote_keys {
|
for remote_keys in candidate_remote_keys {
|
||||||
// Skip this key response if all of its keys were already included
|
|
||||||
// in other key responses.
|
|
||||||
if remote_keys
|
|
||||||
.all_key_ids()
|
|
||||||
.all(|key_id| signed_remote_key_ids.contains(key_id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip this key response if it expires too far in the future.
|
// Skip this key response if it expires too far in the future.
|
||||||
if remote_keys.parsed.valid_until_ts > in_one_week() {
|
if remote_keys.parsed.valid_until_ts > in_one_week() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check query criteria (currently just the minimum expiry time) for
|
// Determine which requested keys (or all keys when no specific keys
|
||||||
// each key included in this key response. We skip this response if
|
// were requested) are newly satisfied by this response.
|
||||||
// _all_ of the keys in the response fail their criteria.
|
let newly_satisfied: Vec<OwnedServerSigningKeyId> = if queries.is_empty() {
|
||||||
|
if remote_keys.parsed.valid_until_ts < start {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let all_verify_keys_expired = remote_keys.parsed.verify_keys.keys().all(|key_id| {
|
|
||||||
let minimum_valid_until_ts = queries
|
|
||||||
.get(key_id)
|
|
||||||
.and_then(|criterion| criterion.minimum_valid_until_ts)
|
|
||||||
.unwrap_or(start);
|
|
||||||
|
|
||||||
remote_keys.parsed.valid_until_ts < minimum_valid_until_ts
|
|
||||||
});
|
|
||||||
|
|
||||||
let all_old_verify_keys_too_old =
|
|
||||||
remote_keys
|
remote_keys
|
||||||
.parsed
|
.all_key_ids()
|
||||||
.old_verify_keys
|
.filter(|key_id| !signed_remote_key_ids.contains(*key_id))
|
||||||
|
.map(ToOwned::to_owned)
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
queries
|
||||||
.iter()
|
.iter()
|
||||||
.all(|(key_id, key)| {
|
.filter_map(|(key_id, criterion)| {
|
||||||
if let Some(criterion) = queries.get(key_id)
|
if signed_remote_key_ids.contains(key_id) {
|
||||||
&& let Some(minimum_valid_until_ts) = criterion.minimum_valid_until_ts
|
return None;
|
||||||
{
|
|
||||||
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.
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if all_verify_keys_expired && all_old_verify_keys_too_old {
|
let minimum_valid_until_ts =
|
||||||
|
criterion.minimum_valid_until_ts.unwrap_or(start);
|
||||||
|
|
||||||
|
if remote_keys.parsed.valid_until_ts < minimum_valid_until_ts {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let satisfied = remote_keys.parsed.verify_keys.contains_key(key_id)
|
||||||
|
|| remote_keys.parsed.old_verify_keys.get(key_id).is_some_and(
|
||||||
|
|old_key| {
|
||||||
|
criterion
|
||||||
|
.minimum_valid_until_ts
|
||||||
|
.is_none_or(|min_ts| old_key.expired_ts >= min_ts)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
satisfied.then(|| key_id.to_owned())
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
if newly_satisfied.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,10 +309,7 @@ async fn acquire_keys_as_notary(
|
|||||||
.expect("should be able to sign remote keys");
|
.expect("should be able to sign remote keys");
|
||||||
|
|
||||||
signed_remote_key_responses.push(signed_remote_keys);
|
signed_remote_key_responses.push(signed_remote_keys);
|
||||||
|
signed_remote_key_ids.extend(newly_satisfied);
|
||||||
for key_id in remote_keys.all_key_ids() {
|
|
||||||
signed_remote_key_ids.insert(key_id.to_owned());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signed_remote_key_responses
|
signed_remote_key_responses
|
||||||
|
|||||||
Reference in new issue
Block a user