Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 1a16f33

Browse files
niklasad15chdn
authored andcommitted
Disable hardware-wallets on platforms that don't support libusb (#8464)
* disable hardware-wallets that don't support libusb * address grumbles * nits * Refactor to get rid off as much annotations asap * Might consume slight more memory than pure conditional compilation flags * formatting nits * Enable libusb for android * Tested by it compiling succesfully with `cargo build --target=armv7--linux-androideabi` * The binary is ~66 MB ```bash $ size size target/armv7-linux-androideabi/release/parity text data bss dec hex filename 50676230 416200 31456 51123886 30c16ae target/armv7-linux-androideabi/release/parity ``` * Move all `fake-hardware-wallet` to its own crate * Removes some conditional compilation flags * Introduces `fake-hardware-wallet` crate * return error if no hardware wallets are found
1 parent 4145be8 commit 1a16f33

File tree

12 files changed

+184
-39
lines changed

12 files changed

+184
-39
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ ethjson = { path = "../json" }
3636
ethkey = { path = "../ethkey" }
3737
ethstore = { path = "../ethstore" }
3838
evm = { path = "evm" }
39-
hardware-wallet = { path = "../hw" }
4039
heapsize = "0.4"
4140
itertools = "0.5"
4241
lazy_static = "1.0"
@@ -70,6 +69,12 @@ journaldb = { path = "../util/journaldb" }
7069
tempdir = { version = "0.3", optional = true }
7170
kvdb-rocksdb = { path = "../util/kvdb-rocksdb" }
7271

72+
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))'.dependencies]
73+
hardware-wallet = { path = "../hw" }
74+
75+
[target.'cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))'.dependencies]
76+
fake-hardware-wallet = { path = "../util/fake-hardware-wallet" }
77+
7378
[dev-dependencies]
7479
trie-standardmap = { path = "../util/trie-standardmap" }
7580

ethcore/src/account_provider/mod.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ mod stores;
2020

2121
use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy};
2222

23-
use std::fmt;
2423
use std::collections::{HashMap, HashSet};
24+
use std::fmt;
2525
use std::time::{Instant, Duration};
26-
use parking_lot::RwLock;
26+
27+
use ethstore::accounts_dir::MemoryDirectory;
28+
use ethstore::ethkey::{Address, Message, Public, Secret, Password, Random, Generator};
29+
use ethjson::misc::AccountMeta;
2730
use ethstore::{
2831
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
2932
random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret,
3033
};
31-
use ethstore::accounts_dir::MemoryDirectory;
32-
use ethstore::ethkey::{Address, Message, Public, Secret, Password, Random, Generator};
33-
use ethjson::misc::AccountMeta;
34-
use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};
35-
use super::transaction::{Action, Transaction};
34+
use parking_lot::RwLock;
35+
3636
pub use ethstore::ethkey::Signature;
3737
pub use ethstore::{Derivation, IndexDerivation, KeyFile};
38+
pub use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath, TransactionInfo};
39+
pub use super::transaction::{Action, Transaction};
3840

