secret store separated from util (#1304)
* bump rust-crypto * initial version of account provider utilizing secret store * update lazy_static to latest version * AccountProvider accounts method * new AccountProvider tests in progress * basic tests for new AccountProvider * ethcore compiles with new account provider and secret store * ethcore-rpc build now compiling with new AccountProvider * most rpc tests passing with new accounts_provider * fixed basic_authority tests * fixed eth_transaction_count rpc test * fixed mocked/eth.rs tests * fixed personal tests * fixed personal signer rpc tests * removed warnings * parity compiling fine with new sstore * fixed import direction * do not unlock temporarily when we have the password * removed TODO in account import * display warning on auto account import failure * fixed compiling of ethstore on windows * ethstore as a part of parity repo * added ethkey
This commit is contained in:
@@ -24,7 +24,7 @@ use docopt::Docopt;
|
||||
|
||||
use die::*;
|
||||
use util::*;
|
||||
use util::keys::store::{ImportKeySet, AccountService};
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use util::network_settings::NetworkSettings;
|
||||
use ethcore::client::{append_path, get_db_path, ClientConfig, Switch, VMType};
|
||||
use ethcore::ethereum;
|
||||
@@ -249,7 +249,10 @@ impl Configuration {
|
||||
sync_config
|
||||
}
|
||||
|
||||
pub fn account_service(&self) -> AccountService {
|
||||
pub fn account_service(&self) -> AccountProvider {
|
||||
use ethcore::ethstore::{import_accounts, EthStore};
|
||||
use ethcore::ethstore::dir::{GethDirectory, DirectoryType, DiskDirectory};
|
||||
|
||||
// Secret Store
|
||||
let passwords = self.args.flag_password.iter().flat_map(|filename| {
|
||||
BufReader::new(&File::open(filename).unwrap_or_else(|_| die!("{} Unable to read password file. Ensure it exists and permissions are correct.", filename)))
|
||||
@@ -258,18 +261,30 @@ impl Configuration {
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
}).collect::<Vec<_>>();
|
||||
let import_keys = match (self.args.flag_no_import_keys, self.args.flag_testnet) {
|
||||
(true, _) => ImportKeySet::None,
|
||||
(false, false) => ImportKeySet::Legacy,
|
||||
(false, true) => ImportKeySet::LegacyTestnet,
|
||||
};
|
||||
let account_service = AccountService::with_security(Path::new(&self.keys_path()), self.keys_iterations(), import_keys);
|
||||
|
||||
if !self.args.flag_no_import_keys {
|
||||
let dir_type = match self.args.flag_testnet {
|
||||
true => DirectoryType::Testnet,
|
||||
false => DirectoryType::Main,
|
||||
};
|
||||
|
||||
let from = GethDirectory::open(dir_type);
|
||||
let to = DiskDirectory::create(self.keys_path()).unwrap();
|
||||
if let Err(e) = import_accounts(&from, &to) {
|
||||
warn!("Could not import accounts {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
let dir = Box::new(DiskDirectory::create(self.keys_path()).unwrap());
|
||||
let iterations = self.keys_iterations();
|
||||
let account_service = AccountProvider::new(Box::new(EthStore::open_with_iterations(dir, iterations).unwrap()));
|
||||
|
||||
if let Some(ref unlocks) = self.args.flag_unlock {
|
||||
for d in unlocks.split(',') {
|
||||
let a = Address::from_str(clean_0x(d)).unwrap_or_else(|_| {
|
||||
die!("{}: Invalid address for --unlock. Must be 40 hex characters, without the 0x at the beginning.", d)
|
||||
});
|
||||
if passwords.iter().find(|p| account_service.unlock_account_no_expire(&a, p).is_ok()).is_none() {
|
||||
if passwords.iter().find(|p| account_service.unlock_account_permanently(a, (*p).clone()).is_ok()).is_none() {
|
||||
die!("No password given to unlock account {}. Pass the password using `--password`.", a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,17 @@ use std::sync::Arc;
|
||||
use ethcore::client::Client;
|
||||
use ethcore::service::{NetSyncMessage, SyncMessage};
|
||||
use ethsync::EthSync;
|
||||
use util::keys::store::AccountService;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use util::{TimerToken, IoHandler, IoContext, NetworkService, NetworkIoMessage};
|
||||
|
||||
use informant::Informant;
|
||||
|
||||
const INFO_TIMER: TimerToken = 0;
|
||||
|
||||
const ACCOUNT_TICK_TIMER: TimerToken = 10;
|
||||
const ACCOUNT_TICK_MS: u64 = 60000;
|
||||
|
||||
pub struct ClientIoHandler {
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub accounts: Arc<AccountService>,
|
||||
pub accounts: Arc<AccountProvider>,
|
||||
pub info: Informant,
|
||||
pub network: Arc<NetworkService<SyncMessage>>,
|
||||
}
|
||||
@@ -39,13 +36,11 @@ pub struct ClientIoHandler {
|
||||
impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
||||
fn initialize(&self, io: &IoContext<NetSyncMessage>) {
|
||||
io.register_timer(INFO_TIMER, 5000).expect("Error registering timer");
|
||||
io.register_timer(ACCOUNT_TICK_TIMER, ACCOUNT_TICK_MS).expect("Error registering account timer");
|
||||
}
|
||||
|
||||
fn timeout(&self, _io: &IoContext<NetSyncMessage>, timer: TimerToken) {
|
||||
match timer {
|
||||
INFO_TIMER => { self.info.tick(&self.client, Some(&self.sync)); }
|
||||
ACCOUNT_TICK_TIMER => { self.accounts.tick(); },
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,9 +478,15 @@ fn execute_signer(conf: Configuration) {
|
||||
}
|
||||
|
||||
fn execute_account_cli(conf: Configuration) {
|
||||
use util::keys::store::SecretStore;
|
||||
use ethcore::ethstore::{SecretStore, EthStore, import_accounts};
|
||||
use ethcore::ethstore::dir::DiskDirectory;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use rpassword::read_password;
|
||||
let mut secret_store = SecretStore::with_security(Path::new(&conf.keys_path()), conf.keys_iterations());
|
||||
|
||||
let dir = Box::new(DiskDirectory::create(conf.keys_path()).unwrap());
|
||||
let iterations = conf.keys_iterations();
|
||||
let secret_store = AccountProvider::new(Box::new(EthStore::open_with_iterations(dir, iterations).unwrap()));
|
||||
|
||||
if conf.args.cmd_new {
|
||||
println!("Please note that password is NOT RECOVERABLE.");
|
||||
print!("Type password: ");
|
||||
@@ -498,15 +504,22 @@ fn execute_account_cli(conf: Configuration) {
|
||||
println!("{:?}", new_address);
|
||||
return;
|
||||
}
|
||||
|
||||
if conf.args.cmd_list {
|
||||
println!("Known addresses:");
|
||||
for &(addr, _) in &secret_store.accounts().unwrap() {
|
||||
for addr in &secret_store.accounts() {
|
||||
println!("{:?}", addr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if conf.args.cmd_import {
|
||||
let imported = util::keys::import_keys_paths(&mut secret_store, &conf.args.arg_path).unwrap();
|
||||
let to = DiskDirectory::create(conf.keys_path()).unwrap();
|
||||
let mut imported = 0;
|
||||
for path in &conf.args.arg_path {
|
||||
let from = DiskDirectory::at(path);
|
||||
imported += import_accounts(&from, &to).unwrap_or_else(|e| die!("Could not import accounts {}", e)).len();
|
||||
}
|
||||
println!("Imported {} keys", imported);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use ethsync::EthSync;
|
||||
use ethcore::miner::{Miner, ExternalMiner};
|
||||
use ethcore::client::Client;
|
||||
use util::RotatingLogger;
|
||||
use util::keys::store::AccountService;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use util::network_settings::NetworkSettings;
|
||||
|
||||
#[cfg(feature="rpc")]
|
||||
@@ -83,7 +83,7 @@ pub struct Dependencies {
|
||||
pub signer_queue: Arc<ConfirmationsQueue>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<EthSync>,
|
||||
pub secret_store: Arc<AccountService>,
|
||||
pub secret_store: Arc<AccountProvider>,
|
||||
pub miner: Arc<Miner>,
|
||||
pub external_miner: Arc<ExternalMiner>,
|
||||
pub logger: Arc<RotatingLogger>,
|
||||
|
||||
Reference in New Issue
Block a user