diff --git a/ethstore/README.md b/ethstore/README.md
index aba4911bf..0cf50f454 100644
--- a/ethstore/README.md
+++ b/ethstore/README.md
@@ -20,6 +20,7 @@ Usage:
ethstore change-pwd
[--dir DIR]
ethstore list [--dir DIR]
ethstore import [--src DIR] [--dir DIR]
+ ethstore import-wallet [--dir DIR]
ethstore remove [--dir DIR]
ethstore sign [--dir DIR]
ethstore [-h | --help]
@@ -38,6 +39,7 @@ Commands:
change-pwd Change account password.
list List accounts.
import Import accounts from src.
+ import-wallet Import presale wallet.
remove Remove account.
sign Sign message.
```
@@ -119,6 +121,19 @@ ethstore list
--
+#### `import-wallet [--dir DIR]`
+*Import account from presale wallet.*
+
+- `` - presale wallet path
+- `` - account password, any string
+- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
+
+```
+e6a3d25a7cb7cd21cb720df5b5e8afd154af1bbb
+```
+
+--
+
#### `remove [--dir DIR]`
*Remove account from secret store.*
diff --git a/ethstore/src/bin/ethstore.rs b/ethstore/src/bin/ethstore.rs
index 6020679d4..948d7a76e 100644
--- a/ethstore/src/bin/ethstore.rs
+++ b/ethstore/src/bin/ethstore.rs
@@ -24,7 +24,7 @@ use std::str::FromStr;
use docopt::Docopt;
use ethstore::ethkey::{Secret, Address, Message};
use ethstore::dir::{KeyDirectory, ParityDirectory, DiskDirectory, GethDirectory, DirectoryType};
-use ethstore::{EthStore, SecretStore, import_accounts, Error};
+use ethstore::{EthStore, SecretStore, import_accounts, Error, PresaleWallet};
pub const USAGE: &'static str = r#"
Ethereum key management.
@@ -35,6 +35,7 @@ Usage:
ethstore change-pwd [--dir DIR]
ethstore list [--dir DIR]
ethstore import [--src DIR] [--dir DIR]
+ ethstore import-wallet [--dir DIR]
ethstore remove [--dir DIR]
ethstore sign [--dir DIR]
ethstore [-h | --help]
@@ -53,6 +54,7 @@ Commands:
change-pwd Change password.
list List accounts.
import Import accounts from src.
+ import-wallet Import presale wallet.
remove Remove account.
sign Sign message.
"#;
@@ -63,6 +65,7 @@ struct Args {
cmd_change_pwd: bool,
cmd_list: bool,
cmd_import: bool,
+ cmd_import_wallet: bool,
cmd_remove: bool,
cmd_sign: bool,
arg_secret: String,
@@ -71,6 +74,7 @@ struct Args {
arg_new_pwd: String,
arg_address: String,
arg_message: String,
+ arg_path: String,
flag_src: String,
flag_dir: String,
}
@@ -128,6 +132,11 @@ fn execute(command: I) -> Result where I: IntoIterator- for [u8] {
pub mod aes {
use rcrypto::blockmodes::{CtrMode, CbcDecryptor, PkcsPadding};
use rcrypto::aessafe::{AesSafe128Encryptor, AesSafe128Decryptor};
- use rcrypto::symmetriccipher::{Encryptor, Decryptor};
+ use rcrypto::symmetriccipher::{Encryptor, Decryptor, SymmetricCipherError};
use rcrypto::buffer::{RefReadBuffer, RefWriteBuffer};
/// Encrypt a message
@@ -83,9 +83,10 @@ pub mod aes {
}
/// Decrypt a message using cbc mode
- pub fn decrypt_cbc(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) {
+ pub fn decrypt_cbc(k: &[u8], iv: &[u8], encrypted: &[u8], dest: &mut [u8]) -> Result<(), SymmetricCipherError> {
let mut encryptor = CbcDecryptor::new(AesSafe128Decryptor::new(k), PkcsPadding, iv.to_vec());
- encryptor.decrypt(&mut RefReadBuffer::new(encrypted), &mut RefWriteBuffer::new(dest), true).expect("Invalid length or padding");
+ try!(encryptor.decrypt(&mut RefReadBuffer::new(encrypted), &mut RefWriteBuffer::new(dest), true));
+ Ok(())
}
}
diff --git a/ethstore/src/ethkey.rs b/ethstore/src/ethkey.rs
index 9d8858b79..eba877397 100644
--- a/ethstore/src/ethkey.rs
+++ b/ethstore/src/ethkey.rs
@@ -31,11 +31,3 @@ impl From for Address {
From::from(a)
}
}
-
-impl<'a> From<&'a json::H160> for Address {
- fn from(json: &'a json::H160) -> Self {
- let mut a = [0u8; 20];
- a.copy_from_slice(json);
- From::from(a)
- }
-}
diff --git a/ethstore/src/presale.rs b/ethstore/src/presale.rs
index 5ba57b8d4..8c8172473 100644
--- a/ethstore/src/presale.rs
+++ b/ethstore/src/presale.rs
@@ -43,7 +43,7 @@ impl PresaleWallet {
pbkdf2(&mut h_mac, password.as_bytes(), 2000, &mut derived_key);
let mut key = [0u8; 64];
- crypto::aes::decrypt_cbc(&derived_key, &self.iv, &self.ciphertext, &mut key);
+ try!(crypto::aes::decrypt_cbc(&derived_key, &self.iv, &self.ciphertext, &mut key).map_err(|_| Error::InvalidPassword));
let secret = Secret::from(key.keccak256());
if let Ok(kp) = KeyPair::from_secret(secret) {