3941
/// Type of unlock.
4042
#[derive(Clone, PartialEq)]
@@ -165,6 +167,7 @@ impl AccountProvider {
165167
/// Creates new account provider.
166168
pub fn new(sstore: Box<SecretStore>, settings: AccountProviderSettings) -> Self {
167169
let mut hardware_store = None;
170+
168171
if settings.enable_hardware_wallets {
169172
match HardwareWalletManager::new() {
170173
Ok(manager) => {
@@ -289,8 +292,12 @@ impl AccountProvider {
289292

290293
/// Returns addresses of hardware accounts.
291294
pub fn hardware_accounts(&self) -> Result<Vec<Address>, Error> {
292-
let accounts = self.hardware_store.as_ref().map_or(Vec::new(), |h| h.list_wallets());
293-
Ok(accounts.into_iter().map(|a| a.address).collect())
295+
if let Some(accounts) = self.hardware_store.as_ref().map(|h| h.list_wallets()) {
296+
if !accounts.is_empty() {
297+
return Ok(accounts.into_iter().map(|a| a.address).collect());
298+
}
299+
}
300+
Err(SSError::Custom("No hardware wallet accounts were found".into()))
294301
}
295302

296303
/// Get a list of paths to locked hardware wallets
@@ -301,7 +308,7 @@ impl AccountProvider {
301308
Some(Ok(s)) => Ok(s),
302309
}
303310
}
304-
311+
305312
/// Provide a pin to a locked hardware wallet on USB path to unlock it
306313
pub fn hardware_pin_matrix_ack(&self, path: &str, pin: &str) -> Result<bool, SignError> {
307314
match self.hardware_store.as_ref().map(|h| h.pin_matrix_ack(path, pin)) {

ethcore/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern crate ethcore_transaction as transaction;
7575
extern crate ethereum_types;
7676
extern crate ethjson;
7777
extern crate ethkey;
78-
extern crate hardware_wallet;
78+
7979
extern crate hashdb;
8080
extern crate itertools;
8181
extern crate kvdb;
@@ -99,7 +99,6 @@ extern crate ansi_term;
9999
extern crate unexpected;
100100
extern crate util_error;
101101
extern crate snappy;
102-
103102
extern crate ethabi;
104103
extern crate rustc_hex;
105104
extern crate stats;
@@ -112,6 +111,12 @@ extern crate journaldb;
112111
#[cfg(any(test, feature = "json-tests", feature = "test-helpers"))]
113112
extern crate tempdir;
114113

114+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
115+
extern crate hardware_wallet;
116+
117+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
118+
extern crate fake_hardware_wallet as hardware_wallet;
119+
115120
#[macro_use]
116121
extern crate ethabi_derive;
117122
#[macro_use]

rpc/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ rlp = { path = "../util/rlp" }
6464
stats = { path = "../util/stats" }
6565
vm = { path = "../ethcore/vm" }
6666

67+
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))'.dependencies]
68+
hardware-wallet = { path = "../hw" }
69+
70+
[target.'cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))'.dependencies]
71+
fake-hardware-wallet = { path = "../util/fake-hardware-wallet" }
72+
6773
[dev-dependencies]
6874
ethcore = { path = "../ethcore", features = ["test-helpers"] }
6975
ethcore-network = { path = "../util/network" }

rpc/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,21 @@ extern crate ethcore_transaction as transaction;
5858
extern crate ethereum_types;
5959
extern crate ethkey;
6060
extern crate ethstore;
61-
extern crate vm;
6261
extern crate fetch;
62+
extern crate keccak_hash as hash;
6363
extern crate node_health;
6464
extern crate parity_reactor;
6565
extern crate parity_updater as updater;
6666
extern crate parity_version as version;
67+
extern crate patricia_trie as trie;
6768
extern crate rlp;
6869
extern crate stats;
69-
extern crate keccak_hash as hash;
70+
extern crate vm;
71+
72+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android"))]
7073
extern crate hardware_wallet;
71-
extern crate patricia_trie as trie;
74+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
75+
extern crate fake_hardware_wallet as hardware_wallet;
7276

7377
#[macro_use]
7478
extern crate log;

rpc/src/v1/helpers/dispatch.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use light::cache::Cache as LightDataCache;
2424
use light::client::LightChainClient;
2525
use light::on_demand::{request, OnDemand};
2626
use light::TransactionQueue as LightTransactionQueue;
27-
use rlp;
2827
use hash::keccak;
2928
use ethereum_types::{H256, H520, Address, U256};
3029
use bytes::Bytes;
@@ -52,6 +51,7 @@ use v1::types::{
5251
SignRequest as RpcSignRequest,
5352
DecryptRequest as RpcDecryptRequest,
5453
};
54+
use rlp;
5555

5656
pub use self::nonce::Reservations;
5757

@@ -323,7 +323,7 @@ impl LightDispatcher {
323323
x.map(move |acc| acc.map_or(account_start_nonce, |acc| acc.nonce))
324324
.map_err(|_| errors::no_light_peers())
325325
),
326-
None => Box::new(future::err(errors::network_disabled()))
326+
None => Box::new(future::err(errors::network_disabled()))
327327
}
328328
}
329329
}
@@ -699,7 +699,6 @@ pub fn execute<D: Dispatcher + 'static>(
699699
if accounts.is_hardware_address(&address) {
700700
return Box::new(future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None)));
701701
}
702-
703702
let res = decrypt(&accounts, address, data, pass)
704703
.map(|result| result
705704
.map(RpcBytes)
@@ -737,8 +736,8 @@ fn hardware_signature(accounts: &AccountProvider, address: Address, t: Transacti
737736

738737
SignedTransaction::new(t.with_signature(signature, chain_id))
739738
.map_err(|e| {
740-
debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e);
741-
errors::account("Invalid signature generated", e)
739+
debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e);
740+
errors::account("Invalid signature generated", e)
742741
})
743742
}
744743

