Skip to content

Commit

Permalink
Fix up blank password validation and remove exit message
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Oct 29, 2024
1 parent 7c02437 commit bede3ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/ciphernode/cipher/src/password_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ impl PasswordManager for FilePasswordManager {
async fn set_key(&mut self, contents: Zeroizing<Vec<u8>>) -> Result<()> {
let path = &self.path;

if contents.len() == 0 {
bail!("Password must contain data!")
}

// Check if file exists
if path.exists() {
bail!("Keyfile already exists. Refusing to overwrite.");
bail!("Keyfile already exists. Refusing to overwrite.")
}

// Create new file with restrictive permissions from the start
Expand Down
11 changes: 9 additions & 2 deletions packages/ciphernode/enclave/src/commands/password/create.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
use anyhow::Result;
use anyhow::{bail, Result};
use cipher::{FilePasswordManager, PasswordManager};
use config::AppConfig;
use rpassword::prompt_password;
use zeroize::{Zeroize, Zeroizing};

fn get_zeroizing_pw_vec(input: Option<String>) -> Result<Zeroizing<Vec<u8>>> {
if let Some(mut pw_str) = input {
if pw_str.trim().is_empty() {
bail!("Password must not be blank")
}
let pw = Zeroizing::new(pw_str.trim().as_bytes().to_owned());
pw_str.zeroize();
return Ok(pw);
}

// First password entry
let mut pw_str = prompt_password("\n\nPlease enter a new password: ")?;
if pw_str.trim().is_empty() {
bail!("Password must not be blank")
}

// Second password entry for confirmation
let mut confirm_pw_str = prompt_password("Please confirm your password: ")?;

Expand All @@ -21,7 +28,7 @@ fn get_zeroizing_pw_vec(input: Option<String>) -> Result<Zeroizing<Vec<u8>>> {
// Clean up sensitive data
pw_str.zeroize();
confirm_pw_str.zeroize();
return Err(anyhow::anyhow!("Passwords do not match"));
bail!("Passwords do not match")
}

let pw = Zeroizing::new(pw_str.trim().as_bytes().to_owned());
Expand Down
1 change: 0 additions & 1 deletion packages/ciphernode/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub async fn main() {
Ok(_) => (),
Err(err) => {
eprintln!("{}", err);
eprintln!("There was a problem running. Goodbye");
std::process::exit(1);
}
}
Expand Down

0 comments on commit bede3ed

Please sign in to comment.