834585d61b
* Crypto utils removed from ethkey * Fix ethkey lib * Switch ethsore to new crypto * Accounts crate fixed * Secret store crate switched to new crypto * Ethcore builtin fixed * Accounts crate fixed * Ethcore crate fixed * Util network fixed * Util network-devp2p fixed * Private tx fixed * Ethcore sync fixed * Secret store fixed * Rpc fixed * Parity fixed * Ethkey cli fixed * Local store fixed * Ethcore blockchain fixed * Cargo.lock pushed; doc comment added for reversed nonce * Ethstore tests fixed * Ethstore cli fixed * Miner fixed * Snapshot tests are fixed * Single brackets removed * Machine fixed * Verification fixed * Executive state fixed * More single brackets removed * Update version of parity-crypto * Use published version 0.4.2 of parity-crypto * New test in tx_filter fixed
68 lines
1.9 KiB
Rust
68 lines
1.9 KiB
Rust
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Ethereum.
|
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use std::{cmp, thread};
|
|
use std::sync::Arc;
|
|
use std::collections::VecDeque;
|
|
use parking_lot::Mutex;
|
|
|
|
use ethstore::{PresaleWallet, Error};
|
|
use ethkey::Password;
|
|
use num_cpus;
|
|
|
|
pub fn run(passwords: VecDeque<Password>, wallet_path: &str) -> Result<(), Error> {
|
|
let passwords = Arc::new(Mutex::new(passwords));
|
|
|
|
let mut handles = Vec::new();
|
|
|
|
for _ in 0..num_cpus::get() {
|
|
let passwords = passwords.clone();
|
|
let wallet = PresaleWallet::open(&wallet_path)?;
|
|
handles.push(thread::spawn(move || {
|
|
look_for_password(passwords, wallet);
|
|
}));
|
|
}
|
|
|
|
for handle in handles {
|
|
handle.join().map_err(|err| Error::Custom(format!("Error finishing thread: {:?}", err)))?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn look_for_password(passwords: Arc<Mutex<VecDeque<Password>>>, wallet: PresaleWallet) {
|
|
let mut counter = 0;
|
|
while !passwords.lock().is_empty() {
|
|
let package = {
|
|
let mut passwords = passwords.lock();
|
|
let len = passwords.len();
|
|
passwords.split_off(cmp::min(len, 32))
|
|
};
|
|
for pass in package {
|
|
counter += 1;
|
|
match wallet.decrypt(&pass) {
|
|
Ok(_) => {
|
|
println!("Found password: {}", pass.as_str());
|
|
passwords.lock().clear();
|
|
return;
|
|
},
|
|
_ if counter % 100 == 0 => print!("."),
|
|
_ => {},
|
|
}
|
|
}
|
|
}
|
|
}
|