completed KeyStoreNodeKeyPair
This commit is contained in:
parent
2e9df2c39d
commit
eb895fbb31
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -794,6 +794,7 @@ name = "ethstore"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"ethcore-util 1.8.0",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -702,6 +702,13 @@ impl AccountProvider {
|
||||
Ok(self.sstore.decrypt(&account, &password, shared_mac, message)?)
|
||||
}
|
||||
|
||||
/// Agree on shared key.
|
||||
pub fn agree(&self, address: Address, password: Option<String>, other_public: &Public) -> Result<Secret, SignError> {
|
||||
let account = self.sstore.account_ref(&address)?;
|
||||
let password = password.map(Ok).unwrap_or_else(|| self.password(&account))?;
|
||||
Ok(self.sstore.agree(&account, &password, other_public)?)
|
||||
}
|
||||
|
||||
/// Returns the underlying `SecretStore` reference if one exists.
|
||||
pub fn list_geth_accounts(&self, testnet: bool) -> Vec<Address> {
|
||||
self.sstore.list_geth_accounts(testnet).into_iter().map(|a| Address::from(a).into()).collect()
|
||||
|
@ -19,6 +19,7 @@ itertools = "0.5"
|
||||
parking_lot = "0.4"
|
||||
ethcrypto = { path = "../ethcrypto" }
|
||||
ethcore-bigint = { path = "../util/bigint" }
|
||||
ethcore-util = { path = "../util" }
|
||||
smallvec = "0.4"
|
||||
parity-wordlist = "1.0"
|
||||
tempdir = "0.3"
|
||||
|
@ -14,7 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethkey::{KeyPair, sign, Address, Signature, Message, Public};
|
||||
use ethkey::{KeyPair, sign, Address, Signature, Message, Public, Secret};
|
||||
use crypto::ecdh::agree;
|
||||
use {json, Error, crypto};
|
||||
use account::Version;
|
||||
use super::crypto::Crypto;
|
||||
@ -135,6 +136,12 @@ impl SafeAccount {
|
||||
crypto::ecies::decrypt(&secret, shared_mac, message).map_err(From::from)
|
||||
}
|
||||
|
||||
/// Agree on shared key.
|
||||
pub fn agree(&self, password: &str, other: &Public) -> Result<Secret, Error> {
|
||||
let secret = self.crypto.secret(password)?;
|
||||
agree(&secret, other).map_err(From::from)
|
||||
}
|
||||
|
||||
/// Derive public key.
|
||||
pub fn public(&self, password: &str) -> Result<Public, Error> {
|
||||
let secret = self.crypto.secret(password)?;
|
||||
|
@ -97,6 +97,10 @@ impl SimpleSecretStore for EthStore {
|
||||
self.store.sign_derived(account_ref, password, derivation, message)
|
||||
}
|
||||
|
||||
fn agree(&self, account: &StoreAccountRef, password: &str, other: &Public) -> Result<Secret, Error> {
|
||||
self.store.agree(account, password, other)
|
||||
}
|
||||
|
||||
fn decrypt(&self, account: &StoreAccountRef, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
let account = self.get(account)?;
|
||||
account.decrypt(password, shared_mac, message)
|
||||
@ -509,6 +513,14 @@ impl SimpleSecretStore for EthMultiStore {
|
||||
Err(Error::InvalidPassword)
|
||||
}
|
||||
|
||||
fn agree(&self, account: &StoreAccountRef, password: &str, other: &Public) -> Result<Secret, Error> {
|
||||
let accounts = self.get_matching(account, password)?;
|
||||
for account in accounts {
|
||||
return account.agree(password, other);
|
||||
}
|
||||
Err(Error::InvalidPassword)
|
||||
}
|
||||
|
||||
fn create_vault(&self, name: &str, password: &str) -> Result<(), Error> {
|
||||
let is_vault_created = { // lock border
|
||||
let mut vaults = self.vaults.lock();
|
||||
|
@ -35,6 +35,7 @@ extern crate ethcore_bigint as bigint;
|
||||
extern crate ethcrypto as crypto;
|
||||
extern crate ethkey as _ethkey;
|
||||
extern crate parity_wordlist;
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -60,6 +60,8 @@ pub trait SimpleSecretStore: Send + Sync {
|
||||
fn sign_derived(&self, account_ref: &StoreAccountRef, password: &str, derivation: Derivation, message: &Message) -> Result<Signature, Error>;
|
||||
/// Decrypt a messages with given account.
|
||||
fn decrypt(&self, account: &StoreAccountRef, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error>;
|
||||
/// Agree on shared key.
|
||||
fn agree(&self, account: &StoreAccountRef, password: &str, other: &Public) -> Result<Secret, Error>;
|
||||
|
||||
/// Returns all accounts in this secret store.
|
||||
fn accounts(&self) -> Result<Vec<StoreAccountRef>, Error>;
|
||||
|
@ -245,7 +245,6 @@ pub mod tests {
|
||||
let key_pairs: Vec<_> = (0..num_nodes).map(|_| Random.generate().unwrap()).collect();
|
||||
let configs: Vec<_> = (0..num_nodes).map(|i| ClusterConfiguration {
|
||||
threads: 1,
|
||||
// self_key_pair: Arc::new(PlainNodeKeyPair::new(key_pairs[i].clone())),
|
||||
listener_address: NodeAddress {
|
||||
address: "127.0.0.1".into(),
|
||||
port: start_port + (i as u16),
|
||||
|
@ -77,7 +77,8 @@ impl NodeKeyPair for KeyStoreNodeKeyPair {
|
||||
.map_err(|e| EthKeyError::Custom(format!("{}", e)))
|
||||
}
|
||||
|
||||
fn compute_shared_key(&self, _peer_public: &Public) -> Result<KeyPair, EthKeyError> {
|
||||
unimplemented!()
|
||||
fn compute_shared_key(&self, peer_public: &Public) -> Result<KeyPair, EthKeyError> {
|
||||
KeyPair::from_secret(self.account_provider.agree(self.address.clone(), Some(self.password.clone()), peer_public)
|
||||
.map_err(|e| EthKeyError::Custom(format!("{}", e)))?)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user