From e0967147bd1176e42ca44f92a7fbb6f2bce190d4 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 28 Sep 2019 18:02:25 +0300 Subject: [PATCH 1/7] --enable-qt-logs implemented --- .../qt-daemon/application/daemon_backend.cpp | 10 ++++--- .../qt-daemon/application/daemon_backend.h | 2 ++ src/gui/qt-daemon/application/mainwindow.cpp | 28 ++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index 3f0a4d02..00f09c46 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -40,7 +40,8 @@ daemon_backend::daemon_backend():m_pview(&m_view_stub), m_offers_service(nullptr), m_ui_opt(AUTO_VAL_INIT(m_ui_opt)), m_remote_node_mode(false), - m_is_pos_allowed(false) + m_is_pos_allowed(false), + m_qt_logs_enbaled(false) { m_offers_service.set_disabled(true); //m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service); @@ -52,6 +53,7 @@ const command_line::arg_descriptor arg_xcode_stub = {"-NSDocumentRe const command_line::arg_descriptor arg_enable_gui_debug_mode = { "gui-debug-mode", "Enable debug options in GUI", false, true }; const command_line::arg_descriptor arg_qt_remote_debugging_port = { "remote-debugging-port", "Specify port for Qt remote debugging", 30333, true }; const command_line::arg_descriptor arg_remote_node = { "remote-node", "Switch GUI to work with remote node instead of local daemon", "", true }; +const command_line::arg_descriptor arg_enable_qt_logs = { "enable-qt-logs", "Forward Qt log messages into main log", false, true }; void wallet_lock_time_watching_policy::watch_lock_time(uint64_t lock_time) { @@ -124,9 +126,7 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler) command_line::add_arg(desc_cmd_sett, arg_enable_gui_debug_mode); command_line::add_arg(desc_cmd_sett, arg_qt_remote_debugging_port); command_line::add_arg(desc_cmd_sett, arg_remote_node); - - - + command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs); currency::core::init_options(desc_cmd_sett); @@ -220,6 +220,8 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler) // configure for remote node } + m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs); + m_pview->init(path_to_html); if (!coomand_line_parsed) diff --git a/src/gui/qt-daemon/application/daemon_backend.h b/src/gui/qt-daemon/application/daemon_backend.h index 1cffbedc..8021ade4 100644 --- a/src/gui/qt-daemon/application/daemon_backend.h +++ b/src/gui/qt-daemon/application/daemon_backend.h @@ -142,6 +142,7 @@ public: void unsubscribe_to_core_events(); void get_gui_options(view::gui_options& opt); std::string get_wallet_log_prefix(size_t wallet_id) const; + bool is_qt_logs_enabled() const { return m_qt_logs_enbaled; } private: void main_worker(const po::variables_map& vm); @@ -187,6 +188,7 @@ private: currency::core_rpc_server m_rpc_server; bool m_remote_node_mode; + bool m_qt_logs_enbaled; std::atomic m_is_pos_allowed; diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 7d5a834c..b0bb4d85 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -609,10 +609,36 @@ bool MainWindow::show_msg_box(const std::string& message) return true; CATCH_ENTRY2(false); } + +void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QByteArray local_msg = msg.toLocal8Bit(); + const char* msg_type = ""; + switch (type) + { + case QtDebugMsg: msg_type = "DEBG "; break; + case QtInfoMsg: msg_type = "INFO "; break; + case QtWarningMsg: msg_type = "WARN "; break; + case QtCriticalMsg: msg_type = "CRIT "; break; + case QtFatalMsg: msg_type = "FATAL "; break; + } + + LOG_PRINT("[QT] " << msg_type << local_msg.constData() << " @ " << context.file << ":" << context.line << ", " << (context.function ? context.function : ""), LOG_LEVEL_0); +} + bool MainWindow::init_backend(int argc, char* argv[]) { TRY_ENTRY(); - return m_backend.init(argc, argv, this); + if (!m_backend.init(argc, argv, this)) + return false; + + if (m_backend.is_qt_logs_enabled()) + { + qInstallMessageHandler(qt_log_message_handler); + QLoggingCategory::setFilterRules("*=true"); // enable all logs + } + + return true; CATCH_ENTRY2(false); } From 6f4b36a8a8456d275e4a5677585b299718dbb0f8 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 28 Sep 2019 18:14:10 +0300 Subject: [PATCH 2/7] minor naming fix --- src/currency_core/currency_format_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 8fd732a3..9870ed52 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1550,8 +1550,8 @@ namespace currency bool check_tx_derivation_hint(const transaction& tx, const crypto::key_derivation& derivation) { bool found_der_xor = false; - uint16_t my_derive_xor = get_derivation_hint(derivation); - tx_derivation_hint dh = make_tx_derivation_hint_from_uint16(my_derive_xor); + uint16_t hint = get_derivation_hint(derivation); + tx_derivation_hint dh = make_tx_derivation_hint_from_uint16(hint); for (auto& e : tx.extra) { if (e.type() == typeid(tx_derivation_hint)) From f9a72e330064b1afecfd740d1cc8365f862a06fd Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 29 Sep 2019 22:56:50 +0300 Subject: [PATCH 3/7] unit_tests: fork_choice_rule_test fixed --- tests/unit_tests/fork_choice_rule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/fork_choice_rule.cpp b/tests/unit_tests/fork_choice_rule.cpp index c3fcf84b..582c9c39 100644 --- a/tests/unit_tests/fork_choice_rule.cpp +++ b/tests/unit_tests/fork_choice_rule.cpp @@ -17,8 +17,8 @@ bool if_alt_chain_stronger(const currency::wide_difficulty_type& pos, const curr alt_cumul_diff.pos_diff = pos; static currency::wide_difficulty_type difficulty_pos_at_split_point = 400000; static currency::wide_difficulty_type difficulty_pow_at_split_point = 4000; - currency::wide_difficulty_type main = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, main_cumul_diff, alt_cumul_diff); - currency::wide_difficulty_type alt = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, alt_cumul_diff, main_cumul_diff); + boost::multiprecision::uint1024_t main = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, main_cumul_diff, alt_cumul_diff); + boost::multiprecision::uint1024_t alt = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, alt_cumul_diff, main_cumul_diff); if (alt > main) return true; return false; From d4a9a0a77d99735b1fc6739a0aec3403ed9b5790 Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 29 Sep 2019 23:53:03 +0300 Subject: [PATCH 4/7] gui: fixed a bug with Qt logs in release --- src/gui/qt-daemon/application/mainwindow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index b0bb4d85..77dff950 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -623,7 +623,16 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c case QtFatalMsg: msg_type = "FATAL "; break; } - LOG_PRINT("[QT] " << msg_type << local_msg.constData() << " @ " << context.file << ":" << context.line << ", " << (context.function ? context.function : ""), LOG_LEVEL_0); + if (context.file == nullptr && context.function == nullptr) + { + // no debug info + LOG_PRINT("[QT] " << msg_type << local_msg.constData(), LOG_LEVEL_0); + } + else + { + // some debug info + LOG_PRINT("[QT] " << msg_type << local_msg.constData() << " @ " << (context.file ? context.file : "") << ":" << context.line << ", " << (context.function ? context.function : ""), LOG_LEVEL_0); + } } bool MainWindow::init_backend(int argc, char* argv[]) From b0f376b7cdf7d9a5c1e9ed4619976b7931ed06ae Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 29 Sep 2019 23:53:59 +0300 Subject: [PATCH 5/7] === build number: 62 -> 63 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index e705f782..6553c607 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -7,6 +7,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 62 +#define PROJECT_VERSION_BUILD_NO 63 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From da79610facf34ae61ff7f389d03c54136e9303ec Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 2 Oct 2019 03:41:24 +0300 Subject: [PATCH 6/7] from now new passwords must consist of allowed characters only --- src/currency_core/currency_format_utils.cpp | 8 ++- src/currency_core/currency_format_utils.h | 1 + src/gui/qt-daemon/application/mainwindow.cpp | 67 ++++++++++++++++---- src/wallet/wallet2.cpp | 1 + src/wallet/wallet2.h | 1 + 5 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 9870ed52..5e3a3df8 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1737,7 +1737,13 @@ namespace currency } return true; } - + //------------------------------------------------------------------ + bool validate_password(const std::string& password) + { + static const std::string allowed_password_symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!?@#$%^&*_+|{}[]()<>:;\"'-=\\/.,"; + size_t n = password.find_first_not_of(allowed_password_symbols, 0); + return n == std::string::npos; + } //------------------------------------------------------------------ #define ANTI_OVERFLOW_AMOUNT 1000000 diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 513df6f1..4a467a3e 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -163,6 +163,7 @@ namespace currency uint64_t get_string_uint64_hash(const std::string& str); bool construct_tx_out(const tx_destination_entry& de, const crypto::secret_key& tx_sec_key, size_t output_index, transaction& tx, std::set& deriv_cache, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED); bool validate_alias_name(const std::string& al); + bool validate_password(const std::string& password); void get_attachment_extra_info_details(const std::vector& attachment, extra_attachment_info& eai); bool construct_tx(const account_keys& sender_account_keys, const std::vector& sources, diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 77dff950..606a8bbe 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -1034,6 +1034,7 @@ void MainWindow::on_complete_events() } CATCH_ENTRY2(void()); } + void MainWindow::on_clear_events() { TRY_ENTRY(); @@ -1055,9 +1056,13 @@ QString MainWindow::get_secure_app_data(const QString& param) } std::string app_data_buff; - bool r = file_io_utils::load_file_to_string(m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME, app_data_buff); + std::string filename = m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME; + bool r = file_io_utils::load_file_to_string(filename, app_data_buff); if (!r) + { + LOG_PRINT_L1("config file was not loaded: " << m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME); return ""; + } if (app_data_buff.size() < sizeof(app_data_file_binary_header)) { @@ -1080,23 +1085,38 @@ QString MainWindow::get_secure_app_data(const QString& param) m_master_password = pwd.pass; + crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length()); + crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash); + LOG_PRINT_L0("get_secure_app_data, pass hash: " << master_password_hash); + return app_data_buff.substr(sizeof(app_data_file_binary_header)).c_str(); CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } QString MainWindow::set_master_password(const QString& param) { + view::api_response ar; + view::password_data pwd = AUTO_VAL_INIT(pwd); if (!epee::serialization::load_t_from_json(pwd, param.toStdString())) { - view::api_response ar; ar.error_code = API_RETURN_CODE_BAD_ARG; return MAKE_RESPONSE(ar); } + + if (!currency::validate_password(pwd.pass)) + { + ar.error_code = API_RETURN_CODE_BAD_ARG; + return MAKE_RESPONSE(ar); + } + m_master_password = pwd.pass; - view::api_response ar; + crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length()); + crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash); + LOG_PRINT_L0("set_master_password, pass hash: " << master_password_hash); + ar.error_code = API_RETURN_CODE_OK; return MAKE_RESPONSE(ar); } @@ -1111,11 +1131,18 @@ QString MainWindow::check_master_password(const QString& param) ar.error_code = API_RETURN_CODE_BAD_ARG; return MAKE_RESPONSE(ar); } + + crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length()); + crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash); + crypto::hash pwd_pre_hash = crypto::cn_fast_hash(pwd.pass.c_str(), pwd.pass.length()); + crypto::hash pwd_hash = crypto::cn_fast_hash(&pwd_pre_hash, sizeof pwd_pre_hash); if (m_master_password != pwd.pass) { ar.error_code = API_RETURN_CODE_WRONG_PASSWORD; - }else + LOG_PRINT_L0("check_master_password: pwd hash: " << pwd_hash << ", expected: " << master_password_hash); + } + else { ar.error_code = API_RETURN_CODE_OK; } @@ -1134,18 +1161,27 @@ QString MainWindow::store_app_data(const QString& param) return MAKE_RESPONSE(ar); } - //bool r = file_io_utils::save_string_to_file(m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME, param.toStdString()); - bool r = file_io_utils::save_string_to_file(m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME, param.toStdString()); - //view::api_response ar; - if (r) - ar.error_code = API_RETURN_CODE_OK; - else - ar.error_code = API_RETURN_CODE_FAIL; + crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length()); + crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash); + LOG_PRINT_L0("store_app_data, pass hash: " << master_password_hash); + + std::string filename = m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME; + bool r = file_io_utils::save_string_to_file(filename, param.toStdString()); + if (r) + { + ar.error_code = API_RETURN_CODE_OK; + LOG_PRINT_L1("config saved: " << filename); + } + else + { + ar.error_code = API_RETURN_CODE_FAIL; + LOG_PRINT_L1("config save failed: " << filename); + } - //ar.error_code = store_to_file((m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME).c_str(), param).toStdString(); return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } + QString MainWindow::is_file_exist(const QString& path) { TRY_ENTRY(); @@ -1158,7 +1194,7 @@ QString MainWindow::is_file_exist(const QString& path) } catch (const std::exception& ex) { - LOG_ERROR("FILED TO STORE TO FILE: " << path.toStdString() << " ERROR:" << ex.what()); + LOG_ERROR("failed to check file existance: " << path.toStdString() << " ERROR:" << ex.what()); return QString(API_RETURN_CODE_ALREADY_EXISTS) + ": " + ex.what(); } @@ -1168,6 +1204,7 @@ QString MainWindow::is_file_exist(const QString& path) } CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR); } + QString MainWindow::store_to_file(const QString& path, const QString& buff) { TRY_ENTRY(); @@ -1256,6 +1293,10 @@ QString MainWindow::store_secure_app_data(const QString& param) else ar.error_code = API_RETURN_CODE_FAIL; + crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length()); + crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash); + LOG_PRINT_L0("store_secure_app_data, r = " << r << ", pass hash: " << master_password_hash); + return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3bb392c3..46cdd2fa 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1962,6 +1962,7 @@ void wallet2::assign_account(const currency::account_base& acc) //---------------------------------------------------------------------------------------------------- void wallet2::generate(const std::wstring& path, const std::string& pass) { + WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(validate_password(pass), "new wallet generation failed: password contains forbidden characters") clear(); prepare_file_names(path); m_password = pass; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f4c741c5..a1d1955b 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -63,6 +63,7 @@ ENABLE_CHANNEL_BY_DEFAULT("wallet"); #define WLT_CHECK_AND_ASSERT_MES(expr, ret, msg) CHECK_AND_ASSERT_MES(expr, ret, "[W:" << m_log_prefix << "]" << msg) #define WLT_CHECK_AND_ASSERT_MES_NO_RET(expr, msg) CHECK_AND_ASSERT_MES_NO_RET(expr, "[W:" << m_log_prefix << "]" << msg) #define WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, "[W:" << m_log_prefix << "]" << msg) +#define WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, "[W:" << m_log_prefix << "]" << msg) class test_generator; From ffe7b1f3b462acd01e261dd56b28b8cdddedb716 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 2 Oct 2019 03:42:35 +0300 Subject: [PATCH 7/7] === build number: 63 -> 64 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 6553c607..0427a194 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -7,6 +7,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 63 +#define PROJECT_VERSION_BUILD_NO 64 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"