Support for decryption in Signer (#2421)

* Adding some tests

* Implementing decrypt in queue

* Removing code duplication.

* Printing public key in ethstore

* Bump UI

* Normalizing dapps format for signer.

* Fixing tests compilation

* fix whitespace

[ci:skip]
This commit is contained in:
Tomasz Drwięga
2016-10-15 14:44:08 +02:00
committed by Gav Wood
parent 85eeb3ea6e
commit 03c1559ead
27 changed files with 457 additions and 278 deletions

View File

@@ -14,7 +14,7 @@
// 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, Secret, Signature, Message};
use ethkey::{KeyPair, sign, Address, Secret, Signature, Message, Public};
use {json, Error, crypto};
use crypto::Keccak256;
use random::Random;
@@ -180,6 +180,11 @@ impl SafeAccount {
crypto::ecies::decrypt(&secret, shared_mac, message).map_err(From::from)
}
pub fn public(&self, password: &str) -> Result<Public, Error> {
let secret = try!(self.crypto.secret(password));
Ok(try!(KeyPair::from_secret(secret)).public().clone())
}
pub fn change_password(&self, old_password: &str, new_password: &str, iterations: u32) -> Result<Self, Error> {
let secret = try!(self.crypto.secret(old_password));
let result = SafeAccount {

View File

@@ -37,6 +37,7 @@ Usage:
ethstore import-wallet <path> <password> [--dir DIR]
ethstore remove <address> <password> [--dir DIR]
ethstore sign <address> <password> <message> [--dir DIR]
ethstore public <address> <password>
ethstore [-h | --help]
Options:
@@ -56,6 +57,7 @@ Commands:
import-wallet Import presale wallet.
remove Remove account.
sign Sign message.
public Displays public key for an address.
"#;
#[derive(Debug, RustcDecodable)]
@@ -67,6 +69,7 @@ struct Args {
cmd_import_wallet: bool,
cmd_remove: bool,
cmd_sign: bool,
cmd_public: bool,
arg_secret: String,
arg_password: String,
arg_old_pwd: String,
@@ -103,7 +106,7 @@ fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> {
fn format_accounts(accounts: &[Address]) -> String {
accounts.iter()
.enumerate()
.map(|(i, a)| format!("{:2}: {}", i, a))
.map(|(i, a)| format!("{:2}: 0x{:?}", i, a))
.collect::<Vec<String>>()
.join("\n")
}
@@ -128,7 +131,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
let secret = try!(args.arg_secret.parse().map_err(|_| Error::InvalidSecret));
let password = try!(load_password(&args.arg_password));
let address = try!(store.insert_account(secret, &password));
Ok(format!("{}", address))
Ok(format!("0x{:?}", address))
} else if args.cmd_change_pwd {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let old_pwd = try!(load_password(&args.arg_old_pwd));
@@ -148,7 +151,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
let password = try!(load_password(&args.arg_password));
let kp = try!(wallet.decrypt(&password));
let address = try!(store.insert_account(kp.secret().clone(), &password));
Ok(format!("{}", address))
Ok(format!("0x{:?}", address))
} else if args.cmd_remove {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let password = try!(load_password(&args.arg_password));
@@ -159,7 +162,12 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
let message = try!(args.arg_message.parse().map_err(|_| Error::InvalidMessage));
let password = try!(load_password(&args.arg_password));
let signature = try!(store.sign(&address, &password, &message));
Ok(format!("{}", signature))
Ok(format!("0x{:?}", signature))
} else if args.cmd_public {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let password = try!(load_password(&args.arg_password));
let public = try!(store.public(&address, &password));
Ok(format!("0x{:?}", public))
} else {
Ok(format!("{}", USAGE))
}

View File

@@ -20,7 +20,7 @@ use std::mem;
use ethkey::KeyPair;
use crypto::KEY_ITERATIONS;
use random::Random;
use ethkey::{Signature, Address, Message, Secret};
use ethkey::{Signature, Address, Message, Secret, Public};
use dir::KeyDirectory;
use account::SafeAccount;
use {Error, SecretStore};
@@ -149,6 +149,11 @@ impl SecretStore for EthStore {
account.decrypt(password, shared_mac, message)
}
fn public(&self, account: &Address, password: &str) -> Result<Public, Error> {
let account = try!(self.get(account));
account.public(password)
}
fn uuid(&self, address: &Address) -> Result<UUID, Error> {
let account = try!(self.get(address));
Ok(account.id.into())

View File

@@ -14,7 +14,7 @@
// 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::{Address, Message, Signature, Secret};
use ethkey::{Address, Message, Signature, Secret, Public};
use Error;
use json::UUID;
@@ -27,6 +27,7 @@ pub trait SecretStore: Send + Sync {
fn sign(&self, account: &Address, password: &str, message: &Message) -> Result<Signature, Error>;
fn decrypt(&self, account: &Address, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error>;
fn public(&self, account: &Address, password: &str) -> Result<Public, Error>;
fn accounts(&self) -> Result<Vec<Address>, Error>;
fn uuid(&self, account: &Address) -> Result<UUID, Error>;