Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet password change #5175

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct Cli {
/// possible.
#[clap(long, env = "TARI_WALLET_PASSWORD", hide_env_values = true)]
pub password: Option<SafePassword>,
/// Change the password for the console wallet
/// Change the password for the console wallet and exit
#[clap(long, alias = "update-password")]
pub change_password: bool,
/// Force wallet recovery
Expand Down
42 changes: 21 additions & 21 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,39 @@ fn prompt_password(prompt: &str) -> Result<SafePassword, ExitError> {
/// Allows the user to change the password of the wallet.
pub async fn change_password(
config: &ApplicationConfig,
arg_password: SafePassword,
existing: SafePassword,
shutdown_signal: ShutdownSignal,
non_interactive_mode: bool,
) -> Result<(), ExitError> {
let mut wallet = init_wallet(config, arg_password, None, None, shutdown_signal, non_interactive_mode).await?;
let mut wallet = init_wallet(
config,
existing.clone(),
None,
None,
shutdown_signal,
non_interactive_mode,
)
.await?;

let passphrase = prompt_password("New wallet password: ")?;
let new = prompt_password("New wallet password: ")?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: while not a reserved word in rust, it does seem strange to see new as a variable

let confirmed = prompt_password("Confirm new password: ")?;

if passphrase.reveal() != confirmed.reveal() {
if new.reveal() != confirmed.reveal() {
return Err(ExitError::new(ExitCode::InputError, "Passwords don't match!"));
}

// wallet
// .remove_encryption()
// .await
// .map_err(|e| ExitError::new(ExitCode::WalletError, e))?;

// wallet
// .apply_encryption(passphrase)
// .await
// .map_err(|e| ExitError::new(ExitCode::WalletError, e))?;

println!("Passwords match.");

// If the passphrase is weak, let the user know
display_password_feedback(&passphrase);
display_password_feedback(&new);

// TODO: remove this warning when this functionality is added
println!();
println!("WARNING: Password change functionality is not yet completed, so continue to use your existing password!");

Ok(())
// Use the existing and new passphrases to attempt to change the wallet passphrase
wallet.db.change_passphrase(&existing, &new).map_err(|e| match e {
WalletStorageError::InvalidPassphrase => {
ExitError::new(ExitCode::IncorrectOrEmptyPassword, "Your password was not changed.")
},
_ => ExitError::new(ExitCode::DatabaseError, "Your password was not changed."),
})
}

/// Populates the PeerConfig struct from:
Expand Down Expand Up @@ -667,7 +667,7 @@ pub(crate) fn boot_with_password(
},
WalletBoot::Existing | WalletBoot::Recovery => {
debug!(target: LOG_TARGET, "Prompting for password.");
prompt_password("Prompt wallet password: ")?
prompt_password("Enter wallet password: ")?
},
};

Expand Down
9 changes: 9 additions & 0 deletions base_layer/wallet/src/storage/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use tari_comms::{
tor::TorIdentity,
};
use tari_key_manager::cipher_seed::CipherSeed;
use tari_utilities::SafePassword;

use crate::{error::WalletStorageError, utxo_scanner_service::service::ScannedBlock};

Expand All @@ -57,6 +58,9 @@ pub trait WalletBackend: Send + Sync + Clone {
height: u64,
exclude_recovered: bool,
) -> Result<(), WalletStorageError>;

/// Change the passphrase used to encrypt the database
fn change_passphrase(&self, existing: &SafePassword, new: &SafePassword) -> Result<(), WalletStorageError>;
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -135,6 +139,11 @@ where T: WalletBackend + 'static
Self { db: Arc::new(db) }
}

pub fn change_passphrase(&self, existing: &SafePassword, new: &SafePassword) -> Result<(), WalletStorageError> {
self.db.change_passphrase(existing, new)?;
Ok(())
}

pub fn get_master_seed(&self) -> Result<Option<CipherSeed>, WalletStorageError> {
let c = match self.db.fetch(&DbKey::MasterSeed) {
Ok(None) => Ok(None),
Expand Down
Loading