Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::SecretStore Class Reference

#include <SecretStore.h>

Classes

struct  EncryptedKey
 

Public Member Functions

 SecretStore ()=default
 
 SecretStore (boost::filesystem::path const &_path)
 Construct a new SecretStore and read all keys in the given directory. More...
 
void setPath (boost::filesystem::path 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)
 
h128 importSecret (bytesSec const &_s, std::string const &_pass)
 
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< h128keys () const
 Returns the uuids of all stored keys. More...
 
bool contains (h128 const &_k) const
 
void clearCache () const
 
h128 readKey (boost::filesystem::path const &_file, bool _takeFileOwnership)
 
h128 readKeyContent (std::string const &_content, boost::filesystem::path const &_file=boost::filesystem::path())
 
void save (boost::filesystem::path 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 boost::filesystem::path defaultPath ()
 

Detailed Description

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.

Note
that most of the functions here affect the filesystem and throw exceptions on failure, and they also throw exceptions upon rare malfunction in the cryptographic functions.

Definition at line 48 of file SecretStore.h.

Constructor & Destructor Documentation

◆ SecretStore() [1/2]

dev::SecretStore::SecretStore ( )
default

Construct a new SecretStore but don't read any keys yet. Call setPath in

◆ SecretStore() [2/2]

dev::SecretStore::SecretStore ( boost::filesystem::path const &  _path)

Construct a new SecretStore and read all keys in the given directory.

Member Function Documentation

◆ address()

Address dev::SecretStore::address ( h128 const &  _uuid) const
inline
Returns
the address of the given key or the zero address if it is unknown.

Definition at line 121 of file SecretStore.h.

◆ clearCache()

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 178 of file SecretStore.cpp.

◆ contains()

bool dev::SecretStore::contains ( h128 const &  _k) const
inline
Returns
true iff we have the given key stored.

Definition at line 98 of file SecretStore.h.

◆ defaultPath()

static boost::filesystem::path dev::SecretStore::defaultPath ( )
inlinestatic
Returns
the default path for the managed directory.

Definition at line 124 of file SecretStore.h.

◆ importKey()

h128 dev::SecretStore::importKey ( std::string const &  _file)
inline

Imports the (encrypted) key stored in the file _file and copies it to the managed directory.

Definition at line 79 of file SecretStore.h.

◆ importKeyContent()

h128 dev::SecretStore::importKeyContent ( std::string const &  _content)
inline

Imports the (encrypted) key contained in the json formatted _content and stores it in the managed directory.

Definition at line 82 of file SecretStore.h.

◆ importSecret() [1/2]

h128 dev::SecretStore::importSecret ( bytesConstRef  _s,
std::string const &  _pass 
)

◆ importSecret() [2/2]

h128 dev::SecretStore::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.

◆ keys()

std::vector<h128> dev::SecretStore::keys ( ) const
inline

Returns the uuids of all stored keys.

Definition at line 95 of file SecretStore.h.

◆ kill()

void SecretStore::kill ( h128 const &  _uuid)

Removes the key specified by _uuid from both memory and disk.

Definition at line 168 of file SecretStore.cpp.

◆ noteAddress()

bool SecretStore::noteAddress ( h128 const &  _uuid,
Address const &  _address 
)
Returns
true if the current file
  • _uuid contains an empty address. m_keys will be updated with the given
  • _address.

Definition at line 205 of file SecretStore.cpp.

◆ readKey()

h128 SecretStore::readKey ( boost::filesystem::path const &  _file,
bool  _takeFileOwnership 
)

Import the key from the file _file, but do not copy it to the managed directory yet.

Parameters
_takeFileOwnershipif true, deletes the file if it is not the canonical file for the key (derived from its uuid).

Definition at line 227 of file SecretStore.cpp.

◆ readKeyContent()

h128 SecretStore::readKeyContent ( std::string const &  _content,
boost::filesystem::path const &  _file = boost::filesystem::path() 
)

Import the key contained in the json-encoded _content, but do not store it in the managed directory.

Parameters
_fileif 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 233 of file SecretStore.cpp.

◆ recode() [1/2]

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.

◆ recode() [2/2]

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.

◆ save() [1/2]

void dev::SecretStore::save ( )
inline

Store all keys in the managed directory.

Definition at line 117 of file SecretStore.h.

◆ save() [2/2]

void dev::SecretStore::save ( boost::filesystem::path const &  _keysPath)

Store all keys in the directory _keysPath.

◆ secret() [1/3]

bytesSec dev::SecretStore::secret ( Address const &  _address,
std::function< std::string()> const &  _pass 
) const
Returns
the secret key stored by the given _address.
Parameters
_passfunction that returns the password for the key.

◆ secret() [2/3]

bytesSec dev::SecretStore::secret ( h128 const &  _uuid,
std::function< std::string()> const &  _pass,
bool  _useCache = true 
) const
Returns
the secret key stored by the given _uuid.
Parameters
_passfunction that returns the password for the key.
_useCacheif true, allow previously decrypted keys to be returned directly.

◆ secret() [3/3]

static bytesSec dev::SecretStore::secret ( std::string const &  _content,
std::string const &  _pass 
)
static
Returns
the secret key stored by the given _uuid.
Parameters
_passfunction that returns the password for the key.

◆ setPath()

void SecretStore::setPath ( boost::filesystem::path const &  _path)

Set a path for finding secrets.

Definition at line 99 of file SecretStore.cpp.


The documentation for this class was generated from the following files: