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: add hidden types and seed words to key manager #4925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5841cde
first commit
jorgeantonio21 Nov 11, 2022
cc21bd9
add seed words
jorgeantonio21 Nov 15, 2022
68bc795
first commit
jorgeantonio21 Nov 15, 2022
9b22bc6
merge development and resolve conflicts
jorgeantonio21 Nov 16, 2022
8b5dca7
address PR changes
jorgeantonio21 Nov 16, 2022
1f0c191
revert unnecessary changes
jorgeantonio21 Nov 16, 2022
b703522
add imports
jorgeantonio21 Nov 17, 2022
f39caac
add serde imports
jorgeantonio21 Nov 17, 2022
2b73026
merge development and resolve conflicts
jorgeantonio21 Nov 18, 2022
bf78cd6
update tari-utilities tag version
jorgeantonio21 Nov 18, 2022
7d7c25c
remove unused dependencies
jorgeantonio21 Nov 18, 2022
f0a16bc
update dependencies and merge development
jorgeantonio21 Nov 21, 2022
85f3b00
update to newer version of tari-crypto + resolve compiler errors
jorgeantonio21 Nov 21, 2022
8d65187
improve code chunks
jorgeantonio21 Nov 21, 2022
b2c6912
Merge branch 'development' into ja-add-zeroize-to-kdfs
jorgeantonio21 Nov 21, 2022
c98c1cd
merge development and compiled tests
jorgeantonio21 Nov 21, 2022
dd08109
catching bugs
jorgeantonio21 Nov 21, 2022
7ebbb1b
add comments
jorgeantonio21 Nov 21, 2022
654364d
add refactor
jorgeantonio21 Nov 21, 2022
75ee612
cargo fmt
jorgeantonio21 Nov 21, 2022
7924a23
refactor get_recovery_seed
jorgeantonio21 Nov 21, 2022
4568c71
Merge branch 'development' into ja-add-zeroize-to-kdfs
jorgeantonio21 Nov 21, 2022
a59985b
further refactor
jorgeantonio21 Nov 21, 2022
d284a4f
Merge branch 'development' into ja-add-zeroize-to-kdfs
jorgeantonio21 Nov 22, 2022
0808539
address PR comments
jorgeantonio21 Nov 22, 2022
c450789
address one more comment
jorgeantonio21 Nov 22, 2022
992b62f
reduce allocations, while preserving security
jorgeantonio21 Nov 22, 2022
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
133 changes: 71 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tonic = "0.6.2"
tracing = "0.1.26"
unicode-segmentation = "1.6.0"
unicode-width = "0.1"
zeroize = "1.3.0"

[dependencies.tari_core]
path = "../../base_layer/core"
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ pub async fn init_wallet(
}
if let Some(file_name) = seed_words_file_name {
let seed_words = wallet.get_seed_words(&MnemonicLanguage::English)?.join(" ");
let _result = fs::write(file_name, seed_words).map_err(|e| {
let _result = fs::write(file_name, seed_words.reveal()).map_err(|e| {
ExitError::new(
ExitCode::WalletError,
&format!("Problem writing seed words to file: {}", e),
Expand Down Expand Up @@ -549,7 +549,7 @@ fn confirm_seed_words(wallet: &mut WalletSqlite) -> Result<(), ExitError> {
println!("WRITE THEM DOWN OR COPY THEM NOW. THIS IS YOUR ONLY CHANCE TO DO SO.");
println!();
println!("=========================");
println!("{}", seed_words.join(" "));
println!("{}", seed_words.join(" ").reveal());
println!("=========================");
println!("\x07"); // beep!

Expand Down
19 changes: 11 additions & 8 deletions applications/tari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ use tari_common::{
configuration::bootstrap::ApplicationType,
exit_codes::{ExitCode, ExitError},
};
use tari_key_manager::cipher_seed::CipherSeed;
use tari_crypto::tari_utilities::Hidden;
use tari_key_manager::{cipher_seed::CipherSeed, SeedWords};
#[cfg(all(unix, feature = "libtor"))]
use tari_libtor::tor::Tor;
use tari_shutdown::Shutdown;
Expand Down Expand Up @@ -213,13 +214,15 @@ fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option<SafePassword> {
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() {
let seed_words: Vec<String> = cli
.seed_words
.clone()
.unwrap()
.split_whitespace()
.map(|v| v.to_string())
.collect();
// need to zeroize first, to clean up memory of cli.seed_words clone
let seed_words: SeedWords = SeedWords::new(
cli.seed_words
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
.as_ref()
.unwrap()
.split_whitespace()
.map(|s| Hidden::hide(s.to_string()))
.collect(),
);
get_seed_from_seed_words(seed_words)?
} else {
prompt_private_key_from_seed_words()?
Expand Down
11 changes: 7 additions & 4 deletions applications/tari_console_wallet/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use futures::FutureExt;
use log::*;
use rustyline::Editor;
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic};
use tari_crypto::tari_utilities::Hidden;
use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic, SeedWords};
use tari_shutdown::Shutdown;
use tari_utilities::hex::Hex;
use tari_wallet::{
Expand All @@ -37,6 +38,7 @@ use tari_wallet::{
WalletSqlite,
};
use tokio::sync::broadcast;
use zeroize::Zeroizing;

use crate::wallet_modes::PeerConfig;

Expand All @@ -51,8 +53,9 @@ pub fn prompt_private_key_from_seed_words() -> Result<CipherSeed, ExitError> {
println!("Recovery Mode");
println!();
println!("Type or paste all of your seed words on one line, only separated by spaces.");
let input = rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?;
let seed_words: Vec<String> = input.split_whitespace().map(str::to_string).collect();
let input = Zeroizing::new(rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?);
let seed_words: SeedWords =
jorgeantonio21 marked this conversation as resolved.
Show resolved Hide resolved
SeedWords::new(input.split_whitespace().map(|s| Hidden::hide(s.to_string())).collect());

match CipherSeed::from_mnemonic(&seed_words, None) {
Ok(seed) => break Ok(seed),
Expand All @@ -66,7 +69,7 @@ pub fn prompt_private_key_from_seed_words() -> Result<CipherSeed, ExitError> {
}

/// Return seed matching the seed words.
pub fn get_seed_from_seed_words(seed_words: Vec<String>) -> Result<CipherSeed, ExitError> {
pub fn get_seed_from_seed_words(seed_words: SeedWords) -> Result<CipherSeed, ExitError> {
debug!(target: LOG_TARGET, "Return seed derived from the provided seed words");
match CipherSeed::from_mnemonic(&seed_words, None) {
Ok(seed) => Ok(seed),
Expand Down
Loading