From 339e683d5af91ea7013d16ea0752c60bfb8adca5 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Mon, 18 Apr 2022 11:09:14 -0400 Subject: [PATCH 1/3] Add very basic 2fa support --- pCloudCC/main.cpp | 4 +++- pCloudCC/pclsync_lib.cpp | 7 +++++++ pCloudCC/pclsync_lib.h | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pCloudCC/main.cpp b/pCloudCC/main.cpp index d2f6a8ff..8d3cbcc3 100644 --- a/pCloudCC/main.cpp +++ b/pCloudCC/main.cpp @@ -12,6 +12,7 @@ int main(int argc, char **argv) { std::cout << "pCloud console client v."<< version << std::endl; std::string username; std::string password; + std::string tfa_code; bool daemon = false; bool commands = false; bool commands_only = false; @@ -26,6 +27,7 @@ int main(int argc, char **argv) { ("help,h", "produce help message") ("username,u", po::value(&username), "pCloud account name") ("password,p", po::bool_switch(&passwordsw), "Ask pCloud account password") + ("tfa_code,t", po::value(&tfa_code), "pCloud tfa code") ("crypto,c", po::bool_switch(&crypto), "Ask crypto password") ("passascrypto,y", po::value(), "Use user password as crypto password also.") ("daemonize,d", po::bool_switch(&daemon), "Daemonize the process.") @@ -63,7 +65,7 @@ int main(int argc, char **argv) { return 1; } console_client::clibrary::pclsync_lib::get_lib().set_username(username); - + console_client::clibrary::pclsync_lib::get_lib().set_tfa_code(tfa_code); if (passwordsw) { console_client::clibrary::pclsync_lib::get_lib().get_pass_from_console(); } diff --git a/pCloudCC/pclsync_lib.cpp b/pCloudCC/pclsync_lib.cpp index 4f49a59e..a33507c9 100644 --- a/pCloudCC/pclsync_lib.cpp +++ b/pCloudCC/pclsync_lib.cpp @@ -163,6 +163,8 @@ static char const * status2string (uint32_t status){ case PSTATUS_SCANNING: return "SCANNING"; case PSTATUS_USER_MISMATCH: return "USER_MISMATCH"; case PSTATUS_ACCOUT_EXPIRED: return "ACCOUT_EXPIRED"; + case PSTATUS_TFA_REQUIRED: return "TFA_REQUIRED"; + case PSTATUS_BAD_TFA_CODE: return "BAD_TFA_CODE"; default :return "Unrecognized status"; } } @@ -183,6 +185,11 @@ static void status_change(pstatus_t* status) { psync_set_user_pass(clib::pclsync_lib::get_lib().get_username().c_str(), clib::pclsync_lib::get_lib().get_password().c_str(), (int) clib::pclsync_lib::get_lib().save_pass_); std::cout << "logging in" << std::endl; } + else if (status->status == PSTATUS_TFA_REQUIRED) + { + std::cout<< "tfa code set"<status==PSTATUS_BAD_LOGIN_DATA){ if (!clib::pclsync_lib::get_lib().newuser_) { clib::pclsync_lib::get_lib().get_pass_from_console(); diff --git a/pCloudCC/pclsync_lib.h b/pCloudCC/pclsync_lib.h index 17d8b417..a1fcfc63 100644 --- a/pCloudCC/pclsync_lib.h +++ b/pCloudCC/pclsync_lib.h @@ -46,9 +46,11 @@ namespace console_client { //Getters const std::string& get_username() {return username_;} const std::string& get_password() {return password_;} + const std::string& get_tfa_code() { return tfa_code_;} const std::string& get_crypto_pass() {return crypto_pass_;}; const std::string& get_mount() {return mount_;} //Setters + void set_tfa_code(const std::string& arg) { tfa_code_ = arg;} void set_username(const std::string& arg) { username_ = arg;} void set_password(const std::string& arg) { password_ = arg;} void set_crypto_pass(const std::string& arg) { crypto_pass_ = arg;}; @@ -85,6 +87,7 @@ namespace console_client { private: std::string username_; std::string password_; + std::string tfa_code_; std::string crypto_pass_; std::string mount_; From 23ed409a4f789e3cda622966ec2c63bc7fe98a03 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Mon, 18 Apr 2022 23:10:59 -0400 Subject: [PATCH 2/3] Add support for retrieving TFA code from console --- pCloudCC/main.cpp | 5 ++++- pCloudCC/pclsync_lib.cpp | 10 ++++++++-- pCloudCC/pclsync_lib.h | 6 +++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pCloudCC/main.cpp b/pCloudCC/main.cpp index 8d3cbcc3..43ff67a7 100644 --- a/pCloudCC/main.cpp +++ b/pCloudCC/main.cpp @@ -20,7 +20,8 @@ int main(int argc, char **argv) { bool passwordsw = false; bool save_pass = false; bool crypto = false; - + bool trusted_device = false; + try { po::options_description desc("Allowed options"); desc.add_options() @@ -28,6 +29,7 @@ int main(int argc, char **argv) { ("username,u", po::value(&username), "pCloud account name") ("password,p", po::bool_switch(&passwordsw), "Ask pCloud account password") ("tfa_code,t", po::value(&tfa_code), "pCloud tfa code") + ("trusted_device,r", po::bool_switch(&trusted_device), "Trust this device.") ("crypto,c", po::bool_switch(&crypto), "Ask crypto password") ("passascrypto,y", po::value(), "Use user password as crypto password also.") ("daemonize,d", po::bool_switch(&daemon), "Daemonize the process.") @@ -66,6 +68,7 @@ int main(int argc, char **argv) { } console_client::clibrary::pclsync_lib::get_lib().set_username(username); console_client::clibrary::pclsync_lib::get_lib().set_tfa_code(tfa_code); + console_client::clibrary::pclsync_lib::get_lib().set_trusted_device(trusted_device); if (passwordsw) { console_client::clibrary::pclsync_lib::get_lib().get_pass_from_console(); } diff --git a/pCloudCC/pclsync_lib.cpp b/pCloudCC/pclsync_lib.cpp index a33507c9..bdc0c6b6 100644 --- a/pCloudCC/pclsync_lib.cpp +++ b/pCloudCC/pclsync_lib.cpp @@ -68,6 +68,11 @@ void clib::pclsync_lib::get_pass_from_console() do_get_pass_from_console(password_); } +void clib::pclsync_lib::get_tfa_code_from_console() +{ + do_get_pass_from_console(tfa_code_); +} + void clib::pclsync_lib::get_cryptopass_from_console() { do_get_pass_from_console(crypto_pass_); @@ -187,8 +192,9 @@ static void status_change(pstatus_t* status) { } else if (status->status == PSTATUS_TFA_REQUIRED) { - std::cout<< "tfa code set"<status==PSTATUS_BAD_LOGIN_DATA){ if (!clib::pclsync_lib::get_lib().newuser_) { diff --git a/pCloudCC/pclsync_lib.h b/pCloudCC/pclsync_lib.h index a1fcfc63..04b0e095 100644 --- a/pCloudCC/pclsync_lib.h +++ b/pCloudCC/pclsync_lib.h @@ -46,10 +46,12 @@ namespace console_client { //Getters const std::string& get_username() {return username_;} const std::string& get_password() {return password_;} - const std::string& get_tfa_code() { return tfa_code_;} + const std::string& get_tfa_code() {return tfa_code_;} const std::string& get_crypto_pass() {return crypto_pass_;}; const std::string& get_mount() {return mount_;} + const bool get_trusted_device() {return trusted_device_;}; //Setters + void set_trusted_device(bool arg) { trusted_device_ = arg;} void set_tfa_code(const std::string& arg) { tfa_code_ = arg;} void set_username(const std::string& arg) { username_ = arg;} void set_password(const std::string& arg) { password_ = arg;} @@ -61,6 +63,7 @@ namespace console_client { void set_daemon(bool p) {daemon_ = p;} void set_status_callback(status_callback_t p) {status_callback_ = p;} //Console + void get_tfa_code_from_console(); void get_pass_from_console(); void get_cryptopass_from_console(); //API calls @@ -76,6 +79,7 @@ namespace console_client { int unlink(); int login(const char* user, const char* pass, int save); + bool trusted_device_; bool crypto_on_; bool save_pass_; bool setup_crypto_; From 6985f17ac845c0649db9e8f238f80d3c8ee823cf Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Mon, 18 Apr 2022 23:16:13 -0400 Subject: [PATCH 3/3] Echo the 2fa code --- pCloudCC/pclsync_lib.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pCloudCC/pclsync_lib.cpp b/pCloudCC/pclsync_lib.cpp index bdc0c6b6..0afabbe6 100644 --- a/pCloudCC/pclsync_lib.cpp +++ b/pCloudCC/pclsync_lib.cpp @@ -70,7 +70,12 @@ void clib::pclsync_lib::get_pass_from_console() void clib::pclsync_lib::get_tfa_code_from_console() { - do_get_pass_from_console(tfa_code_); + if (daemon_) { + std::cout << "Not able to read 2fa code when started as daemon." << std::endl; + exit(1); + } + std::cout << "Please enter 2fa code" << std::endl; + getline(std::cin, tfa_code_); } void clib::pclsync_lib::get_cryptopass_from_console()