![]() |
Fabcoin Core
0.16.2
P2P Digital Currency
|
Manages encrypted keys stored in a certain directory on disk. More...
#include <SecretStore.h>
Classes | |
| struct | EncryptedKey |
Public Member Functions | |
| SecretStore ()=default | |
| Construct a new SecretStore but don't read any keys yet. More... | |
| SecretStore (std::string const &_path) | |
| Construct a new SecretStore and read all keys in the given directory. More... | |
| void | setPath (std::string const &_path) |
| Set a path for finding secrets. More... | |
| bytesSec | secret (h128 const &_uuid, std::function< std::string()> const &_pass, bool _useCache=true) const |
| bytesSec | secret (Address const &_address, std::function< std::string()> const &_pass) const |
| h128 | importKey (std::string const &_file) |
| Imports the (encrypted) key stored in the file _file and copies it to the managed directory. More... | |
| h128 | importKeyContent (std::string const &_content) |
| Imports the (encrypted) key contained in the json formatted _content and stores it in the managed directory. More... | |
| 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 _pass. More... | |
| h128 | importSecret (bytesConstRef _s, std::string const &_pass) |
| bool | recode (h128 const &_uuid, std::string const &_newPass, std::function< std::string()> const &_pass, KDF _kdf=KDF::Scrypt) |
| Decrypts and re-encrypts the key identified by _uuid. More... | |
| bool | recode (Address const &_address, std::string const &_newPass, std::function< std::string()> const &_pass, KDF _kdf=KDF::Scrypt) |
| Decrypts and re-encrypts the key identified by _address. More... | |
| void | kill (h128 const &_uuid) |
| Removes the key specified by _uuid from both memory and disk. More... | |
| std::vector< h128 > | keys () const |
| Returns the uuids of all stored keys. More... | |
| bool | contains (h128 const &_k) const |
| void | clearCache () const |
| Clears all cached decrypted keys. More... | |
| h128 | readKey (std::string const &_file, bool _takeFileOwnership) |
| Import the key from the file _file, but do not copy it to the managed directory yet. More... | |
| h128 | readKeyContent (std::string const &_content, std::string const &_file=std::string()) |
| Import the key contained in the json-encoded _content, but do not store it in the managed directory. More... | |
| void | save (std::string const &_keysPath) |
| Store all keys in the directory _keysPath. More... | |
| void | save () |
| Store all keys in the managed directory. More... | |
| bool | noteAddress (h128 const &_uuid, Address const &_address) |
| Address | address (h128 const &_uuid) const |
Static Public Member Functions | |
| static bytesSec | secret (std::string const &_content, std::string const &_pass) |
| static std::string | defaultPath () |
Private Member Functions | |
| void | load (std::string const &_keysPath) |
| Loads all keys in the given directory. More... | |
| void | load () |
| std::pair< h128 const, EncryptedKey > const * | key (Address const &_address) const |
| std::pair< h128 const, EncryptedKey > * | key (Address const &_address) |
Static Private Member Functions | |
| static std::string | encrypt (bytesConstRef _v, std::string const &_pass, KDF _kdf=KDF::Scrypt) |
| Encrypts _v with a key derived from _pass or the empty string on error. More... | |
| static bytesSec | decrypt (std::string const &_v, std::string const &_pass) |
| Decrypts _v with a key derived from _pass or the empty byte array on error. More... | |
Private Attributes | |
| std::unordered_map< h128, bytesSec > | m_cached |
| Stores decrypted keys by uuid. More... | |
| std::unordered_map< h128, EncryptedKey > | m_keys |
| Stores encrypted keys together with the file they were loaded from by uuid. More... | |
| std::string | m_path |
Manages encrypted keys stored in a certain directory on disk.
The keys are read into memory and changes to the keys are automatically synced to the directory. Each file stores exactly one key in a specific JSON format whose file name is derived from the UUID of the key.
Definition at line 46 of file SecretStore.h.
|
default |
Construct a new SecretStore but don't read any keys yet.
Call setPath in
| dev::SecretStore::SecretStore | ( | std::string const & | _path | ) |
Construct a new SecretStore and read all keys in the given directory.
Definition at line 119 of file SecretStore.h.
| void SecretStore::clearCache | ( | ) | const |
Clears all cached decrypted keys.
The passwords have to be supplied in order to retrieve secrets again after calling this function.
Definition at line 174 of file SecretStore.cpp.
|
inline |
Definition at line 96 of file SecretStore.h.
|
staticprivate |
Decrypts _v with a key derived from _pass or the empty byte array on error.
Definition at line 367 of file SecretStore.cpp.
|
inlinestatic |
Definition at line 122 of file SecretStore.h.
|
staticprivate |
Encrypts _v with a key derived from _pass or the empty string on error.
Definition at line 337 of file SecretStore.cpp.
|
inline |
Imports the (encrypted) key stored in the file _file and copies it to the managed directory.
Definition at line 77 of file SecretStore.h.
|
inline |
Imports the (encrypted) key contained in the json formatted _content and stores it in the managed directory.
Definition at line 80 of file SecretStore.h.
Imports the decrypted key given by _s and stores it, encrypted with (a key derived from) the password _pass.
| h128 dev::SecretStore::importSecret | ( | bytesConstRef | _s, |
| std::string const & | _pass | ||
| ) |
|
private |
Definition at line 274 of file SecretStore.cpp.
|
private |
|
inline |
Returns the uuids of all stored keys.
Definition at line 93 of file SecretStore.h.
| void SecretStore::kill | ( | h128 const & | _uuid | ) |
Removes the key specified by _uuid from both memory and disk.
Definition at line 164 of file SecretStore.cpp.
|
private |
Loads all keys in the given directory.
|
inlineprivate |
Definition at line 127 of file SecretStore.h.
Definition at line 202 of file SecretStore.cpp.
| h128 SecretStore::readKey | ( | std::string const & | _file, |
| bool | _takeFileOwnership | ||
| ) |
Import the key from the file _file, but do not copy it to the managed directory yet.
| _takeFileOwnership | if true, deletes the file if it is not the canonical file for the key (derived from its uuid). |
Definition at line 224 of file SecretStore.cpp.
| h128 SecretStore::readKeyContent | ( | std::string const & | _content, |
| std::string const & | _file = std::string() |
||
| ) |
Import the key contained in the json-encoded _content, but do not store it in the managed directory.
| _file | if given, assume this file contains _content and delete it later, if it is not the canonical file for the key (derived from the uuid). |
Definition at line 230 of file SecretStore.cpp.
| bool dev::SecretStore::recode | ( | h128 const & | _uuid, |
| std::string const & | _newPass, | ||
| std::function< std::string()> const & | _pass, | ||
| KDF | _kdf = KDF::Scrypt |
||
| ) |
Decrypts and re-encrypts the key identified by _uuid.
| bool dev::SecretStore::recode | ( | Address const & | _address, |
| std::string const & | _newPass, | ||
| std::function< std::string()> const & | _pass, | ||
| KDF | _kdf = KDF::Scrypt |
||
| ) |
Decrypts and re-encrypts the key identified by _address.
| void dev::SecretStore::save | ( | std::string const & | _keysPath | ) |
|
inline |
Store all keys in the managed directory.
Definition at line 115 of file SecretStore.h.
| bytesSec dev::SecretStore::secret | ( | h128 const & | _uuid, |
| std::function< std::string()> const & | _pass, | ||
| bool | _useCache = true |
||
| ) | const |
| _pass | function that returns the password for the key. |
| _useCache | if true, allow previously decrypted keys to be returned directly. |
|
static |
| _pass | function that returns the password for the key. |
| bytesSec dev::SecretStore::secret | ( | Address const & | _address, |
| std::function< std::string()> const & | _pass | ||
| ) | const |
| _pass | function that returns the password for the key. |
| void SecretStore::setPath | ( | std::string const & | _path | ) |
Set a path for finding secrets.
Definition at line 99 of file SecretStore.cpp.
Stores decrypted keys by uuid.
Definition at line 136 of file SecretStore.h.
|
private |
Stores encrypted keys together with the file they were loaded from by uuid.
Definition at line 138 of file SecretStore.h.
|
private |
Definition at line 140 of file SecretStore.h.
1.8.11