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

fix(console_wallet): use cli.non_interactive instead of prompt to show seed words #4612

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 18 additions & 14 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ pub async fn change_password(
config: &ApplicationConfig,
arg_password: Option<SafePassword>,
shutdown_signal: ShutdownSignal,
non_interactive_mode: bool,
) -> Result<(), ExitError> {
let mut wallet = init_wallet(config, arg_password, None, None, shutdown_signal).await?;
let mut wallet = init_wallet(config, arg_password, None, None, shutdown_signal, non_interactive_mode).await?;

let passphrase = prompt_password("New wallet password: ")?;
let confirmed = prompt_password("Confirm new password: ")?;
Expand Down Expand Up @@ -248,6 +249,7 @@ pub async fn init_wallet(
seed_words_file_name: Option<PathBuf>,
recovery_seed: Option<CipherSeed>,
shutdown_signal: ShutdownSignal,
non_interactive_mode: bool,
) -> Result<WalletSqlite, ExitError> {
fs::create_dir_all(
&config
Expand Down Expand Up @@ -359,27 +361,29 @@ pub async fn init_wallet(
debug!(target: LOG_TARGET, "Wallet is not encrypted.");

// create using --password arg if supplied and skip seed words confirmation
let (passphrase, interactive) = if let Some(password) = arg_password {
debug!(target: LOG_TARGET, "Setting password from command line argument.");

(password, false)
} else {
debug!(target: LOG_TARGET, "Prompting for password.");
let password = prompt_password("Create wallet password: ")?;
let confirmed = prompt_password("Confirm wallet password: ")?;
let passphrase = match arg_password {
Some(password) => {
debug!(target: LOG_TARGET, "Setting password from command line argument.");
password
},
None => {
debug!(target: LOG_TARGET, "Prompting for password.");
let password = prompt_password("Create wallet password: ")?;
let confirmed = prompt_password("Confirm wallet password: ")?;

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

(password, true)
password
},
};

wallet.apply_encryption(passphrase).await?;

debug!(target: LOG_TARGET, "Wallet encrypted.");

if interactive && recovery_seed.is_none() {
if !non_interactive_mode && recovery_seed.is_none() {
match confirm_seed_words(&mut wallet) {
Ok(()) => {
print!("\x1Bc"); // Clear the screen
Expand Down
25 changes: 17 additions & 8 deletions applications/tari_console_wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use tari_key_manager::cipher_seed::CipherSeed;
#[cfg(all(unix, feature = "libtor"))]
use tari_libtor::tor::Tor;
use tari_shutdown::Shutdown;
use tari_utilities::SafePassword;
use tracing_subscriber::{layer::SubscriberExt, Registry};
use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode};

Expand Down Expand Up @@ -92,8 +93,7 @@ fn main() {
fn main_inner() -> Result<(), ExitError> {
let cli = Cli::parse();

let config_path = cli.common.config_path();
let cfg = load_configuration(config_path.as_path(), true, &cli)?;
let cfg = load_configuration(cli.common.config_path().as_path(), true, &cli)?;
initialize_logging(
&cli.common.log_config_path("wallet"),
include_str!("../log4rs_sample.yml"),
Expand All @@ -118,11 +118,7 @@ fn main_inner() -> Result<(), ExitError> {
consts::APP_VERSION
);

let password = cli
.password
.as_ref()
.or(config.wallet.password.as_ref())
.map(|s| s.to_owned());
let password = get_password(&config, &cli);

if password.is_none() {
tari_splash_screen("Console Wallet");
Expand All @@ -141,7 +137,12 @@ fn main_inner() -> Result<(), ExitError> {

if cli.change_password {
info!(target: LOG_TARGET, "Change password requested.");
return runtime.block_on(change_password(&config, password, shutdown_signal));
return runtime.block_on(change_password(
&config,
password,
shutdown_signal,
cli.non_interactive_mode,
));
}

// Run our own Tor instance, if configured
Expand All @@ -164,6 +165,7 @@ fn main_inner() -> Result<(), ExitError> {
seed_words_file_name,
recovery_seed,
shutdown_signal,
cli.non_interactive_mode,
))?;

// Check if there is an in progress recovery in the wallet's database
Expand Down Expand Up @@ -219,6 +221,13 @@ fn main_inner() -> Result<(), ExitError> {
result
}

fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option<SafePassword> {
cli.password
.as_ref()
.or(config.wallet.password.as_ref())
sdbondi marked this conversation as resolved.
Show resolved Hide resolved
.map(|s| s.to_owned())
}

fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result<Option<CipherSeed>, ExitError> {
if matches!(boot_mode, WalletBoot::Recovery) {
let seed = if cli.seed_words.is_some() {
Expand Down