From 89d494d605a87bb909e4a8f8dce1c960743a0f86 Mon Sep 17 00:00:00 2001 From: Thomas Fossati Date: Thu, 11 Jan 2024 11:56:45 +0100 Subject: [PATCH] Handle "ear.veraison.key-attestation" on deserialisation Fix #7 Signed-off-by: Thomas Fossati --- src/appraisal.rs | 3 +++ src/ear.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/appraisal.rs b/src/appraisal.rs index d32e60b..854055c 100644 --- a/src/appraisal.rs +++ b/src/appraisal.rs @@ -146,6 +146,9 @@ impl<'de> Visitor<'de> for AppraisalVisitor { loop { if self.is_human_readable { match map.next_key::<&str>()? { + Some("ear.veraison.key-attestation") => { + appraisal.key_attestation = Some(map.next_value::()?) + } Some("ear.status") => appraisal.status = map.next_value::()?, Some("ear.trustworthiness-vector") => { appraisal.trust_vector = map.next_value::()? diff --git a/src/ear.rs b/src/ear.rs index 71834a0..bcf4378 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -656,4 +656,23 @@ MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgPp4XZRnRHSMhGg0t assert_eq!(ear.vid.developer, ear2.vid.developer); assert_eq!(ear.raw_evidence, ear2.raw_evidence); } + + #[test] + fn verify() { + const VERIF_KEY: &str = r#" + { + "crv": "P-256", + "kty": "EC", + "x": "usWxHK2PmfnHKwXPS54m0kTcGJ90UiglWiGahtagnv8", + "y": "IBOL-C3BttVivg-lSreASjpkttcsz-1rb7btKLv8EX4" + } + "#; + + let ear_jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJlYXIudmVyaWZpZXItaWQiOnsiYnVpbGQiOiJOL0EiLCJkZXZlbG9wZXIiOiJWZXJhaXNvbiBQcm9qZWN0In0sImVhdF9ub25jZSI6IjNXSHlqbmRHT1RJPSIsImVhdF9wcm9maWxlIjoidGFnOmdpdGh1Yi5jb20sMjAyMzp2ZXJhaXNvbi9lYXIiLCJpYXQiOjE3MDQ5MDgxOT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TFRNZDN5MUFLTWVoaFNiWEMvYzQiLCJ0cG1WZXIiOiIyLjAifSwicGF0Ijp7ImF0dGVzdEluZm8iOiIvMVJEUjRBWUFDSUFDNE9mcktPRktIbGEzakV6VVBLM01KQ1MrVzJ0d0JWVEVERjhFOTZ3MVZaWkFBZ0FBUUlEQkFVR0J3QUFBQUFhdkk5Mk9IVGc5M050eWJRQkRNNkg1UlJBMWM0QUFBQUJBQXNEQndBQUFDQXVxYXVSbU5GamdBZEFETkxEdnZITWRGdUdTM1lCR2c0YnhTR0FyR1JTMUE9PSIsImtpZCI6IkFhRkpRQ1FIM3NPdHFIV1RVazZaNStmdy9rMTh2eXZKRW5ZdzFNN2tUdnRUIiwic2lnIjoiQUJnQUN3QWdNcWN0TlRuZFh3VU5MZkNERW1lOC81c0hVM2diaGFPL05OdW4xY2tpT0xBQUlLVFkwU2VWUUJIWkpuaXNPRzNTb2VOQ1dHYTJnWlMrSUhuWkN2M3dUOTVJIiwidHBtVmVyIjoiMi4wIn19LCJlYXIudmVyYWlzb24ua2V5LWF0dGVzdGF0aW9uIjp7ImFrcHViIjoiTUZrd0V3WUhLb1pJemowQ0FRWUlLb1pJemowREFRY0RRZ0FFb1Q4RUhiYXNsb0tjcEQ2bXJjMDdFUFd0dG5uUEpfNmN6eXpYOXlYMm5CTjJQOUJvaDBwOURiaWphR2lVUXVmREdYM1pfRlhkVWp3ckJNRkQtOU9NbncifX19fQ.eRyCRmGEOt2GeMvi1-PiSaIVOuixBHwz8FYPSm7XuKnZd6XYe_8HQaCXEtarpOppvzoyHcZvU_4rV54iE7PQaw"; + + let ear = Ear::from_jwt_jwk(ear_jwt, Algorithm::ES256, VERIF_KEY.as_bytes()) + .expect("successfully verified"); + + assert_eq!("tag:github.com,2023:veraison/ear", ear.profile); + } }