From 1f21eeeb53db9b502f32d8b5acb90e2e003e536e Mon Sep 17 00:00:00 2001 From: Vecna Date: Tue, 5 Dec 2023 18:05:44 -0500 Subject: [PATCH] Make bridge tokens optional --- src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4977d72..d568c28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,9 @@ use sha3::Sha3_256; // for generating ed25519 keys during initial development use rand::rngs::OsRng; +// TODO: These should be loaded from config file +pub const REQUIRE_BRIDGE_TOKEN: bool = true; + /// Get Julian date pub fn today() -> u32 { time::OffsetDateTime::now_utc() @@ -127,7 +130,7 @@ pub struct PositiveUserReport { /// hashed fingerprint (SHA-1 hash of 20-byte bridge ID) pub fingerprint: [u8; 20], /// token from the bridge indicating it was reached - pub bridge_token: BridgeToken, + pub bridge_token: Option, // TODO: proof of level, something involving credential show /// user's country code, may be an empty string pub country: String, @@ -136,7 +139,7 @@ pub struct PositiveUserReport { } impl PositiveUserReport { - pub fn new(bridge_id: [u8; 20], bridge_token: BridgeToken, country: String) -> Self { + pub fn new(bridge_id: [u8; 20], bridge_token: Option, country: String) -> Self { let mut hasher = Sha1::new(); hasher.update(bridge_id); let fingerprint: [u8; 20] = hasher.finalize().into(); @@ -153,9 +156,15 @@ impl PositiveUserReport { impl Report for PositiveUserReport { fn verify(&self) -> bool { // possibly include check that self.today is recent as well - self.today == self.bridge_token.unsigned_bridge_token.today - && self.today <= today() - && self.bridge_token.verify() + self.today <= today() + && (!REQUIRE_BRIDGE_TOKEN || { + if self.bridge_token.is_none() { + false + } else { + let bt = self.bridge_token.as_ref().unwrap(); + self.today == bt.unsigned_bridge_token.today && bt.verify() + } + }) } }