Merge branch 'master' into path-man

Conflicts:
	parity/configuration.rs
This commit is contained in:
Nikolay Volf 2016-05-14 20:22:59 +03:00
commit 93aa6c613a
19 changed files with 85 additions and 44 deletions

12
Cargo.lock generated
View File

@ -301,7 +301,7 @@ dependencies = [
"ethsync 1.2.0", "ethsync 1.2.0",
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)", "json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -577,6 +577,16 @@ dependencies = [
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "jsonrpc-http-server"
version = "5.1.0"
source = "git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains#9c026feeb6573c82c99c8005c5d8244de68a2e30"
dependencies = [
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "kernel32-sys" name = "kernel32-sys"
version = "0.2.2" version = "0.2.2"

View File

@ -59,7 +59,7 @@ impl RandomTempPath {
impl Drop for RandomTempPath { impl Drop for RandomTempPath {
fn drop(&mut self) { fn drop(&mut self) {
if let Err(e) = fs::remove_dir_all(self.as_path()) { if let Err(e) = fs::remove_dir_all(self.as_path()) {
panic!("failed to remove temp directory, probably something failed to destroyed ({})", e); panic!("Failed to remove temp directory. Here's what prevented this from happening: ({})", e);
} }
} }
} }

View File

@ -424,7 +424,7 @@ impl<V> Client<V> where V: Verifier {
} }
impl<V> BlockChainClient for Client<V> where V: Verifier { impl<V> BlockChainClient for Client<V> where V: Verifier {
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let header = self.block_header(BlockId::Latest).unwrap(); let header = self.block_header(BlockId::Latest).unwrap();
let view = HeaderView::new(&header); let view = HeaderView::new(&header);
let last_hashes = self.build_last_hashes(view.hash()); let last_hashes = self.build_last_hashes(view.hash());
@ -439,7 +439,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
}; };
// that's just a copy of the state. // that's just a copy of the state.
let mut state = self.state(); let mut state = self.state();
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender); let balance = state.balance(&sender);
// give the sender max balance // give the sender max balance
state.sub_balance(&sender, &balance); state.sub_balance(&sender, &balance);

View File

@ -42,7 +42,7 @@ use header::{BlockNumber, Header};
use transaction::{LocalizedTransaction, SignedTransaction}; use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use filter::Filter; use filter::Filter;
use error::{ImportResult, Error}; use error::{ImportResult, ExecutionError};
use receipt::LocalizedReceipt; use receipt::LocalizedReceipt;
use engine::{Engine}; use engine::{Engine};
use trace::LocalizedTrace; use trace::LocalizedTrace;
@ -133,7 +133,7 @@ pub trait BlockChainClient : Sync + Send {
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>; fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
/// Makes a non-persistent transaction call. /// Makes a non-persistent transaction call.
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error>; fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Attempt to seal the block internally. See `Engine`. /// Attempt to seal the block internally. See `Engine`.
fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) } fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) }

View File

@ -31,7 +31,7 @@ use error::{ImportResult};
use block_queue::BlockQueueInfo; use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock, LockedBlock}; use block::{SealedBlock, ClosedBlock, LockedBlock};
use executive::Executed; use executive::Executed;
use error::Error; use error::{ExecutionError};
use engine::Engine; use engine::Engine;
use trace::LocalizedTrace; use trace::LocalizedTrace;
@ -221,7 +221,7 @@ impl TestBlockChainClient {
} }
impl BlockChainClient for TestBlockChainClient { impl BlockChainClient for TestBlockChainClient {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
Ok(self.execution_result.read().unwrap().clone().unwrap()) Ok(self.execution_result.read().unwrap().clone().unwrap())
} }

View File

