Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-protocols-mv/blob/main/crates/aien-evaluation-protocol/tests/verify_binding_tests.rs # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-protocols-mv / crates / aien-evaluation-protocol / tests / verify_binding_tests.rs` 108 lines ยท 3758 bytes Raw Blame History 1 //! Issue #20: verification must bind the signature to the key, tier and fingerprint. 2 3 use aien_evaluation_protocol::{ 4 verifying_key_fingerprint, CryptographicTier, EvaluationError, EvaluationReceipt, 5 SignedEvaluationReceipt, SoftwareP256Signer, Verdict, VerifierIdentity, VerifierSigner, 6 FRAMED_RECEIPT_PROTOCOL_VERSION, 7 }; 8 use aien_protocol_types::{Digest32, EvaluationId, Timestamp}; 9 use p256::ecdsa::SigningKey; 10 11 const TIER2: CryptographicTier = CryptographicTier::Tier2SoftwareKey; 12 13 fn signer(seed: u8) -> SoftwareP256Signer { 14 SoftwareP256Signer::new(SigningKey::from_slice(&[seed; 32]).expect("valid p256 key")) 15 } 16 17 fn signed_by(signer: &SoftwareP256Signer) -> SignedEvaluationReceipt { 18 let receipt = EvaluationReceipt { 19 protocol_version: FRAMED_RECEIPT_PROTOCOL_VERSION, 20 evaluation_id: EvaluationId::new_v4(), 21 request_digest: Digest32([1u8; 32]), 22 subject_digest: Digest32([2u8; 32]), 23 plan_digest: Digest32([3u8; 32]), 24 evidence_root: Digest32([4u8; 32]), 25 outcomes_root: Digest32([5u8; 32]), 26 verdict: Verdict::Pass, 27 verifier: VerifierIdentity { 28 principal_id: "verifier-node-01".to_string(), 29 key_id: signer.key_fingerprint(), 30 trust_epoch: 1, 31 trusted_build_digest: Digest32([6u8; 32]), 32 policy_bundle_digest: Digest32([7u8; 32]), 33 }, 34 started_at: Timestamp(1000), 35 completed_at: Timestamp(1050), 36 }; 37 receipt.sign_with_signer(signer).expect("signing failed") 38 } 39 40 #[test] 41 fn genuine_receipt_verifies_strictly() { 42 let s = signer(42); 43 let signed = signed_by(&s); 44 assert_eq!( 45 signed.key_fingerprint, 46 verifying_key_fingerprint(&s.verifying_key()) 47 ); 48 assert!(signed.verify_with(&s.verifying_key(), TIER2).unwrap()); 49 } 50 51 #[test] 52 fn legacy_receipt_version_is_not_signed_or_verified() { 53 let s = signer(42); 54 let mut old = signed_by(&s); 55 old.receipt.protocol_version = 1; 56 assert!(matches!( 57 old.receipt.sign_with_signer(&s), 58 Err(EvaluationError::UnsupportedProtocolVersion(1)) 59 )); 60 assert!(matches!( 61 old.verify_with(&s.verifying_key(), TIER2), 62 Err(EvaluationError::UnsupportedProtocolVersion(1)) 63 )); 64 } 65 66 #[test] 67 fn n10_wrong_key_with_same_tier_is_refused() { 68 let signed = signed_by(&signer(42)); 69 let other = signer(43); 70 assert!(signed.verify_with(&other.verifying_key(), TIER2).is_err()); 71 #[allow(deprecated)] 72 let old = signed.verify(&other.verifying_key()); 73 assert!(old.is_err()); 74 } 75 76 #[test] 77 fn n10_stored_fingerprint_mismatch_is_refused_even_with_valid_signature() { 78 let s = signer(42); 79 let mut signed = signed_by(&s); 80 signed.key_fingerprint = "00".repeat(32); // not covered by the signed digest 81 assert!(matches!( 82 signed.verify_with(&s.verifying_key(), TIER2), 83 Err(EvaluationError::KeyIdentityMismatch { .. }) 84 )); 85 #[allow(deprecated)] 86 let old = signed.verify(&s.verifying_key()); 87 assert!(matches!( 88 old, 89 Err(EvaluationError::KeyIdentityMismatch { .. }) 90 )); 91 } 92 93 #[test] 94 fn n10_claimed_tier4_signed_by_software_key_is_refused() { 95 let s = signer(42); 96 let mut signed = signed_by(&s); 97 signed.cryptographic_tier = CryptographicTier::Tier4HardwareTpm; // also not in the digest 98 assert!(matches!( 99 signed.verify_with(&s.verifying_key(), TIER2), 100 Err(EvaluationError::TierMismatch { .. }) 101 )); 102 // The operator pinning Tier4 is also refused when the receipt honestly says Tier2. 103 let honest = signed_by(&s); 104 assert!(matches!( 105 honest.verify_with(&s.verifying_key(), CryptographicTier::Tier4HardwareTpm), 106 Err(EvaluationError::TierMismatch { .. }) 107 )); 108 }