Browse Source

Get bucket when redeeming invite

Vecna 8 months ago
parent
commit
ae8ca89bc6
2 changed files with 18 additions and 2 deletions
  1. 17 0
      src/client_lib.rs
  2. 1 2
      src/main.rs

+ 17 - 0
src/client_lib.rs

@@ -1,7 +1,10 @@
 use async_trait::async_trait;
 use curve25519_dalek::scalar::Scalar;
+use lox_library::bridge_table::from_scalar;
 use lox_library::bridge_table::BridgeLine;
+use lox_library::bridge_table::BridgeTable;
 use lox_library::bridge_table::EncryptedBucket;
+use lox_library::bridge_table::MAX_BRIDGES_PER_BUCKET;
 use lox_library::proto::*;
 use lox_library::scalar_u32;
 use lox_library::IssuerPubKey;
@@ -110,6 +113,20 @@ pub async fn get_reachability_credential(net: &dyn Networking) -> HashMap<u32, E
     reachability_cred.etable
 }
 
+// Get encrypted bridge table from BridgeDB and decrypt our entry
+pub async fn get_bucket(
+    net: &dyn Networking,
+    lox_cred: &lox_library::cred::Lox,
+) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] {
+    let encbuckets = get_reachability_credential(net).await;
+    let (id, key) = from_scalar(lox_cred.bucket).unwrap();
+    let encbucket = match encbuckets.get(&id) {
+        Some(encbucket) => encbucket,
+        None => panic!("Provided ID not found"),
+    };
+    BridgeTable::decrypt_bucket(id, &key, &encbucket).unwrap().0
+}
+
 // Get an open invitation
 pub async fn get_open_invitation(net: &dyn Networking) -> [u8; OPENINV_LENGTH] {
     let resp = net.request("/invite".to_string(), [].to_vec()).await;

+ 1 - 2
src/main.rs

@@ -115,8 +115,7 @@ async fn main() {
             get_invitation_pub(&lox_auth_pubkeys),
         )
         .await;
-        let bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
-        //TODO: let bucket = get_bucket();
+        let bucket = get_bucket(&net, &cred).await;
 
         // save to files for future use
         save_object(&cred, &lox_cred_filename);