rpc/src/v1/impls/light/parity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ impl Parity for ParityClient {
305305
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>> {
306306
let stats = self.light_dispatch.sync.transactions_stats();
307307
Ok(stats.into_iter()
308-
.map(|(hash, stats)| (hash.into(), stats.into()))
309-
.collect()
308+
.map(|(hash, stats)| (hash.into(), stats.into()))
309+
.collect()
310310
)
311311
}
312312

rpc/src/v1/impls/parity.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use ethcore::state::StateInfo;
3434
use ethcore_logger::RotatingLogger;
3535
use node_health::{NodeHealth, Health};
3636
use updater::{Service as UpdateService};
37-
3837
use jsonrpc_core::{BoxFuture, Result};
3938
use jsonrpc_core::futures::{future, Future};
4039
use jsonrpc_macros::Trailing;
@@ -53,7 +52,7 @@ use v1::types::{
5352
use Host;
5453

5554
/// Parity implementation.
56-
pub struct ParityClient<C, M, U> {
55+
pub struct ParityClient<C, M, U> {
5756
client: Arc<C>,
5857
miner: Arc<M>,
5958
updater: Arc<U>,
@@ -143,11 +142,11 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
143142
.collect()
144143
)
145144
}
146-
145+
147146
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>> {
148147
self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))
149148
}
150-
149+
151150
fn default_account(&self, meta: Self::Metadata) -> Result<H160> {
152151
let dapp_id = meta.dapp_id();
153152

@@ -312,9 +311,9 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
312311
);
313312

314313
Ok(ready_transactions
315-
.into_iter()
316-
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
317-
.collect()
314+
.into_iter()
315+
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
316+
.collect()
318317
)
319318
}
320319

@@ -323,9 +322,9 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
323322
let all_transactions = self.miner.queued_transactions();
324323

325324
Ok(all_transactions
326-
.into_iter()
327-
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
328-
.collect()
325+
.into_iter()
326+
.map(|t| Transaction::from_pending(t.pending().clone(), block_number, self.eip86_transition))
327+
.collect()
329328
)
330329
}
331330

@@ -336,18 +335,18 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
336335
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>> {
337336
let stats = self.sync.transactions_stats();
338337
Ok(stats.into_iter()
339-
.map(|(hash, stats)| (hash.into(), stats.into()))
340-
.collect()
338+
.map(|(hash, stats)| (hash.into(), stats.into()))
339+
.collect()
341340
)
342341
}
343342

344343
fn local_transactions(&self) -> Result<BTreeMap<H256, LocalTransactionStatus>> {
345344
let transactions = self.miner.local_transactions();
346345
let block_number = self.client.chain_info().best_block_number;
347346
Ok(transactions
348-
.into_iter()
349-
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
350-
.collect()
347+
.into_iter()
348+
.map(|(hash, status)| (hash.into(), LocalTransactionStatus::from(status, block_number, self.eip86_transition)))
349+
.collect()
351350
)
352351
}
353352

rpc/src/v1/impls/parity_accounts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use ethereum_types::Address;
2222
use ethkey::{Brain, Generator, Secret};
2323
use ethstore::KeyFile;
2424
use ethcore::account_provider::AccountProvider;
25-
2625
use jsonrpc_core::Result;
2726
use v1::helpers::errors;
2827
use v1::traits::ParityAccounts;

util/fake-hardware-wallet/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
description = "Fake hardware-wallet, for OS' that don't support libusb"
3+
name = "fake-hardware-wallet"
4+
version = "0.0.1"
5+
license = "GPL-3.0"
6+
authors = ["Parity Technologies <[email protected]>"]
7+
8+
[dependencies]
9+
ethereum-types = "0.3"
10+
ethkey = { path = "../../ethkey" }

0 commit comments

Comments
 (0)