Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,20 @@ impl RevocationRegistry {
}
let recorded_at = record.recorded_at;
let from = record.effective_from;
let until = record.effective_until;
let subject = record.subject.clone();
self.revocations.push(record);
let mut affected = Vec::new();
for rec in &mut self.records {
if !subject_matches(&subject, &rec.key, &rec.peer_id) {
continue;
}
// A bounded interval ends at its exclusive `until`: a record
// admitted then or later was admitted after the revocation
// stopped applying, so the sweep leaves it alone.
if until.is_some_and(|until| rec.admitted_at >= until) {
continue;
}
let escalate =
matches!(rec.status, RecordStatus::Flagged { .. }) && rec.admitted_at >= from;
if !matches!(rec.status, RecordStatus::Accepted) && !escalate {
Expand Down
66 changes: 62 additions & 4 deletions pkgs/id/crates/id-sync/tests/federation_b02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ fn ref_peer_tag(peer: &str) -> String {
}

impl RefModel {
fn sweep(&mut self, tag: &str, by_key: bool, from: u64) {
fn sweep(&mut self, tag: &str, by_key: bool, from: u64, until: Option<u64>) {
for (ktag, ptag, admitted_at, verdict) in self.records.values_mut() {
let hit = if by_key { ktag == tag } else { ptag == tag };
let after_end = until.is_some_and(|u| *admitted_at >= u);
let hit = !after_end && if by_key { ktag == tag } else { ptag == tag };
let escalate = *verdict == RefVerdict::FlaggedIndeterminate && *admitted_at >= from;
if hit && (*verdict == RefVerdict::AcceptedValid || escalate) {
*verdict = if *admitted_at >= from {
Expand All @@ -111,7 +112,7 @@ impl RefModel {
.entry(tag.clone())
.or_default()
.push((from, until));
self.sweep(&tag, true, from);
self.sweep(&tag, true, from, until);
}

fn revoke_peer(&mut self, peer: &str, from: u64, until: Option<u64>) {
Expand All @@ -120,7 +121,7 @@ impl RefModel {
.entry(tag.clone())
.or_default()
.push((from, until));
self.sweep(&tag, false, from);
self.sweep(&tag, false, from, until);
}

fn blocked(
Expand Down Expand Up @@ -682,6 +683,63 @@ fn bounded_interval_blocks_only_inside_and_quarantine_is_sticky() {
));
}

#[test]
fn late_bounded_revocation_sweeps_only_records_admitted_inside_it() {
let (_ska, key_a) = keypair([3u8; 32]);
let mut reg = RevocationRegistry::new();
admit(&mut reg, "before", key_a, "peer-1", 100, None);
admit(&mut reg, "inside", key_a, "peer-1", 250, None);
admit(&mut reg, "at-end", key_a, "peer-1", 300, None);
admit(&mut reg, "after", key_a, "peer-1", 400, None);

// The suspension is learned only after every admission.
let affected = reg
.apply_revocation(RevocationRecord {
record_id: "late-suspension".to_string(),
subject: RevocationSubject::Key(key_a),
effective_from: 200,
effective_until: Some(300),
reason: RevocationReason::AdministrativeDisable,
recorded_at: 500,
})
.expect("bounded revocation must apply");
assert_eq!(affected, vec!["before".to_string(), "inside".to_string()]);
assert!(matches!(
status_of(&reg, "before"),
RecordStatus::Flagged { .. }
));
assert!(matches!(
status_of(&reg, "inside"),
RecordStatus::Quarantined { .. }
));
assert_eq!(status_of(&reg, "at-end"), RecordStatus::Accepted);
assert_eq!(status_of(&reg, "after"), RecordStatus::Accepted);

// A later unbounded revocation still reaches the post-interval
// records, and the earlier quarantine stays.
reg.apply_revocation(RevocationRecord {
record_id: "compromise".to_string(),
subject: RevocationSubject::Key(key_a),
effective_from: 350,
effective_until: None,
reason: RevocationReason::KeyCompromise,
recorded_at: 600,
})
.expect("unbounded revocation must apply");
assert!(matches!(
status_of(&reg, "inside"),
RecordStatus::Quarantined { .. }
));
assert!(matches!(
status_of(&reg, "at-end"),
RecordStatus::Flagged { .. }
));
assert!(matches!(
status_of(&reg, "after"),
RecordStatus::Quarantined { .. }
));
}

#[test]
fn malformed_revocation_and_admission_inputs_are_rejected() {
let (_ska, key_a) = keypair([3u8; 32]);
Expand Down