From bea5ba715755f8749a543b5c490211c3f1070efb Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Wed, 6 May 2020 15:11:00 +0100 Subject: [PATCH 1/3] Mixnode keys loaded in run command --- mixnode/src/commands/run.rs | 19 +++++++++++++++++-- mixnode/src/node/mod.rs | 15 +-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index 467f06d73d3..14f2e585324 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -13,10 +13,12 @@ // limitations under the License. use crate::commands::override_config; -use crate::config::Config; +use crate::config::{persistence::pathfinder::MixNodePathfinder, Config}; use crate::node::MixNode; use clap::{App, Arg, ArgMatches}; use config::NymConfig; +use crypto::encryption; +use pemstore::pemstore::PemStore; pub fn command_args<'a, 'b>() -> App<'a, 'b> { App::new("run") @@ -94,6 +96,17 @@ fn special_addresses() -> Vec<&'static str> { vec!["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"] } +fn load_sphinx_keys(config_file: &Config) -> encryption::KeyPair { + let sphinx_keypair = PemStore::new(MixNodePathfinder::new_from_config(&config_file)) + .read_encryption() + .expect("Failed to read stored sphinx key files"); + println!( + "Public key: {}\n", + sphinx_keypair.public_key().to_base58_string() + ); + sphinx_keypair +} + pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); @@ -105,6 +118,8 @@ pub fn execute(matches: &ArgMatches) { config = override_config(config, matches); + let sphinx_keypair = load_sphinx_keys(&config); + let listening_ip_string = config.get_listening_address().ip().to_string(); if special_addresses().contains(&listening_ip_string.as_ref()) { show_binding_warning(listening_ip_string); @@ -128,5 +143,5 @@ pub fn execute(matches: &ArgMatches) { config.get_announce_address() ); - MixNode::new(config).run(); + MixNode::new(config, sphinx_keypair).run(); } diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index e0e007da306..2696f9bc0cb 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -38,20 +38,7 @@ pub struct MixNode { } impl MixNode { - fn load_sphinx_keys(config_file: &Config) -> encryption::KeyPair { - let sphinx_keypair = PemStore::new(MixNodePathfinder::new_from_config(&config_file)) - .read_encryption() - .expect("Failed to read stored sphinx key files"); - println!( - "Public key: {}\n", - sphinx_keypair.public_key().to_base58_string() - ); - sphinx_keypair - } - - pub fn new(config: Config) -> Self { - let sphinx_keypair = Self::load_sphinx_keys(&config); - + pub fn new(config: Config, sphinx_keypair: encryption::KeyPair) -> Self { MixNode { runtime: Runtime::new().unwrap(), config, From 8a784b5e30af006d178facbe843948a752f66d7d Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Wed, 6 May 2020 15:11:09 +0100 Subject: [PATCH 2/3] Client keys loaded in run command --- clients/desktop/src/client/mod.rs | 15 +-------------- clients/desktop/src/commands/run.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/clients/desktop/src/client/mod.rs b/clients/desktop/src/client/mod.rs index 6972cefcb80..6d942e1c3b7 100644 --- a/clients/desktop/src/client/mod.rs +++ b/clients/desktop/src/client/mod.rs @@ -63,20 +63,7 @@ pub struct NymClient { pub(crate) struct InputMessage(pub Destination, pub Vec); impl NymClient { - fn load_identity_keys(config_file: &Config) -> MixIdentityKeyPair { - let identity_keypair = PemStore::new(ClientPathfinder::new_from_config(&config_file)) - .read_identity() - .expect("Failed to read stored identity key files"); - println!( - "Public identity key: {}\n", - identity_keypair.public_key.to_base58_string() - ); - identity_keypair - } - - pub fn new(config: Config) -> Self { - let identity_keypair = Self::load_identity_keys(&config); - + pub fn new(config: Config, identity_keypair: MixIdentityKeyPair) -> Self { NymClient { runtime: Runtime::new().unwrap(), config, diff --git a/clients/desktop/src/commands/run.rs b/clients/desktop/src/commands/run.rs index 2138f2a7ad1..964cc3116bf 100644 --- a/clients/desktop/src/commands/run.rs +++ b/clients/desktop/src/commands/run.rs @@ -14,9 +14,11 @@ use crate::client::NymClient; use crate::commands::override_config; -use crate::config::Config; +use crate::config::{persistence::pathfinder::ClientPathfinder, Config}; use clap::{App, Arg, ArgMatches}; use config::NymConfig; +use crypto::identity::MixIdentityKeyPair; +use pemstore::pemstore::PemStore; pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { App::new("run") @@ -55,6 +57,17 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { ) } +fn load_identity_keys(config_file: &Config) -> MixIdentityKeyPair { + let identity_keypair = PemStore::new(ClientPathfinder::new_from_config(&config_file)) + .read_identity() + .expect("Failed to read stored identity key files"); + println!( + "Public identity key: {}\n", + identity_keypair.public_key.to_base58_string() + ); + identity_keypair +} + pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); @@ -63,5 +76,6 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to load config file"); config = override_config(config, matches); - NymClient::new(config).run_forever(); + let identity_keypair = load_identity_keys(&config); + NymClient::new(config, identity_keypair).run_forever(); } From 0124b2ea9f32bb8a5b4ce62ab0859d774d5e1ad1 Mon Sep 17 00:00:00 2001 From: jstuczyn Date: Wed, 6 May 2020 15:12:25 +0100 Subject: [PATCH 3/3] Removed unused imports --- clients/desktop/src/client/mod.rs | 2 -- mixnode/src/node/mod.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/clients/desktop/src/client/mod.rs b/clients/desktop/src/client/mod.rs index 6d942e1c3b7..926f2106243 100644 --- a/clients/desktop/src/client/mod.rs +++ b/clients/desktop/src/client/mod.rs @@ -20,7 +20,6 @@ use crate::client::received_buffer::{ use crate::client::topology_control::{ TopologyAccessor, TopologyRefresher, TopologyRefresherConfig, }; -use crate::config::persistence::pathfinder::ClientPathfinder; use crate::config::{Config, SocketType}; use crate::websocket; use crypto::identity::MixIdentityKeyPair; @@ -31,7 +30,6 @@ use gateway_requests::auth_token::AuthToken; use log::*; use nymsphinx::chunking::split_and_prepare_payloads; use nymsphinx::{Destination, DestinationAddressBytes}; -use pemstore::pemstore::PemStore; use received_buffer::{ReceivedBufferMessage, ReconstructeredMessagesReceiver}; use tokio::runtime::Runtime; use topology::NymTopology; diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 2696f9bc0cb..7bbe8bebc45 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -12,14 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::config::persistence::pathfinder::MixNodePathfinder; use crate::config::Config; use crate::node::packet_processing::PacketProcessor; use crypto::encryption; use directory_client::presence::Topology; use futures::channel::mpsc; use log::*; -use pemstore::pemstore::PemStore; use std::net::SocketAddr; use tokio::runtime::Runtime; use topology::NymTopology;