From a6e33aafea89ba86ac94bbc33a503f1ef5644828 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 May 2022 13:36:45 +0200 Subject: Fix things --- Cargo.lock | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 4 +++- src/bayou.rs | 4 ++-- src/login/mod.rs | 28 ++++++++++++++--------- src/main.rs | 5 +++++ 5 files changed, 94 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39a6fa4..1d4104d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.57" @@ -290,6 +299,19 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -520,6 +542,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "hyper" version = "0.14.18" @@ -617,10 +648,10 @@ dependencies = [ [[package]] name = "k2v-client" version = "0.1.0" -source = "git+https://git.deuxfleurs.fr/Deuxfleurs/garage.git#64c193e3dbb536d5d3c2881bc9aebbb3e4e6272e" dependencies = [ "base64", "http", + "log", "rusoto_core", "rusoto_credential", "rusoto_signature", @@ -676,6 +707,7 @@ dependencies = [ "im", "itertools", "k2v-client", + "pretty_env_logger", "rand", "rmp-serde", "rpassword", @@ -876,6 +908,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -909,6 +951,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.18" @@ -977,6 +1025,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + [[package]] name = "remove_dir_all" version = "0.5.3" diff --git a/Cargo.toml b/Cargo.toml index 0205f10..addf945 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ clap = { version = "3.1.18", features = ["derive", "env"] } hex = "0.4" im = "15" itertools = "0.10" +pretty_env_logger = "0.4" rusoto_core = "0.48.0" rusoto_credential = "0.48.0" rusoto_s3 = "0.48" @@ -28,4 +29,5 @@ tokio = "1.17.0" toml = "0.5" zstd = { version = "0.9", default-features = false } -k2v-client = { git = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git" } +#k2v-client = { git = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git" } +k2v-client = { path = "../garage/src/k2v-client" } 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