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
54 changes: 54 additions & 0 deletions pkgs/id/src/invites/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,57 @@ fn role_from_code(code: u8) -> Result<Role> {
pub(super) fn ticket_digest(ticket: &EndpointTicket) -> [u8; 32] {
*Hash::digest([TICKET_DOMAIN, &ticket.encode_bytes()].concat()).as_bytes()
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s};

fn body_for(key: &SigningKey) -> InviteBody {
InviteBody {
inviter: key.verifying_key().to_bytes(),
ticket_digest: [3; 32],
group: [4; 32],
role: Role::Read,
expires_ms: 1_800_000_000_000,
}
}

#[test]
fn verify_signature_rejects_the_small_order_identity_forgery() {
// #1386: the identity point is a small-order key, and the shared
// forgery (R = identity, S = 0) passes plain verify for any
// message under it — only verify_strict keeps it out.
let event = InviteEvent {
body: InviteBody {
inviter: IDENTITY_KEY,
ticket_digest: [3; 32],
group: [4; 32],
role: Role::Read,
expires_ms: 1_800_000_000_000,
},
signature: identity_forgery(),
};
assert!(event.verify_signature().is_err());
}

#[test]
fn verify_signature_rejects_a_non_canonical_s() {
// #1386: a genuine signature mutated to S + L must be refused,
// while the original verifies.
let key = SigningKey::from_bytes(&[7; 32]);
let body = body_for(&key);
let signature = key.sign(&body.message()).to_bytes();
let good = InviteEvent {
body: body.clone(),
signature,
};
assert!(good.verify_signature().is_ok());
let malleated = InviteEvent {
body,
signature: with_non_canonical_s(signature),
};
assert!(malleated.verify_signature().is_err());
}
}
34 changes: 34 additions & 0 deletions pkgs/id/src/seitan/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use super::derive;
use super::freshness::{DEFAULT_WINDOW, Freshness};
use super::token::{ALPHABET, Token, TokenError};

use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s};

const VECTOR_TOKEN: &str = "4uywza+b3cga7rd6yc";
const VECTOR_INVITE_ID: &str = "6303ec43bd61d21edb95a433faf06227";
const VECTOR_SIKEY_B64: &str = "Il9ZFgI1yP2b6Hvt53jWIoo8sDre3puyNH8b2es9TTQ=";
Expand Down Expand Up @@ -277,6 +279,38 @@ fn a_proof_from_another_token_fails_under_this_key() {
);
}

#[test]
fn the_identity_forgery_fails_under_the_identity_key() {
// #1386: the identity point is a small-order key, and the shared
// forgery (R = identity, S = 0) passes plain verify for any message
// under it — only verify_strict keeps it out.
let proof = Proof {
message: b"any accept message".to_vec(),
signature: identity_forgery(),
};
assert_eq!(
accept::verify(&IDENTITY_KEY, &proof),
Err(ProofError::BadSignature)
);
}

#[test]
fn a_non_canonical_s_fails() {
// #1386: a genuine proof mutated to S + L must be refused, while
// the original verifies.
let invite = vector_invite();
let proof = accept_from(&vector_token(), "alice", 3, CREATED);
assert_eq!(accept::verify(&invite.public_key(), &proof), Ok(()));
let malleated = Proof {
signature: with_non_canonical_s(proof.signature),
..proof
};
assert_eq!(
accept::verify(&invite.public_key(), &malleated),
Err(ProofError::BadSignature)
);
}

#[test]
fn changing_any_byte_of_the_signed_message_fails() {
let invite = vector_invite();
Expand Down
Loading