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

Feature/load keys on run #220

Merged
merged 3 commits into from
May 6, 2020
Merged
Changes from all commits
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
17 changes: 1 addition & 16 deletions clients/desktop/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -63,20 +61,7 @@ pub struct NymClient {
pub(crate) struct InputMessage(pub Destination, pub Vec<u8>);

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,
18 changes: 16 additions & 2 deletions clients/desktop/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -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();
}
19 changes: 17 additions & 2 deletions mixnode/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -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();
}
17 changes: 1 addition & 16 deletions mixnode/src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -38,20 +36,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,