@ -59,7 +59,9 @@ pub enum ExecutionError {
got: U512 got: U512
}, },
/// Returned when internal evm error occurs. /// Returned when internal evm error occurs.
Internal Internal,
/// Returned when generic transaction occurs
TransactionMalformed(String),
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -119,7 +119,7 @@ impl<'a> Executive<'a> {
} }
/// This function should be used to execute transaction. /// This function should be used to execute transaction.
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, Error> { pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, ExecutionError> {
let check = options.check_nonce; let check = options.check_nonce;
match options.tracing { match options.tracing {
true => self.transact_with_tracer(t, check, ExecutiveTracer::default()), true => self.transact_with_tracer(t, check, ExecutiveTracer::default()),
@ -128,8 +128,11 @@ impl<'a> Executive<'a> {
} }
/// Execute transaction/call with tracing enabled /// Execute transaction/call with tracing enabled
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, Error> where T: Tracer { pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, ExecutionError> where T: Tracer {
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let nonce = self.state.nonce(&sender); let nonce = self.state.nonce(&sender);
let schedule = self.engine.schedule(self.info); let schedule = self.engine.schedule(self.info);
@ -983,8 +986,8 @@ mod tests {
}; };
match res { match res {
Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature))) => (), Err(ExecutionError::TransactionMalformed(_)) => (),
_ => assert!(false, "Expected invalid signature error.") _ => assert!(false, "Expected an invalid transaction error.")
} }
} }
@ -1015,7 +1018,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got })) Err(ExecutionError::InvalidNonce { expected, got })
if expected == U256::zero() && got == U256::one() => (), if expected == U256::zero() && got == U256::one() => (),
_ => assert!(false, "Expected invalid nonce error.") _ => assert!(false, "Expected invalid nonce error.")
} }
@ -1049,7 +1052,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })) Err(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })
if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (), if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (),
_ => assert!(false, "Expected block gas limit error.") _ => assert!(false, "Expected block gas limit error.")
} }
@ -1083,7 +1086,7 @@ mod tests {
}; };
match res { match res {
Err(Error::Execution(ExecutionError::NotEnoughCash { required , got })) Err(ExecutionError::NotEnoughCash { required , got })
if required == U512::from(100_018) && got == U512::from(100_017) => (), if required == U512::from(100_018) && got == U512::from(100_017) => (),
_ => assert!(false, "Expected not enough cash error. {:?}", res) _ => assert!(false, "Expected not enough cash error. {:?}", res)
} }

View File

