From 5f35397080d43281fe295a1c667425ed54e68ddb Mon Sep 17 00:00:00 2001 From: Tommy Volk Date: Wed, 18 Dec 2024 12:52:43 -0600 Subject: [PATCH] feat: gateway CLI can generate bcrypt password hashes --- Cargo.lock | 1 + gateway/cli/Cargo.toml | 1 + gateway/cli/src/general_commands.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f066caf0b15..f1b15ce0cbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2556,6 +2556,7 @@ name = "fedimint-gateway-cli" version = "0.6.0-alpha" dependencies = [ "anyhow", + "bcrypt", "bitcoin", "clap", "clap_complete", diff --git a/gateway/cli/Cargo.toml b/gateway/cli/Cargo.toml index c7feb92ff1d..1871f66ecfe 100644 --- a/gateway/cli/Cargo.toml +++ b/gateway/cli/Cargo.toml @@ -20,6 +20,7 @@ path = "src/main.rs" [dependencies] anyhow = { workspace = true } +bcrypt = { workspace = true } bitcoin = { workspace = true } clap = { workspace = true } clap_complete = "4.5.38" diff --git a/gateway/cli/src/general_commands.rs b/gateway/cli/src/general_commands.rs index ff9c2d2084f..2b914a14c71 100644 --- a/gateway/cli/src/general_commands.rs +++ b/gateway/cli/src/general_commands.rs @@ -50,6 +50,14 @@ pub enum GeneralCommands { #[clap(long)] event_kinds: Vec, }, + /// Create a bcrypt hash of a password, for use in gateway deployment + CreatePasswordHash { + password: String, + + /// The bcrypt cost factor to use when hashing the password + #[clap(long)] + cost: Option, + }, } impl GeneralCommands { @@ -124,6 +132,10 @@ impl GeneralCommands { .await?; print_response(payment_log); } + Self::CreatePasswordHash { password, cost } => print_response( + bcrypt::hash(password, cost.unwrap_or(bcrypt::DEFAULT_COST)) + .expect("Unable to create bcrypt hash"), + ), } Ok(())