Browse Source

Make bridge tokens optional

Vecna 1 year ago
parent
commit
1f21eeeb53
1 changed files with 14 additions and 5 deletions
  1. 14 5
      src/lib.rs

+ 14 - 5
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<BridgeToken>,
     // 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<BridgeToken>, 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()
+                }
+            })
     }
 }