From 68f3f37bdf9ae2677cb7b1e5491fe5a53870aa7b Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 14 Nov 2023 17:35:14 +0000 Subject: [PATCH 01/31] Update Rust crate clap to 4.4.8 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a62c4a..fcf854c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" +checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" dependencies = [ "clap_builder", "clap_derive", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" +checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" dependencies = [ "anstream", "anstyle", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index a6f2c61..573468c 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -30,7 +30,7 @@ zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp" } lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} -clap = { version = "4.4.7", features = ["derive"] } +clap = { version = "4.4.8", features = ["derive"] } serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" From ec15d0f229268ed7665a922d314eb52faba6a704 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 20 Nov 2023 16:06:32 +0000 Subject: [PATCH 02/31] Update Rust crate thiserror to 1.0.50 --- Cargo.lock | 8 ++++---- crates/lox-library/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcf854c..1ccb8e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2068,18 +2068,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 91d032b..927cc16 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -30,7 +30,7 @@ base64 = "0.21" time = "0.3.30" prometheus = "0.13.3" subtle = "2.5" -thiserror = "1.0.49" +thiserror = "1.0.50" zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp" } [features] From 02df29a249a63a703a3183d9d835ab8260d5fe8c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 21 Nov 2023 02:07:04 +0000 Subject: [PATCH 03/31] Update Rust crate serde to 1.0.193 --- Cargo.lock | 8 ++++---- crates/lox-library/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ccb8e7..3935b7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1862,18 +1862,18 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 927cc16..f74291b 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -19,7 +19,7 @@ ed25519-dalek = { version = "2", features = ["serde", "rand_core"] } bincode = "1" chrono = "0.4" rand = { version = "0.8", features = ["std_rng"]} -serde = "1.0.192" +serde = "1.0.193" serde_with = {version = "3.4.0", features = ["json"]} sha2 = "0.10" statistical = "1.0.0" From fdde186c922bb32495609a2a3fc3e33618cc09f7 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Thu, 9 Nov 2023 16:09:05 -0500 Subject: [PATCH 04/31] Add lox-wasm and lox-utils READMEs and other fmt fixes --- crates/lox-distributor/src/db_handler.rs | 2 +- crates/lox-distributor/src/main.rs | 3 ++- crates/lox-library/src/lib.rs | 1 - crates/lox-wasm/README.md | 13 +++++++------ crates/lox-wasm/src/lib.rs | 3 +++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index 06c0382..e3588a6 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -42,7 +42,7 @@ impl DB { // If roll_back_date is empty, opens the most recent entry in the lox database or if none exists, creates a // new database. If roll_back_date is not empty, use the specified date to roll back to a previous lox-context - // either exactly the entry at the roll_back_date or within 24 hours from thhe roll_back_date. + // either exactly the entry at the roll_back_date or within 24 hours from the roll_back_date. pub fn open_new_or_existing_db( db_config: DbConfig, roll_back_date: Option, diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 8840481..289540a 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -326,7 +326,8 @@ async fn main() { }); let (tx, rx) = mpsc::channel(32); - let rdsys_request_handler = spawn(async { rdsys_request_creator(config.rtype, tx, kill_stream).await }); + let rdsys_request_handler = + spawn(async { rdsys_request_creator(config.rtype, tx, kill_stream).await }); let rdsys_resource_receiver = spawn(async { rdsys_bridge_parser(rdsys_tx, rx, kill_parser).await }); diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 3afd928..5c6256f 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -113,7 +113,6 @@ impl IssuerPrivKey { } } - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct IssuerPubKey { X: Vec, diff --git a/crates/lox-wasm/README.md b/crates/lox-wasm/README.md index ac8fc3b..0dacc84 100644 --- a/crates/lox-wasm/README.md +++ b/crates/lox-wasm/README.md @@ -1,6 +1,6 @@ # lox-wasm -wasm bindings for the lox crate: https://git-crysp.uwaterloo.ca/iang/lox +wasm bindings for Lox client requests and response handling. These bindings are compatible with the endpoints in the [`lox-distributor`'s](../../lox-distributor/) [`request_handler`](../../lox-distributor/src/request_handler.rs). # Dependencies @@ -14,12 +14,9 @@ cargo install wasm-pack wasm-pack build --target web ``` -# Testing +# Testing Locally - -### Testing Locally - -The provided `index.html` file can be used for testing the lox bindings. First, follow the instructions to [run a lox server](https://gitlab.torproject.org/cohosh/lox-server). +The provided `index.html` file can be used for testing the lox bindings. First, follow the instructions to [run the lox-distributor](../../lox-distributor/README.md). Then, spin up a simple local webserver in the current directory: ``` @@ -27,3 +24,7 @@ python3 -m http.server 8000 ``` Next, open the dev console in your browser and navigate to `http://localhost:8000`. + +### Note + +Although all Lox protocols are implemented, they will not all work with the existing [`index.js`](index.js) and the `lox-distributor`'s `request_handler`. This is because varying time intervals must pass between successful requests for certain Lox credentials. To fully test whether or not the full set of Lox credentials are working as intended (while rejecting patience as an acceptable method), the agreed upon time between the client and server must be artificially accelerated in tandem to the required future date after each relevant request so credentials can be validated. An earlier version of the `lox-distributor`: [`lox-server`](https://gitlab.torproject.org/cohosh/lox-server/-/blob/main/src/main.rs) includes some server side examples of how to accomplish this on the server side and the `lox-wasm` crate can be edited to artificially increase the time as shown [here](https://gitlab.torproject.org/tpo/anti-censorship/lox/-/blob/73c3ef872878b295d84cddc51320d476d6fbcb7f/crates/lox-wasm/src/lib.rs#L102). diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 468ded6..e790a41 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -9,6 +9,7 @@ use lox_library::scalar_u32; use std::panic; use wasm_bindgen::prelude::*; +// Returns today's Julian date as a u32 value fn today() -> u32 { let naive_now = Utc::now().date_naive(); JulianDay::from(naive_now).inner().try_into().unwrap() @@ -45,6 +46,8 @@ pub fn set_panic_hook() { panic::set_hook(Box::new(console_error_panic_hook::hook)); } +// Receives an invite and prepares an open_invite request, returning the +// Request and State #[wasm_bindgen] pub fn open_invite(invite: &[u8]) -> Result { log(&format!("Using invite: {:?}", invite)); From 88a865d04ce76bffafdffaf4c918293c459b590a Mon Sep 17 00:00:00 2001 From: onyinyang Date: Tue, 21 Nov 2023 18:41:53 -0500 Subject: [PATCH 05/31] Remove time manipulation and other fmt fixes --- crates/lox-distributor/src/db_handler.rs | 1 - crates/lox-wasm/src/lib.rs | 71 +++++------------------- 2 files changed, 15 insertions(+), 57 deletions(-) diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index e3588a6..e7b76c0 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -1,4 +1,3 @@ -use std::fs::OpenOptions; use std::sync::{Arc, Mutex}; use crate::metrics::Metrics; diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index e790a41..b283646 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -1,11 +1,10 @@ -use chrono::{Duration, Utc}; +use chrono::Utc; use julianday::JulianDay; -use lox_library::cred::{Invitation, Lox, Migration}; +use lox_library::cred::{Invitation, Migration}; use lox_library::proto::{ blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite, redeem_invite, trust_promotion, }; -use lox_library::scalar_u32; use std::panic; use wasm_bindgen::prelude::*; @@ -15,26 +14,6 @@ fn today() -> u32 { JulianDay::from(naive_now).inner().try_into().unwrap() } -// This should only be used for testing, use today in production -fn test_today(days: i64) -> u32 { - let naive_now_plus = (Utc::now() + Duration::days(days)).date_naive(); - JulianDay::from(naive_now_plus).inner().try_into().unwrap() -} - -fn calc_test_days(lox_cred: &Lox) -> Result { - let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) { - Some(v) => v as i64, - None => return Err("Error: Trust level does not exist".to_string()), - }; - let mut total = 31; - // for level in 0..trust_level { - // let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize]; - // total += level_interval; - total += trust_level * 85; - // } - Ok(total) -} - #[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = console)] @@ -105,15 +84,8 @@ pub fn handle_new_lox_credential( pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap(); let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); - // To test creation of the credential we need to advance the day to 30 - // in production this should just use the today() function - log(&format!( - "TEST ONLY: Add 31 days to today's date: {}", - test_today(31) - )); let tp_result = - //CHANGE add_today(31) to today() for production - match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, test_today(31)) { + match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, today()) { Ok(tp_result) => tp_result, Err(e) => { log(&format!("Error: {:?}", e.to_string())); @@ -229,32 +201,19 @@ pub fn level_up( let reach_cred = lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table); - // To test level up of the credential we need to advance the day to the correct interval - // In this case, the maximum of 85 can be used to test all level ups - // in production this should just use the today() function - // decrypt trust level and use to calculate the correct date for now - // The trust level has to be at least 1 - let test_cumulative_days = match calc_test_days(&lox_cred.lox_credential) { - Ok(v) => v, + let lu_result = match level_up::request( + &lox_cred.lox_credential, + &reach_cred, + &pubkeys.lox_pub, + &pubkeys.reachability_pub, + today(), + ) { + Ok(lu_result) => lu_result, Err(e) => { - log(&format!("Error: {:?}", e)); - return Err(JsValue::from(e)); + log(&format!("Error: {:?}", e.to_string())); + return Err(JsValue::from(e.to_string())); } }; - - log(&format!( - "TEST ONLY: Add 31 (open invitation) + Trust Level*85 days to today's date: {}", - test_today(test_cumulative_days) - )); - let lu_result = - //CHANGE add_today(31) to today() for production - match level_up::request(&lox_cred.lox_credential, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(test_cumulative_days)) { - Ok(lu_result) => lu_result, - Err(e) => { - log(&format!("Error: {:?}", e.to_string())); - return Err(JsValue::from(e.to_string())); - } - }; let req_state = lox_utils::LevelupReqState { request: lu_result.0, state: lu_result.1, @@ -314,7 +273,7 @@ pub fn issue_invite( &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, - test_today(371), + today(), ) { Ok(issue_result) => issue_result, Err(e) => { @@ -386,7 +345,7 @@ pub fn redeem_invite(invitation: String, lox_pub: String) -> Result redeem_result, Err(e) => { log(&format!("Error: {:?}", e.to_string())); From a27df0b6c6a94f7d9954dfa9c4aa168374c7ad32 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Wed, 22 Nov 2023 14:41:22 -0500 Subject: [PATCH 06/31] Update Cargo.tomls to point to correct README location --- crates/lox-distributor/Cargo.toml | 4 ++-- crates/lox-library/Cargo.toml | 4 ++-- crates/lox-wasm/Cargo.toml | 4 ++-- crates/rdsys-backend-api/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 573468c..c671ccc 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -10,7 +10,7 @@ description = "Tool for receving Tor bridges from rdsys and distributing them to keywords = ["tor", "lox", "bridges","censorship-resistance"] categories = ["web-programming::http-server"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-distributor" -readme = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/blob/main/crates/lox-distributor/README.md" +readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -26,7 +26,7 @@ rand = "0.8.5" reqwest = { version = "0.11", features = ["json", "stream"]} serde = { version = "1.0", features = ["derive", "rc"] } serde_with = "3.4.0" -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp" } +zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index f74291b..17d8def 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -10,7 +10,7 @@ description = "Main Lox library with protocols and functions that that make up L keywords = ["tor", "lox", "bridge-distribution","censorship-resistance"] categories = ["cryptography"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-library" -readme = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/blob/main/crates/lox-library/README.md" +readme = "README.md" [dependencies] @@ -31,7 +31,7 @@ time = "0.3.30" prometheus = "0.13.3" subtle = "2.5" thiserror = "1.0.50" -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp" } +zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } [features] fast = [] diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml index 14fa9f5..82fe4a5 100644 --- a/crates/lox-wasm/Cargo.toml +++ b/crates/lox-wasm/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" keywords = ["tor", "lox", "bridges","censorship-resistance"] categories = ["wasm", "web-programming::http-client","external-ffi-bindings"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-wasm" -readme = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/blob/main/crates/lox-wasm/README.md" +readme = "README.md" [lib] crate-type = ["cdylib"] @@ -27,7 +27,7 @@ serde_json = "1.0.108" console_error_panic_hook = "0.1.7" js-sys = "0.3.65" rand = { version = "0.7", features = ["wasm-bindgen"] } -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp" } +zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } [dependencies.chrono] version = "0.4.31" diff --git a/crates/rdsys-backend-api/Cargo.toml b/crates/rdsys-backend-api/Cargo.toml index 916d282..46df638 100644 --- a/crates/rdsys-backend-api/Cargo.toml +++ b/crates/rdsys-backend-api/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" keywords = ["tor", "lox", "bridges","censorship-resistance"] categories = ["api-bindings", "encoding"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/rdsys-backend-api" -readme = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/blob/main/crates/rdsys-backend-api/README.md" +readme = "README.md" [dependencies] From 472445a9a52b0f2eca999154b6a777275c9e435d Mon Sep 17 00:00:00 2001 From: onyinyang Date: Thu, 23 Nov 2023 11:44:05 -0500 Subject: [PATCH 07/31] Add README for rdsys-backend-api, lox-utils and switch to lox-zkp crate --- Cargo.lock | 32 +++++++++---------- crates/lox-distributor/Cargo.toml | 2 +- crates/lox-distributor/src/lox_context.rs | 2 +- crates/lox-library/Cargo.toml | 2 +- crates/lox-library/src/lib.rs | 2 +- .../src/proto/blockage_migration.rs | 16 +++++----- .../lox-library/src/proto/check_blockage.rs | 12 +++---- crates/lox-library/src/proto/issue_invite.rs | 6 ++-- crates/lox-library/src/proto/level_up.rs | 6 ++-- crates/lox-library/src/proto/migration.rs | 6 ++-- crates/lox-library/src/proto/open_invite.rs | 6 ++-- crates/lox-library/src/proto/redeem_invite.rs | 6 ++-- .../lox-library/src/proto/trust_promotion.rs | 6 ++-- crates/lox-utils/README.md | 3 ++ crates/lox-wasm/Cargo.toml | 2 +- crates/rdsys-backend-api/Cargo.toml | 1 + crates/rdsys-backend-api/README.md | 27 ++++++++++++++-- 17 files changed, 82 insertions(+), 55 deletions(-) create mode 100644 crates/lox-utils/README.md diff --git a/Cargo.lock b/Cargo.lock index 3935b7c..9cd9581 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1055,6 +1055,7 @@ dependencies = [ "hyper", "julianday", "lox-library", + "lox-zkp", "lox_utils", "prometheus", "prometheus-client", @@ -1067,7 +1068,6 @@ dependencies = [ "sled", "time", "tokio", - "zkp", ] [[package]] @@ -1082,6 +1082,7 @@ dependencies = [ "ed25519-dalek", "hex_fmt", "lazy_static", + "lox-zkp", "prometheus", "rand 0.8.5", "serde", @@ -1091,7 +1092,6 @@ dependencies = [ "subtle", "thiserror", "time", - "zkp", ] [[package]] @@ -1105,12 +1105,25 @@ dependencies = [ "julianday", "lazy_static", "lox-library", + "lox-zkp", "lox_utils", "rand 0.7.3", "serde_json", "time", "wasm-bindgen", - "zkp", +] + +[[package]] +name = "lox-zkp" +version = "0.8.0" +source = "git+https://gitlab.torproject.org/onyinyang/lox-zkp#10a8379081f079fc09669640f29c255897b3b454" +dependencies = [ + "curve25519-dalek", + "merlin", + "rand 0.8.5", + "serde", + "serde_derive", + "thiserror", ] [[package]] @@ -2529,16 +2542,3 @@ dependencies = [ "quote", "syn", ] - -[[package]] -name = "zkp" -version = "0.8.0" -source = "git+https://gitlab.torproject.org/onyinyang/lox-zkp#7dc7562ecdac3a6c7c7ecc31cace192174d34778" -dependencies = [ - "curve25519-dalek", - "merlin", - "rand 0.8.5", - "serde", - "serde_derive", - "thiserror", -] diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index c671ccc..0d34843 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -26,7 +26,7 @@ rand = "0.8.5" reqwest = { version = "0.11", features = ["json", "stream"]} serde = { version = "1.0", features = ["derive", "rc"] } serde_with = "3.4.0" -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } +lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 5ab7b95..1ddf245 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -16,7 +16,7 @@ use std::{ collections::HashMap, sync::{Arc, Mutex}, }; -use zkp::ProofError; +use lox_zkp::ProofError; use crate::metrics::Metrics; use crate::resource_parser::{parse_into_bridgelines, sort_for_parsing}; diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 17d8def..9797dcb 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -31,7 +31,7 @@ time = "0.3.30" prometheus = "0.13.3" subtle = "2.5" thiserror = "1.0.50" -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } +lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } [features] fast = [] diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 5c6256f..0cf3a5f 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -15,7 +15,7 @@ The notation follows that of the paper "Hyphae: Social Secret Sharing" #![allow(non_snake_case)] #[macro_use] -extern crate zkp; +extern crate lox_zkp; pub mod bridge_table; pub mod cred; diff --git a/crates/lox-library/src/proto/blockage_migration.rs b/crates/lox-library/src/proto/blockage_migration.rs index c367dcf..e2b5f58 100644 --- a/crates/lox-library/src/proto/blockage_migration.rs +++ b/crates/lox-library/src/proto/blockage_migration.rs @@ -37,9 +37,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; @@ -76,7 +76,7 @@ pub struct Request { EncBucket: (RistrettoPoint, RistrettoPoint), EncBlockages: (RistrettoPoint, RistrettoPoint), - // The combined ZKP + // The combined lox_zkp piUser: CompactProof, } @@ -107,7 +107,7 @@ pub struct Response { TBucket: RistrettoPoint, TBlockages: RistrettoPoint, - // The ZKP + // The lox_zkp piBlindIssue: CompactProof, } @@ -224,7 +224,7 @@ pub fn request( // Form a Pedersen commitment to the MAC Q // We flip the sign of zQ from that of the Hyphae paper so that - // the ZKP has a "+" instead of a "-", as that's what the zkp + // the lox_zkp has a "+" instead of a "-", as that's what the zkp // macro supports. let negzQ_lox = Scalar::random(&mut rng); let CQ_lox = Q_lox - &negzQ_lox * Atable; @@ -251,7 +251,7 @@ pub fn request( // Form a Pedersen commitment to the MAC Q // We flip the sign of zQ from that of the Hyphae paper so that - // the ZKP has a "+" instead of a "-", as that's what the zkp + // the lox_zkp has a "+" instead of a "-", as that's what the zkp // macro supports. let negzQ_mig = Scalar::random(&mut rng); let CQ_mig = Q_mig - &negzQ_mig * Atable; @@ -416,7 +416,7 @@ impl BridgeAuth { + self.migration_priv.x[3] * req.CToBucket - req.CQ_mig; - // Verify the ZKP + // Verify the zkp let mut transcript = Transcript::new(b"blockage migration request"); requestproof::verify_compact( &req.piUser, diff --git a/crates/lox-library/src/proto/check_blockage.rs b/crates/lox-library/src/proto/check_blockage.rs index 323ad01..a2cc009 100644 --- a/crates/lox-library/src/proto/check_blockage.rs +++ b/crates/lox-library/src/proto/check_blockage.rs @@ -33,9 +33,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; use serde_with::serde_as; @@ -69,7 +69,7 @@ pub struct Request { D: RistrettoPoint, EncBucket: (RistrettoPoint, RistrettoPoint), - // The combined ZKP + // The combined lox_zkp piUser: CompactProof, } @@ -158,7 +158,7 @@ pub fn request( // Form a Pedersen commitment to the MAC Q // We flip the sign of zQ from that of the Hyphae paper so that - // the ZKP has a "+" instead of a "-", as that's what the zkp + // the lox_zkp has a "+" instead of a "-", as that's what the lox_zkp // macro supports. let negzQ = Scalar::random(&mut rng); let CQ = Q - &negzQ * Atable; @@ -268,7 +268,7 @@ impl BridgeAuth { + self.lox_priv.x[6] * req.CBlockages - req.CQ; - // Verify the ZKP + // Verify the zkp let mut transcript = Transcript::new(b"check blockage request"); requestproof::verify_compact( &req.piUser, diff --git a/crates/lox-library/src/proto/issue_invite.rs b/crates/lox-library/src/proto/issue_invite.rs index a512270..4efd1c9 100644 --- a/crates/lox-library/src/proto/issue_invite.rs +++ b/crates/lox-library/src/proto/issue_invite.rs @@ -50,9 +50,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; diff --git a/crates/lox-library/src/proto/level_up.rs b/crates/lox-library/src/proto/level_up.rs index 2480b81..c267825 100644 --- a/crates/lox-library/src/proto/level_up.rs +++ b/crates/lox-library/src/proto/level_up.rs @@ -43,9 +43,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; diff --git a/crates/lox-library/src/proto/migration.rs b/crates/lox-library/src/proto/migration.rs index ce7bc5f..df6a402 100644 --- a/crates/lox-library/src/proto/migration.rs +++ b/crates/lox-library/src/proto/migration.rs @@ -35,9 +35,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; diff --git a/crates/lox-library/src/proto/open_invite.rs b/crates/lox-library/src/proto/open_invite.rs index b95fc4a..cf4cf7c 100644 --- a/crates/lox-library/src/proto/open_invite.rs +++ b/crates/lox-library/src/proto/open_invite.rs @@ -18,9 +18,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; use serde_with::serde_as; diff --git a/crates/lox-library/src/proto/redeem_invite.rs b/crates/lox-library/src/proto/redeem_invite.rs index 9f288d6..230fe7c 100644 --- a/crates/lox-library/src/proto/redeem_invite.rs +++ b/crates/lox-library/src/proto/redeem_invite.rs @@ -26,9 +26,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; diff --git a/crates/lox-library/src/proto/trust_promotion.rs b/crates/lox-library/src/proto/trust_promotion.rs index 18b921a..2e2266f 100644 --- a/crates/lox-library/src/proto/trust_promotion.rs +++ b/crates/lox-library/src/proto/trust_promotion.rs @@ -32,9 +32,9 @@ use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::IsIdentity; -use zkp::CompactProof; -use zkp::ProofError; -use zkp::Transcript; +use lox_zkp::CompactProof; +use lox_zkp::ProofError; +use lox_zkp::Transcript; use serde::{Deserialize, Serialize}; use serde_with::serde_as; diff --git a/crates/lox-utils/README.md b/crates/lox-utils/README.md new file mode 100644 index 0000000..e35dfab --- /dev/null +++ b/crates/lox-utils/README.md @@ -0,0 +1,3 @@ +# Lox Utils + +This crate contains a number of helper structs and functions that are used by multiple lox crates. \ No newline at end of file diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml index 82fe4a5..53e919e 100644 --- a/crates/lox-wasm/Cargo.toml +++ b/crates/lox-wasm/Cargo.toml @@ -27,7 +27,7 @@ serde_json = "1.0.108" console_error_panic_hook = "0.1.7" js-sys = "0.3.65" rand = { version = "0.7", features = ["wasm-bindgen"] } -zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } +lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } [dependencies.chrono] version = "0.4.31" diff --git a/crates/rdsys-backend-api/Cargo.toml b/crates/rdsys-backend-api/Cargo.toml index 46df638..378f5ef 100644 --- a/crates/rdsys-backend-api/Cargo.toml +++ b/crates/rdsys-backend-api/Cargo.toml @@ -4,6 +4,7 @@ authors = ["Cecylia Bocovich , Lindsey Tulloch Date: Thu, 23 Nov 2023 11:57:04 -0500 Subject: [PATCH 08/31] Fixup keywords in all Cargo.toml files --- crates/lox-distributor/Cargo.toml | 2 +- crates/lox-library/Cargo.toml | 2 +- crates/lox-utils/Cargo.toml | 2 +- crates/lox-wasm/Cargo.toml | 2 +- crates/rdsys-backend-api/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 0d34843..4752582 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -7,7 +7,7 @@ rust-version = "1.65.0" license = "MIT" homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" description = "Tool for receving Tor bridges from rdsys and distributing them to users" -keywords = ["tor", "lox", "bridges","censorship-resistance"] +keywords = ["tor", "lox", "bridges","anti-censorship", "distributor"] categories = ["web-programming::http-server"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-distributor" readme = "README.md" diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 9797dcb..2989f44 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -7,7 +7,7 @@ rust-version = "1.65.0" license = "MIT" homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" description = "Main Lox library with protocols and functions that that make up Lox" -keywords = ["tor", "lox", "bridge-distribution","censorship-resistance"] +keywords = ["tor", "lox", "bridges","anti-censorship", "anonymous-cred"] categories = ["cryptography"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-library" readme = "README.md" diff --git a/crates/lox-utils/Cargo.toml b/crates/lox-utils/Cargo.toml index d4804af..7c32b6e 100644 --- a/crates/lox-utils/Cargo.toml +++ b/crates/lox-utils/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" rust-version = "1.65" homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" description = "General helpers used by Lox" -keywords = ["tor", "lox"] +keywords = ["tor", "lox", "utilities"] categories = ["rust-patterns"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox.git/" diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml index 53e919e..c12bf72 100644 --- a/crates/lox-wasm/Cargo.toml +++ b/crates/lox-wasm/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" description = "WASM bindings for lox" license = "MIT" homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" -keywords = ["tor", "lox", "bridges","censorship-resistance"] +keywords = ["tor", "lox", "bridges","anti-censorship", "wasm"] categories = ["wasm", "web-programming::http-client","external-ffi-bindings"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/lox-wasm" readme = "README.md" diff --git a/crates/rdsys-backend-api/Cargo.toml b/crates/rdsys-backend-api/Cargo.toml index 378f5ef..bd957d6 100644 --- a/crates/rdsys-backend-api/Cargo.toml +++ b/crates/rdsys-backend-api/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" license = "MIT" description = "A backend API to receive resources from rdsys" homepage = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/wikis/home" -keywords = ["tor", "lox", "bridges","censorship-resistance"] +keywords = ["tor", "lox", "bridges","anti-censorship", "API"] categories = ["api-bindings", "encoding"] repository = "https://gitlab.torproject.org/tpo/anti-censorship/lox/-/tree/main/crates/rdsys-backend-api" readme = "README.md" From 2a2708c5b5a3267021067e9418168c17f8b60568 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Thu, 23 Nov 2023 12:24:20 -0500 Subject: [PATCH 09/31] Add license to lox-util Cargo.toml --- crates/lox-utils/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lox-utils/Cargo.toml b/crates/lox-utils/Cargo.toml index 7c32b6e..23fe66c 100644 --- a/crates/lox-utils/Cargo.toml +++ b/crates/lox-utils/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["The Tor Project, Inc.", "Lindsey Tulloch Date: Mon, 27 Nov 2023 15:37:39 +0000 Subject: [PATCH 10/31] Update Rust crate js-sys to 0.3.66 --- Cargo.lock | 24 ++++++++++++------------ crates/lox-wasm/Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9cd9581..463ab75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -984,9 +984,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -2330,9 +2330,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2340,9 +2340,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -2367,9 +2367,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2377,9 +2377,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -2390,9 +2390,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-streams" diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml index c12bf72..d50b9db 100644 --- a/crates/lox-wasm/Cargo.toml +++ b/crates/lox-wasm/Cargo.toml @@ -25,7 +25,7 @@ time = "0.3.30" serde_json = "1.0.108" console_error_panic_hook = "0.1.7" -js-sys = "0.3.65" +js-sys = "0.3.66" rand = { version = "0.7", features = ["wasm-bindgen"] } lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } From 49aa3f57ed210e97060f58e7bdb70b778458c125 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 28 Nov 2023 03:37:14 +0000 Subject: [PATCH 11/31] Update Rust crate clap to 4.4.10 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 463ab75..0b259b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.8" +version = "4.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" +checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" dependencies = [ "clap_builder", "clap_derive", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.8" +version = "4.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" +checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" dependencies = [ "anstream", "anstyle", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 4752582..c6bc1bd 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -30,7 +30,7 @@ lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = " lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} -clap = { version = "4.4.8", features = ["derive"] } +clap = { version = "4.4.10", features = ["derive"] } serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" From d7613eb5144f510668c215f72133b4522c13046c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 4 Dec 2023 18:21:13 +0000 Subject: [PATCH 12/31] Update Rust crate clap to 4.4.11 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b259b2..399f426 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.10" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" dependencies = [ "clap_builder", "clap_derive", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.9" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" dependencies = [ "anstream", "anstyle", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index c6bc1bd..e7160af 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -30,7 +30,7 @@ lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = " lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} -clap = { version = "4.4.10", features = ["derive"] } +clap = { version = "4.4.11", features = ["derive"] } serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" From 67577026627efe2cb490aeb215f17b6138f09a8b Mon Sep 17 00:00:00 2001 From: onyinyang Date: Fri, 15 Dec 2023 11:27:33 -0500 Subject: [PATCH 13/31] Add getter functions for wasm Lox credential attributes --- crates/lox-wasm/index.js | 14 ++++++++++- crates/lox-wasm/src/lib.rs | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index ad303ca..dd25abf 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -16,7 +16,7 @@ import init, { handle_check_blockage, blockage_migration, handle_blockage_migration, - set_panic_hook } from "./pkg/lox_wasm.js"; + set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_invite_expiry} from "./pkg/lox_wasm.js"; let pubkeys = await simple_request("/pubkeys"); console.log("Got pubkeys: " + pubkeys); @@ -41,6 +41,14 @@ let open_lox_cred = await init().then(() => { return cred; }); +let info = get_last_upgrade_time(open_lox_cred); +console.log("Last upgrade time: "+info); +let info_two = get_trust_level(open_lox_cred); +console.log("Last upgrade time: "+info_two); +let info_three = get_invites_remaining(open_lox_cred); +console.log("Last upgrade time: "+info_three); +let info_four = get_invite_expiry(open_lox_cred); +console.log("Last upgrade time: "+info_four); let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys); // Get Migration credential for Trust Promotion from Trust Level 0 -> 1 @@ -95,6 +103,10 @@ lox_cred = await init().then(() => { return cred; }); +info_three = get_invites_remaining(lox_cred); +console.log("Last upgrade time: "+info_three); +info_four = get_invite_expiry(lox_cred); +console.log("Last upgrade time: "+info_four); // Update reachability cred encrypted_table = await simple_request("/reachability"); diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index b283646..1c4d325 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -5,6 +5,7 @@ use lox_library::proto::{ blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite, redeem_invite, trust_promotion, }; +use lox_library::scalar_u32; use std::panic; use wasm_bindgen::prelude::*; @@ -506,3 +507,51 @@ pub fn handle_blockage_migration( )); Ok(serde_json::to_string(&lox_cred).unwrap()) } + +#[wasm_bindgen] +pub fn get_last_upgrade_time(lox_cred_str: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let upgrade_date = scalar_u32(&lox_cred.lox_credential.level_since).unwrap(); + let date_time = JulianDay::new(upgrade_date as i32).to_date(); + log(&format!( + "Time of last upgrade {}", + serde_json::to_string(&date_time).unwrap() + )); + serde_json::to_string(&date_time).unwrap() +} + + +#[wasm_bindgen] +pub fn get_trust_level(lox_cred_str: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap(); + log(&format!( + "Trust level {}", + serde_json::to_string(&trust_level).unwrap() + )); + serde_json::to_string(&trust_level).unwrap() +} + +#[wasm_bindgen] +pub fn get_invites_remaining(lox_cred_str: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining); + log(&format!( + "Invites remaining {}", + serde_json::to_string(&invites).unwrap() + )); + serde_json::to_string(&invites).unwrap() +} + +#[wasm_bindgen] +pub fn get_invite_expiry(lox_cred_str: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let expiry = (scalar_u32(&lox_cred.invitation.unwrap().date).unwrap()+15) as i32; + let date_time = JulianDay::new(expiry as i32).to_date(); + println!("Datetime is: {:?}", date_time); + log(&format!( + "Invitation Expiry {}", + serde_json::to_string(&date_time).unwrap() + )); + serde_json::to_string(&date_time).unwrap() +} \ No newline at end of file From aeddbb5d711631045e15d9dfc77c8144a2b51a4b Mon Sep 17 00:00:00 2001 From: onyinyang Date: Sun, 17 Dec 2023 23:43:16 -0500 Subject: [PATCH 14/31] Add error handling and Invitation expiry getter for wasm --- crates/lox-utils/src/lib.rs | 5 +++++ crates/lox-wasm/index.js | 8 ++++++-- crates/lox-wasm/src/lib.rs | 27 ++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/crates/lox-utils/src/lib.rs b/crates/lox-utils/src/lib.rs index 62b04ae..bb0bde2 100644 --- a/crates/lox-utils/src/lib.rs +++ b/crates/lox-utils/src/lib.rs @@ -84,6 +84,11 @@ pub struct LoxCredential { pub invitation: Option, } +#[derive(Debug, Deserialize, Serialize)] +pub struct IssuedInvitation { + pub invitation: Invitation, +} + // This should also check the pubkey pub fn validate(invite: &[u8]) -> Result<[u8; OPENINV_LENGTH], TryFromSliceError> { invite.try_into() diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index dd25abf..52e781f 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -16,7 +16,7 @@ import init, { handle_check_blockage, blockage_migration, handle_blockage_migration, - set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_invite_expiry} from "./pkg/lox_wasm.js"; + set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry} from "./pkg/lox_wasm.js"; let pubkeys = await simple_request("/pubkeys"); console.log("Got pubkeys: " + pubkeys); @@ -47,7 +47,7 @@ let info_two = get_trust_level(open_lox_cred); console.log("Last upgrade time: "+info_two); let info_three = get_invites_remaining(open_lox_cred); console.log("Last upgrade time: "+info_three); -let info_four = get_invite_expiry(open_lox_cred); +let info_four = get_issued_invite_expiry(open_lox_cred); console.log("Last upgrade time: "+info_four); let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys); @@ -142,6 +142,10 @@ let prepared_invitation = prepare_invite(lox_cred); // Trusted Invitation Request let requested_invitation = redeem_invite(prepared_invitation, pubkeys); // Redeem an Invitation cred + +info_four = get_received_invite_expiry(prepared_invitation); +console.log("Last upgrade time: "+info_four); + let lox_cred_from_invite = await init().then(() => { set_panic_hook(); let cred = requested_cred("/redeem", requested_invitation).then((response)=> { diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 1c4d325..51abf22 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -520,7 +520,6 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> String { serde_json::to_string(&date_time).unwrap() } - #[wasm_bindgen] pub fn get_trust_level(lox_cred_str: String) -> String { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); @@ -544,14 +543,32 @@ pub fn get_invites_remaining(lox_cred_str: String) -> String { } #[wasm_bindgen] -pub fn get_invite_expiry(lox_cred_str: String) -> String { +pub fn get_issued_invite_expiry(lox_cred_str: String) -> String { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); - let expiry = (scalar_u32(&lox_cred.invitation.unwrap().date).unwrap()+15) as i32; - let date_time = JulianDay::new(expiry as i32).to_date(); + match lox_cred.invitation { + Some(invitation) => { + let expiry = (scalar_u32(&invitation.date).unwrap() + 15) as i32; + let date_time = JulianDay::new(expiry).to_date(); + println!("Datetime is: {:?}", date_time); + log(&format!( + "Invitation Expiry {}", + serde_json::to_string(&date_time).unwrap() + )); + serde_json::to_string(&date_time).unwrap() + } + None => serde_json::to_string("No Invitation Issued").unwrap(), + } +} + +#[wasm_bindgen] +pub fn get_received_invite_expiry(invite_cred_str: String) -> String { + let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap(); + let expiry = (scalar_u32(&invite_cred.invitation.date).unwrap() + 15) as i32; + let date_time = JulianDay::new(expiry).to_date(); println!("Datetime is: {:?}", date_time); log(&format!( "Invitation Expiry {}", serde_json::to_string(&date_time).unwrap() )); serde_json::to_string(&date_time).unwrap() -} \ No newline at end of file +} From d8e40b53c44b149fb0eaa69e714e74d1aa67edec Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 18 Dec 2023 15:06:53 +0000 Subject: [PATCH 15/31] Update Rust crate hyper to 0.14.28 --- Cargo.lock | 4 ++-- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 399f426..9cdf39f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -856,9 +856,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index e7160af..0a3196d 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -17,7 +17,7 @@ readme = "README.md" [dependencies] julianday = "1.2.0" base64 = "0.21.5" -hyper = { version = "0.14.27", features = ["server"] } +hyper = { version = "0.14.28", features = ["server"] } hex_fmt = "0.3" futures = "0.3.29" time = "0.3.30" From 5ed62d239d7a5020f130c15e0af5dc93ee57bbc4 Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Mon, 20 Nov 2023 15:28:25 -0500 Subject: [PATCH 16/31] Check whether lox_db is empty after recovering --- crates/lox-distributor/src/db_handler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index e7b76c0..c5a63f4 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -51,7 +51,7 @@ impl DB { let (lox_db, context) = match sled::open(db_config.db_path) { Ok(lox_db) => { // Check if the lox_db already exists - if lox_db.was_recovered() { + if lox_db.was_recovered() && !lox_db.is_empty() { context = read_lox_context_from_db(lox_db.clone(), roll_back_date); context.metrics = metrics; //Otherwise, create a new Lox context From 7d94b3c8619d261c1adc7ee1e424d0c61878301f Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Mon, 18 Dec 2023 14:17:13 -0500 Subject: [PATCH 17/31] Add LoxDBError and refactor to return Result Add a new error type to capture multiple possible database reading errors and refactor both read_lox_context_from_db and use_last_context to return a Result. --- Cargo.lock | 1 + crates/lox-distributor/Cargo.toml | 1 + crates/lox-distributor/src/db_handler.rs | 37 ++++++++++++++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9cdf39f..9f414ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1066,6 +1066,7 @@ dependencies = [ "serde_json", "serde_with", "sled", + "thiserror", "time", "tokio", ] diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 0a3196d..d71cbb5 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -35,6 +35,7 @@ serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" prometheus-client = "0.22.0" +thiserror = "1" [dependencies.chrono] version = "0.4.31" diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index c5a63f4..7493aba 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -5,6 +5,18 @@ use crate::{lox_context, DbConfig}; use chrono::{naive::Days, DateTime, Local, NaiveDateTime, Utc}; use lox_library::{BridgeAuth, BridgeDb}; use sled::IVec; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum LoxDBError { + //failed to get last db entry + #[error("Failed to read last database entry")] + ReadFailure(#[from] sled::Error), + + //no last db entries + #[error("No database entries stored")] + DatabaseEmpty, +} // Database of Lox Distributor State pub struct DB { @@ -52,7 +64,10 @@ impl DB { Ok(lox_db) => { // Check if the lox_db already exists if lox_db.was_recovered() && !lox_db.is_empty() { - context = read_lox_context_from_db(lox_db.clone(), roll_back_date); + context = match read_lox_context_from_db(lox_db.clone(), roll_back_date) { + Ok(ctx) => ctx, + Err(e) => panic!("Unable to read lox database {:?}", e) + }; context.metrics = metrics; //Otherwise, create a new Lox context } else { @@ -80,7 +95,7 @@ impl DB { fn read_lox_context_from_db( lox_db: sled::Db, roll_back_date: Option, -) -> lox_context::LoxServerContext { +) -> Result { let context: lox_context::LoxServerContext; // Check if there is a roll back date and try to choose the appropriate context // to rollback to, otherwise, take the last saved context @@ -119,10 +134,10 @@ fn read_lox_context_from_db( } // Use the last entry to populate the Lox context if no rollback date is set (which should be most common) None => { - context = use_last_context(lox_db); + context = use_last_context(lox_db)? } } - context + Ok(context) } fn compute_startdate_string(date_range_end: String) -> Option> { @@ -133,11 +148,15 @@ fn compute_startdate_string(date_range_end: String) -> Option> { } // Use the last context that was entered into the database -fn use_last_context(lox_db: sled::Db) -> lox_context::LoxServerContext { - let ivec_context = lox_db.last().unwrap().unwrap(); - let ivec_date: String = String::from_utf8(ivec_context.0.to_vec()).unwrap(); - println!("Using last context with date: {:?}", ivec_date); - serde_json::from_slice(&ivec_context.1).unwrap() +fn use_last_context(lox_db: sled::Db) -> Result { + match lox_db.last()? { + Some(ivec_context) => { + let ivec_date: String = String::from_utf8(ivec_context.0.to_vec()).unwrap(); + println!("Using last context with date: {:?}", ivec_date); + Ok(serde_json::from_slice(&ivec_context.1).unwrap()) + }, + None => Err(LoxDBError::DatabaseEmpty) + } } #[cfg(test)] From 918a5555b881f7690f9d65692c59444b8c4e25e9 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 19 Dec 2023 10:06:55 +0000 Subject: [PATCH 18/31] Update Rust crate time to 0.3.31 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- crates/lox-library/Cargo.toml | 2 +- crates/lox-wasm/Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f414ee..47f4bd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2102,9 +2102,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -2122,9 +2122,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index d71cbb5..c090691 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -20,7 +20,7 @@ base64 = "0.21.5" hyper = { version = "0.14.28", features = ["server"] } hex_fmt = "0.3" futures = "0.3.29" -time = "0.3.30" +time = "0.3.31" tokio = { version = "1", features = ["full", "macros", "signal"] } rand = "0.8.5" reqwest = { version = "0.11", features = ["json", "stream"]} diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 2989f44..82535b6 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -27,7 +27,7 @@ lazy_static = "1" hex_fmt = "0.3" aes-gcm = { version = "0.10", features =["aes"]} base64 = "0.21" -time = "0.3.30" +time = "0.3.31" prometheus = "0.13.3" subtle = "2.5" thiserror = "1.0.50" diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml index d50b9db..3d090cf 100644 --- a/crates/lox-wasm/Cargo.toml +++ b/crates/lox-wasm/Cargo.toml @@ -21,7 +21,7 @@ lazy_static = "1.4.0" lox-library = { path = "../lox-library", version = "0.1.0" } lox_utils = { path = "../lox-utils", version = "0.1.0" } wasm-bindgen = "0.2" -time = "0.3.30" +time = "0.3.31" serde_json = "1.0.108" console_error_panic_hook = "0.1.7" From 711a34cc2dd5596d7d29cf21ca1761784fb8a33e Mon Sep 17 00:00:00 2001 From: onyinyang Date: Mon, 18 Dec 2023 16:06:57 -0500 Subject: [PATCH 19/31] Add bridgeline getters to wasm and Lox system info --- crates/lox-utils/src/lib.rs | 32 ++++++++++++++++++++++++++++++-- crates/lox-wasm/src/lib.rs | 30 +++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/crates/lox-utils/src/lib.rs b/crates/lox-utils/src/lib.rs index bb0bde2..8f1d7a2 100644 --- a/crates/lox-utils/src/lib.rs +++ b/crates/lox-utils/src/lib.rs @@ -1,4 +1,6 @@ -use lox_library::bridge_table::{from_scalar, BridgeLine, BridgeTable, EncryptedBucket}; +use lox_library::bridge_table::{ + from_scalar, BridgeLine, BridgeTable, EncryptedBucket, MAX_BRIDGES_PER_BUCKET, +}; use lox_library::cred::{BucketReachability, Invitation, Lox}; use lox_library::proto; use lox_library::{IssuerPubKey, OPENINV_LENGTH}; @@ -71,6 +73,21 @@ pub struct PubKeys { pub invitation_pub: IssuerPubKey, } +#[derive(Debug, Deserialize, Serialize)] +pub struct LoxSystemInfo { + max_blockages: [u32; proto::level_up::MAX_LEVEL + 1], + level_interval: [u32; proto::level_up::MAX_LEVEL + 1], + level_invitations: [u32; proto::level_up::MAX_LEVEL + 1], + min_trust_level: u32, +} + +pub const LOX_SYSTEM_INFO: LoxSystemInfo = LoxSystemInfo { + max_blockages: proto::level_up::MAX_BLOCKAGES, + level_interval: proto::level_up::LEVEL_INTERVAL, + level_invitations: proto::level_up::LEVEL_INVITATIONS, + min_trust_level: proto::check_blockage::MIN_TRUST_LEVEL, +}; + #[serde_as] #[derive(Serialize, Deserialize)] pub struct EncBridgeTable { @@ -80,7 +97,7 @@ pub struct EncBridgeTable { #[derive(Debug, Deserialize, Serialize)] pub struct LoxCredential { pub lox_credential: Lox, - pub bridgeline: Option, + pub bridgelines: Option>, pub invitation: Option, } @@ -102,6 +119,17 @@ pub fn generate_reachability_cred(lox_cred: &Lox, encrypted_table: String) -> Bu bucket.1.unwrap() } +pub fn get_credential_bridgelines( + lox_cred: &Lox, + encrypted_table: String, +) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] { + let (id, key) = from_scalar(lox_cred.bucket).unwrap(); + let enc_buckets: EncBridgeTable = serde_json::from_str(&encrypted_table).unwrap(); + let bucket = + BridgeTable::decrypt_bucket(id, &key, enc_buckets.etable.get(&id).unwrap()).unwrap(); + bucket.0 +} + //pub const MAX_LEVEL: usize = 4; //pub const LEVEL_INTERVAL: [u32; MAX_LEVEL + 1] = [0, 14, 28, 56, 84]; pub fn calc_test_days(trust_level: i64) -> i64 { diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 51abf22..f106b4e 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -67,7 +67,7 @@ pub fn handle_new_lox_credential( }; let lox_cred = lox_utils::LoxCredential { lox_credential: lox_cred.0, - bridgeline: Some(lox_cred.1), + bridgelines: Some(vec![lox_cred.1]), invitation: None, }; log(&format!( @@ -76,7 +76,7 @@ pub fn handle_new_lox_credential( )); log(&format!( "Got new bridgeline: {}", - serde_json::to_string(&lox_cred.bridgeline).unwrap() + serde_json::to_string(&lox_cred.bridgelines).unwrap() )); Ok(serde_json::to_string(&lox_cred).unwrap()) } @@ -176,7 +176,7 @@ pub fn handle_trust_migration( ) { Ok(level_1_cred) => lox_utils::LoxCredential { lox_credential: level_1_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -243,7 +243,7 @@ pub fn handle_level_up( ) { Ok(level_up_cred) => lox_utils::LoxCredential { lox_credential: level_up_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -318,7 +318,7 @@ pub fn handle_issue_invite( }; let invitation_cred = lox_utils::LoxCredential { lox_credential: issue_invite_cred.0, - bridgeline: None, + bridgelines: None, invitation: Some(issue_invite_cred.1), }; @@ -382,7 +382,7 @@ pub fn handle_redeem_invite( ) { Ok(issue_invite_cred) => lox_utils::LoxCredential { lox_credential: issue_invite_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -493,7 +493,7 @@ pub fn handle_blockage_migration( ) { Ok(lox_cred) => lox_utils::LoxCredential { lox_credential: lox_cred, - bridgeline: None, + bridgelines: None, invitation: None, }, Err(e) => { @@ -572,3 +572,19 @@ pub fn get_received_invite_expiry(invite_cred_str: String) -> String { )); serde_json::to_string(&date_time).unwrap() } + +#[wasm_bindgen] +pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String) -> String { + let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let bridgelines = + lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table); + log(&format!( + "Lox BridgeLines Expiry {}", + serde_json::to_string(&bridgelines).unwrap() + )); + serde_json::to_string(&bridgelines).unwrap() +} + +pub fn get_constants() -> String { + serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO).unwrap() +} From c8b6bb9fdd54ac38299ae6e73ae49d371a15c0d6 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Mon, 18 Dec 2023 22:56:26 -0500 Subject: [PATCH 20/31] Formatting and clippy changes --- crates/lox-distributor/src/db_handler.rs | 20 +++++++++---------- crates/lox-distributor/src/lox_context.rs | 2 +- crates/lox-distributor/src/request_handler.rs | 4 +++- crates/lox-distributor/src/resource_parser.rs | 2 -- crates/lox-library/src/lib.rs | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index 7493aba..4440feb 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -66,7 +66,7 @@ impl DB { if lox_db.was_recovered() && !lox_db.is_empty() { context = match read_lox_context_from_db(lox_db.clone(), roll_back_date) { Ok(ctx) => ctx, - Err(e) => panic!("Unable to read lox database {:?}", e) + Err(e) => panic!("Unable to read lox database {:?}", e), }; context.metrics = metrics; //Otherwise, create a new Lox context @@ -133,9 +133,7 @@ fn read_lox_context_from_db( } } // Use the last entry to populate the Lox context if no rollback date is set (which should be most common) - None => { - context = use_last_context(lox_db)? - } + None => context = use_last_context(lox_db)?, } Ok(context) } @@ -149,14 +147,14 @@ fn compute_startdate_string(date_range_end: String) -> Option> { // Use the last context that was entered into the database fn use_last_context(lox_db: sled::Db) -> Result { - match lox_db.last()? { - Some(ivec_context) => { - let ivec_date: String = String::from_utf8(ivec_context.0.to_vec()).unwrap(); - println!("Using last context with date: {:?}", ivec_date); - Ok(serde_json::from_slice(&ivec_context.1).unwrap()) - }, - None => Err(LoxDBError::DatabaseEmpty) + match lox_db.last()? { + Some(ivec_context) => { + let ivec_date: String = String::from_utf8(ivec_context.0.to_vec()).unwrap(); + println!("Using last context with date: {:?}", ivec_date); + Ok(serde_json::from_slice(&ivec_context.1).unwrap()) } + None => Err(LoxDBError::DatabaseEmpty), + } } #[cfg(test)] diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 1ddf245..a2a5d06 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -11,12 +11,12 @@ use lox_library::{ use rdsys_backend::proto::{Resource, ResourceState}; use serde::{Deserialize, Serialize}; +use lox_zkp::ProofError; use std::{ cmp::Ordering, collections::HashMap, sync::{Arc, Mutex}, }; -use lox_zkp::ProofError; use crate::metrics::Metrics; use crate::resource_parser::{parse_into_bridgelines, sort_for_parsing}; diff --git a/crates/lox-distributor/src/request_handler.rs b/crates/lox-distributor/src/request_handler.rs index 3be045f..dcfb0bf 100644 --- a/crates/lox-distributor/src/request_handler.rs +++ b/crates/lox-distributor/src/request_handler.rs @@ -409,9 +409,11 @@ mod tests { &pubkeys_obj.lox_pub, ) .unwrap(); + let mut bridge = Vec::new(); + bridge.push(lox_cred.1); let lox_cred: lox_utils::LoxCredential = lox_utils::LoxCredential { lox_credential: lox_cred.0, - bridgeline: Some(lox_cred.1), + bridgelines: Some(bridge), invitation: None, }; diff --git a/crates/lox-distributor/src/resource_parser.rs b/crates/lox-distributor/src/resource_parser.rs index d71c01e..7d01aa1 100644 --- a/crates/lox-distributor/src/resource_parser.rs +++ b/crates/lox-distributor/src/resource_parser.rs @@ -1,5 +1,3 @@ -use std::process::exit; - use chrono::{Duration, Utc}; use lox_library::bridge_table::{BridgeLine, BRIDGE_BYTES, MAX_BRIDGES_PER_BUCKET}; use rdsys_backend::proto::Resource; diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 0cf3a5f..9992e9a 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -266,11 +266,11 @@ impl BridgeDb { let bucket = u32::from_le_bytes(invitation[32..(32 + 4)].try_into().unwrap()); let s = Scalar::from_canonical_bytes(invitation[0..32].try_into().unwrap()); if s.is_some().into() { - return Ok((s.unwrap(), bucket)); + Ok((s.unwrap(), bucket)) } else { // It should never happen that there's a valid signature on // an invalid serialization of a Scalar, but check anyway. - return Err(SignatureError::new()); + Err(SignatureError::new()) } } } From 364b55dc4cb6106c84955424c88f084495a1e7ce Mon Sep 17 00:00:00 2001 From: onyinyang Date: Tue, 19 Dec 2023 12:29:01 -0500 Subject: [PATCH 21/31] Make wasm getter functions return Result --- crates/lox-wasm/src/lib.rs | 55 +++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index f106b4e..bfd173f 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -509,7 +509,7 @@ pub fn handle_blockage_migration( } #[wasm_bindgen] -pub fn get_last_upgrade_time(lox_cred_str: String) -> String { +pub fn get_last_upgrade_time(lox_cred_str: String) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); let upgrade_date = scalar_u32(&lox_cred.lox_credential.level_since).unwrap(); let date_time = JulianDay::new(upgrade_date as i32).to_date(); @@ -517,33 +517,42 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> String { "Time of last upgrade {}", serde_json::to_string(&date_time).unwrap() )); - serde_json::to_string(&date_time).unwrap() + match serde_json::to_string(&date_time) { + Ok(date_str) => Ok(date_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] -pub fn get_trust_level(lox_cred_str: String) -> String { +pub fn get_trust_level(lox_cred_str: String) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap(); log(&format!( "Trust level {}", serde_json::to_string(&trust_level).unwrap() )); - serde_json::to_string(&trust_level).unwrap() + match serde_json::to_string(&trust_level) { + Ok(trust_str) => Ok(trust_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] -pub fn get_invites_remaining(lox_cred_str: String) -> String { +pub fn get_invites_remaining(lox_cred_str: String) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining); log(&format!( "Invites remaining {}", serde_json::to_string(&invites).unwrap() )); - serde_json::to_string(&invites).unwrap() + match serde_json::to_string(&invites) { + Ok(invite_str) => Ok(invite_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] -pub fn get_issued_invite_expiry(lox_cred_str: String) -> String { +pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); match lox_cred.invitation { Some(invitation) => { @@ -554,14 +563,18 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> String { "Invitation Expiry {}", serde_json::to_string(&date_time).unwrap() )); - serde_json::to_string(&date_time).unwrap() + let inv_date_str = match serde_json::to_string(&date_time) { + Ok(inv_date_str) => Ok(inv_date_str), + Err(e) => Err(JsValue::from(e.to_string())), + }; + inv_date_str } - None => serde_json::to_string("No Invitation Issued").unwrap(), + None => Err(JsValue::from("No Invitation Issued")), } } #[wasm_bindgen] -pub fn get_received_invite_expiry(invite_cred_str: String) -> String { +pub fn get_received_invite_expiry(invite_cred_str: String) -> Result { let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap(); let expiry = (scalar_u32(&invite_cred.invitation.date).unwrap() + 15) as i32; let date_time = JulianDay::new(expiry).to_date(); @@ -570,11 +583,17 @@ pub fn get_received_invite_expiry(invite_cred_str: String) -> String { "Invitation Expiry {}", serde_json::to_string(&date_time).unwrap() )); - serde_json::to_string(&date_time).unwrap() + match serde_json::to_string(&date_time) { + Ok(date_str) => Ok(date_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] -pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String) -> String { +pub fn get_bridgelines_from_bucket( + lox_cred_str: String, + encrypted_table: String, +) -> Result { let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); let bridgelines = lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table); @@ -582,9 +601,15 @@ pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String "Lox BridgeLines Expiry {}", serde_json::to_string(&bridgelines).unwrap() )); - serde_json::to_string(&bridgelines).unwrap() + match serde_json::to_string(&bridgelines) { + Ok(bridgelines_str) => Ok(bridgelines_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } -pub fn get_constants() -> String { - serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO).unwrap() +pub fn get_constants() -> Result { + match serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO) { + Ok(system_info_str) => Ok(system_info_str), + Err(e) => Err(JsValue::from(e.to_string())), + } } From 39449cabe86b1d55ae44928514f1cb6125e00905 Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Wed, 20 Dec 2023 13:52:42 -0500 Subject: [PATCH 22/31] Respond with error when open invitation buckets are empty Expand the error type returns by invite() to include a new error for when there are no available bridges for open invitation users. This fixes a bug that previously caused a panic when we have no bridges to distribute. See https://gitlab.torproject.org/tpo/anti-censorship/lox/-/issues/43 --- crates/lox-distributor/src/lox_context.rs | 6 +++--- crates/lox-library/src/lib.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index a2a5d06..a967b40 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -6,7 +6,7 @@ use lox_library::{ blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite, redeem_invite, trust_promotion, }, - BridgeAuth, BridgeDb, ExceededMaxBridgesError, IssuerPubKey, + BridgeAuth, BridgeDb, OpenInvitationError, IssuerPubKey, }; use rdsys_backend::proto::{Resource, ResourceState}; use serde::{Deserialize, Serialize}; @@ -361,7 +361,7 @@ impl LoxServerContext { // Generates a Lox invitation if fewer than MAX_BRIDGES_PER_DAY have been // requested on a given day - fn gen_invite(&self) -> Result { + fn gen_invite(&self) -> Result { let mut obj = self.db.lock().unwrap(); match obj.invite() { Ok(invite) => { @@ -450,7 +450,7 @@ impl LoxServerContext { } }, Err(e) => { - println!("Error parsing Invite to JSON"); + println!("Error generating open invitation"); prepare_error_header(e.to_string()) } } diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 9992e9a..6c20292 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -86,9 +86,12 @@ pub enum NoAvailableIDError { /// This error is thrown after the MAX_DAILY_BRIDGES threshold for bridges /// distributed in a day has been reached #[derive(Error, Debug)] -pub enum ExceededMaxBridgesError { +pub enum OpenInvitationError { #[error("The maximum number of bridges has already been distributed today, please try again tomorrow!")] ExceededMaxBridges, + + #[error("There are no bridges available for open invitations.")] + NoBridgesAvailable, } /// Private Key of the Issuer @@ -215,7 +218,7 @@ impl BridgeDb { /// Produce an open invitation such that the next k users, where k is < /// OPENINV_K, will receive the same open invitation bucket /// chosen randomly from the set of open-invitation buckets. - pub fn invite(&mut self) -> Result<[u8; OPENINV_LENGTH], ExceededMaxBridgesError> { + pub fn invite(&mut self) -> Result<[u8; OPENINV_LENGTH], OpenInvitationError> { let mut res: [u8; OPENINV_LENGTH] = [0; OPENINV_LENGTH]; let mut rng = rand::thread_rng(); // Choose a random invitation id (a Scalar) and serialize it @@ -226,6 +229,9 @@ impl BridgeDb { self.today = Utc::now(); self.daily_bridges_distributed = 0; } + if self.openinv_buckets.is_empty() { + return Err(OpenInvitationError::NoBridgesAvailable) + } if self.daily_bridges_distributed < MAX_DAILY_BRIDGES { if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() { bucket_num = *self.distributed_buckets.last().unwrap(); @@ -246,7 +252,7 @@ impl BridgeDb { res[(32 + 4)..].copy_from_slice(&sig.to_bytes()); Ok(res) } else { - Err(ExceededMaxBridgesError::ExceededMaxBridges) + Err(OpenInvitationError::ExceededMaxBridges) } } From 9d4a293ee993c4fc4afabb86e85e4394953a09da Mon Sep 17 00:00:00 2001 From: onyinyang Date: Wed, 20 Dec 2023 13:50:12 -0500 Subject: [PATCH 23/31] Add invitation_is_trusted function, fixup error handling --- crates/lox-wasm/src/lib.rs | 41 +++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index bfd173f..3179cde 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -50,10 +50,19 @@ pub fn handle_new_lox_credential( open_lox_response: String, lox_pub: String, ) -> Result { - let req_state: lox_utils::OpenReqState = serde_json::from_str(&open_lox_result).unwrap(); + let req_state: lox_utils::OpenReqState = match serde_json::from_str(&open_lox_result) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&open_lox_response).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let deserialized_response = match serde_json::from_str(&open_lox_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let lox_cred = match open_invite::handle_response( deserialized_state, deserialized_response, @@ -78,7 +87,13 @@ pub fn handle_new_lox_credential( "Got new bridgeline: {}", serde_json::to_string(&lox_cred.bridgelines).unwrap() )); - Ok(serde_json::to_string(&lox_cred).unwrap()) + match serde_json::to_string(&lox_cred) { + Ok(lox_cred) => Ok(lox_cred), + Err(e) => { + log(&format!("Error: {:?}", e.to_string())); + Err(JsValue::from(e.to_string())) + } + } } #[wasm_bindgen] @@ -563,11 +578,10 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result "Invitation Expiry {}", serde_json::to_string(&date_time).unwrap() )); - let inv_date_str = match serde_json::to_string(&date_time) { + match serde_json::to_string(&date_time) { Ok(inv_date_str) => Ok(inv_date_str), Err(e) => Err(JsValue::from(e.to_string())), - }; - inv_date_str + } } None => Err(JsValue::from("No Invitation Issued")), } @@ -613,3 +627,16 @@ pub fn get_constants() -> Result { Err(e) => Err(JsValue::from(e.to_string())), } } + +pub fn invitation_is_trusted(unspecified_invitation_str: String) -> Result { + match serde_json::from_str::(&unspecified_invitation_str) { + Ok(_) => Ok(true), + Err(_) => { + let invite = unspecified_invitation_str.as_bytes(); + match lox_utils::validate(invite) { + Ok(_) => Ok(false), + Err(e) => Err(JsValue::from(e.to_string())), + } + } + } +} From c1f6ab0b77d2f9a9f82c48100da254e8d0389b31 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Wed, 20 Dec 2023 19:04:13 -0500 Subject: [PATCH 24/31] Gracefully recovers from rdsys shutdown or lack of resources --- crates/lox-distributor/src/main.rs | 8 +++++--- crates/rdsys-backend-api/src/lib.rs | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 289540a..acd912c 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -124,14 +124,16 @@ async fn rdsys_request(rtype: ResourceInfo, tx: mpsc::Sender) { let mut interval = interval(Duration::from_secs(5)); loop { interval.tick().await; - let resources = request_resources( + let resources = match request_resources( rtype.endpoint.clone(), rtype.name.clone(), rtype.token.clone(), rtype.types.clone(), ) - .await - .unwrap(); + .await{ + Ok(resources)=> resources, + Err(e) => {println!("No resources received from rdsys: {:?}", e); continue}, + }; tx.send(resources).await.unwrap(); } } diff --git a/crates/rdsys-backend-api/src/lib.rs b/crates/rdsys-backend-api/src/lib.rs index 51e2bdc..3000fde 100644 --- a/crates/rdsys-backend-api/src/lib.rs +++ b/crates/rdsys-backend-api/src/lib.rs @@ -284,8 +284,7 @@ pub async fn request_resources( .header("Authorization", &auth_value) .body(json) .send() - .await - .unwrap(); + .await?; match response.status() { reqwest::StatusCode::OK => { fetched_resources = match response.json::().await { From 075d51b08898704ff78e27b5fc5eddcb9a72f36b Mon Sep 17 00:00:00 2001 From: onyinyang Date: Wed, 20 Dec 2023 18:45:04 -0500 Subject: [PATCH 25/31] Add better serde error handling to wasm functions --- crates/lox-distributor/src/lox_context.rs | 2 +- crates/lox-library/src/lib.rs | 2 +- crates/lox-wasm/index.js | 18 +- crates/lox-wasm/src/lib.rs | 288 +++++++++++++++++----- 4 files changed, 238 insertions(+), 72 deletions(-) diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index a967b40..4e2eb49 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -6,7 +6,7 @@ use lox_library::{ blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite, redeem_invite, trust_promotion, }, - BridgeAuth, BridgeDb, OpenInvitationError, IssuerPubKey, + BridgeAuth, BridgeDb, IssuerPubKey, OpenInvitationError, }; use rdsys_backend::proto::{Resource, ResourceState}; use serde::{Deserialize, Serialize}; diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 6c20292..d04c297 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -230,7 +230,7 @@ impl BridgeDb { self.daily_bridges_distributed = 0; } if self.openinv_buckets.is_empty() { - return Err(OpenInvitationError::NoBridgesAvailable) + return Err(OpenInvitationError::NoBridgesAvailable); } if self.daily_bridges_distributed < MAX_DAILY_BRIDGES { if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() { diff --git a/crates/lox-wasm/index.js b/crates/lox-wasm/index.js index 52e781f..cbd3d30 100644 --- a/crates/lox-wasm/index.js +++ b/crates/lox-wasm/index.js @@ -16,7 +16,7 @@ import init, { handle_check_blockage, blockage_migration, handle_blockage_migration, - set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry} from "./pkg/lox_wasm.js"; + set_panic_hook, get_last_upgrade_time, get_trust_level, get_invites_remaining, get_issued_invite_expiry, get_received_invite_expiry, get_bridgelines_from_bucket} from "./pkg/lox_wasm.js"; let pubkeys = await simple_request("/pubkeys"); console.log("Got pubkeys: " + pubkeys); @@ -41,14 +41,12 @@ let open_lox_cred = await init().then(() => { return cred; }); -let info = get_last_upgrade_time(open_lox_cred); -console.log("Last upgrade time: "+info); -let info_two = get_trust_level(open_lox_cred); -console.log("Last upgrade time: "+info_two); -let info_three = get_invites_remaining(open_lox_cred); -console.log("Last upgrade time: "+info_three); -let info_four = get_issued_invite_expiry(open_lox_cred); -console.log("Last upgrade time: "+info_four); +get_last_upgrade_time(open_lox_cred); +get_trust_level(open_lox_cred); +get_invites_remaining(open_lox_cred); +let encrypted_table = await simple_request("/reachability"); +let info_five = get_bridgelines_from_bucket(open_lox_cred, encrypted_table); +console.log("Bridgelines available: "+info_five); let requested_trust_promo = trust_promotion(open_lox_cred, pubkeys); // Get Migration credential for Trust Promotion from Trust Level 0 -> 1 @@ -74,7 +72,7 @@ let lox_cred = await init().then(() => { return cred; }); -let encrypted_table = await simple_request("/reachability"); +encrypted_table = await simple_request("/reachability"); console.log("Got Encrypted Table: " + encrypted_table); let requested_level_two = level_up(lox_cred, encrypted_table, pubkeys); diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs index 3179cde..fa40174 100644 --- a/crates/lox-wasm/src/lib.rs +++ b/crates/lox-wasm/src/lib.rs @@ -41,7 +41,10 @@ pub fn open_invite(invite: &[u8]) -> Result { "Formatted open invite request: {}", serde_json::to_string(&req_state).unwrap() )); - Ok(serde_json::to_string(&req_state).unwrap()) + match serde_json::to_string(&req_state) { + Ok(req_state) => Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -98,8 +101,14 @@ pub fn handle_new_lox_credential( #[wasm_bindgen] pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&open_lox_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let tp_result = match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, today()) { Ok(tp_result) => tp_result, @@ -116,7 +125,10 @@ pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -124,9 +136,15 @@ pub fn handle_trust_promotion( trust_promo_request: String, trust_promo_response: String, ) -> Result { - let req_state: lox_utils::TrustReqState = serde_json::from_str(&trust_promo_request).unwrap(); + let req_state: lox_utils::TrustReqState = match serde_json::from_str(&trust_promo_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&trust_promo_response).unwrap(); + let deserialized_response = match serde_json::from_str(&trust_promo_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let migration_cred = match trust_promotion::handle_response(deserialized_state, deserialized_response) { Ok(migration_cred) => migration_cred, @@ -139,7 +157,10 @@ pub fn handle_trust_promotion( "Got new Migration Credential: {}", serde_json::to_string(&migration_cred).unwrap() )); - Ok(serde_json::to_string(&migration_cred).unwrap()) + match serde_json::to_string(&migration_cred) { + Ok(migration_cred) => Ok(migration_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -148,8 +169,14 @@ pub fn trust_migration( trust_promo_cred: String, lox_pub: String, ) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&open_lox_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let mig_cred: Migration = serde_json::from_str(&trust_promo_cred).unwrap(); let tm_result = match migration::request( &lox_cred.lox_credential, @@ -171,7 +198,10 @@ pub fn trust_migration( "Formatted Trust Migration request: {}", serde_json::to_string(&req_state).unwrap() )); - Ok(serde_json::to_string(&req_state).unwrap()) + match serde_json::to_string(&req_state) { + Ok(req_state) => Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -180,10 +210,19 @@ pub fn handle_trust_migration( trust_migration_response: String, lox_pub: String, ) -> Result { - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); - let req_state: lox_utils::MigReqState = serde_json::from_str(&trust_migration_request).unwrap(); + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let req_state: lox_utils::MigReqState = match serde_json::from_str(&trust_migration_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&trust_migration_response).unwrap(); + let deserialized_response = match serde_json::from_str(&trust_migration_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let level_one_cred = match migration::handle_response( deserialized_state, deserialized_response, @@ -203,7 +242,11 @@ pub fn handle_trust_migration( "Got new Level 1 Credential: {}", serde_json::to_string(&level_one_cred).unwrap() )); - Ok(serde_json::to_string(&level_one_cred).unwrap()) + + match serde_json::to_string(&level_one_cred) { + Ok(level_one_cred) => Ok(level_one_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -212,8 +255,14 @@ pub fn level_up( encrypted_table: String, lox_pub: String, ) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&level_one_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&level_one_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let reach_cred = lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table); @@ -238,7 +287,10 @@ pub fn level_up( "Formatted Level Up request: {}", serde_json::to_string(&req_state).unwrap() )); - Ok(serde_json::to_string(&req_state).unwrap()) + match serde_json::to_string(&req_state) { + Ok(req_state) => Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -247,10 +299,19 @@ pub fn handle_level_up( levelup_response: String, lox_pub: String, ) -> Result { - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); - let req_state: lox_utils::LevelupReqState = serde_json::from_str(&levelup_request).unwrap(); + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let req_state: lox_utils::LevelupReqState = match serde_json::from_str(&levelup_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&levelup_response).unwrap(); + let deserialized_response = match serde_json::from_str(&levelup_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let level_up_cred = match level_up::handle_response( deserialized_state, deserialized_response, @@ -270,7 +331,10 @@ pub fn handle_level_up( "Got new Level Up Credential: {}", serde_json::to_string(&level_up_cred).unwrap() )); - Ok(serde_json::to_string(&level_up_cred).unwrap()) + match serde_json::to_string(&level_up_cred) { + Ok(level_up_cred) => Ok(level_up_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -279,8 +343,14 @@ pub fn issue_invite( encrypted_table: String, lox_pub: String, ) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&trusted_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&trusted_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let reach_cred = lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table); @@ -305,7 +375,10 @@ pub fn issue_invite( "Formatted Issue Invite request: {}", serde_json::to_string(&req_state).unwrap() )); - Ok(serde_json::to_string(&req_state).unwrap()) + match serde_json::to_string(&req_state) { + Ok(req_state) => Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -314,11 +387,20 @@ pub fn handle_issue_invite( issue_invite_response: String, lox_pub: String, ) -> Result { - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let req_state: lox_utils::IssueInviteReqState = - serde_json::from_str(&issue_invite_request).unwrap(); + match serde_json::from_str(&issue_invite_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&issue_invite_response).unwrap(); + let deserialized_response = match serde_json::from_str(&issue_invite_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let issue_invite_cred = match issue_invite::handle_response( deserialized_state, deserialized_response, @@ -341,25 +423,40 @@ pub fn handle_issue_invite( "Got new Invitation Credential and Lox Credential: {}", serde_json::to_string(&invitation_cred).unwrap() )); - Ok(serde_json::to_string(&invitation_cred).unwrap()) + match serde_json::to_string(&invitation_cred) { + Ok(invitation_cred) => Ok(invitation_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } // Separate Trusted Invite from credential prior to passing it to friend #[wasm_bindgen] -pub fn prepare_invite(invitation_cred: String) -> String { - let cred: lox_utils::LoxCredential = serde_json::from_str(&invitation_cred).unwrap(); +pub fn prepare_invite(invitation_cred: String) -> Result { + let cred: lox_utils::LoxCredential = match serde_json::from_str(&invitation_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; log(&format!( "Prepared Invitation: {}", serde_json::to_string(&cred.invitation).unwrap() )); - serde_json::to_string(&cred.invitation).unwrap() + match serde_json::to_string(&cred.invitation) { + Ok(invitation) => Ok(invitation), + Err(e) => Err(JsValue::from(e.to_string())), + } } // #[wasm_bindgen] pub fn redeem_invite(invitation: String, lox_pub: String) -> Result { - let invitation_cred: Invitation = serde_json::from_str(&invitation).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let invitation_cred: Invitation = match serde_json::from_str(&invitation) { + Ok(invitation_cred) => invitation_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let redeem_result = match redeem_invite::request(&invitation_cred, &pubkeys.invitation_pub, today()) { Ok(redeem_result) => redeem_result, @@ -376,7 +473,10 @@ pub fn redeem_invite(invitation: String, lox_pub: String) -> Result Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -385,11 +485,19 @@ pub fn handle_redeem_invite( redeem_invite_response: String, lox_pub: String, ) -> Result { - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); - let req_state: lox_utils::RedeemReqState = - serde_json::from_str(&redeem_invite_request).unwrap(); + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let req_state: lox_utils::RedeemReqState = match serde_json::from_str(&redeem_invite_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&redeem_invite_response).unwrap(); + let deserialized_response = match serde_json::from_str(&redeem_invite_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let redeem_invite_cred = match redeem_invite::handle_response( deserialized_state, deserialized_response, @@ -409,14 +517,23 @@ pub fn handle_redeem_invite( "Got new Trusted Lox Credential from Invitation: {}", serde_json::to_string(&redeem_invite_cred).unwrap() )); - Ok(serde_json::to_string(&redeem_invite_cred).unwrap()) + match serde_json::to_string(&redeem_invite_cred) { + Ok(redeem_invite_cred) => Ok(redeem_invite_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result { - let lox: lox_utils::LoxCredential = serde_json::from_str(&lox_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); - let cb_result = match check_blockage::request(&lox.lox_credential, &pubkeys.lox_pub) { + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let cb_result = match check_blockage::request(&lox_cred.lox_credential, &pubkeys.lox_pub) { Ok(cb_result) => cb_result, Err(e) => { log(&format!("Error: {:?}", e.to_string())); @@ -431,7 +548,10 @@ pub fn check_blockage(lox_cred: String, lox_pub: String) -> Result Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -440,9 +560,15 @@ pub fn handle_check_blockage( check_blockage_response: String, ) -> Result { let req_state: lox_utils::CheckBlockageReqState = - serde_json::from_str(&check_blockage_request).unwrap(); + match serde_json::from_str(&check_blockage_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&check_blockage_response).unwrap(); + let deserialized_response = match serde_json::from_str(&check_blockage_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let migration_cred = match check_blockage::handle_response(deserialized_state, deserialized_response) { Ok(migration_cred) => migration_cred, @@ -455,7 +581,10 @@ pub fn handle_check_blockage( "Got new Blockage Migration Credential: {}", serde_json::to_string(&migration_cred).unwrap() )); - Ok(serde_json::to_string(&migration_cred).unwrap()) + match serde_json::to_string(&migration_cred) { + Ok(migration_cred) => Ok(migration_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -464,8 +593,14 @@ pub fn blockage_migration( check_migration_cred: String, lox_pub: String, ) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred).unwrap(); - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let mig_cred: Migration = serde_json::from_str(&check_migration_cred).unwrap(); let bm_result = match blockage_migration::request( &lox_cred.lox_credential, @@ -487,7 +622,10 @@ pub fn blockage_migration( "Formatted Blockage Migration request: {}", serde_json::to_string(&req_state).unwrap() )); - Ok(serde_json::to_string(&req_state).unwrap()) + match serde_json::to_string(&req_state) { + Ok(req_state) => Ok(req_state), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] @@ -496,11 +634,20 @@ pub fn handle_blockage_migration( blockage_migration_response: String, lox_pub: String, ) -> Result { - let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap(); + let pubkeys: lox_utils::PubKeys = match serde_json::from_str(&lox_pub) { + Ok(pubkeys) => pubkeys, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let req_state: lox_utils::BlockageMigReqState = - serde_json::from_str(&blockage_migration_request).unwrap(); + match serde_json::from_str(&blockage_migration_request) { + Ok(req_state) => req_state, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let deserialized_state = req_state.state; - let deserialized_response = serde_json::from_str(&blockage_migration_response).unwrap(); + let deserialized_response = match serde_json::from_str(&blockage_migration_response) { + Ok(deserialized_response) => deserialized_response, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let lox_cred = match blockage_migration::handle_response( deserialized_state, deserialized_response, @@ -520,12 +667,18 @@ pub fn handle_blockage_migration( "Got new Lox Credential after Migration: {}", serde_json::to_string(&lox_cred).unwrap() )); - Ok(serde_json::to_string(&lox_cred).unwrap()) + match serde_json::to_string(&lox_cred) { + Ok(lox_cred) => Ok(lox_cred), + Err(e) => Err(JsValue::from(e.to_string())), + } } #[wasm_bindgen] pub fn get_last_upgrade_time(lox_cred_str: String) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let upgrade_date = scalar_u32(&lox_cred.lox_credential.level_since).unwrap(); let date_time = JulianDay::new(upgrade_date as i32).to_date(); log(&format!( @@ -540,7 +693,10 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> Result { #[wasm_bindgen] pub fn get_trust_level(lox_cred_str: String) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap(); log(&format!( "Trust level {}", @@ -554,7 +710,10 @@ pub fn get_trust_level(lox_cred_str: String) -> Result { #[wasm_bindgen] pub fn get_invites_remaining(lox_cred_str: String) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining); log(&format!( "Invites remaining {}", @@ -568,7 +727,10 @@ pub fn get_invites_remaining(lox_cred_str: String) -> Result { #[wasm_bindgen] pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; match lox_cred.invitation { Some(invitation) => { let expiry = (scalar_u32(&invitation.date).unwrap() + 15) as i32; @@ -589,7 +751,10 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result #[wasm_bindgen] pub fn get_received_invite_expiry(invite_cred_str: String) -> Result { - let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap(); + let invite_cred: lox_utils::IssuedInvitation = match serde_json::from_str(&invite_cred_str) { + Ok(invite_cred) => invite_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let expiry = (scalar_u32(&invite_cred.invitation.date).unwrap() + 15) as i32; let date_time = JulianDay::new(expiry).to_date(); println!("Datetime is: {:?}", date_time); @@ -608,11 +773,14 @@ pub fn get_bridgelines_from_bucket( lox_cred_str: String, encrypted_table: String, ) -> Result { - let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap(); + let lox_cred: lox_utils::LoxCredential = match serde_json::from_str(&lox_cred_str) { + Ok(lox_cred) => lox_cred, + Err(e) => return Err(JsValue::from(e.to_string())), + }; let bridgelines = lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table); log(&format!( - "Lox BridgeLines Expiry {}", + "Lox BridgeLines available {}", serde_json::to_string(&bridgelines).unwrap() )); match serde_json::to_string(&bridgelines) { From 771db10cd11045a99e3271c3fe4287e1ee9aa0c8 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 4 Jan 2024 19:39:11 +0000 Subject: [PATCH 26/31] Update Rust crate clap to 4.4.13 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47f4bd7..14a0a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.11" +version = "4.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" dependencies = [ "clap_builder", "clap_derive", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.11" +version = "4.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" dependencies = [ "anstream", "anstyle", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index c090691..80c1634 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -30,7 +30,7 @@ lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = " lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} -clap = { version = "4.4.11", features = ["derive"] } +clap = { version = "4.4.13", features = ["derive"] } serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" From 46ba68e1b5c6a4182d3ea494259c4de669230387 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 2 Jan 2024 06:39:01 +0000 Subject: [PATCH 27/31] Update Rust crate thiserror to 1.0.56 --- Cargo.lock | 20 ++++++++++---------- crates/lox-library/Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14a0a54..8975ece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1474,9 +1474,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" dependencies = [ "unicode-ident", ] @@ -1527,9 +1527,9 @@ checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" [[package]] name = "quote" -version = "1.0.32" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2058,9 +2058,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.32" +version = "2.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" dependencies = [ "proc-macro2", "quote", @@ -2082,18 +2082,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 82535b6..84a4591 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -30,7 +30,7 @@ base64 = "0.21" time = "0.3.31" prometheus = "0.13.3" subtle = "2.5" -thiserror = "1.0.50" +thiserror = "1.0.56" lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = "0.8.0" } [features] From fb8a5e89a20dc45047429a5fb1f51b89b1bd9772 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 8 Jan 2024 16:12:22 +0000 Subject: [PATCH 28/31] Update Rust crate serde to 1.0.195 --- Cargo.lock | 8 ++++---- crates/lox-library/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8975ece..c14c983 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1876,18 +1876,18 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 84a4591..d7db1e4 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -19,7 +19,7 @@ ed25519-dalek = { version = "2", features = ["serde", "rand_core"] } bincode = "1" chrono = "0.4" rand = { version = "0.8", features = ["std_rng"]} -serde = "1.0.193" +serde = "1.0.195" serde_with = {version = "3.4.0", features = ["json"]} sha2 = "0.10" statistical = "1.0.0" From ffedd7f2c983a92080d0707a8ab29c9a6f642337 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 8 Jan 2024 16:12:09 +0000 Subject: [PATCH 29/31] Update Rust crate base64 to 0.21.6 --- Cargo.lock | 4 ++-- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c14c983..da6358c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" [[package]] name = "base64ct" diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 80c1634..176fd87 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -16,7 +16,7 @@ readme = "README.md" [dependencies] julianday = "1.2.0" -base64 = "0.21.5" +base64 = "0.21.6" hyper = { version = "0.14.28", features = ["server"] } hex_fmt = "0.3" futures = "0.3.29" From c2a40658e32349cacfcde1dc9667ede1e629f8ff Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 8 Jan 2024 17:18:37 +0000 Subject: [PATCH 30/31] Update Rust crate clap to 4.4.14 --- Cargo.lock | 8 ++++---- crates/lox-distributor/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da6358c..71089f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.13" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" +checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" dependencies = [ "clap_builder", "clap_derive", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.12" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" dependencies = [ "anstream", "anstyle", diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 176fd87..46e19e9 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -30,7 +30,7 @@ lox-zkp = { git = "https://gitlab.torproject.org/onyinyang/lox-zkp", version = " lox-library = { path = "../lox-library", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"} -clap = { version = "4.4.13", features = ["derive"] } +clap = { version = "4.4.14", features = ["derive"] } serde_json = "1.0.108" prometheus = "0.13.3" sled = "0.34.7" From ed7c94b9127b6eeed278d729a5384ae9cf850338 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Mon, 8 Jan 2024 19:24:46 -0500 Subject: [PATCH 31/31] Send Response as json, errors with OK Status Code --- crates/lox-distributor/Cargo.toml | 2 +- crates/lox-distributor/src/lox_context.rs | 106 +++++++++++++----- crates/lox-distributor/src/main.rs | 10 +- crates/lox-distributor/src/request_handler.rs | 2 +- 4 files changed, 86 insertions(+), 34 deletions(-) diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index 46e19e9..4b138ca 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -17,7 +17,7 @@ readme = "README.md" [dependencies] julianday = "1.2.0" base64 = "0.21.6" -hyper = { version = "0.14.28", features = ["server"] } +hyper = { version = "0.14.28", features = ["deprecated", "backports","server"] } hex_fmt = "0.3" futures = "0.3.29" time = "0.3.31" diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 4e2eb49..bc0112d 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -1,5 +1,4 @@ use hyper::{body::Bytes, header::HeaderValue, Body, Response}; - use lox_library::{ bridge_table::{BridgeLine, EncryptedBucket, MAX_BRIDGES_PER_BUCKET}, proto::{ @@ -12,6 +11,7 @@ use rdsys_backend::proto::{Resource, ResourceState}; use serde::{Deserialize, Serialize}; use lox_zkp::ProofError; +use serde_json::json; use std::{ cmp::Ordering, collections::HashMap, @@ -446,12 +446,16 @@ impl LoxServerContext { Ok(resp) => prepare_header(resp), Err(e) => { println!("Error parsing Invite to JSON"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } }, Err(e) => { println!("Error generating open invitation"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -464,7 +468,9 @@ impl LoxServerContext { Ok(resp) => prepare_header(resp), Err(e) => { println!("Error parsing encrypted bridgetable to JSON"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -476,7 +482,9 @@ impl LoxServerContext { Ok(resp) => prepare_header(resp), Err(e) => { println!("Error parsing Pubkeys to JSON"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -485,7 +493,11 @@ impl LoxServerContext { pub fn verify_and_send_open_cred(self, request: Bytes) -> Response { let req = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.open_inv(req) { Ok(resp) => { @@ -495,7 +507,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Open Invitation request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -504,7 +518,11 @@ impl LoxServerContext { pub fn verify_and_send_trust_promo(self, request: Bytes) -> Response { let req: trust_promotion::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.trust_promo(req) { Ok(resp) => { @@ -514,7 +532,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Trust Promotion request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -523,7 +543,11 @@ impl LoxServerContext { pub fn verify_and_send_trust_migration(self, request: Bytes) -> Response { let req: migration::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.trust_migration(req) { Ok(resp) => { @@ -533,7 +557,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Trust Migration request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -542,7 +568,11 @@ impl LoxServerContext { pub fn verify_and_send_level_up(self, request: Bytes) -> Response { let req: level_up::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.level_up(req) { Ok(resp) => { @@ -552,7 +582,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Level up request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -561,7 +593,11 @@ impl LoxServerContext { pub fn verify_and_send_issue_invite(self, request: Bytes) -> Response { let req: issue_invite::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.issue_invite(req) { Ok(resp) => { @@ -571,7 +607,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Issue invite request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -580,7 +618,11 @@ impl LoxServerContext { pub fn verify_and_send_redeem_invite(self, request: Bytes) -> Response { let req: redeem_invite::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.redeem_invite(req) { Ok(resp) => { @@ -590,7 +632,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Redeem Invite request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -599,7 +643,11 @@ impl LoxServerContext { pub fn verify_and_send_check_blockage(self, request: Bytes) -> Response { let req: check_blockage::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.check_blockage(req) { Ok(resp) => { @@ -609,7 +657,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Check blockage request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -618,7 +668,11 @@ impl LoxServerContext { pub fn verify_and_send_blockage_migration(self, request: Bytes) -> Response { let req: blockage_migration::Request = match serde_json::from_slice(&request) { Ok(req) => req, - Err(e) => return prepare_error_header(e.to_string()), + Err(e) => { + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + return prepare_header(val); + } }; match self.blockage_migration(req) { Ok(resp) => { @@ -628,7 +682,9 @@ impl LoxServerContext { } Err(e) => { println!("Invalid Blockage Migration request, Proof Error"); - prepare_error_header(e.to_string()) + let response = json!({"error": e.to_string()}); + let val = serde_json::to_string(&response).unwrap(); + prepare_header(val) } } } @@ -641,11 +697,3 @@ fn prepare_header(response: String) -> Response { .insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); resp } - -// Prepare HTTP Response for errored Server Request -fn prepare_error_header(error: String) -> Response { - Response::builder() - .status(hyper::StatusCode::BAD_REQUEST) - .body(Body::from(error)) - .unwrap() -} diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index acd912c..214fd62 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -130,9 +130,13 @@ async fn rdsys_request(rtype: ResourceInfo, tx: mpsc::Sender) { rtype.token.clone(), rtype.types.clone(), ) - .await{ - Ok(resources)=> resources, - Err(e) => {println!("No resources received from rdsys: {:?}", e); continue}, + .await + { + Ok(resources) => resources, + Err(e) => { + println!("No resources received from rdsys: {:?}", e); + continue; + } }; tx.send(resources).await.unwrap(); } diff --git a/crates/lox-distributor/src/request_handler.rs b/crates/lox-distributor/src/request_handler.rs index dcfb0bf..560146b 100644 --- a/crates/lox-distributor/src/request_handler.rs +++ b/crates/lox-distributor/src/request_handler.rs @@ -336,7 +336,7 @@ mod tests { .body(Body::empty()) .unwrap(); let not_found_response = handle(th.context.clone(), req).await.unwrap(); - assert_eq!(not_found_response.status(), StatusCode::BAD_REQUEST); + assert_eq!(not_found_response.status(), StatusCode::OK) } #[tokio::test]