2 Commits 9fefbc2989 ... a9662950ec

Author SHA1 Message Date
  onyinyang a9662950ec Add verify checks for all lox credentials in mock Lox auth 1 month ago
  onyinyang 7b2588ba0b Fixup subtraction in issue invite protocol 1 month ago
2 changed files with 42 additions and 37 deletions
  1. 41 36
      src/mock_auth.rs
  2. 1 1
      src/proto/issue_invite.rs

+ 41 - 36
src/mock_auth.rs

@@ -57,58 +57,63 @@ impl TestHarness {
             !bool::from(cred.MAC.P.is_identity()),
             "Lox cred MAC P should not be identity"
         );
-
-        let Q = (self.ba.lox_priv.x[0]
-            + cred.id.unwrap() * self.ba.lox_priv.x[1]
-            + cred.bucket.unwrap() * self.ba.lox_priv.x[2]
-            + cred.trust_level.unwrap() * self.ba.lox_priv.x[3]
-            + cred.level_since.unwrap() * self.ba.lox_priv.x[4]
-            + cred.invites_remaining.unwrap() * self.ba.lox_priv.x[5]
-            + cred.blockages.unwrap() * self.ba.lox_priv.x[6])
+        let Q = (self.ba.lox_priv.x0
+            + self.ba.lox_priv.xr
+            + cred.id.unwrap() * self.ba.lox_priv.x[0]
+            + cred.bucket.unwrap() * self.ba.lox_priv.x[1]
+            + cred.trust_level.unwrap() * self.ba.lox_priv.x[2]
+            + cred.level_since.unwrap() * self.ba.lox_priv.x[3]
+            + cred.invites_remaining.unwrap() * self.ba.lox_priv.x[4]
+            + cred.blockages.unwrap() * self.ba.lox_priv.x[5])
             * cred.MAC.P;
-
         assert_eq!(Q, cred.MAC.Q, "Lox MAC Q should match computation");
     }
 
     /// Verify the MAC on a Migration credential
-    /*    pub fn verify_migration(&self, cred: &lox_creds::Migration) {
-            if cred.P.is_identity() {
-            }
+    pub fn verify_migration(&self, cred: &lox_creds::Migration) {
+        assert!(
+            !bool::from(cred.MAC.P.is_identity()),
+            "Migration cred MAC P should not be identity"
+        );
 
-            let Q = (self.migration_priv.x[0]
-                + cred.lox_id * self.migration_priv.x[1]
-                + cred.from_bucket * self.migration_priv.x[2]
-                + cred.to_bucket * self.migration_priv.x[3])
-                * cred.P;
+        let Q = (self.ba.migration_priv.x0
+            + self.ba.migration_priv.xr
+            + cred.lox_id.unwrap() * self.ba.migration_priv.x[0]
+            + cred.from_bucket.unwrap() * self.ba.migration_priv.x[1]
+            + cred.to_bucket.unwrap() * self.ba.migration_priv.x[2])
+            * cred.MAC.P;
 
-            Q == cred.Q
-        }
+        assert_eq!(Q, cred.MAC.Q, "Migration MAC Q should match computation");
+    }
 
-        /// Verify the MAC on a Bucket Reachability credential
-        pub fn verify_reachability(&self, cred: &lox_creds::BucketReachability) {
-            if cred.MAC.P.is_identity() {
-                return false;
-            }
+    /// Verify the MAC on a Bucket Reachability credential
+    pub fn verify_reachability(&self, cred: &lox_creds::BucketReachability) {
+        assert!(
+            !bool::from(cred.MAC.P.is_identity()),
+            "Reachability cred MAC P should not be identity"
+        );
 
-            let Q = (self.reachability_priv.x[0]
-                + cred.date * self.reachability_priv.x[1]
-                + cred.bucket * self.reachability_priv.x[2])
-                * cred.P;
+        let Q = (self.ba.reachability_priv.x0
+            + self.ba.reachability_priv.xr
+            + cred.date.unwrap() * self.ba.reachability_priv.x[0]
+            + cred.bucket.unwrap() * self.ba.reachability_priv.x[1])
+            * cred.MAC.P;
+
+        assert_eq!(Q, cred.MAC.Q, "Reachability MAC Q should match computation");
+    }
 
-            Q == cred.Q
-        }
-    */
     /// Verify the MAC on a Invitation credential
     pub fn verify_invitation(&mut self, cred: &lox_creds::Invitation) {
         assert!(
             !bool::from(cred.MAC.P.is_identity()),
             "Invitation MAC P should not be identity"
         );
-        let Q = (self.ba.invitation_priv.x[0]
-            + cred.inv_id.unwrap() * self.ba.invitation_priv.x[1]
-            + cred.date.unwrap() * self.ba.invitation_priv.x[2]
-            + cred.bucket.unwrap() * self.ba.invitation_priv.x[3]
-            + cred.blockages.unwrap() * self.ba.invitation_priv.x[4])
+        let Q = (self.ba.invitation_priv.x0
+            + self.ba.invitation_priv.xr
+            + cred.inv_id.unwrap() * self.ba.invitation_priv.x[0]
+            + cred.date.unwrap() * self.ba.invitation_priv.x[1]
+            + cred.bucket.unwrap() * self.ba.invitation_priv.x[2]
+            + cred.blockages.unwrap() * self.ba.invitation_priv.x[3])
             * cred.MAC.P;
         assert_eq!(Q, cred.MAC.Q, "Invitation MAC Q should match");
     }

+ 1 - 1
src/proto/issue_invite.rs

@@ -73,7 +73,7 @@ muCMZProtocol! { issue_invite<max_invitations>,
     N.bucket = L.bucket,
     N.trust_level = L.trust_level,
     N.level_since = L.level_since,
-    N.invites_remaining = L.invites_remaining - {1},
+    N.invites_remaining = L.invites_remaining - 1,
     N.blockages = L.blockages,
     I. bucket = L.bucket,
     I.blockages = L.blockages