diff --git a/ethstore/README.md b/ethstore/README.md index 121515943..1986da72b 100644 --- a/ethstore/README.md +++ b/ethstore/README.md @@ -16,23 +16,33 @@ Ethereum key management. Copyright 2016, 2017 Parity Technologies (UK) Ltd Usage: - ethstore insert [--dir DIR] - ethstore change-pwd
[--dir DIR] - ethstore list [--dir DIR] + ethstore insert [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore change-pwd
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore list [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] ethstore import [--src DIR] [--dir DIR] - ethstore import-wallet [--dir DIR] - ethstore remove
[--dir DIR] - ethstore sign
[--dir DIR] + ethstore import-wallet [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore remove
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore sign
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore public
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore list-vaults [--dir DIR] + ethstore create-vault [--dir DIR] + ethstore change-vault-pwd [--dir DIR] + ethstore move-to-vault
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore move-from-vault
[--dir DIR] ethstore [-h | --help] Options: - -h, --help Display this message and exit. - --dir DIR Specify the secret store directory. It may be either - parity, parity-test, geth, geth-test - or a path [default: parity]. - --src DIR Specify import source. It may be either - parity, parity-test, get, geth-test - or a path [default: geth]. + -h, --help Display this message and exit. + --dir DIR Specify the secret store directory. It may be either + parity, parity-test, geth, geth-test + or a path [default: parity]. + --vault VAULT Specify vault to use in this operation. + --vault-pwd VAULTPWD Specify vault password to use in this operation. Please note + that this option is required when vault option is set. + Otherwise it is ignored. + --src DIR Specify import source. It may be either + parity, parity-test, get, geth-test + or a path [default: geth]. Commands: insert Save account with password. @@ -42,16 +52,24 @@ Commands: import-wallet Import presale wallet. remove Remove account. sign Sign message. + public Displays public key for an address. + list-vaults List vaults. + create-vault Create new vault. + change-vault-pwd Change vault password. + move-to-vault Move account to vault from another vault/root directory. + move-from-vault Move account to root directory from given vault or root. ``` ### Examples -#### `insert [--dir DIR]` +#### `insert [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *Encrypt secret with a password and save it in secret store.* - `` - ethereum secret, 32 bytes long - `` - account password, file path - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore insert 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5 password.txt @@ -73,13 +91,15 @@ ethstore insert `ethkey generate random -s` "this is sparta" -- -#### `change-pwd
[--dir DIR]` +#### `change-pwd
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *Change account password.* - `
` - ethereum address, 20 bytes long - `` - old account password, file path - `` - new account password, file path - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore change-pwd a8fa5dd30a87bb9e3288d604eb74949c515ab66e old_pwd.txt new_pwd.txt @@ -91,10 +111,12 @@ true -- -#### `list [--dir DIR]` +#### `list [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *List secret store accounts.* - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore list @@ -125,12 +147,14 @@ ethstore import -- -#### `import-wallet [--dir DIR]` +#### `import-wallet [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *Import account from presale wallet.* - `` - presale wallet path - `` - account password, file path - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore import-wallet ethwallet.json password.txt @@ -142,12 +166,14 @@ e6a3d25a7cb7cd21cb720df5b5e8afd154af1bbb -- -#### `remove
[--dir DIR]` +#### `remove
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *Remove account from secret store.* - `
` - ethereum address, 20 bytes long - `` - account password, file path - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore remove a8fa5dd30a87bb9e3288d604eb74949c515ab66e password.txt @@ -159,13 +185,15 @@ true -- -#### `sign
[--dir DIR]` +#### `sign
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` *Sign message with account's secret.* - `
` - ethereum address, 20 bytes long - `` - account password, file path - `` - message to sign, 32 bytes long - `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path ``` ethstore sign 24edfff680d536a5f6fe862d36df6f8f6f40f115 password.txt 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5 @@ -177,6 +205,119 @@ c6649f9555232d90ff716d7e552a744c5af771574425a74860e12f763479eb1b708c1f3a7dc0a0a7 -- +#### `public
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` +*Displays public key for an address.* + +- `
` - ethereum address, 20 bytes long +- `` - account password, file path +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - vault to use in this operation +- `[--vault-pwd VAULTPWD]` - vault password to use in this operation, file path + +``` +ethstore public 00e63fdb87ceb815ec96ae185b8f7381a0b4a5ea account_password.txt --vault vault_name --vault-pwd vault_password.txt +``` + +``` +0x84161d8c05a996a534efbec50f24485cfcc07458efaef749a1b22156d7836c903eeb39bf2df74676e702eacc4cfdde069e5fd86692b5ef6ef81ba906e9e77d82 +``` + +-- + +#### `list-vaults [--dir DIR]` +*List vaults.* + +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity + +``` +ethstore list-vaults +``` + +``` +vault1 +vault2 +vault3 +``` + +-- + +#### `create-vault [--dir DIR]` +*Create new vault.* + +- `` - name of new vault. This can only contain letters, digits, whitespaces, dashes and underscores +- `` - vault password, file path +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity + +``` +ethstore create-vault vault3 vault3_password.txt +``` + +``` +OK +``` + +-- + +#### `change-vault-pwd [--dir DIR]` +*Change vault password.* + +- `` - name of existing vault +- `` - old vault password, file path +- `` - new vault password, file path +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity + +``` +ethstore change-vault-pwd vault3 vault3_password.txt new_vault3_password.txt +``` + +``` +OK +``` + +-- + +#### `move-to-vault
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD]` +*Move account to vault from another vault/root directory.* + +- `
` - ethereum address, 20 bytes long +- `` - name of existing vault to move account to +- `` - password of existing `` to move account to, file path +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity +- `[--vault VAULT]` - current vault of the `
` argument, if set +- `[--vault-pwd VAULTPWD]` - password for the current vault of the `
` argument, if any. file path + + +``` +ethstore move-to-vault 00e63fdb87ceb815ec96ae185b8f7381a0b4a5ea vault3 vault3_password.txt +ethstore move-to-vault 00e63fdb87ceb815ec96ae185b8f7381a0b4a5ea vault1 vault1_password.txt --vault vault3 --vault-pwd vault3_password.txt +``` + +``` +OK +OK +``` + +-- + +#### `move-from-vault
[--dir DIR]` +*Move account to root directory from given vault.* + +- `
` - ethereum address, 20 bytes long +- `` - name of existing vault to move account to +- `` - password of existing `` to move account to, file path +- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity + + +``` +ethstore move-from-vault 00e63fdb87ceb815ec96ae185b8f7381a0b4a5ea vault1 vault1_password.txt +``` + +``` +OK +``` + +-- + # Ethcore toolchain *this project is a part of the ethcore toolchain* diff --git a/ethstore/src/bin/ethstore.rs b/ethstore/src/bin/ethstore.rs index 06a0b40a8..20411a629 100644 --- a/ethstore/src/bin/ethstore.rs +++ b/ethstore/src/bin/ethstore.rs @@ -31,24 +31,33 @@ Ethereum key management. Copyright 2016, 2017 Parity Technologies (UK) Ltd Usage: - ethstore insert [--dir DIR] - ethstore change-pwd
[--dir DIR] - ethstore list [--dir DIR] + ethstore insert [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore change-pwd
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore list [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] ethstore import [--src DIR] [--dir DIR] - ethstore import-wallet [--dir DIR] - ethstore remove
[--dir DIR] - ethstore sign
[--dir DIR] - ethstore public
+ ethstore import-wallet [--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore remove
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore sign
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore public
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore list-vaults [--dir DIR] + ethstore create-vault [--dir DIR] + ethstore change-vault-pwd [--dir DIR] + ethstore move-to-vault
[--dir DIR] [--vault VAULT] [--vault-pwd VAULTPWD] + ethstore move-from-vault
[--dir DIR] ethstore [-h | --help] Options: - -h, --help Display this message and exit. - --dir DIR Specify the secret store directory. It may be either - parity, parity-test, geth, geth-test - or a path [default: parity]. - --src DIR Specify import source. It may be either - parity, parity-test, get, geth-test - or a path [default: geth]. + -h, --help Display this message and exit. + --dir DIR Specify the secret store directory. It may be either + parity, parity-test, geth, geth-test + or a path [default: parity]. + --vault VAULT Specify vault to use in this operation. + --vault-pwd VAULTPWD Specify vault password to use in this operation. Please note + that this option is required when vault option is set. + Otherwise it is ignored. + --src DIR Specify import source. It may be either + parity, parity-test, get, geth-test + or a path [default: geth]. Commands: insert Save account with password. @@ -59,6 +68,11 @@ Commands: remove Remove account. sign Sign message. public Displays public key for an address. + list-vaults List vaults. + create-vault Create new vault. + change-vault-pwd Change vault password. + move-to-vault Move account to vault from another vault/root directory. + move-from-vault Move account to root directory from given vault. "#; #[derive(Debug, RustcDecodable)] @@ -71,6 +85,11 @@ struct Args { cmd_remove: bool, cmd_sign: bool, cmd_public: bool, + cmd_list_vaults: bool, + cmd_create_vault: bool, + cmd_change_vault_pwd: bool, + cmd_move_to_vault: bool, + cmd_move_from_vault: bool, arg_secret: String, arg_password: String, arg_old_pwd: String, @@ -78,8 +97,11 @@ struct Args { arg_address: String, arg_message: String, arg_path: String, + arg_vault: String, flag_src: String, flag_dir: String, + flag_vault: String, + flag_vault_pwd: String, } fn main() { @@ -104,6 +126,23 @@ fn key_dir(location: &str) -> Result, Error> { Ok(dir) } +fn open_args_vault(store: &EthStore, args: &Args) -> Result { + if args.flag_vault.is_empty() { + return Ok(SecretVaultRef::Root); + } + + let vault_pwd = load_password(&args.flag_vault_pwd)?; + store.open_vault(&args.flag_vault, &vault_pwd)?; + Ok(SecretVaultRef::Vault(args.flag_vault.clone())) +} + +fn open_args_vault_account(store: &EthStore, address: Address, args: &Args) -> Result { + match open_args_vault(store, args)? { + SecretVaultRef::Root => Ok(StoreAccountRef::root(address)), + SecretVaultRef::Vault(name) => Ok(StoreAccountRef::vault(&name, address)), + } +} + fn format_accounts(accounts: &[Address]) -> String { accounts.iter() .enumerate() @@ -112,10 +151,14 @@ fn format_accounts(accounts: &[Address]) -> String { .join("\n") } +fn format_vaults(vaults: &[String]) -> String { + vaults.join("\n") +} + fn load_password(path: &str) -> Result { - let mut file = fs::File::open(path)?; + let mut file = fs::File::open(path).map_err(|e| Error::Custom(format!("Error opening password file {}: {}", path, e)))?; let mut password = String::new(); - file.read_to_string(&mut password)?; + file.read_to_string(&mut password).map_err(|e| Error::Custom(format!("Error reading password file {}: {}", path, e)))?; // drop EOF let _ = password.pop(); Ok(password) @@ -131,17 +174,24 @@ fn execute(command: I) -> Result where I: IntoIterator = accounts.into_iter().map(|a| a.address).collect(); + let accounts: Vec<_> = accounts + .into_iter() + .filter(|a| &a.vault == &vault_ref) + .map(|a| a.address) + .collect(); Ok(format_accounts(&accounts)) } else if args.cmd_import { let src = key_dir(&args.flag_src)?; @@ -152,24 +202,54 @@ fn execute(command: I) -> Result where I: IntoIterator