From 8725bafbdb681ea25293d5a96629472c002d111d Mon Sep 17 00:00:00 2001 From: Green Sky Date: Tue, 10 Oct 2023 18:17:27 +0200 Subject: [PATCH] hide pw in memory --- src/tox_client.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tox_client.cpp b/src/tox_client.cpp index b299b1b..358db54 100644 --- a/src/tox_client.cpp +++ b/src/tox_client.cpp @@ -12,6 +12,12 @@ #include #include +static void eee(std::string& mod) { + for (char& c : mod) { + c ^= 0x59; + } +} + ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) : _tox_profile_path(save_path), _tox_profile_password(save_password) { @@ -51,6 +57,7 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) )) { throw std::runtime_error("FAILED to decrypt save file!!!!"); } + eee(_tox_profile_password); } tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, profile_data.data(), profile_data.size()); @@ -144,14 +151,17 @@ void ToxClient::saveToxProfile(void) { std::vector unencrypted_copy(data.begin(), data.end()); //profile_data.clear(); data.resize(unencrypted_copy.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH); + eee(_tox_profile_password); if (!tox_pass_encrypt( unencrypted_copy.data(), unencrypted_copy.size(), reinterpret_cast(_tox_profile_password.data()), _tox_profile_password.size(), data.data(), nullptr // TODO: error checking )) { + eee(_tox_profile_password); throw std::runtime_error("FAILED to encrypt save file!!!!"); } + eee(_tox_profile_password); } std::ofstream ofile{_tox_profile_path, std::ios::binary}; // TODO: improve