From 73f30320a6ba03e2d9b908211bee8368053fe29e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 23 Mar 2021 16:53:25 +1100 Subject: [PATCH] Seed should neither be Clone nor Copy It is better to not copy around secret data within our process to make heartbleed-like attacks harder. --- swap/src/bin/swap.rs | 10 +++++----- swap/src/seed.rs | 2 +- swap/tests/testutils/mod.rs | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 7f05fa12..2455753c 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -101,7 +101,7 @@ async fn main() -> Result<()> { } let bitcoin_wallet = - init_bitcoin_wallet(electrum_rpc_url, seed, data_dir.clone(), env_config).await?; + init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir.clone(), env_config).await?; let (monero_wallet, _process) = init_monero_wallet(data_dir, monero_daemon_host, env_config).await?; let bitcoin_wallet = Arc::new(bitcoin_wallet); @@ -183,7 +183,7 @@ async fn main() -> Result<()> { } let bitcoin_wallet = - init_bitcoin_wallet(electrum_rpc_url, seed, data_dir.clone(), env_config).await?; + init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir.clone(), env_config).await?; let (monero_wallet, _process) = init_monero_wallet(data_dir, monero_daemon_host, env_config).await?; let bitcoin_wallet = Arc::new(bitcoin_wallet); @@ -223,7 +223,7 @@ async fn main() -> Result<()> { electrum_rpc_url, } => { let bitcoin_wallet = - init_bitcoin_wallet(electrum_rpc_url, seed, data_dir, env_config).await?; + init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir, env_config).await?; let resume_state = db.get_state(swap_id)?.try_into_bob()?.into(); let cancel = @@ -248,7 +248,7 @@ async fn main() -> Result<()> { electrum_rpc_url, } => { let bitcoin_wallet = - init_bitcoin_wallet(electrum_rpc_url, seed, data_dir, env_config).await?; + init_bitcoin_wallet(electrum_rpc_url, &seed, data_dir, env_config).await?; let resume_state = db.get_state(swap_id)?.try_into_bob()?.into(); @@ -260,7 +260,7 @@ async fn main() -> Result<()> { async fn init_bitcoin_wallet( electrum_rpc_url: Url, - seed: Seed, + seed: &Seed, data_dir: PathBuf, env_config: Config, ) -> Result { diff --git a/swap/src/seed.rs b/swap/src/seed.rs index 7432adc5..1536959d 100644 --- a/swap/src/seed.rs +++ b/swap/src/seed.rs @@ -15,7 +15,7 @@ use std::path::{Path, PathBuf}; pub const SEED_LENGTH: usize = 32; -#[derive(Clone, Copy, Eq, PartialEq)] +#[derive(Eq, PartialEq)] pub struct Seed([u8; SEED_LENGTH]); impl Seed { diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index d9070d8e..d22fc2e9 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -43,7 +43,6 @@ pub struct StartingBalances { pub btc: bitcoin::Amount, } -#[derive(Clone)] struct BobParams { seed: Seed, db_path: PathBuf,