diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-20 13:36:45 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-20 13:36:45 +0200 |
commit | a6e33aafea89ba86ac94bbc33a503f1ef5644828 (patch) | |
tree | b0a9a9eeaa33da1c1e840721c4849b2364471d96 /src | |
parent | 3ac6896da966da3a73610cbe00c550e7ce4c0616 (diff) | |
download | aerogramme-a6e33aafea89ba86ac94bbc33a503f1ef5644828.tar.gz aerogramme-a6e33aafea89ba86ac94bbc33a503f1ef5644828.zip |
Fix things
Diffstat (limited to 'src')
-rw-r--r-- | src/bayou.rs | 4 | ||||
-rw-r--r-- | src/login/mod.rs | 28 | ||||
-rw-r--r-- | src/main.rs | 5 |
3 files changed, 25 insertions, 12 deletions
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<Vec .map_err(|e| anyhow!("Invalid argon2 params: {}", e))?; let argon2 = Argon2::new(Algorithm::default(), Version::default(), params); - let salt = base64::encode(salt); + let salt = base64::encode_config(salt, base64::STANDARD_NO_PAD); let hash = argon2 .hash_password(password, &salt) .map_err(|e| anyhow!("Unable to hash: {}", e))?; diff --git a/src/main.rs b/src/main.rs index dcdd335..a2630d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,11 @@ struct StorageCredsArgs { #[tokio::main] async fn main() -> 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 { |