Skip to content
Closed
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
42 changes: 40 additions & 2 deletions pkgs/id/src/hosted_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,11 @@ impl HostedBindingService {
/// Verify the key signature from the record's own stored transcript
/// (§1.2): reconstruct the signed message from `challenge_id`, `sub`,
/// `iroh_id`, `nonce`, and `expires_at` with no hosted-service access.
/// Returns `false` on any malformed field or mismatch.
/// Returns `false` on any malformed field or mismatch. After a rebind
/// the transcript still names the key that performed the ceremony, so
/// a transcript key superseded into `history` verifies too — the
/// rebind chain (service attestation plus backing rebind records)
/// is what links it to the current key.
#[must_use]
pub fn verify_key_signature(record: &BindingRecord) -> bool {
let transcript = &record.challenge_transcript;
Expand All @@ -1891,7 +1895,11 @@ impl HostedBindingService {
};
if transcript.challenge_id != record.challenge_id
|| transcript.sub != record.sub
|| transcript.iroh_id != record.iroh_id
|| (transcript.iroh_id != record.iroh_id
&& !record
.history
.iter()
.any(|entry| entry.iroh_id == transcript.iroh_id))
{
return false;
}
Expand Down Expand Up @@ -3001,6 +3009,36 @@ mod tests {
.unwrap();
}

#[test]
fn key_signature_verifies_for_a_rebound_binding() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prefix the newly added test functions with test_

The 15 new test functions across this file and hosted_export.rs omit the test_ prefix explicitly required by the naming convention in pkgs/id/AGENTS.md. Rename these newly introduced tests to follow the documented package convention.

AGENTS.md reference: pkgs/id/AGENTS.md:L140-L140

Useful? React with 👍 / 👎.

let mut service = service();
let binding = bind(&mut service, SUB, 21);
let new_key = root_key(22);
let (challenge_id, proof) = signed_challenge(&mut service, SUB, &new_key);
let (request, _) = service
.request_delayed_rebind(SUB, &challenge_id, &proof)
.unwrap();
let counter = countersign(
&binding.binding_id,
&binding.iroh_id,
&new_key,
REBIND_VIA_DELAYED,
);
service.set_now_override(Some(T0 + REBIND_WAITING_PERIOD_SECS));
let (updated, _) = service
.effect_due_rebind(&request.rebind_id, &counter)
.unwrap();
// The transcript still names the ceremony key, now superseded
// into history: the signature verifies, linked to the current
// key by the attested history and the rebind records.
assert_eq!(updated.challenge_transcript.iroh_id, binding.iroh_id);
assert!(HostedBindingService::verify_key_signature(&updated));
// A transcript naming a key outside the chain still fails.
let mut foreign = updated.clone();
foreign.challenge_transcript.iroh_id = hex_encode(&root_key(77).verifying_key().to_bytes());
assert!(!HostedBindingService::verify_key_signature(&foreign));
}

#[test]
fn delayed_rebind_effect_refuses_a_target_bound_elsewhere_without_mutation() {
let mut service = service();
Expand Down
Loading