aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock67
-rw-r--r--Cargo.toml4
-rw-r--r--src/bayou.rs4
-rw-r--r--src/login/mod.rs28
-rw-r--r--src/main.rs5
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
@@ -3,6 +3,15 @@
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -291,6 +300,19 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -521,6 +543,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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",
@@ -877,6 +909,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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -910,6 +952,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -978,6 +1026,23 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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<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 {