diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index ee389cd..248d432 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -16,6 +16,7 @@ lazy_static = "1" hex_fmt = "0.3" aes-gcm = "0.8" base64 = "0.13" +time = "0.2" [features] default = ["u64_backend"] diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 639a231..109ac54 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -18,6 +18,7 @@ The notation follows that of the paper "Hyphae: Social Secret Sharing" extern crate zkp; pub mod bridge_table; +pub mod cred; pub mod dup_filter; use sha2::Sha512; @@ -114,11 +115,11 @@ pub const OPENINV_LENGTH: usize = 32 // the length of the random impl BridgeDb { /// Create the BridgeDb. - pub fn new(num_openinv_buckets: u32) -> BridgeDb { + pub fn new(num_openinv_buckets: u32) -> Self { let mut csprng = OsRng {}; let keypair = Keypair::generate(&mut csprng); let pubkey = keypair.public; - BridgeDb { + Self { keypair, pubkey, num_openinv_buckets, @@ -165,3 +166,62 @@ impl BridgeDb { } } } + +/// The bridge authority. This will typically be a singleton object. +#[derive(Debug)] +pub struct BridgeAuth { + /// The private key for the main Lox credential + lox_priv: IssuerPrivKey, + /// The public key for the main Lox credential + pub lox_pub: IssuerPubKey, + /// The private key for migration credentials + migration_priv: IssuerPrivKey, + /// The public key for migration credentials + pub migration_pub: IssuerPubKey, + + /// The public key of the BridgeDb issuing open invitations + pub bridgedb_pub: PublicKey, + + /// Duplicate filter for open invitations + openinv_filter: dup_filter::DupFilter, + /// Duplicate filter for credential ids + id_filter: dup_filter::DupFilter, + + /// For testing only: offset of the true time to the simulated time + time_offset: time::Duration, +} + +impl BridgeAuth { + pub fn new(bridgedb_pub: PublicKey) -> Self { + let lox_priv = IssuerPrivKey::new(6); + let lox_pub = IssuerPubKey::new(&lox_priv); + let migration_priv = IssuerPrivKey::new(3); + let migration_pub = IssuerPubKey::new(&migration_priv); + Self { + lox_priv, + lox_pub, + migration_priv, + migration_pub, + bridgedb_pub, + openinv_filter: Default::default(), + id_filter: Default::default(), + time_offset: time::Duration::zero(), + } + } + + /// For testing only: manually advance the day by 1 day + pub fn advance_day(&mut self) { + self.time_offset += time::Duration::days(1); + } + + /// For testing only: manually advance the day by the given number + /// of days + pub fn advance_days(&mut self, days: u16) { + self.time_offset += time::Duration::days(days.into()); + } + + /// Get today's (real or simulated) date + fn today(&self) -> i64 { + (time::OffsetDateTime::now_utc().date() + self.time_offset).julian_day() + } +} diff --git a/crates/lox-library/tests/tests.rs b/crates/lox-library/tests/tests.rs index ce497fa..9c67e68 100644 --- a/crates/lox-library/tests/tests.rs +++ b/crates/lox-library/tests/tests.rs @@ -1,5 +1,6 @@ use lox::dup_filter; use lox::dup_filter::SeenType::{Fresh, Seen}; +use lox::BridgeAuth; use lox::BridgeDb; use curve25519_dalek::scalar::Scalar; @@ -44,3 +45,11 @@ fn test_dup_filter() { println!("df1 = {:?}", df1); println!("df2 = {:?}", df2); } + +#[test] +fn test_bridgeauth() { + let bdb = BridgeDb::new(20); + let mut ba = BridgeAuth::new(bdb.pubkey); + ba.advance_day(); + ba.advance_days(30); +}