From a6e33aafea89ba86ac94bbc33a503f1ef5644828 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 May 2022 13:36:45 +0200 Subject: Fix things --- src/bayou.rs | 4 ++-- src/login/mod.rs | 28 ++++++++++++++++++---------- src/main.rs | 5 +++++ 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/bayou.rs b/src/bayou.rs index cc83667..56203eb 100644 --- a/src/bayou.rs +++ b/src/bayou.rs @@ -19,8 +19,8 @@ const SAVE_STATE_EVERY: usize = 64; // Checkpointing interval constants: a checkpoint is not made earlier // than CHECKPOINT_INTERVAL time after the last one, and is not made // if there are less than CHECKPOINT_MIN_OPS new operations since last one. -const CHECKPOINT_INTERVAL: Duration = Duration::from_secs(60); -const CHECKPOINT_MIN_OPS: usize = 4; +const CHECKPOINT_INTERVAL: Duration = Duration::from_secs(3600); +const CHECKPOINT_MIN_OPS: usize = 16; // HYPOTHESIS: processes are able to communicate in a synchronous // fashion in times that are small compared to CHECKPOINT_INTERVAL. // More precisely, if a process tried to save an operation within the last diff --git a/src/login/mod.rs b/src/login/mod.rs index 3d15d6b..de04126 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -3,7 +3,7 @@ pub mod static_provider; use std::collections::BTreeMap; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Context, Result}; use async_trait::async_trait; use k2v_client::{ BatchInsertOp, BatchReadOp, CausalValue, CausalityToken, Filter, K2vClient, K2vValue, @@ -133,7 +133,8 @@ impl CryptoKeys { k2v_insert_single_key("keys", "public", None, &keys.public), k2v_insert_single_key("keys", &password_sortkey, None, &password_blob), ]) - .await?; + .await + .context("InsertBatch for salt, public, and password")?; Ok(keys) } @@ -164,7 +165,8 @@ impl CryptoKeys { k2v_insert_single_key("keys", "salt", None, &ident_salt), k2v_insert_single_key("keys", "public", None, &keys.public), ]) - .await?; + .await + .context("InsertBatch for salt and public")?; Ok(keys) } @@ -182,7 +184,8 @@ impl CryptoKeys { let password_blob = { let mut params = k2v .read_batch(&[k2v_read_single_key("keys", &password_sortkey)]) - .await?; + .await + .context("ReadBatch to read password")?; if params.len() != 1 { bail!( "Invalid response from k2v storage: {:?} (expected one item)", @@ -280,7 +283,8 @@ impl CryptoKeys { ct, &password_blob, )]) - .await?; + .await + .context("InsertBatch for new password")?; Ok(()) } @@ -311,7 +315,8 @@ impl CryptoKeys { } k2v.delete_item("keys", &password_sortkey, pw.causality.clone()) - .await?; + .await + .context("DeleteItem for password")?; Ok(()) } @@ -324,7 +329,8 @@ impl CryptoKeys { k2v_read_single_key("keys", "salt"), k2v_read_single_key("keys", "public"), ]) - .await?; + .await + .context("ReadBatch for salt and public in check_uninitialized")?; if params.len() != 2 { bail!( "Invalid response from k2v storage: {:?} (expected two items)", @@ -344,7 +350,8 @@ impl CryptoKeys { k2v_read_single_key("keys", "salt"), k2v_read_single_key("keys", "public"), ]) - .await?; + .await + .context("ReadBatch for salt and public in load_salt_and_public")?; if params.len() != 2 { bail!( "Invalid response from k2v storage: {:?} (expected two items)", @@ -399,7 +406,8 @@ impl CryptoKeys { tombstones: false, single_item: false, }]) - .await?; + .await + .context("ReadBatch for prefix password: in list_existing_passwords")?; if res.len() != 1 { bail!("unexpected k2v result: {:?}, expected one item", res); } @@ -443,7 +451,7 @@ pub fn argon2_kdf(salt: &[u8], password: &[u8], output_len: usize) -> Result Result<()> { + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "mailrage=info,k2v_client=info") + } + pretty_env_logger::init(); + let args = Args::parse(); match args.command { -- cgit v1.2.3