diff --git a/src/lib/utils/SecureLogon.cpp b/src/lib/utils/SecureLogon.cpp index 96ce4e914..23cd3ea53 100644 --- a/src/lib/utils/SecureLogon.cpp +++ b/src/lib/utils/SecureLogon.cpp @@ -1,6 +1,7 @@ #ifndef _WIN32 #include "SecureLogon.h" #include "lib/utils/bts_assert.h" +#include "lib/utils/datetime.h" #include "lib/config/config.h" #include "lib/config/protos/system.pb.h" @@ -19,12 +20,24 @@ #include using namespace CryptoPP; + using namespace boost; using std::string; namespace glbx { +bool is_expired(const string& expiration) { + char_separator sep("-\\"); + tokenizer> tokens(expiration, sep); + auto t = tokens.begin(); + int year = std::stoi(*t); + int month = std::stoi(*(++t)); + int day = std::stoi(*(++t)); + bts::datetime::Date dtexp(year, month, day); + auto today = bts::datetime::today(); + return dtexp < today; +} + std::tuple load_session_keys(const string& session) { - using namespace boost; using namespace boost::filesystem; auto path = bts::config::get().data_path() + "glbx_logon/"; if (is_directory(path)) { @@ -42,7 +55,11 @@ std::tuple load_session_keys(const string& session) { if (t != tokens.end() && *t == session) { auto id = *(++t); auto secret = *(++t); - return {id,secret}; + auto create_date = *(++t); + auto expiration_date = *(++t); + if (!is_expired(expiration_date)) { + return {id,secret}; + } } } } @@ -112,7 +129,6 @@ LogonData calculate_hmac( bts_assert(false); } - // TEST_CASE("LoadSessionKeys", "") { // std::string session_id = "1U7"; // string secret_key, access_id; @@ -122,5 +138,4 @@ LogonData calculate_hmac( // } } - #endif \ No newline at end of file