diff --git a/parity/account_utils.rs b/parity/account_utils.rs index 9fc748a43..1261ab2de 100644 --- a/parity/account_utils.rs +++ b/parity/account_utils.rs @@ -61,7 +61,7 @@ mod accounts { mod accounts { use super::*; use upgrade::upgrade_key_location; - use ethereum_types::H160; + use ethereum_types::{H160, H256}; use std::str::FromStr; pub use accounts::AccountProvider; @@ -132,9 +132,17 @@ mod accounts { LocalAccounts(account_provider) } - pub fn miner_author(spec: &SpecType, dirs: &Directories, account_provider: &Arc, engine_signer: Address, passwords: &[Password]) -> Result, String> { + pub fn miner_author( + spec: &SpecType, + dirs: &Directories, + account_provider: &Arc, + engine_signer: Address, + passwords: &[Password] + ) -> Result, String> { use engine::signer::EngineSigner; + const SECP_TEST_MESSAGE: H256 = H256([1_u8; 32]); + // Check if engine signer exists if !account_provider.has_account(engine_signer) { return Err(format!("Consensus signer account not found for the current chain. {}", build_create_account_hint(spec, &dirs.keys))); @@ -145,25 +153,27 @@ mod accounts { return Err(format!("No password found for the consensus signer {}. {}", engine_signer, VERIFY_PASSWORD_HINT)); } - let mut author = None; - for password in passwords { + let mut invalid_reasons = std::collections::HashSet::new(); + for (idx, password) in passwords.iter().enumerate() { let signer = parity_rpc::signer::EngineSigner::new( account_provider.clone(), engine_signer, password.clone(), ); - if signer.sign(Default::default()).is_ok() { - author = Some(::ethcore::miner::Author::Sealer(Box::new(signer))); + if let Err(e) = signer.sign(SECP_TEST_MESSAGE) { + debug!(target: "account", "Signing test of `EngineSigner ({})` with password index: {} failed because of: {:?}", engine_signer, idx, e); + invalid_reasons.insert(e.to_string()); + } else { + return Ok(Some(ethcore::miner::Author::Sealer(Box::new(signer)))); } } - if author.is_none() { - return Err(format!("No valid password for the consensus signer {}. {}", engine_signer, VERIFY_PASSWORD_HINT)); - } - Ok(author) + Err(format!( + "No valid password found for EngineSigner {}, the following errors were found during testing: {:?}. {}", + engine_signer, invalid_reasons, VERIFY_PASSWORD_HINT + )) } - mod private_tx { use super::*; use parity_crypto::publickey::{Signature, Message}; diff --git a/rpc/src/v1/helpers/engine_signer.rs b/rpc/src/v1/helpers/engine_signer.rs index 7602673fb..032fc97de 100644 --- a/rpc/src/v1/helpers/engine_signer.rs +++ b/rpc/src/v1/helpers/engine_signer.rs @@ -36,16 +36,14 @@ impl EngineSigner { impl engine::signer::EngineSigner for EngineSigner { fn sign(&self, message: Message) -> Result { - match self.accounts.sign(self.address, Some(self.password.clone()), message) { - Ok(ok) => Ok(ok), - Err(_) => Err(Error::InvalidSecretKey), - } + self.accounts.sign(self.address, Some(self.password.clone()), message).map_err(|e| { + Error::Custom(e.to_string()) + }) } fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result, Error> { self.accounts.decrypt(self.address, None, auth_data, cipher).map_err(|e| { - warn!("Unable to decrypt message: {:?}", e); - Error::InvalidMessage + Error::Custom(e.to_string()) }) }