Use ZeroingString for password and passpharse in wallet (#2285)
This commit is contained in:
committed by
Ignotus Peverell
parent
950fa0e496
commit
5cf4d7acfe
+17
-13
@@ -14,7 +14,7 @@
|
||||
|
||||
use crate::api::TLSConfig;
|
||||
use crate::util::file::get_first_line;
|
||||
use crate::util::Mutex;
|
||||
use crate::util::{Mutex, ZeroingString};
|
||||
/// Argument parsing and error handling for wallet commands
|
||||
use clap::ArgMatches;
|
||||
use failure::Fail;
|
||||
@@ -57,19 +57,23 @@ impl From<std::io::Error> for ParseError {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prompt_password(password: &Option<String>) -> String {
|
||||
fn prompt_password_stdout(prompt: &str) -> ZeroingString {
|
||||
ZeroingString::from(rpassword::prompt_password_stdout(prompt).unwrap())
|
||||
}
|
||||
|
||||
pub fn prompt_password(password: &Option<ZeroingString>) -> ZeroingString {
|
||||
match password {
|
||||
None => rpassword::prompt_password_stdout("Password: ").unwrap(),
|
||||
Some(p) => p.to_owned(),
|
||||
None => prompt_password_stdout("Password: "),
|
||||
Some(p) => p.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_password_confirm() -> String {
|
||||
let mut first = String::from("first");
|
||||
let mut second = String::from("second");
|
||||
fn prompt_password_confirm() -> ZeroingString {
|
||||
let mut first = ZeroingString::from("first");
|
||||
let mut second = ZeroingString::from("second");
|
||||
while first != second {
|
||||
first = rpassword::prompt_password_stdout("Password: ").unwrap();
|
||||
second = rpassword::prompt_password_stdout("Confirm Password: ").unwrap();
|
||||
first = prompt_password_stdout("Password: ");
|
||||
second = prompt_password_stdout("Confirm Password: ");
|
||||
}
|
||||
first
|
||||
}
|
||||
@@ -101,9 +105,9 @@ fn prompt_replace_seed() -> Result<bool, ParseError> {
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_recovery_phrase() -> Result<String, ParseError> {
|
||||
fn prompt_recovery_phrase() -> Result<ZeroingString, ParseError> {
|
||||
let interface = Arc::new(Interface::new("recover")?);
|
||||
let mut phrase = String::new();
|
||||
let mut phrase = ZeroingString::from("");
|
||||
interface.set_report_signal(Signal::Interrupt, true);
|
||||
interface.set_prompt("phrase> ")?;
|
||||
loop {
|
||||
@@ -119,7 +123,7 @@ fn prompt_recovery_phrase() -> Result<String, ParseError> {
|
||||
}
|
||||
ReadResult::Input(line) => {
|
||||
if WalletSeed::from_mnemonic(&line).is_ok() {
|
||||
phrase = line;
|
||||
phrase = ZeroingString::from(line);
|
||||
break;
|
||||
} else {
|
||||
println!();
|
||||
@@ -194,7 +198,7 @@ pub fn parse_global_args(
|
||||
let node_api_secret = get_first_line(config.node_api_secret_path.clone());
|
||||
let password = match args.value_of("pass") {
|
||||
None => None,
|
||||
Some(p) => Some(p.to_owned()),
|
||||
Some(p) => Some(ZeroingString::from(p)),
|
||||
};
|
||||
|
||||
let tls_conf = match config.tls_certificate_file.clone() {
|
||||
|
||||
Reference in New Issue
Block a user