@ -63,7 +63,7 @@ pub use external::{ExternalMiner, ExternalMinerService};
use util::{H256, U256, Address, Bytes}; use util::{H256, U256, Address, Bytes};
use ethcore::client::{BlockChainClient, Executed}; use ethcore::client::{BlockChainClient, Executed};
use ethcore::block::{ClosedBlock}; use ethcore::block::{ClosedBlock};
use ethcore::error::{Error}; use ethcore::error::{Error, ExecutionError};
use ethcore::transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
/// Miner client API /// Miner client API
@ -150,7 +150,7 @@ pub trait MinerService : Send + Sync {
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256; fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256;
/// Call into contract code using pending state. /// Call into contract code using pending state.
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error>; fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Get storage value in pending state. /// Get storage value in pending state.
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256; fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256;

View File

@ -240,7 +240,7 @@ impl MinerService for Miner {
} }
} }
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let sealing_work = self.sealing_work.lock().unwrap(); let sealing_work = self.sealing_work.lock().unwrap();
match sealing_work.peek_last_ref() { match sealing_work.peek_last_ref() {
Some(work) => { Some(work) => {
@ -258,7 +258,10 @@ impl MinerService for Miner {
}; };
// that's just a copy of the state. // that's just a copy of the state.
let mut state = block.state().clone(); let mut state = block.state().clone();
let sender = try!(t.sender()); let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender); let balance = state.balance(&sender);
// give the sender max balance // give the sender max balance
state.sub_balance(&sender, &balance); state.sub_balance(&sender, &balance);

View File

@ -42,6 +42,9 @@ Account Options:
ACCOUNTS is a comma-delimited list of addresses. ACCOUNTS is a comma-delimited list of addresses.
--password FILE Provide a file containing a password for unlocking --password FILE Provide a file containing a password for unlocking
an account. an account.
--keys-iterations NUM Specify the number of iterations to use when deriving key
from the password (bigger is more secure)
[default: 10240].
Networking Options: Networking Options:
--port PORT Override the port on which the node should listen --port PORT Override the port on which the node should listen
@ -182,6 +185,7 @@ pub struct Args {
pub flag_password: Vec<String>, pub flag_password: Vec<String>,
pub flag_cache: Option<usize>, pub flag_cache: Option<usize>,
pub flag_keys_path: String, pub flag_keys_path: String,
pub flag_keys_iterations: u32,
pub flag_bootnodes: Option<String>, pub flag_bootnodes: Option<String>,
pub flag_network_id: Option<String>, pub flag_network_id: Option<String>,
pub flag_pruning: String, pub flag_pruning: String,

View File

@ -241,7 +241,7 @@ impl Configuration {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter() .into_iter()
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let account_service = AccountService::new_in(Path::new(&self.keys_path())); let account_service = AccountService::with_security(Path::new(&self.keys_path()), self.keys_iterations());
if let Some(ref unlocks) = self.args.flag_unlock { if let Some(ref unlocks) = self.args.flag_unlock {
for d in unlocks.split(',') { for d in unlocks.split(',') {
let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| { let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| {
@ -259,8 +259,9 @@ impl Configuration {
self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone()) self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone())
} }
pub fn rpc_cors(&self) -> Option<String> { pub fn rpc_cors(&self) -> Vec<String> {
self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone()) let cors = self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone());
cors.map_or_else(Vec::new, |c| c.split(',').map(|s| s.to_owned()).collect())
} }
fn geth_ipc_path() -> String { fn geth_ipc_path() -> String {
@ -360,7 +361,7 @@ mod tests {
assert_eq!(net.rpc_enabled, true); assert_eq!(net.rpc_enabled, true);
assert_eq!(net.rpc_interface, "all".to_owned()); assert_eq!(net.rpc_interface, "all".to_owned());
assert_eq!(net.rpc_port, 8000); assert_eq!(net.rpc_port, 8000);
assert_eq!(conf.rpc_cors(), Some("*".to_owned())); assert_eq!(conf.rpc_cors(), vec!["*".to_owned()]);
assert_eq!(conf.rpc_apis(), "web3,eth".to_owned()); assert_eq!(conf.rpc_apis(), "web3,eth".to_owned());
} }

View File

@ -219,7 +219,7 @@ fn flush_stdout() {
fn execute_account_cli(conf: Configuration) { fn execute_account_cli(conf: Configuration) {
use util::keys::store::SecretStore; use util::keys::store::SecretStore;
use rpassword::read_password; use rpassword::read_password;
let mut secret_store = SecretStore::new_in(Path::new(&conf.keys_path())); let mut secret_store = SecretStore::with_security(Path::new(&conf.keys_path()), conf.keys_iterations());
if conf.args.cmd_new { if conf.args.cmd_new {
println!("Please note that password is NOT RECOVERABLE."); println!("Please note that password is NOT RECOVERABLE.");
print!("Type password: "); print!("Type password: ");

View File

@ -41,7 +41,7 @@ pub struct HttpConfiguration {
pub interface: String, pub interface: String,
pub port: u16, pub port: u16,
pub apis: String, pub apis: String,
pub cors: Option<String>, pub cors: Vec<String>,
} }
pub struct IpcConfiguration { pub struct IpcConfiguration {
@ -139,11 +139,11 @@ pub fn setup_http_rpc_server(
pub fn setup_http_rpc_server( pub fn setup_http_rpc_server(
dependencies: &Arc<Dependencies>, dependencies: &Arc<Dependencies>,
url: &SocketAddr, url: &SocketAddr,
cors_domain: Option<String>, cors_domains: Vec<String>,
apis: Vec<&str>, apis: Vec<&str>,
) -> RpcServer { ) -> RpcServer {
let server = setup_rpc_server(apis, dependencies); let server = setup_rpc_server(apis, dependencies);
let start_result = server.start_http(url, cors_domain); let start_result = server.start_http(url, cors_domains);
let deps = dependencies.clone(); let deps = dependencies.clone();
match start_result { match start_result {
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err), Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),

View File

@ -13,7 +13,7 @@ log = "0.3"
serde = "0.7.0" serde = "0.7.0"
serde_json = "0.7.0" serde_json = "0.7.0"
jsonrpc-core = "2.0" jsonrpc-core = "2.0"
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" } jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git", branch = "multiple_cors_domains" }
ethcore-util = { path = "../util" } ethcore-util = { path = "../util" }
ethcore = { path = "../ethcore" } ethcore = { path = "../ethcore" }
ethash = { path = "../ethash" } ethash = { path = "../ethash" }

View File

@ -59,9 +59,11 @@ impl RpcServer {
} }
/// Start http server asynchronously and returns result with `Server` handle on success or an error. /// Start http server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_http(&self, addr: &SocketAddr, cors_domain: Option<String>) -> Result<Server, RpcServerError> { pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
let cors_domain = cors_domain.to_owned(); let cors_domains = cors_domains.into_iter()
Server::start(addr, self.handler.clone(), cors_domain.map(jsonrpc_http_server::AccessControlAllowOrigin::Value)) .map(jsonrpc_http_server::AccessControlAllowOrigin::Value)
.collect();
Server::start(addr, self.handler.clone(), cors_domains)
} }
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error. /// Start ipc server asynchronously and returns result with `Server` handle on success or an error.

View File

@ -18,7 +18,7 @@
use util::{Address, H256, Bytes, U256, FixedHash, Uint}; use util::{Address, H256, Bytes, U256, FixedHash, Uint};
use util::standard::*; use util::standard::*;
use ethcore::error::Error; use ethcore::error::{Error, ExecutionError};
use ethcore::client::{BlockChainClient, Executed}; use ethcore::client::{BlockChainClient, Executed};
use ethcore::block::{ClosedBlock, IsBlock}; use ethcore::block::{ClosedBlock, IsBlock};
use ethcore::transaction::SignedTransaction; use ethcore::transaction::SignedTransaction;
@ -179,7 +179,7 @@ impl MinerService for TestMinerService {
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone()) self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
} }
fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, Error> { fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
unimplemented!(); unimplemented!();
} }

View File

@ -1193,7 +1193,7 @@ impl ChainSync {
let mut rlp_stream = RlpStream::new_list(route.blocks.len()); let mut rlp_stream = RlpStream::new_list(route.blocks.len());
for block_hash in route.blocks { for block_hash in route.blocks {
let mut hash_rlp = RlpStream::new_list(2); let mut hash_rlp = RlpStream::new_list(2);
let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Mallformed block without a difficulty on the chain!"); let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Malformed block without a difficulty on the chain!");
hash_rlp.append(&block_hash); hash_rlp.append(&block_hash);
hash_rlp.append(&difficulty); hash_rlp.append(&difficulty);
rlp_stream.append_raw(&hash_rlp.out(), 1); rlp_stream.append_raw(&hash_rlp.out(), 1);
@ -1570,7 +1570,7 @@ mod tests {
} }
#[test] #[test]
fn handles_peer_new_block_mallformed() { fn handles_peer_new_block_malformed() {
let mut client = TestBlockChainClient::new(); let mut client = TestBlockChainClient::new();
client.add_blocks(10, EachBlockWith::Uncle); client.add_blocks(10, EachBlockWith::Uncle);

View File

@ -381,7 +381,7 @@ impl KeyFileContent {
} }
} }
/// Loads key from valid json, returns error and records warning if key is mallformed /// Loads key from valid json, returns error and records warning if key is malformed
pub fn load(json: &Json) -> Result<KeyFileContent, ()> { pub fn load(json: &Json) -> Result<KeyFileContent, ()> {
match Self::from_json(json) { match Self::from_json(json) {
Ok(key_file) => Ok(key_file), Ok(key_file) => Ok(key_file),

View File

@ -73,6 +73,7 @@ pub enum SigningError {
pub struct SecretStore { pub struct SecretStore {
directory: KeyDirectory, directory: KeyDirectory,
unlocks: RwLock<HashMap<Address, AccountUnlock>>, unlocks: RwLock<HashMap<Address, AccountUnlock>>,
key_iterations: u32,
} }
struct AccountUnlock { struct AccountUnlock {
@ -128,10 +129,15 @@ impl AccountProvider for AccountService {
impl AccountService { impl AccountService {
/// New account service with the keys store in specific location /// New account service with the keys store in specific location
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
let secret_store = RwLock::new(SecretStore::new_in(path)); AccountService::with_security(path, KEY_ITERATIONS)
}
/// New account service with the keys store in specific location and configured security parameters
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
let secret_store = RwLock::new(SecretStore::with_security(path, key_iterations));
secret_store.write().unwrap().try_import_existing(); secret_store.write().unwrap().try_import_existing();
AccountService { AccountService {
secret_store: secret_store secret_store: secret_store,
} }
} }
@ -157,10 +163,16 @@ impl AccountService {
impl SecretStore { impl SecretStore {
/// new instance of Secret Store in specific directory /// new instance of Secret Store in specific directory
pub fn new_in(path: &Path) -> Self { pub fn new_in(path: &Path) -> Self {
SecretStore::with_security(path, KEY_ITERATIONS)
}
/// new instance of Secret Store in specific directory and configured security parameters
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical"); ::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical");
SecretStore { SecretStore {
directory: KeyDirectory::new(path), directory: KeyDirectory::new(path),
unlocks: RwLock::new(HashMap::new()), unlocks: RwLock::new(HashMap::new()),
key_iterations: key_iterations,
} }
} }
@ -206,6 +218,7 @@ impl SecretStore {
SecretStore { SecretStore {
directory: KeyDirectory::new(path.as_path()), directory: KeyDirectory::new(path.as_path()),
unlocks: RwLock::new(HashMap::new()), unlocks: RwLock::new(HashMap::new()),
key_iterations: KEY_ITERATIONS,
} }
} }
@ -289,8 +302,8 @@ fn derive_key_iterations(password: &str, salt: &H256, c: u32) -> (Bytes, Bytes)
(derived_right_bits.to_vec(), derived_left_bits.to_vec()) (derived_right_bits.to_vec(), derived_left_bits.to_vec())
} }
fn derive_key(password: &str, salt: &H256) -> (Bytes, Bytes) { fn derive_key(password: &str, salt: &H256, iterations: u32) -> (Bytes, Bytes) {
derive_key_iterations(password, salt, KEY_ITERATIONS) derive_key_iterations(password, salt, iterations)
} }
fn derive_key_scrypt(password: &str, salt: &H256, n: u32, p: u32, r: u32) -> (Bytes, Bytes) { fn derive_key_scrypt(password: &str, salt: &H256, n: u32, p: u32, r: u32) -> (Bytes, Bytes) {
@ -346,7 +359,7 @@ impl EncryptedHashMap<H128> for SecretStore {
// two parts of derived key // two parts of derived key
// DK = [ DK[0..15] DK[16..31] ] = [derived_left_bits, derived_right_bits] // DK = [ DK[0..15] DK[16..31] ] = [derived_left_bits, derived_right_bits]
let (derived_left_bits, derived_right_bits) = derive_key(password, &salt); let (derived_left_bits, derived_right_bits) = derive_key(password, &salt, self.key_iterations);
let mut cipher_text = vec![0u8; value.as_slice().len()]; let mut cipher_text = vec![0u8; value.as_slice().len()];
// aes-128-ctr with initial vector of iv // aes-128-ctr with initial vector of iv
@ -361,7 +374,7 @@ impl EncryptedHashMap<H128> for SecretStore {
iv, iv,
salt, salt,
mac, mac,
KEY_ITERATIONS, self.key_iterations,
KEY_LENGTH)); KEY_LENGTH));
key_file.id = key; key_file.id = key;
if let Err(io_error) = self.directory.save(key_file) { if let Err(io_error) = self.directory.save(key_file) {