25 #include <boost/filesystem.hpp> 35 namespace fs = boost::filesystem;
37 KeyManager::KeyManager(
string const& _keysFile,
string const& _secretsPath):
38 m_keysFile(_keysFile), m_store(_secretsPath)
85 return recode(_address, p,
string(), _pass, _kdf);
99 unsigned version = unsigned(s[0]);
102 bool saveRequired =
false;
103 for (
auto const& i: s[1])
118 cwarn <<
"Missing key:" << uuid << addr;
130 for (
auto const& i: s[2])
154 return brain(_pass());
159 if (_usePasswordCache)
160 return Secret(
m_store.
secret(_uuid, [&](){ return getPassword(_uuid, _pass); }, _usePasswordCache));
173 ph = kit->second.passHash;
183 for (
unsigned i = 0; i < 10; ++i)
188 if (_passHash == UnknownPassword ||
hashPassword(p) == _passHash)
230 for (
auto i = 0; i < 16384; ++i)
252 m_keyInfo[addr].accountName = _accountName;
253 m_keyInfo[addr].passwordHint = _passwordHint;
260 m_keyInfo[_a].accountName = _accountName;
261 m_keyInfo[_a].passwordHint = _passwordHint;
283 m_keyInfo[_address].passHash = _passHash;
284 m_keyInfo[_address].accountName = _accountName;
303 string p = _password(
true);
316 if ((p = _password(
false)).empty())
330 set<Address> addresses;
332 addresses.insert(i.first);
355 return m_keyInfo.at(_address).accountName;
368 it->second.accountName = _name;
378 if (info.passwordHint.size())
379 return info.passwordHint;
410 writeFile(_keysFile +
".salt", salt,
true);
415 write(key, _keysFile);
427 auto const& ki = info.second;
428 s.
appendList(5) << info.first <<
id << ki.passHash << ki.accountName << ki.passwordHint;
444 bool keepGoing =
true;
446 function<void()>
f = [&]() {
451 if (done % 1000 == 0)
452 cnote <<
"Tried" << done <<
"keys";
469 vector<std::thread*> ts;
470 for (
unsigned t = 0; t < std::thread::hardware_concurrency() - 1; ++t)
471 ts.push_back(
new std::thread(f));
474 for (std::thread* t: ts)
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Address address(h128 const &_uuid) const
static KeyPair presaleSecret(std::string const &_json, std::function< std::string(bool)> const &_password)
Extracts the secret key from the presale wallet.
bool recode(Address const &_address, SemanticPassword _newPass, std::function< std::string()> const &_pass=DontKnowThrow, KDF _kdf=KDF::Scrypt)
std::string const & accountName(Address const &_address) const
void writeFile(std::string const &_file, bytesConstRef _data, bool _writeDeleteRename=false)
Write the given binary data into the given file, replacing the file if it pre-exists.
bool hasAccount(Address const &_address) const
RLPStream & append(unsigned _s)
Append given datum to the byte stream.
bytes const & out() const
Read the byte stream.
h128 uuid(Address const &_a) const
bytesSec decryptSymNoAuth(SecureFixedHash< 16 > const &_k, h128 const &_iv, bytesConstRef _cipher)
Decrypts payload with specified IV/ctr using AES128-CTR.
bytesSec pbkdf2(std::string const &_pass, bytes const &_salt, unsigned _iterations, unsigned _dkLen=32)
Derive key via PBKDF2.
Address importBrain(std::string const &_seed, std::string const &_accountName, std::string const &_seedHint)
void noteHint(std::string const &_pass, std::string const &_hint)
Simple class that represents a "key pair".
h256 hashPassword(std::string const &_pass) const
h160 Address
An Ethereum address: 20 bytes.
std::pair< bytes, h128 > encryptSymNoAuth(SecureFixedHash< 16 > const &_k, bytesConstRef _plain)
Encrypts payload with random IV/ctr using AES128-CTR.
std::vector< h128 > keys() const
Returns the uuids of all stored keys.
static KeyPair create()
Create a new, randomly generated object.
SecureFixedHash< 32 > Secret
for(size_t i=trim;i< len;i++) hash[i-trim]
std::hash for asio::adress
void cleanse()
Securely overwrite the memory.
void importExistingBrain(Address const &_a, std::string const &_accountName, std::string const &_seedHint)
static KeyPair newKeyPair(NewKeyType _type)
std::string const & passwordHint(Address const &_address) const
Secret secret(Address const &_address, std::function< std::string()> const &_pass=DontKnowThrow, bool _usePasswordCache=true) const
h128 import(Secret const &_s, std::string const &_accountName, std::string const &_pass, std::string const &_passwordHint)
bytesConstRef ref() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
bool read_string(const String_type &s, Value_type &value)
Base class for all exceptions.
bytesSec asBytesSec() const
bytesSec secret(h128 const &_uuid, std::function< std::string()> const &_pass, bool _useCache=true) const
void create(std::string const &_pass)
void kill(h128 const &_id)
std::vector< byte > bytes
static KeyPair fromEncryptedSeed(bytesConstRef _seed, std::string const &_password)
Create from an encrypted seed.
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
RLPStream & appendList(size_t _items)
Appends a list.
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
std::string getPassword(h128 const &_uuid, std::function< std::string()> const &_pass=DontKnowThrow) const
Address toAddress(std::string const &_s)
Convert the given string into an address.
std::string m_defaultPasswordDeprecated
void cachePassword(std::string const &_password) const
Stores the password by its hash in the password cache.
h128 importSecret(bytesSec const &_s, std::string const &_pass)
Imports the decrypted key given by _s and stores it, encrypted with (a key derived from) the password...
h160s Addresses
A vector of Ethereum addresses.
std::vector< T > & writable()
Address const & address() const
Retrieve the associated address of the public key.
static FixedHash random()
void importExisting(h128 const &_uuid, std::string const &_accountName, std::string const &_pass, std::string const &_passwordHint)
Address address(h128 const &_uuid) const
PlatformStyle::TableColorType type
std::unordered_map< h256, std::string > m_passwordHint
Mapping password hash -> password hint.
bool load(std::string const &_pass)
void save(std::string const &_keysPath)
Store all keys in the directory _keysPath.
SecureFixedHash< 16 > m_keysFileKey
boost::error_info< struct tag_comment, std::string > errinfo_comment
bool contains(h128 const &_k) const
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
std::unordered_map< Address, KeyInfo > m_keyInfo
Mapping address -> key info.
void kill(h128 const &_uuid)
Removes the key specified by _uuid from both memory and disk.
std::unordered_map< h256, std::string > m_cachedPasswords
void swapOut(bytes &_dest)
Swap the contents of the output stream out for some other byte array.
std::unordered_map< Address, h128 > m_addrLookup
Mapping address -> key uuid.
Addresses accounts() const
static Secret brain(std::string const &_seed)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Class for writing to an RLP bytestream.
bytes contents(std::string const &_file)
Retrieve and returns the contents of the given file.
Class for interpreting Recursive Linear-Prefix Data.
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
void changeName(Address const &_address, std::string const &_name)
Should be called to change password.
static Secret subkey(Secret const &_s, unsigned _index)
bool noteAddress(h128 const &_uuid, Address const &_address)
std::string defaultPassword(std::function< std::string()> const &_pass=DontKnowThrow) const
std::unordered_map< h128, Address > m_uuidLookup
Mapping key uuid -> address.