Start creating the bridge authority
This commit is contained in:
parent
3ccd3087cf
commit
996463d1c0
|
@ -16,6 +16,7 @@ lazy_static = "1"
|
||||||
hex_fmt = "0.3"
|
hex_fmt = "0.3"
|
||||||
aes-gcm = "0.8"
|
aes-gcm = "0.8"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
|
time = "0.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["u64_backend"]
|
default = ["u64_backend"]
|
||||||
|
|
|
@ -18,6 +18,7 @@ The notation follows that of the paper "Hyphae: Social Secret Sharing"
|
||||||
extern crate zkp;
|
extern crate zkp;
|
||||||
|
|
||||||
pub mod bridge_table;
|
pub mod bridge_table;
|
||||||
|
pub mod cred;
|
||||||
pub mod dup_filter;
|
pub mod dup_filter;
|
||||||
|
|
||||||
use sha2::Sha512;
|
use sha2::Sha512;
|
||||||
|
@ -114,11 +115,11 @@ pub const OPENINV_LENGTH: usize = 32 // the length of the random
|
||||||
|
|
||||||
impl BridgeDb {
|
impl BridgeDb {
|
||||||
/// Create the 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 mut csprng = OsRng {};
|
||||||
let keypair = Keypair::generate(&mut csprng);
|
let keypair = Keypair::generate(&mut csprng);
|
||||||
let pubkey = keypair.public;
|
let pubkey = keypair.public;
|
||||||
BridgeDb {
|
Self {
|
||||||
keypair,
|
keypair,
|
||||||
pubkey,
|
pubkey,
|
||||||
num_openinv_buckets,
|
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<Scalar>,
|
||||||
|
/// Duplicate filter for credential ids
|
||||||
|
id_filter: dup_filter::DupFilter<Scalar>,
|
||||||
|
|
||||||
|
/// 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use lox::dup_filter;
|
use lox::dup_filter;
|
||||||
use lox::dup_filter::SeenType::{Fresh, Seen};
|
use lox::dup_filter::SeenType::{Fresh, Seen};
|
||||||
|
use lox::BridgeAuth;
|
||||||
use lox::BridgeDb;
|
use lox::BridgeDb;
|
||||||
|
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
|
@ -44,3 +45,11 @@ fn test_dup_filter() {
|
||||||
println!("df1 = {:?}", df1);
|
println!("df1 = {:?}", df1);
|
||||||
println!("df2 = {:?}", df2);
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue