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 @@ -198,6 +198,10 @@ pub enum DedupError {
/// Completion was reported for an in-flight request whose
/// binding does not match the registered binding.
BindingMismatch,
/// Completion was reported with an identity whose claimed request
/// ID does not derive from its own origin, nonce and binding; the
/// ledger entry is left unchanged.
InvalidIdentity,
/// A completed request was completed again with a different
/// outcome ID; the first deterministic outcome stands.
OutcomeConflict,
Expand Down Expand Up @@ -338,6 +342,9 @@ impl DedupLedger {
identity: &RequestIdentity,
outcome: OutcomeId,
) -> Result<(), DedupError> {
if !identity.binding_is_valid() {
return Err(DedupError::InvalidIdentity);
}
let entry = self
.entries
.get_mut(&identity.id)
Expand Down
31 changes: 31 additions & 0 deletions pkgs/id/crates/id-sync/tests/federation_b20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,37 @@ fn completion_rules() {
assert_eq!(ledger.cached_outcome(&req.id), Some([1; 32]));
}

#[test]
fn completion_rejects_an_identity_that_does_not_derive_its_id() {
let mut ledger = DedupLedger::new(8, 10);
let req = identity(7, 1, binding(6, 0, 1_000));
assert_eq!(ledger.observe(&req, 10), Classification::New);
let mut other_origin = req.clone();
other_origin.origin = [0xEE; 32];
let mut other_nonce = req.clone();
other_nonce.nonce = [0xDD; 32];
for forged in [&other_origin, &other_nonce] {
assert_eq!(forged.id, req.id);
assert!(!forged.binding_is_valid());
assert_eq!(
ledger.complete(forged, [3; 32]),
Err(DedupError::InvalidIdentity)
);
assert_eq!(ledger.cached_outcome(&req.id), None);
}
// The registered request is still in flight and its valid identity
// completes as before.
assert_eq!(ledger.observe(&req, 11), Classification::DuplicateInFlight);
ledger.complete(&req, [1; 32]).unwrap();
assert_eq!(ledger.cached_outcome(&req.id), Some([1; 32]));
// A forged identity cannot complete an already completed entry
// either, even with the stored outcome.
assert_eq!(
ledger.complete(&other_origin, [1; 32]),
Err(DedupError::InvalidIdentity)
);
}

#[test]
fn prune_keeps_tombstones_through_expiry_plus_grace() {
let mut ledger = DedupLedger::new(8, 10);
Expand Down