Skip to content

Commit

Permalink
fix sec_mod dummy, some bugs, fix sample commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Feb 13, 2019
1 parent 185e441 commit f95a691
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
47 changes: 33 additions & 14 deletions keychain_cmd_app/sec_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,51 @@ std::string keychain_app::sec_mod_dummy::exec_cmd(const std::string& json_cmd) c
secmod_commands::secmod_parser_f parser;
auto etype = parser(json_cmd);
int unlock_time = 0;
bool no_password = false;
switch (etype)
{
case secmod_commands::events_te::create_key:
case secmod_commands::events_te::sign_hex:
case secmod_commands::events_te::sign_hash:
case secmod_commands::events_te::remove_key:
case secmod_commands::events_te::export_keys:
case secmod_commands::events_te::import_keys:
break;
case secmod_commands::events_te::sign_hex:
no_password = parser.params<secmod_commands::events_te::sign_hex>().no_password;
break;
case secmod_commands::events_te::sign_hash:
no_password = parser.params<secmod_commands::events_te::sign_hash>().no_password;
break;
case secmod_commands::events_te::unlock:
{
std::string str = "blank";
keychain_app::byte_seq_t pass(str.begin(), str.end());

secmod_commands::secmod_response_common response;
response.etype = secmod_commands::response_te::boolean;
// response.etype = secmod_commands::response_te::password;
// response.params = pass;
response.params = true;
return fc_light::json::to_pretty_string(response);
}
no_password = parser.params<secmod_commands::events_te::unlock>().no_password;
break;
default:
{
FC_LIGHT_THROW_EXCEPTION(fc_light::internal_error_exception, "Secmod command is not implemented, etype = %{ETYPE}", ("ETYPE", etype));
}
}


std::string str = "blank";
keychain_app::byte_seq_t pass(str.begin(), str.end());

switch(no_password)
{
case true:
{
secmod_commands::secmod_response_common response;
response.etype = secmod_commands::response_te::password;
response.params = pass;
return fc_light::json::to_pretty_string(response);
}
case false:
{
secmod_commands::secmod_response_common response;
response.etype = secmod_commands::response_te::boolean;
response.params = true;
return fc_light::json::to_pretty_string(response);
}
}



}

32 changes: 31 additions & 1 deletion keychain_lib/include/keychain_lib/keychain_commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "keyfile_singleton.hpp"
#include "secmod_protocol.hpp"

#include "secmod_parser_cmd.hpp"

#include "version_info.hpp"
#include <arpa/inet.h>

Expand Down Expand Up @@ -694,9 +696,37 @@ struct keychain_command<command_te::create>: keychain_command_base
}
}
auto secmod_cmd = [](const std::string& keyname){
secmod_commands::secmod_command cmd;
using params_t = secmod_commands::secmod_event<secmod_commands::events_te::create_key>::params_t;
params_t params;
params.keyname = keyname;
params.keyname = std::move(keyname);
cmd.etype = secmod_commands::events_te::create_key;
cmd.params = params;
return fc_light::variant(cmd);
};
if (params.encrypted)
{
auto passwd = *keychain->get_passwd_on_create(keyname);
auto result = std::move(*(keychain->run_secmod_cmd(fc_light::json::to_string(secmod_cmd(params.keyname)))));
secmod_commands::secmod_result_parser_f parser;
byte_seq_t passwd;
switch (parser(result))
{
case secmod_commands::response_te::password:
passwd = std::move(parser.params<secmod_commands::response_te::password>());
if (passwd.empty())
FC_LIGHT_THROW_EXCEPTION(fc_light::password_input_exception, "");
break;
case secmod_commands::response_te::canceled:
FC_LIGHT_THROW_EXCEPTION(fc_light::operation_canceled, "");
default:
FC_LIGHT_THROW_EXCEPTION(fc_light::password_input_exception, "");
}
if (passwd.empty())
FC_LIGHT_THROW_EXCEPTION(fc_light::password_input_exception, "");
auto& encryptor = encryptor_singleton::instance();
Expand Down
2 changes: 2 additions & 0 deletions keychain_lib/src/keychain_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ dev::Secret keychain_base::get_private_key(const dev::Public& public_key, int un
{
case secmod_commands::response_te::password:
{
FC_LIGHT_ASSERT(keyfile.keyinfo.encrypted == true);
password = std::move(parser.params<secmod_commands::response_te::password>());
if (password.empty())
FC_LIGHT_THROW_EXCEPTION(fc_light::password_input_exception, "");
Expand All @@ -223,6 +224,7 @@ dev::Secret keychain_base::get_private_key(const dev::Public& public_key, int un
break;
case secmod_commands::response_te::boolean:
{
FC_LIGHT_ASSERT(keyfile.keyinfo.encrypted == false);
auto confirm = std::move(parser.params<secmod_commands::response_te::boolean>());
if (confirm)
{
Expand Down

0 comments on commit f95a691

Please sign in to comment.