Add working reachability cred, test credential aging needs work

This commit is contained in:
onyinyang 2023-02-23 13:18:11 -05:00
parent d8cdf3ccab
commit 01a6cb37e1
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
3 changed files with 31 additions and 14 deletions

View File

@ -11,11 +11,13 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
julianday = "1.2.0" julianday = "1.2.0"
lazy_static = "1.4.0"
lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git", branch = "master" } lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git", branch = "master" }
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
time = "0.2" time = "0.2"
serde_json = "1.0.87" serde_json = "1.0.87"
serde = "1" serde = "1"
serde_with = "1.9.1"
serde-wasm-bindgen = "0.4.5" serde-wasm-bindgen = "0.4.5"
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"

View File

@ -40,7 +40,6 @@ let trust_promo_cred = await init().then(() => {
return cred; return cred;
}); });
console.log("Got reachability credential: " + reachability_cred);
let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred, pubkeys); let requested_trust_migration = trust_migration(open_lox_cred, trust_promo_cred, pubkeys);
@ -53,8 +52,9 @@ let level_one_cred = await init().then(() => {
return cred; return cred;
}); });
let reachability_cred = await simple_request("/reachability"); let encrypted_table = await simple_request("/reachability");
let requested_level_two = level_up(level_one_cred, reachability_cred, pubkeys); console.log("Got Encrypted Table: " + encrypted_table);
let requested_level_two = level_up(level_one_cred, encrypted_table, pubkeys);
let level_two_cred = await init().then(() => { let level_two_cred = await init().then(() => {
set_panic_hook(); set_panic_hook();

View File

@ -1,17 +1,21 @@
use chrono::{Duration, Utc}; use chrono::{Duration, Utc, NaiveDate};
use std::sync::atomic::{AtomicI64, Ordering};
use julianday::JulianDay; use julianday::JulianDay;
use lox::bridge_table::BridgeLine; use lazy_static::lazy_static;
use lox::bridge_table::{BridgeLine,from_scalar,BridgeTable, ENC_BUCKET_BYTES};
use lox::cred::{BucketReachability, Lox, Migration}; use lox::cred::{BucketReachability, Lox, Migration};
use lox::proto::{open_invite, trust_promotion, migration, level_up, use lox::proto::{open_invite, trust_promotion, migration, level_up,
issue_invite, redeem_invite, check_blockage, blockage_migration}; issue_invite, redeem_invite, check_blockage, blockage_migration};
use lox::{IssuerPubKey, OPENINV_LENGTH}; use lox::{IssuerPubKey, OPENINV_LENGTH};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::{serde_as};
use serde_json; use serde_json;
//use serde_wasm_bindgen; //use serde_wasm_bindgen;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
use std::{panic}; use std::{panic};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
struct OpenReqState { struct OpenReqState {
request: open_invite::Request, request: open_invite::Request,
@ -45,6 +49,13 @@ struct PubKeys {
invitation_pub: IssuerPubKey, invitation_pub: IssuerPubKey,
} }
#[serde_as]
#[derive(Serialize, Deserialize)]
pub struct EncBridgeTable {
#[serde_as(as = "Vec<[_; ENC_BUCKET_BYTES]>")]
pub etable: Vec<[u8; ENC_BUCKET_BYTES]>,
}
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct Credential { struct Credential {
lox_credential: Lox, lox_credential: Lox,
@ -58,8 +69,8 @@ fn today() -> u32 {
} }
// This should only be used for testing, use today in production // This should only be used for testing, use today in production
fn add_today(sum: i64) -> u32 { fn test_today(days: i64) -> u32 {
let naive_now_plus = (Utc::now() + Duration::days(sum)).date_naive(); let naive_now_plus = (Utc::now() + Duration::days(days)).date_naive();
JulianDay::from(naive_now_plus).inner().try_into().unwrap() JulianDay::from(naive_now_plus).inner().try_into().unwrap()
} }
@ -144,11 +155,11 @@ pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result<String,
// in production this should just use the today() function // in production this should just use the today() function
log(&format!( log(&format!(
"TEST ONLY: Add 31 days to today's date: {}", "TEST ONLY: Add 31 days to today's date: {}",
add_today(31) test_today(31)
)); ));
let tp_result = let tp_result =
//CHANGE add_today(31) to today() for production //CHANGE add_today(31) to today() for production
match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, add_today(31)) { match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, test_today(31)) {
Ok(tp_result) => tp_result, Ok(tp_result) => tp_result,
Err(e) => { Err(e) => {
log(&format!("Error: {:?}", e.to_string())); log(&format!("Error: {:?}", e.to_string()));
@ -247,20 +258,24 @@ pub fn handle_trust_migration(
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn level_up(level_one_cred: String, reachability_cred: String, lox_pub: String) -> Result<String, JsValue> { pub fn level_up(level_one_cred: String, encrypted_table: String, lox_pub: String) -> Result<String, JsValue> {
let lox_cred: Lox = serde_json::from_str(&level_one_cred).unwrap(); let lox_cred: Lox = serde_json::from_str(&level_one_cred).unwrap();
let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap(); let pubkeys: PubKeys = serde_json::from_str(&lox_pub).unwrap();
let reach_cred: BucketReachability = serde_json::from_str(&reachability_cred).unwrap(); 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[id as usize]).unwrap();
let reach_cred = bucket.1.unwrap();
// To test level up of the credential we need to advance the day to the correct interval // 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 this case, the maximum of 85 can be used to test all level ups
// in production this should just use the today() function // in production this should just use the today() function
// decrypt trust level and use to calculate the correct date for now
log(&format!( log(&format!(
"TEST ONLY: Add 85 days to today's date: {}", "TEST ONLY: Add 31 (open invitation) + x*85 days to today's date: {}",
add_today(85) test_today(31+85)
)); ));
let lu_result = let lu_result =
//CHANGE add_today(31) to today() for production //CHANGE add_today(31) to today() for production
match level_up::request(&lox_cred, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, add_today(85)) { match level_up::request(&lox_cred, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(31+85)) {
Ok(lu_result) => lu_result, Ok(lu_result) => lu_result,
Err(e) => { Err(e) => {
log(&format!("Error: {:?}", e.to_string())); log(&format!("Error: {:?}", e.to_string()));