Skip to content

Commit

Permalink
#121 add unlock function for remove key
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Feb 13, 2019
1 parent a76cfbe commit d7481bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 4 additions & 2 deletions keychain_lib/include/keychain_lib/keyfile_singleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,18 @@ class keyfile_singleton
void flush_all() const;
};

using get_password_f = std::function<byte_seq_t(const std::string&)>; //NOTE: may incapsulate call to sec module or just return password string
using get_password_create_f = std::function<byte_seq_t(const std::string&)>; //NOTE: may incapsulate call to sec module or just return password string

keyfile_format::keyfile_t create_new_keyfile(
const std::string& keyname,
const std::string& description,
bool encrypted,
keyfile_format::cipher_etype cipher,
keyfile_format::curve_etype curve,
get_password_f&& get_passwd);
get_password_create_f&& get_passwd);

using get_password_f = std::function<std::pair<byte_seq_t, bool>(const std::string&, bool no_password)>; //NOTE: may incapsulate call to sec module or just return password string

bool remove_unlock(const keyfile_format::keyfile_t& keyfile, get_password_f&& get_passwd);

}
23 changes: 22 additions & 1 deletion keychain_lib/src/keyfile_singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ keyfile_format::keyfile_t keychain_app::create_new_keyfile(
bool encrypted,
keyfile_format::cipher_etype cipher,
keyfile_format::curve_etype curve,
get_password_f&& get_passwd)
get_password_create_f&& get_passwd)
{
keyfile_format::keyfile_t keyfile;
dev::Secret priv_key;
Expand Down Expand Up @@ -394,4 +394,25 @@ keyfile_format::keyfile_t keychain_app::create_new_keyfile(
keyfile.keychain_version = version_info::short_version();
keyfile.filetype = keyfile_format::TYPE_KEY;
keyfile.keyinfo.curve_type = curve;
}

bool keychain_app::remove_unlock(const keyfile_format::keyfile_t& keyfile, get_password_f&& get_passwd)
{
try {
if(!keyfile.keyinfo.encrypted)
return get_passwd(keyfile.keyname, true).second; //Need user approve without password entry
auto passwd = get_passwd(keyfile.keyname, false).first;//operation canceled exception need to be thrown into get_password functor
if (passwd.empty())
FC_LIGHT_THROW_EXCEPTION(fc_light::password_input_exception, "");
auto encrypted_data = keyfile.keyinfo.priv_key_data.as<keyfile_format::encrypted_data>();
auto& encryptor = encryptor_singleton::instance();
encryptor.decrypt_private_key(passwd, encrypted_data); //unlock verifing incapsulated here
return true;
}
catch(fc_light::privkey_invalid_unlock& exc)
{
return false;
}


}

0 comments on commit d7481bd

Please sign in to comment.